@vite-hub/cli 0.1.0 → 0.3.1
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 +52 -13
- package/dist/commands-DPg3kL8m.js +3104 -0
- package/dist/console-auth-xl7kLQNt.js +315 -0
- package/dist/console-env-C5YeAm2-.js +198 -0
- package/dist/env-DzoVtVJO.js +5820 -0
- package/dist/envelope-Cf56AJLa.js +88 -0
- package/dist/index.d.ts +22 -50
- package/dist/index.js +665 -1212
- package/dist/provision-C9p1wSzq.d.ts +170 -0
- package/dist/provision-D8OvBBzi.js +2262 -0
- package/dist/setup/index.d.ts +919 -0
- package/dist/setup/index.js +231 -0
- package/package.json +31 -12
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { P as setupStatus, R as readSetupProject, c as linkSetupProject, d as readSetupLinkStatus, f as readSetupLinks, m as unlinkSetupProject, p as selectSetupLink, r as SETUP_LINK_FILE, u as readSetupLinkState } from "../env-DzoVtVJO.js";
|
|
2
|
+
import { m as cliErrorDiagnostics } from "../provision-D8OvBBzi.js";
|
|
3
|
+
import { i as setupFailure, o as writeSetupError, r as setupExitCodes } from "../envelope-Cf56AJLa.js";
|
|
4
|
+
import { S as shellQuote, _ as setupCatalog, a as readRemoveArgs, b as planSetupAdd, c as initPackages, d as readSetupStack, f as deployCommand, g as readSetupLive, h as deploymentsCommand, i as planSetupRemove, l as nuxiPackage, m as STATUS_HOST_TIMEOUT_MS, n as setupCommands, o as removeCommand, p as readDeployArgs, r as applySetupRemove, s as initCommandDefinition, u as readInitArgs, v as addCommand, x as readAddArgs, y as applySetupAdd } from "../commands-DPg3kL8m.js";
|
|
5
|
+
import { a as defaultConsoleUrl, c as readConsoleCredential, i as consoleUrlVariable, l as whoamiCommand, n as consoleOrigin, o as loginCommand, r as consoleTokenVariable, s as logoutCommand, t as consoleCredentialsFile } from "../console-auth-xl7kLQNt.js";
|
|
6
|
+
import { join } from "pathe";
|
|
7
|
+
import { readFile } from "node:fs/promises";
|
|
8
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
9
|
+
//#region src/setup/session.ts
|
|
10
|
+
const featurePattern = /^[a-z][a-z-]*$/iu;
|
|
11
|
+
function invalid(message) {
|
|
12
|
+
return cliErrorDiagnostics.CLI_R0003({ message: `[vitehub] ${message}` });
|
|
13
|
+
}
|
|
14
|
+
function isObject(value) {
|
|
15
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
function readStrings(value, field) {
|
|
18
|
+
if (value === void 0) return [];
|
|
19
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) throw invalid(`\`${field}\` must be a list of strings.`);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
function readFlag(value, field) {
|
|
23
|
+
if (value === void 0 || typeof value === "boolean") return value;
|
|
24
|
+
throw invalid(`\`${field}\` must be true or false.`);
|
|
25
|
+
}
|
|
26
|
+
/** The CLI arguments of a request. Every value goes inline after `=`, so no value can become another flag. */
|
|
27
|
+
function setupRequestArgs(request) {
|
|
28
|
+
if (!isObject(request)) throw invalid("The request must be a JSON object.");
|
|
29
|
+
const action = request.action;
|
|
30
|
+
if (action !== "add" && action !== "remove") throw invalid("`action` must be \"add\" or \"remove\".");
|
|
31
|
+
const allowed = action === "add" ? [
|
|
32
|
+
"action",
|
|
33
|
+
"features",
|
|
34
|
+
"options",
|
|
35
|
+
"name",
|
|
36
|
+
"install"
|
|
37
|
+
] : [
|
|
38
|
+
"action",
|
|
39
|
+
"features",
|
|
40
|
+
"force",
|
|
41
|
+
"keepFiles",
|
|
42
|
+
"uninstall"
|
|
43
|
+
];
|
|
44
|
+
const unknown = Object.keys(request).find((key) => !allowed.includes(key));
|
|
45
|
+
if (unknown) throw invalid(`Unknown field \`${unknown}\` for ${action}.`);
|
|
46
|
+
const features = readStrings(request.features, "features");
|
|
47
|
+
if (!features.length) throw invalid("Name at least one feature.");
|
|
48
|
+
const bad = features.find((feature) => !featurePattern.test(feature));
|
|
49
|
+
if (bad !== void 0) throw invalid(`Unknown feature ${JSON.stringify(bad)}.`);
|
|
50
|
+
const argv = [...features];
|
|
51
|
+
if (action === "add") {
|
|
52
|
+
if (request.name !== void 0 && typeof request.name !== "string") throw invalid("`name` must be a string.");
|
|
53
|
+
if (request.name !== void 0) argv.push(`--name=${request.name}`);
|
|
54
|
+
for (const option of readStrings(request.options, "options")) argv.push(`--option=${option}`);
|
|
55
|
+
if (readFlag(request.install, "install") === false) argv.push("--no-install");
|
|
56
|
+
} else {
|
|
57
|
+
if (readFlag(request.force, "force")) argv.push("--force");
|
|
58
|
+
if (readFlag(request.keepFiles, "keepFiles")) argv.push("--keep-files");
|
|
59
|
+
if (readFlag(request.uninstall, "uninstall") === false) argv.push("--no-uninstall");
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
action,
|
|
63
|
+
argv
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** The SHA-256 of each file, or `absent`. */
|
|
67
|
+
async function fingerprint(root, paths) {
|
|
68
|
+
const files = /* @__PURE__ */ new Map();
|
|
69
|
+
for (const path of new Set(paths)) {
|
|
70
|
+
const content = await readFile(join(root, path)).catch(() => void 0);
|
|
71
|
+
files.set(path, content === void 0 ? "absent" : createHash("sha256").update(content).digest("hex"));
|
|
72
|
+
}
|
|
73
|
+
return files;
|
|
74
|
+
}
|
|
75
|
+
function sameChange(left, right) {
|
|
76
|
+
const install = (plan) => "install" in plan ? plan.install : plan.uninstall;
|
|
77
|
+
return JSON.stringify([left.changes, install(left)]) === JSON.stringify([right.changes, install(right)]);
|
|
78
|
+
}
|
|
79
|
+
function failureResult(error) {
|
|
80
|
+
let output = "";
|
|
81
|
+
const sink = { write: (chunk) => {
|
|
82
|
+
output += String(chunk);
|
|
83
|
+
} };
|
|
84
|
+
const exitCode = writeSetupError({
|
|
85
|
+
stderr: sink,
|
|
86
|
+
stdout: sink
|
|
87
|
+
}, true, error);
|
|
88
|
+
return {
|
|
89
|
+
body: JSON.parse(output),
|
|
90
|
+
exitCode
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The setup engine for a long-running process, such as the dev Setup page. It does what `vitehub status`, `catalog`,
|
|
95
|
+
* `add`, and `remove` do, with the same documents, and keeps each plan until one `apply()` uses it.
|
|
96
|
+
*/
|
|
97
|
+
function createSetupSession(options) {
|
|
98
|
+
const plans = /* @__PURE__ */ new Map();
|
|
99
|
+
const maxPlans = options.maxPlans ?? 20;
|
|
100
|
+
let queue = Promise.resolve();
|
|
101
|
+
async function plan(request) {
|
|
102
|
+
try {
|
|
103
|
+
const { action, argv } = setupRequestArgs(request);
|
|
104
|
+
const command = `vitehub ${action} ${[...argv, "--yes"].map(shellQuote).join(" ")}`;
|
|
105
|
+
const project = await readSetupProject(options.root, options.env);
|
|
106
|
+
let stored;
|
|
107
|
+
if (action === "add") {
|
|
108
|
+
const args = readAddArgs([
|
|
109
|
+
...argv,
|
|
110
|
+
"--dry-run",
|
|
111
|
+
"--json"
|
|
112
|
+
]);
|
|
113
|
+
const planned = await planSetupAdd(project, args, options.env);
|
|
114
|
+
stored = {
|
|
115
|
+
action,
|
|
116
|
+
args,
|
|
117
|
+
fields: {
|
|
118
|
+
command,
|
|
119
|
+
restart: !!planned.configFile
|
|
120
|
+
},
|
|
121
|
+
files: /* @__PURE__ */ new Map(),
|
|
122
|
+
planned
|
|
123
|
+
};
|
|
124
|
+
} else {
|
|
125
|
+
const args = readRemoveArgs([
|
|
126
|
+
...argv,
|
|
127
|
+
"--dry-run",
|
|
128
|
+
"--json"
|
|
129
|
+
]);
|
|
130
|
+
const planned = await planSetupRemove(project, args, options.env);
|
|
131
|
+
stored = {
|
|
132
|
+
action,
|
|
133
|
+
args,
|
|
134
|
+
fields: {
|
|
135
|
+
command,
|
|
136
|
+
restart: !!planned.configFile
|
|
137
|
+
},
|
|
138
|
+
files: /* @__PURE__ */ new Map(),
|
|
139
|
+
planned
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const { plan: document } = stored.planned;
|
|
143
|
+
if (document.status === "planned") {
|
|
144
|
+
stored.files = await fingerprint(project.root, [
|
|
145
|
+
"package.json",
|
|
146
|
+
...project.configFile ? [project.configFile] : [],
|
|
147
|
+
...document.changes.map((change) => change.path)
|
|
148
|
+
]);
|
|
149
|
+
const planId = randomUUID();
|
|
150
|
+
stored.fields.planId = planId;
|
|
151
|
+
plans.set(planId, stored);
|
|
152
|
+
for (const id of plans.keys()) {
|
|
153
|
+
if (plans.size <= maxPlans) break;
|
|
154
|
+
plans.delete(id);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
body: {
|
|
159
|
+
schemaVersion: 1,
|
|
160
|
+
...document,
|
|
161
|
+
...stored.fields
|
|
162
|
+
},
|
|
163
|
+
exitCode: setupExitCodes.done
|
|
164
|
+
};
|
|
165
|
+
} catch (error) {
|
|
166
|
+
return failureResult(error);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function applyStored(planId, onOutput) {
|
|
170
|
+
try {
|
|
171
|
+
const stored = typeof planId === "string" ? plans.get(planId) : void 0;
|
|
172
|
+
if (!stored || typeof planId !== "string") throw setupFailure(cliErrorDiagnostics.SETUP_PLAN_UNKNOWN(), setupExitCodes.error);
|
|
173
|
+
plans.delete(planId);
|
|
174
|
+
const current = await fingerprint(options.root, stored.files.keys());
|
|
175
|
+
for (const [path, hash] of stored.files) if (current.get(path) !== hash) throw setupFailure(cliErrorDiagnostics.SETUP_STALE_PLAN({ file: path }), setupExitCodes.stalePlan);
|
|
176
|
+
const project = await readSetupProject(options.root, options.env);
|
|
177
|
+
const again = stored.action === "add" ? await planSetupAdd(project, stored.args, options.env) : await planSetupRemove(project, stored.args, options.env);
|
|
178
|
+
if (!sameChange(stored.planned.plan, again.plan)) throw setupFailure(cliErrorDiagnostics.SETUP_STALE_PLAN({ file: project.configFile ?? "the project" }), setupExitCodes.stalePlan);
|
|
179
|
+
const spawn = async (command, args, spawnOptions) => await options.run(command, args, {
|
|
180
|
+
cwd: spawnOptions?.cwd ?? project.root,
|
|
181
|
+
env: spawnOptions?.env ?? options.env,
|
|
182
|
+
onOutput
|
|
183
|
+
});
|
|
184
|
+
const context = {
|
|
185
|
+
env: options.env,
|
|
186
|
+
spawn
|
|
187
|
+
};
|
|
188
|
+
if (stored.action === "add") await applySetupAdd(project, stored.planned, stored.args, context);
|
|
189
|
+
else await applySetupRemove(project, stored.planned, stored.args, context, { configLast: true });
|
|
190
|
+
const { planId: _planId, ...fields } = stored.fields;
|
|
191
|
+
return {
|
|
192
|
+
body: {
|
|
193
|
+
schemaVersion: 1,
|
|
194
|
+
...stored.planned.plan,
|
|
195
|
+
status: "applied",
|
|
196
|
+
...fields
|
|
197
|
+
},
|
|
198
|
+
exitCode: setupExitCodes.done
|
|
199
|
+
};
|
|
200
|
+
} catch (error) {
|
|
201
|
+
return failureResult(error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
apply: async (planId, onOutput = () => {}) => {
|
|
206
|
+
const result = queue.then(async () => await applyStored(planId, onOutput));
|
|
207
|
+
queue = result;
|
|
208
|
+
return await result;
|
|
209
|
+
},
|
|
210
|
+
catalog: () => {
|
|
211
|
+
const catalog = setupCatalog();
|
|
212
|
+
return {
|
|
213
|
+
body: JSON.parse(JSON.stringify(catalog)),
|
|
214
|
+
exitCode: setupExitCodes.done
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
plan,
|
|
218
|
+
status: async () => {
|
|
219
|
+
try {
|
|
220
|
+
return {
|
|
221
|
+
body: { ...setupStatus(await readSetupProject(options.root, options.env), options.env) },
|
|
222
|
+
exitCode: setupExitCodes.done
|
|
223
|
+
};
|
|
224
|
+
} catch (error) {
|
|
225
|
+
return failureResult(error);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
export { SETUP_LINK_FILE, STATUS_HOST_TIMEOUT_MS, addCommand, applySetupAdd, applySetupRemove, consoleCredentialsFile, consoleOrigin, consoleTokenVariable, consoleUrlVariable, createSetupSession, defaultConsoleUrl, deployCommand, deploymentsCommand, initCommandDefinition, initPackages, linkSetupProject, loginCommand, logoutCommand, nuxiPackage, planSetupAdd, planSetupRemove, readAddArgs, readConsoleCredential, readDeployArgs, readInitArgs, readRemoveArgs, readSetupLinkState, readSetupLinkStatus, readSetupLinks, readSetupLive, readSetupProject, readSetupStack, removeCommand, selectSetupLink, setupCatalog, setupCommands, setupExitCodes, setupRequestArgs, setupStatus, unlinkSetupProject, whoamiCommand };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/cli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Command-line workflows for ViteHub projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -21,9 +21,6 @@
|
|
|
21
21
|
"url": "git+https://github.com/vite-hub/vitehub.git",
|
|
22
22
|
"directory": "packages/cli"
|
|
23
23
|
},
|
|
24
|
-
"bin": {
|
|
25
|
-
"vitehub": "./dist/index.js"
|
|
26
|
-
},
|
|
27
24
|
"files": [
|
|
28
25
|
"dist",
|
|
29
26
|
"package.json"
|
|
@@ -37,38 +34,60 @@
|
|
|
37
34
|
"import": "./dist/index.js",
|
|
38
35
|
"default": "./dist/index.js"
|
|
39
36
|
},
|
|
37
|
+
"./setup": {
|
|
38
|
+
"types": "./dist/setup/index.d.ts",
|
|
39
|
+
"import": "./dist/setup/index.js",
|
|
40
|
+
"default": "./dist/setup/index.js"
|
|
41
|
+
},
|
|
40
42
|
"./package.json": "./package.json"
|
|
41
43
|
},
|
|
42
44
|
"dependencies": {
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"
|
|
45
|
+
"@babel/parser": "^7.29.9",
|
|
46
|
+
"@dotenvx/primitives": "^4.4.0",
|
|
47
|
+
"@noble/ciphers": "^2.4.0",
|
|
48
|
+
"@noble/hashes": "^2.4.0",
|
|
49
|
+
"@vite-hub/runtime": "0.3.1",
|
|
50
|
+
"birpc": "^4.2.0",
|
|
51
|
+
"diff": "^9.0.0",
|
|
52
|
+
"nostics": "1.4.0",
|
|
53
|
+
"pathe": "^2.0.3",
|
|
54
|
+
"semver": "^7.8.5"
|
|
46
55
|
},
|
|
47
56
|
"devDependencies": {
|
|
48
57
|
"@types/node": "^24.19.1",
|
|
58
|
+
"@types/semver": "^7.8.0",
|
|
59
|
+
"@vite-hub/forge": "0.3.1",
|
|
60
|
+
"@vite-hub/internal": "0.0.1",
|
|
61
|
+
"nuxt": "npm:nuxt-nightly@5.0.0-2611052317-a04317f",
|
|
49
62
|
"typescript": "^6.0.3",
|
|
50
63
|
"valibot": "^1.5.0",
|
|
51
64
|
"vite": "^8.2.2",
|
|
52
65
|
"vite-plus": "^0.3.3",
|
|
53
|
-
"vitest": "^4.1.11"
|
|
54
|
-
"@vite-hub/internal": "0.0.1"
|
|
66
|
+
"vitest": "^4.1.11"
|
|
55
67
|
},
|
|
56
68
|
"peerDependencies": {
|
|
57
|
-
"
|
|
69
|
+
"@vite-hub/forge": "0.3.1",
|
|
70
|
+
"nuxt": ">=5.0.0-0",
|
|
58
71
|
"vite": ">=8.0.0"
|
|
59
72
|
},
|
|
60
73
|
"engines": {
|
|
61
|
-
"node": ">=
|
|
74
|
+
"node": ">=22.18.0"
|
|
62
75
|
},
|
|
63
76
|
"peerDependenciesMeta": {
|
|
77
|
+
"@vite-hub/forge": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
64
80
|
"nuxt": {
|
|
65
81
|
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"vite": {
|
|
84
|
+
"optional": true
|
|
66
85
|
}
|
|
67
86
|
},
|
|
68
87
|
"scripts": {
|
|
69
88
|
"build": "vp pack",
|
|
70
89
|
"dev": "vp pack --watch",
|
|
71
90
|
"typecheck": "vp run --cache -t @vite-hub/cli#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
72
|
-
"test": "vp run -t @vite-hub/cli#build && vp test"
|
|
91
|
+
"test": "vp run --cache -t vite-hub#build && vp run --cache -t @vite-hub/cli#build && vp test"
|
|
73
92
|
}
|
|
74
93
|
}
|