embedlabs 0.1.0-alpha.12 → 0.1.0-alpha.121
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 +2 -2
- package/bin/install-progress.js +175 -0
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# embedlabs
|
|
2
2
|
|
|
3
|
-
Experimental npm alias for
|
|
3
|
+
Experimental npm alias for EmbedLabs CLI.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install -g embedlabs@alpha
|
|
7
7
|
embedlabs --help
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
This package forwards to `@kvell007/embed-labs-cli@0.1.0-alpha.
|
|
10
|
+
This package forwards to `@kvell007/embed-labs-cli@0.1.0-alpha.121`.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { arch, platform } from "node:os";
|
|
5
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
6
|
+
|
|
7
|
+
const phase = process.argv[2] ?? "postinstall";
|
|
8
|
+
const target = `${platform()}-${arch()}`;
|
|
9
|
+
if (phase === "preinstall") {
|
|
10
|
+
cleanupWindowsInstallState();
|
|
11
|
+
} else {
|
|
12
|
+
verifyInstallState();
|
|
13
|
+
}
|
|
14
|
+
const steps = phase === "preinstall"
|
|
15
|
+
? [
|
|
16
|
+
[5, `install: initializing (${target})`],
|
|
17
|
+
[18, "install: checking platform"],
|
|
18
|
+
[30, "install: resolving packages"],
|
|
19
|
+
[45, "install: downloading dependencies"],
|
|
20
|
+
[60, "install: extracting files"],
|
|
21
|
+
[75, "install: preparing commands"],
|
|
22
|
+
[84, "install: waiting for npm"]
|
|
23
|
+
]
|
|
24
|
+
: [
|
|
25
|
+
[88, "install: verifying commands"],
|
|
26
|
+
[94, "install: finalizing installation"],
|
|
27
|
+
[100, "install: complete"]
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
if (shouldShowProgress()) {
|
|
31
|
+
for (let index = 0; index < steps.length; index += 1) {
|
|
32
|
+
const [percent, message] = steps[index];
|
|
33
|
+
writeProgress(percent, message, index === steps.length - 1);
|
|
34
|
+
await sleep(1000);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function shouldShowProgress() {
|
|
39
|
+
return (
|
|
40
|
+
process.stdout.isTTY ||
|
|
41
|
+
process.env.npm_config_foreground_scripts === "true" ||
|
|
42
|
+
process.env.EMBEDLABS_INSTALL_FORCE_PROGRESS === "1" ||
|
|
43
|
+
process.env.EMBEDLABS_INSTALL_NO_TTY === "1"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function writeProgress(percent, message, final = false) {
|
|
48
|
+
const text = `[EmbedLabs] ${String(percent).padStart(3, " ")}% ${message}`;
|
|
49
|
+
const line = `\r\x1b[2K${text}${final ? "\n" : ""}`;
|
|
50
|
+
if (process.stdout.isTTY || process.env.EMBEDLABS_INSTALL_NO_TTY === "1") {
|
|
51
|
+
process.stdout.write(line);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
writeFileSync(platform() === "win32" ? "\\\\.\\CONOUT$" : "/dev/tty", line, { flag: "a" });
|
|
56
|
+
} catch {
|
|
57
|
+
process.stdout.write(line);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function cleanupWindowsInstallState() {
|
|
62
|
+
stopOldBridgeProcess();
|
|
63
|
+
deleteLegacyBridgeScheduledTask();
|
|
64
|
+
cleanupOldCommandShims();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function stopOldBridgeProcess() {
|
|
68
|
+
if (platform() !== "win32") {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
for (const imageName of ["embed-local-bridge.exe", "embed-local-bridge-fixed.exe"]) {
|
|
72
|
+
spawnSync("taskkill.exe", ["/IM", imageName, "/F"], { stdio: "ignore" });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function deleteLegacyBridgeScheduledTask() {
|
|
77
|
+
if (platform() !== "win32") {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
spawnSync("schtasks.exe", ["/Delete", "/TN", "EmbedLabsLocalBridge", "/F"], { stdio: "ignore" });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function cleanupOldCommandShims() {
|
|
84
|
+
for (const prefix of installPrefixes()) {
|
|
85
|
+
for (const candidate of commandShimCandidates(prefix)) {
|
|
86
|
+
const filePath = join(prefix, candidate);
|
|
87
|
+
if (!existsSync(filePath) || !isEmbedLabsShim(filePath)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
rmSync(filePath, { force: true });
|
|
92
|
+
writeProgress(3, `install: removed stale command shim (${basename(filePath)})`);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
95
|
+
throw new Error(`stale EmbedLabs command shim is locked: ${filePath}; close running terminals or processes and retry npm install. ${message}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function installPrefixes() {
|
|
102
|
+
const prefixes = new Set();
|
|
103
|
+
for (const candidate of [
|
|
104
|
+
process.env.npm_config_prefix,
|
|
105
|
+
process.env.PREFIX,
|
|
106
|
+
dirname(dirname(process.execPath))
|
|
107
|
+
]) {
|
|
108
|
+
if (candidate) {
|
|
109
|
+
prefixes.add(resolve(candidate));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return [...prefixes];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function commandShimCandidates(prefix) {
|
|
116
|
+
if (platform() === "win32") {
|
|
117
|
+
return ["embedlabs", "embedlabs.cmd", "embedlabs.ps1", "embedlabs.bat"];
|
|
118
|
+
}
|
|
119
|
+
return [join("bin", "embedlabs")];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function isEmbedLabsShim(filePath) {
|
|
123
|
+
try {
|
|
124
|
+
const body = readFileSync(filePath, "utf8").toLowerCase();
|
|
125
|
+
return body.includes("embedlabs")
|
|
126
|
+
&& (
|
|
127
|
+
body.includes("@kvell007\\embed-labs-cli")
|
|
128
|
+
|| body.includes("@kvell007/embed-labs-cli")
|
|
129
|
+
|| body.includes("node_modules\\embedlabs")
|
|
130
|
+
|| body.includes("node_modules/embedlabs")
|
|
131
|
+
|| body.includes("embed-labs-cli")
|
|
132
|
+
);
|
|
133
|
+
} catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function verifyInstallState() {
|
|
139
|
+
for (const prefix of installPrefixes()) {
|
|
140
|
+
if (platform() === "win32") {
|
|
141
|
+
const shimPath = join(prefix, "embedlabs.cmd");
|
|
142
|
+
mkdirSync(dirname(shimPath), { recursive: true });
|
|
143
|
+
writeFileSync(shimPath, windowsCmdShim(), "utf8");
|
|
144
|
+
chmodSync(shimPath, 0o755);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const shimPath = join(prefix, "bin", "embedlabs");
|
|
148
|
+
mkdirSync(dirname(shimPath), { recursive: true });
|
|
149
|
+
writeFileSync(shimPath, unixShellShim(), "utf8");
|
|
150
|
+
chmodSync(shimPath, 0o755);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function windowsCmdShim() {
|
|
155
|
+
return [
|
|
156
|
+
"@ECHO off",
|
|
157
|
+
"SETLOCAL",
|
|
158
|
+
"SET \"EMBEDLABS_ALIAS_DIR=%~dp0\"",
|
|
159
|
+
"node \"%EMBEDLABS_ALIAS_DIR%node_modules\\embedlabs\\bin\\embedlabs.js\" %*",
|
|
160
|
+
""
|
|
161
|
+
].join("\r\n");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function unixShellShim() {
|
|
165
|
+
return [
|
|
166
|
+
"#!/bin/sh",
|
|
167
|
+
"basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")",
|
|
168
|
+
"exec node \"$basedir/../lib/node_modules/embedlabs/bin/embedlabs.js\" \"$@\"",
|
|
169
|
+
""
|
|
170
|
+
].join("\n");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function sleep(ms) {
|
|
174
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
175
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "embedlabs",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-alpha.121",
|
|
4
|
+
"description": "EmbedLabs CLI alias package for local-first embedded agent testing.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"preinstall": "node bin/install-progress.js preinstall",
|
|
9
|
+
"postinstall": "node bin/install-progress.js postinstall"
|
|
10
|
+
},
|
|
7
11
|
"bin": {
|
|
8
12
|
"embedlabs": "bin/embedlabs.js"
|
|
9
13
|
},
|
|
@@ -12,7 +16,7 @@
|
|
|
12
16
|
"README.md"
|
|
13
17
|
],
|
|
14
18
|
"dependencies": {
|
|
15
|
-
"@kvell007/embed-labs-cli": "0.1.0-alpha.
|
|
19
|
+
"@kvell007/embed-labs-cli": "0.1.0-alpha.121"
|
|
16
20
|
},
|
|
17
21
|
"publishConfig": {
|
|
18
22
|
"access": "public",
|