@vite-hub/cli 0.5.1 → 0.6.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.
- package/dist/{commands-C003KqWY.js → commands-D0WSlS7h.js} +6 -7
- package/dist/{console-env-CsBruJnE.js → console-env-CYHb4owT.js} +1 -3
- package/dist/{deploy-BZ2iQjZL.js → deploy-DwNjKrHq.js} +91 -11
- package/dist/{env-DRI0QH4-.js → env-BiVwma4a.js} +153 -485
- package/dist/index.js +56 -12
- package/dist/{provision-DlknnTAt.js → provision-akHsvf-B.js} +1138 -34
- package/dist/setup/index.d.ts +25 -3
- package/dist/setup/index.js +4 -6
- package/package.json +4 -4
- package/dist/console-auth-CpOpbA7U.js +0 -311
- package/dist/envelope-DbplCDko.js +0 -87
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as readProvisionStateSync, At as viteCliProjectConfig, B as readConsoleCredential, Ct as quoteSupportedInstallSpecifier, Dt as createCliDiscoveryNitroCloser, Et as collectViteHubCliContribution, Mt as isRecord, Ot as findViteHubDevServerUrl, Tt as appUrlError, X as PROVISION_STATE_FILE, Y as cliErrorDiagnostics, at as collectOperationContributions, ct as operationCliOptions, dt as parseOperationInput, ft as operationInputJsonSchema, ht as resolveViteHubProjectRoot, jt as withStdoutOnStderr, kt as getStableStdoutWrite, lt as operationCliPath, mt as setupCommandNames, nt as withViteStageEnvironment, ot as createOperationRegistry, pt as reservedOperationNamespaces, rt as callOperation, st as operationCall, t as createProvisionNamespace, tt as loadAllEnv, ut as operationsOf, v as consoleClient } from "./provision-akHsvf-B.js";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
import process$1 from "node:process";
|
|
@@ -733,7 +733,7 @@ function helpOf(operation, flags) {
|
|
|
733
733
|
];
|
|
734
734
|
const described = flags.map((flag) => ` ${positional.includes(flag.key) ? `<${kebab(flag.key)}>` : `--${kebab(flag.key)}`} ${describeFlag(flag)}${flag.description ? `. ${flag.description}` : ""}`);
|
|
735
735
|
if (described.length) lines.push("Input:", ...described, "");
|
|
736
|
-
lines.push("Options:", " --input <json|@file> Pass the whole input as JSON or from a file. Flags override it.", " --json Print JSON.", ...operation.kind === "destructive" ? [" --yes Run without asking. This operation changes or removes data."] : [], " --url <origin> The app URL, such as https://app.example.com. Without it the command calls the running dev server.", " --timeout <ms> Wait this long for the answer. Default 30000.", " -h, --help Show this help.", "");
|
|
736
|
+
lines.push("Options:", " --input <json|@file> Pass the whole input as JSON or from a file. Flags override it.", " --json Print JSON.", ...operation.kind === "destructive" ? [" --yes Run without asking. This operation changes or removes data."] : [], " --url <origin> The app URL, such as https://app.example.com. Without it the command calls the running dev server.", " After `vitehub login`, the call to an app of the Console goes through the Console.", " --timeout <ms> Wait this long for the answer. Default 30000.", " -h, --help Show this help.", "");
|
|
737
737
|
return lines.join("\n");
|
|
738
738
|
}
|
|
739
739
|
function usageError(message) {
|
|
@@ -836,7 +836,7 @@ function parseCall(operation, flags, args, cwd) {
|
|
|
836
836
|
else if (name === "input") whole = readWholeInput(take(), cwd);
|
|
837
837
|
else if (name === "timeout") {
|
|
838
838
|
const timeout = Number(take());
|
|
839
|
-
if (!Number.isInteger(timeout) || timeout < 1) throw usageError("--timeout must be a whole number of milliseconds.");
|
|
839
|
+
if (!Number.isInteger(timeout) || timeout < 1 || timeout > 2147483647) throw usageError("--timeout must be a whole number of milliseconds between 1 and 2147483647.");
|
|
840
840
|
parsed.timeout = timeout;
|
|
841
841
|
} else {
|
|
842
842
|
const negated = name.startsWith("no-") && flags.some((flag) => flag.key === camel(name.slice(3)) && flag.type === "boolean");
|
|
@@ -905,6 +905,45 @@ async function confirm(operation, target) {
|
|
|
905
905
|
function acceptedRoots(rootDir) {
|
|
906
906
|
return [.../* @__PURE__ */ new Set([rootDir, resolveViteHubProjectRoot(rootDir)])];
|
|
907
907
|
}
|
|
908
|
+
async function throughConsole(url, context, signal) {
|
|
909
|
+
if (Object.keys(context.env).some((name) => name.startsWith("VITEHUB_CONSOLE_PRIVATE_KEY_") && context.env[name])) return;
|
|
910
|
+
const warnDiscoveryFailed = () => {
|
|
911
|
+
context.stderr.write("Warning: Console discovery failed. The CLI will call the app directly if time remains.\n");
|
|
912
|
+
};
|
|
913
|
+
try {
|
|
914
|
+
const credential = await readConsoleCredential(context.env, void 0, signal);
|
|
915
|
+
if (!credential) return;
|
|
916
|
+
const { body } = await consoleClient(context, credential, signal).request("/api/projects");
|
|
917
|
+
signal.throwIfAborted();
|
|
918
|
+
if (!Array.isArray(body.projects)) {
|
|
919
|
+
warnDiscoveryFailed();
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
if (body.cliForwarding !== true) return;
|
|
923
|
+
const projects = body.projects;
|
|
924
|
+
for (const project of projects) {
|
|
925
|
+
if (project === null || typeof project !== "object") continue;
|
|
926
|
+
const { id, publicKey, url: linked } = project;
|
|
927
|
+
if (typeof id === "string" && id && typeof publicKey === "string" && publicKey && typeof linked === "string" && sameApp(linked, url)) return {
|
|
928
|
+
authorization: `Bearer ${credential.token}`,
|
|
929
|
+
target: `${credential.origin}/p/${encodeURIComponent(id)}`
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
} catch {
|
|
933
|
+
warnDiscoveryFailed();
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
function sameApp(linked, url) {
|
|
937
|
+
const key = (value) => {
|
|
938
|
+
const parsed = new URL(value);
|
|
939
|
+
return `${parsed.origin}${parsed.pathname.replace(/\/+$/u, "")}`;
|
|
940
|
+
};
|
|
941
|
+
try {
|
|
942
|
+
return key(linked) === key(url);
|
|
943
|
+
} catch {
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
908
947
|
function resolveTarget(parsed, context) {
|
|
909
948
|
if (parsed.url) {
|
|
910
949
|
const message = appUrlError(parsed.url);
|
|
@@ -925,7 +964,7 @@ function resolveTarget(parsed, context) {
|
|
|
925
964
|
}
|
|
926
965
|
function featureOf(operation) {
|
|
927
966
|
const flags = flagsOf(operation);
|
|
928
|
-
const { command } = operationCliPath(operation);
|
|
967
|
+
const { command, namespace } = operationCliPath(operation);
|
|
929
968
|
return {
|
|
930
969
|
description: operation.description,
|
|
931
970
|
name: command,
|
|
@@ -957,14 +996,19 @@ function featureOf(operation) {
|
|
|
957
996
|
if (!(process.stdin.isTTY && process.stderr.isTTY) || !await confirm(operation, target)) return writeFailure(failureOf(cliErrorDiagnostics.CLI_R0004({ message: `${operation.name} changes or removes data and was not confirmed.` })), parsed, context);
|
|
958
997
|
confirmed = true;
|
|
959
998
|
}
|
|
960
|
-
const
|
|
999
|
+
const signal = AbortSignal.timeout(parsed.timeout ?? 3e4);
|
|
1000
|
+
const proxy = parsed.url ? await throughConsole(parsed.url, context, signal) : void 0;
|
|
1001
|
+
const rpcTarget = {
|
|
1002
|
+
...proxy ? { authorization: proxy.authorization } : {},
|
|
961
1003
|
confirmed,
|
|
962
1004
|
env: context.env,
|
|
963
1005
|
...context.fetch ? { fetch: context.fetch } : {},
|
|
964
1006
|
...resolved.roots ? { roots: resolved.roots } : {},
|
|
965
|
-
|
|
966
|
-
url: target
|
|
967
|
-
}
|
|
1007
|
+
signal,
|
|
1008
|
+
url: proxy?.target ?? target
|
|
1009
|
+
};
|
|
1010
|
+
let result = await callOperation(rpcTarget, operation.name, parsed.input);
|
|
1011
|
+
if (!result.ok && result.status === 404 && result.code === "CONSOLE_NOT_FOUND" && operation.name === "invocations.usage" && operation.kind === "read" && namespace === "agent" && command === "usage") result = await callOperation(rpcTarget, "usage.get", parsed.input);
|
|
968
1012
|
if (!result.ok) return writeFailure(result, parsed, context);
|
|
969
1013
|
const format = operationCliOptions(operation)?.format;
|
|
970
1014
|
const output = !parsed.json && format ? format(result.value) : `${JSON.stringify(result.value ?? null, null, 2)}\n`;
|
|
@@ -1355,7 +1399,7 @@ const hostEnvFeatures = {
|
|
|
1355
1399
|
{
|
|
1356
1400
|
description: "Compare the env names of the last build with the names on the linked host. Exits with 1 when a required name is missing. Never reads values.",
|
|
1357
1401
|
name: "diff",
|
|
1358
|
-
run: async (args, context) => await (await import("./env-
|
|
1402
|
+
run: async (args, context) => await (await import("./env-BiVwma4a.js").then((n) => n.n)).runEnvCommand({
|
|
1359
1403
|
...hostEnvFeatures.features[0],
|
|
1360
1404
|
name: "diff"
|
|
1361
1405
|
}, args, context),
|
|
@@ -1364,7 +1408,7 @@ const hostEnvFeatures = {
|
|
|
1364
1408
|
{
|
|
1365
1409
|
description: "Set the host variables of the build's env names from the shell and .env.<stage>, with the host CLI. Prints names, never values. Never deletes a host variable.",
|
|
1366
1410
|
name: "push",
|
|
1367
|
-
run: async (args, context) => await (await import("./env-
|
|
1411
|
+
run: async (args, context) => await (await import("./env-BiVwma4a.js").then((n) => n.n)).runEnvCommand({
|
|
1368
1412
|
...hostEnvFeatures.features[1],
|
|
1369
1413
|
name: "push"
|
|
1370
1414
|
}, args, context),
|
|
@@ -1373,14 +1417,14 @@ const hostEnvFeatures = {
|
|
|
1373
1417
|
{
|
|
1374
1418
|
description: "Write the env values of a stage from a self-hosted Console to .env.<stage>. Needs `vitehub login` and the owner or admin role.",
|
|
1375
1419
|
name: "pull",
|
|
1376
|
-
run: async (args, context) => await (await import("./console-env-
|
|
1420
|
+
run: async (args, context) => await (await import("./console-env-CYHb4owT.js")).envPullFeature.run(args, context),
|
|
1377
1421
|
usage: "vitehub env pull --from console [--stage <name>] [--project <id>] [--console <url>] [--yes] [--json]"
|
|
1378
1422
|
}
|
|
1379
1423
|
],
|
|
1380
1424
|
name: "env"
|
|
1381
1425
|
};
|
|
1382
1426
|
async function loadSetupCommands() {
|
|
1383
|
-
return (await import("./commands-
|
|
1427
|
+
return (await import("./commands-D0WSlS7h.js").then((n) => n.t)).setupCommands;
|
|
1384
1428
|
}
|
|
1385
1429
|
async function loadNuxtViteConfig(rootDir, command, mode) {
|
|
1386
1430
|
if (![
|