astrobit 0.1.2 → 0.1.3

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 +60 -0
  2. package/package.json +5 -1
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ import { execSync, spawnSync } from "node:child_process";
3
+ import { platform } from "node:os";
4
+
5
+ const [, , command, ...args] = process.argv;
6
+
7
+ function run(cmd, opts = {}) {
8
+ const result = spawnSync(cmd, { shell: true, stdio: "inherit", ...opts });
9
+ if (result.status !== 0) process.exit(result.status ?? 1);
10
+ }
11
+
12
+ function hasMoon() {
13
+ const result = spawnSync("moon --version", { shell: true, stdio: "pipe" });
14
+ return result.status === 0;
15
+ }
16
+
17
+ function installMoon() {
18
+ if (platform() === "win32") {
19
+ console.error(
20
+ "[astrobit] moon is not installed. Please install it manually: https://www.moonbitlang.com/download"
21
+ );
22
+ process.exit(1);
23
+ }
24
+ console.log("[astrobit] moon not found, installing...");
25
+ run("curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash");
26
+ // Add moon to PATH for subsequent commands in this process
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
+ }
36
+ }
37
+
38
+ if (command === "build") {
39
+ if (!hasMoon()) {
40
+ installMoon();
41
+ } else {
42
+ try {
43
+ const version = execSync("moon --version").toString().trim();
44
+ console.log(`[astrobit] moon already available: ${version}`);
45
+ } catch {
46
+ // ignore
47
+ }
48
+ }
49
+
50
+ console.log("[astrobit] running moon build...");
51
+ run("moon build");
52
+
53
+ console.log("[astrobit] running astro build...");
54
+ run("astro build");
55
+ } else {
56
+ console.error(
57
+ `[astrobit] Unknown command: ${command ?? "(none)"}\n\nUsage:\n astrobit build`
58
+ );
59
+ process.exit(1);
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astrobit",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
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": {