astrobit 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/astrobit.js +17 -23
- package/package.json +1 -1
package/bin/astrobit.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
3
|
import { platform } from "node:os";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const MOON_VERSION_CMD = "moon version";
|
|
6
|
+
const MOON_INSTALL_CMD = "curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash";
|
|
7
|
+
const MOON_BIN_PATH = `${process.env.HOME}/.moon/bin`;
|
|
8
|
+
|
|
9
|
+
const [, , command] = process.argv;
|
|
6
10
|
|
|
7
11
|
function run(cmd, opts = {}) {
|
|
8
12
|
const result = spawnSync(cmd, { shell: true, stdio: "inherit", ...opts });
|
|
9
13
|
if (result.status !== 0) process.exit(result.status ?? 1);
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
function
|
|
13
|
-
const result = spawnSync(
|
|
14
|
-
|
|
16
|
+
function moonVersion() {
|
|
17
|
+
const result = spawnSync(MOON_VERSION_CMD, { shell: true, stdio: "pipe" });
|
|
18
|
+
if (result.status !== 0) return null;
|
|
19
|
+
return result.stdout.toString().trim();
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
function installMoon() {
|
|
@@ -22,29 +27,18 @@ function installMoon() {
|
|
|
22
27
|
process.exit(1);
|
|
23
28
|
}
|
|
24
29
|
console.log("[astrobit] moon not found, installing...");
|
|
25
|
-
run(
|
|
26
|
-
|
|
27
|
-
process.env.PATH = `${process.env.HOME}/.moon/bin:${process.env.PATH}`;
|
|
28
|
-
try {
|
|
29
|
-
const version = execSync("moon --version", { env: process.env })
|
|
30
|
-
.toString()
|
|
31
|
-
.trim();
|
|
32
|
-
console.log(`[astrobit] moon installed: ${version}`);
|
|
33
|
-
} catch {
|
|
34
|
-
// ignore version display failure
|
|
35
|
-
}
|
|
30
|
+
run(MOON_INSTALL_CMD);
|
|
31
|
+
process.env.PATH = `${MOON_BIN_PATH}:${process.env.PATH}`;
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
if (command === "build") {
|
|
39
|
-
|
|
35
|
+
let version = moonVersion();
|
|
36
|
+
if (version === null) {
|
|
40
37
|
installMoon();
|
|
38
|
+
version = moonVersion();
|
|
39
|
+
if (version) console.log(`[astrobit] moon installed: ${version}`);
|
|
41
40
|
} else {
|
|
42
|
-
|
|
43
|
-
const version = execSync("moon --version").toString().trim();
|
|
44
|
-
console.log(`[astrobit] moon already available: ${version}`);
|
|
45
|
-
} catch {
|
|
46
|
-
// ignore
|
|
47
|
-
}
|
|
41
|
+
console.log(`[astrobit] moon already available: ${version}`);
|
|
48
42
|
}
|
|
49
43
|
|
|
50
44
|
console.log("[astrobit] running moon build...");
|