astrobit 0.1.2 → 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.
Files changed (2) hide show
  1. package/bin/astrobit.js +54 -0
  2. package/package.json +5 -1
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process";
3
+ import { platform } from "node:os";
4
+
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;
10
+
11
+ function run(cmd, opts = {}) {
12
+ const result = spawnSync(cmd, { shell: true, stdio: "inherit", ...opts });
13
+ if (result.status !== 0) process.exit(result.status ?? 1);
14
+ }
15
+
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();
20
+ }
21
+
22
+ function installMoon() {
23
+ if (platform() === "win32") {
24
+ console.error(
25
+ "[astrobit] moon is not installed. Please install it manually: https://www.moonbitlang.com/download"
26
+ );
27
+ process.exit(1);
28
+ }
29
+ console.log("[astrobit] moon not found, installing...");
30
+ run(MOON_INSTALL_CMD);
31
+ process.env.PATH = `${MOON_BIN_PATH}:${process.env.PATH}`;
32
+ }
33
+
34
+ if (command === "build") {
35
+ let version = moonVersion();
36
+ if (version === null) {
37
+ installMoon();
38
+ version = moonVersion();
39
+ if (version) console.log(`[astrobit] moon installed: ${version}`);
40
+ } else {
41
+ console.log(`[astrobit] moon already available: ${version}`);
42
+ }
43
+
44
+ console.log("[astrobit] running moon build...");
45
+ run("moon build");
46
+
47
+ console.log("[astrobit] running astro build...");
48
+ run("astro build");
49
+ } else {
50
+ console.error(
51
+ `[astrobit] Unknown command: ${command ?? "(none)"}\n\nUsage:\n astrobit build`
52
+ );
53
+ process.exit(1);
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astrobit",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/integration.js",
6
6
  "types": "./dist/integration.d.ts",
@@ -13,8 +13,12 @@
13
13
  "types": "./env.d.ts"
14
14
  }
15
15
  },
16
+ "bin": {
17
+ "astrobit": "./bin/astrobit.js"
18
+ },
16
19
  "files": [
17
20
  "dist",
21
+ "bin",
18
22
  "env.d.ts"
19
23
  ],
20
24
  "scripts": {