Skip to content

Commit

Permalink
Merge branch 'nithinkjoy-tech-nithin/deprecated-deno-run-api-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanisham committed Feb 11, 2024
2 parents 3a7770e + a30c6a0 commit fb6c8ef
Show file tree
Hide file tree
Showing 18 changed files with 279 additions and 171 deletions.
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/zig-cache
/zig-out
/build
/dist
/demo
zig-cache/
zig-out/
build/
dist/
demo/
zvm
testdata
testdata/
.env*
Empty file removed .gitmodules
Empty file.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

## Join our Community

- [Discord](https://discord.gg/NhaNhCMYX8)
- [Twitch](https://twitch.tv/atalocke)
- [Twitter|X](https://twitter.com/atalocke)

<hr>

Expand Down Expand Up @@ -197,9 +197,19 @@ zvm help

## Option flags

### Color Toggle
```sh
--nocolor, --nocolour # Turns off ANSI color.
--color, --colour # Toggles ANSI color.
--yescolor, --yescolour # Turns on ANSI color.
--versionmapurl # Changes the version map(version history) url
-color # Turn ANSI color printing on or off for ZVM's output, i.e. -color=true

```

### Version Map Source
```sh
-vmu="https://validurl.local/vmu.json" # Change the source ZVM pulls Zig release information from. Good for self-hosted Zig CDNs.
# ZVM only supports schemas that match the offical version map schema.
# Run `-vmu=default` to reset your version map.

-vmu default # Resets back to default Zig releases.
-vmu mach # Sets ZVM to pull from Mach nominated Zig.
```

26 changes: 14 additions & 12 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ for (const os of GOOS) {
Deno.env.set("GOARCH", ar);
const zvm_str = `zvm-${os}-${ar}`;
console.time(`Build zvm: ${zvm_str}`);
// deno-lint-ignore no-deprecated-deno-api
const build_cmd = Deno.run({
cmd: [
"go",

const build_cmd = new Deno.Command("go", {
args: [
"build",
"-o",
`build/${zvm_str}/zvm${(os == "windows" ? ".exe" : "")}`,
"-ldflags=-w -s", "-trimpath",
`build/${zvm_str}/zvm${os === "windows" ? ".exe" : ""}`,
"-ldflags=-w -s",
"-trimpath",
],
});

const { code } = await build_cmd.status();
const { code } = await build_cmd.output();
if (code !== 0) {
console.error("Something went wrong");
Deno.exit(1);
Expand All @@ -61,19 +61,21 @@ for (const os of GOOS) {
}
const zvm_str = `zvm-${os}-${ar}`;

if (os == "windows") {
console.time(`Compress zvm: ${zvm_str}`);
if (os === "windows") {
console.time(`Compress zvm (zip): ${zvm_str}`);
const zip = new Deno.Command(`zip`, {
args: [`${zvm_str}.zip`, `${zvm_str}/zvm.exe`],
stdin: "piped",
stdout: "piped",
});

zip.spawn();
console.timeEnd(`Compress zvm: ${zvm_str}`);

console.timeEnd(`Compress zvm (zip): ${zvm_str}`);
continue;
}
const tar = new Tar();
console.time(`Compress zvm: ${zvm_str}`);
console.time(`Compress zvm (tar): ${zvm_str}`);
await tar.append("zvm", {
filePath: `${zvm_str}/zvm`,
});
Expand All @@ -83,7 +85,7 @@ for (const os of GOOS) {
});
await copy(tar.getReader(), writer);
writer.close();
console.timeEnd(`Compress zvm: ${zvm_str}`);
console.timeEnd(`Compress zvm (tar): ${zvm_str}`);
}
}

Expand Down
12 changes: 4 additions & 8 deletions cli/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ package cli
import (
"os"
"path/filepath"
"strings"
)

func (z *ZVM) Clean() error {
dir, err := os.ReadDir(z.zvmBaseDir)
dir, err := os.ReadDir(z.baseDir)
if err != nil {
return err
}

for _, entry := range dir {
if strings.Contains(entry.Name(), "bin") {
continue
}

if filepath.Ext(entry.Name()) == ".zip" || filepath.Ext(entry.Name()) == ".xz" {
if err := os.Remove(filepath.Join(z.zvmBaseDir, entry.Name())); err != nil {

if filepath.Ext(entry.Name()) == ".zip" || filepath.Ext(entry.Name()) == ".xz" || filepath.Ext(entry.Name()) == ".tar" {
if err := os.Remove(filepath.Join(z.baseDir, entry.Name())); err != nil {
return err
}
}
Expand Down
20 changes: 11 additions & 9 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ func Initialize() *ZVM {
}

zvm := &ZVM{
zvmBaseDir: zvm_path,
baseDir: zvm_path,
}

zvm.Settings.basePath = filepath.Join(zvm_path, "settings.json")

if err := zvm.loadSettings(); err != nil {
if errors.Is(err, ErrNoSettings) {
zvm.Settings = Settings{
UseColor: true,
UseColor: true,
VersionMapUrl: "https://ziglang.org/download/index.json",
}

out_settings, err := json.MarshalIndent(&zvm.Settings, "", " ")
Expand All @@ -50,13 +53,12 @@ func Initialize() *ZVM {
}
}

zvm.Settings.basePath = filepath.Join(zvm_path, "settings.json")
return zvm
}

type ZVM struct {
zvmBaseDir string
Settings Settings
baseDir string
Settings Settings
}

// A representaiton of the offical json schema for Zig versions
Expand Down Expand Up @@ -88,10 +90,10 @@ type ZigOnlVersion = map[string][]map[string]string
// }

func (z ZVM) getVersion(version string) error {
if _, err := os.Stat(filepath.Join(z.zvmBaseDir, version)); err != nil {
if _, err := os.Stat(filepath.Join(z.baseDir, version)); err != nil {
return err
}
targetZig := strings.TrimSpace(filepath.Join(z.zvmBaseDir, version, "zig"))
targetZig := strings.TrimSpace(filepath.Join(z.baseDir, version, "zig"))
cmd := exec.Command(targetZig, "version")
var zigVersion strings.Builder
cmd.Stdout = &zigVersion
Expand All @@ -116,12 +118,12 @@ func (z ZVM) getVersion(version string) error {
}

func (z *ZVM) loadSettings() error {
set_path := filepath.Join(z.zvmBaseDir, "settings.json")
set_path := z.Settings.basePath
if _, err := os.Stat(set_path); errors.Is(err, os.ErrNotExist) {
return ErrNoSettings
}

data, err := os.ReadFile(filepath.Join(z.zvmBaseDir, "settings.json"))
data, err := os.ReadFile(set_path)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit fb6c8ef

Please sign in to comment.