@socrates-ai/cli 0.1.0 → 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/README.md +6 -0
- package/package.json +1 -1
- package/src/cli.mjs +1 -1
- package/src/runtime.mjs +35 -8
package/README.md
CHANGED
|
@@ -7,3 +7,9 @@ npx @socrates-ai/cli
|
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
The CLI downloads the matching runtime bundle from GitHub Releases, stores it under `~/.Socrates/runtimes/`, starts local services on `127.0.0.1`, and opens the browser.
|
|
10
|
+
|
|
11
|
+
Force a fresh runtime download/extract with:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx @socrates-ai/cli --reset-runtime
|
|
15
|
+
```
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -92,7 +92,7 @@ Options:
|
|
|
92
92
|
--home <path> Use a custom Socrates data directory.
|
|
93
93
|
--backend-port <port> Use a fixed backend port.
|
|
94
94
|
--web-port <port> Use a fixed web port.
|
|
95
|
-
--runtime-version <tag> Use a specific GitHub Release tag, e.g. v0.1.
|
|
95
|
+
--runtime-version <tag> Use a specific GitHub Release tag, e.g. v0.1.2.
|
|
96
96
|
--reset-runtime Redownload and extract the runtime bundle.
|
|
97
97
|
--help Show this help.
|
|
98
98
|
`;
|
package/src/runtime.mjs
CHANGED
|
@@ -29,6 +29,7 @@ export const parseArgs = (argv) => {
|
|
|
29
29
|
options.noOpen = true;
|
|
30
30
|
break;
|
|
31
31
|
case "--reset-runtime":
|
|
32
|
+
case "--resest-runtime":
|
|
32
33
|
options.resetRuntime = true;
|
|
33
34
|
break;
|
|
34
35
|
case "--home":
|
|
@@ -261,17 +262,43 @@ const downloadFile = async (url, target) => {
|
|
|
261
262
|
};
|
|
262
263
|
|
|
263
264
|
const extractZip = async (archivePath, targetDir) => {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
265
|
+
const commands = zipExtractCommandsFor(process.platform, archivePath, targetDir);
|
|
266
|
+
let lastError;
|
|
267
|
+
for (let index = 0; index < commands.length; index += 1) {
|
|
268
|
+
const { command, args } = commands[index];
|
|
269
|
+
try {
|
|
270
|
+
await run(command, args);
|
|
271
|
+
return;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
lastError = error;
|
|
274
|
+
if (index < commands.length - 1) {
|
|
275
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
276
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
271
279
|
}
|
|
272
|
-
|
|
280
|
+
throw lastError;
|
|
273
281
|
};
|
|
274
282
|
|
|
283
|
+
export const zipExtractCommandsFor = (platform, archivePath, targetDir) => {
|
|
284
|
+
if (platform === "win32") {
|
|
285
|
+
return [
|
|
286
|
+
{ command: "tar.exe", args: ["-xf", archivePath, "-C", targetDir] },
|
|
287
|
+
{
|
|
288
|
+
command: "powershell.exe",
|
|
289
|
+
args: [
|
|
290
|
+
"-NoProfile",
|
|
291
|
+
"-Command",
|
|
292
|
+
`Expand-Archive -LiteralPath ${powerShellSingleQuoted(archivePath)} -DestinationPath ${powerShellSingleQuoted(targetDir)} -Force`,
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
];
|
|
296
|
+
}
|
|
297
|
+
return [{ command: "unzip", args: ["-q", archivePath, "-d", targetDir] }];
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
export const powerShellSingleQuoted = (value) => `'${String(value).replaceAll("'", "''")}'`;
|
|
301
|
+
|
|
275
302
|
const run = (command, args) =>
|
|
276
303
|
new Promise((resolve, reject) => {
|
|
277
304
|
const child = defaultSpawn(command, args, { stdio: "ignore" });
|