gaia-framework 1.0.0

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.
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ─────────────────────────────────────────────────────────────────────────────
4
+ // GAIA Framework — npm CLI wrapper
5
+ // Clones the GAIA repo, delegates to gaia-install.sh, and cleans up.
6
+ // ─────────────────────────────────────────────────────────────────────────────
7
+
8
+ const { execSync, execFileSync } = require("child_process");
9
+ const { mkdtempSync, rmSync, existsSync } = require("fs");
10
+ const { join } = require("path");
11
+ const { tmpdir } = require("os");
12
+
13
+ const REPO_URL = "https://github.com/J-louage/Gaia-framework.git";
14
+ const SCRIPT_NAME = "gaia-install.sh";
15
+
16
+ let tempDir = null;
17
+
18
+ // ─── Helpers ────────────────────────────────────────────────────────────────
19
+
20
+ function fail(message) {
21
+ console.error(`\x1b[31m✖\x1b[0m ${message}`);
22
+ process.exit(1);
23
+ }
24
+
25
+ function info(message) {
26
+ console.log(`\x1b[34mℹ\x1b[0m ${message}`);
27
+ }
28
+
29
+ function cleanup() {
30
+ if (tempDir && existsSync(tempDir)) {
31
+ try {
32
+ rmSync(tempDir, { recursive: true, force: true });
33
+ } catch {
34
+ // Best-effort cleanup
35
+ }
36
+ }
37
+ }
38
+
39
+ function ensureGit() {
40
+ try {
41
+ execSync("git --version", { stdio: "ignore" });
42
+ } catch {
43
+ fail(
44
+ "git is required but was not found.\n" +
45
+ " Install git: https://git-scm.com/downloads"
46
+ );
47
+ }
48
+ }
49
+
50
+ function showUsage() {
51
+ console.log(`
52
+ \x1b[1mGAIA Framework — npm installer\x1b[0m
53
+
54
+ Usage: npx gaia-framework <command> [options] [target]
55
+
56
+ Commands:
57
+ init Install GAIA into a project
58
+ update Update framework files (preserves config and memory)
59
+ validate Check installation integrity
60
+ status Show installation info
61
+
62
+ Options:
63
+ --yes Skip confirmation prompts
64
+ --dry-run Show what would be done without making changes
65
+ --verbose Show detailed progress
66
+ --help Show this help message
67
+
68
+ Examples:
69
+ npx gaia-framework init .
70
+ npx gaia-framework init ~/my-new-project
71
+ npx gaia-framework update .
72
+ npx gaia-framework validate .
73
+ npx gaia-framework status .
74
+ npx gaia-framework init --yes ~/my-project
75
+ `);
76
+ }
77
+
78
+ // ─── Main ───────────────────────────────────────────────────────────────────
79
+
80
+ function main() {
81
+ const args = process.argv.slice(2);
82
+
83
+ // Handle help / no args
84
+ if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
85
+ showUsage();
86
+ process.exit(0);
87
+ }
88
+
89
+ if (args.includes("--version") || args.includes("-v")) {
90
+ const pkg = require("../package.json");
91
+ console.log(`gaia-framework v${pkg.version}`);
92
+ process.exit(0);
93
+ }
94
+
95
+ // Validate command
96
+ const command = args[0];
97
+ const validCommands = ["init", "update", "validate", "status"];
98
+ if (!validCommands.includes(command)) {
99
+ fail(`Unknown command: ${command}\n Run 'npx gaia-framework --help' for usage.`);
100
+ }
101
+
102
+ // Ensure git is available
103
+ ensureGit();
104
+
105
+ // Clone the repo to a temp directory
106
+ tempDir = mkdtempSync(join(tmpdir(), "gaia-framework-"));
107
+
108
+ // Register cleanup for all exit scenarios
109
+ process.on("exit", cleanup);
110
+ process.on("SIGINT", () => { cleanup(); process.exit(130); });
111
+ process.on("SIGTERM", () => { cleanup(); process.exit(143); });
112
+
113
+ info("Cloning GAIA framework from GitHub...");
114
+
115
+ try {
116
+ execSync(`git clone --depth 1 ${REPO_URL} "${tempDir}"`, {
117
+ stdio: ["ignore", "ignore", "pipe"],
118
+ });
119
+ } catch (err) {
120
+ fail(
121
+ `Failed to clone from ${REPO_URL}\n` +
122
+ ` ${err.stderr ? err.stderr.toString().trim() : "Check your network connection."}`
123
+ );
124
+ }
125
+
126
+ // Locate the installer script
127
+ const scriptPath = join(tempDir, SCRIPT_NAME);
128
+ if (!existsSync(scriptPath)) {
129
+ fail(`Installer script not found in cloned repo: ${SCRIPT_NAME}`);
130
+ }
131
+
132
+ // Build the shell command: inject --source pointing to the temp clone
133
+ // so the shell script doesn't need to clone again
134
+ const passthrough = args.slice(0);
135
+ // Insert --source right after the command
136
+ passthrough.splice(1, 0, "--source", tempDir);
137
+
138
+ info("Running installer...\n");
139
+
140
+ try {
141
+ execFileSync("bash", [scriptPath, ...passthrough], {
142
+ stdio: "inherit",
143
+ env: { ...process.env, GAIA_SOURCE: tempDir },
144
+ });
145
+ } catch (err) {
146
+ process.exit(err.status || 1);
147
+ }
148
+ }
149
+
150
+ main();