@iola_adm/iola-cli 0.1.92 → 0.1.93
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/postinstall.js +98 -0
- package/package.json +3 -3
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
|
|
6
|
+
const rootDir = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
+
const cliPath = resolve(rootDir, "bin", "iola.js");
|
|
8
|
+
const node = process.execPath;
|
|
9
|
+
const frames = ["|", "/", "-", "\\"];
|
|
10
|
+
|
|
11
|
+
const steps = [
|
|
12
|
+
{
|
|
13
|
+
title: "Подготовка локальной БД",
|
|
14
|
+
args: [cliPath, "db", "init", "--silent"],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
title: "Проверка браузерного runtime",
|
|
18
|
+
args: [cliPath, "browser", "install"],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: "Проверка локальной модели IOLA",
|
|
22
|
+
args: [cliPath, "ai", "setup", "iola", "--yes", "--quiet", "--optional"],
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const canAnimate = process.stdout.isTTY && process.env.CI !== "true";
|
|
27
|
+
|
|
28
|
+
console.log("");
|
|
29
|
+
console.log("IOLA CLI: настройка после установки");
|
|
30
|
+
|
|
31
|
+
for (let index = 0; index < steps.length; index += 1) {
|
|
32
|
+
const step = steps[index];
|
|
33
|
+
await runStep(step, index + 1, steps.length);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log("IOLA CLI готова. Запуск: iola");
|
|
37
|
+
|
|
38
|
+
async function runStep(step, current, total) {
|
|
39
|
+
const started = Date.now();
|
|
40
|
+
let frame = 0;
|
|
41
|
+
let lastOutput = "";
|
|
42
|
+
const prefix = `[${current}/${total}] ${step.title}`;
|
|
43
|
+
const render = () => {
|
|
44
|
+
if (!canAnimate) return;
|
|
45
|
+
const seconds = Math.max(1, Math.round((Date.now() - started) / 1000));
|
|
46
|
+
process.stdout.write(`\r${frames[frame]} ${prefix}... ${seconds}s`);
|
|
47
|
+
frame = (frame + 1) % frames.length;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (!canAnimate) {
|
|
51
|
+
console.log(`... ${prefix}`);
|
|
52
|
+
}
|
|
53
|
+
render();
|
|
54
|
+
const timer = setInterval(render, 120);
|
|
55
|
+
const result = await run(node, ["--no-warnings", ...step.args], (chunk) => {
|
|
56
|
+
lastOutput = chunk.trim() || lastOutput;
|
|
57
|
+
});
|
|
58
|
+
clearInterval(timer);
|
|
59
|
+
|
|
60
|
+
if (result.code !== 0) {
|
|
61
|
+
if (canAnimate) process.stdout.write(`\r`);
|
|
62
|
+
if (lastOutput) console.error(lastOutput);
|
|
63
|
+
console.error(`× ${prefix}: ошибка установки`);
|
|
64
|
+
process.exit(result.code || 1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (canAnimate) {
|
|
68
|
+
process.stdout.write(`\r✓ ${prefix} готово за ${formatDuration(Date.now() - started)}\n`);
|
|
69
|
+
} else {
|
|
70
|
+
console.log(`✓ ${prefix} готово за ${formatDuration(Date.now() - started)}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function run(command, args, onOutput) {
|
|
75
|
+
return new Promise((resolvePromise) => {
|
|
76
|
+
const child = spawn(command, args, {
|
|
77
|
+
cwd: rootDir,
|
|
78
|
+
windowsHide: true,
|
|
79
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
child.stdout.on("data", (chunk) => onOutput(String(chunk)));
|
|
83
|
+
child.stderr.on("data", (chunk) => onOutput(String(chunk)));
|
|
84
|
+
child.on("close", (code) => resolvePromise({ code }));
|
|
85
|
+
child.on("error", (error) => {
|
|
86
|
+
onOutput(error.message);
|
|
87
|
+
resolvePromise({ code: 1 });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function formatDuration(ms) {
|
|
93
|
+
const seconds = Math.max(1, Math.round(ms / 1000));
|
|
94
|
+
if (seconds < 60) return `${seconds}s`;
|
|
95
|
+
const minutes = Math.floor(seconds / 60);
|
|
96
|
+
const rest = seconds % 60;
|
|
97
|
+
return `${minutes}m ${rest}s`;
|
|
98
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iola_adm/iola-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.93",
|
|
4
4
|
"description": "CLI и AI-агент городского округа Йошкар-Ола.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/adm-iola/iola-cli#readme",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"iola": "bin/iola.js"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"postinstall": "node --no-warnings bin/
|
|
19
|
+
"postinstall": "node --no-warnings bin/postinstall.js",
|
|
20
20
|
"start": "node --no-warnings bin/iola.js",
|
|
21
|
-
"test": "node --no-warnings --check bin/iola.js && node --no-warnings --check src/cli.js && node --no-warnings test/smoke-test.js"
|
|
21
|
+
"test": "node --no-warnings --check bin/iola.js && node --no-warnings --check bin/postinstall.js && node --no-warnings --check src/cli.js && node --no-warnings test/smoke-test.js"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"bin",
|