@vite-hub/cli 0.0.4 → 0.3.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/README.md +82 -12
- 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 +38 -10
- package/dist/index.js +1462 -218
- 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 +46 -16
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { m as cliErrorDiagnostics } from "./provision-D8OvBBzi.js";
|
|
2
|
+
import { formatRuntimeDiagnosticError } from "@vite-hub/runtime";
|
|
3
|
+
//#region src/setup/envelope.ts
|
|
4
|
+
/** Exit codes of the setup commands. */
|
|
5
|
+
const setupExitCodes = {
|
|
6
|
+
done: 0,
|
|
7
|
+
error: 1,
|
|
8
|
+
inputNeeded: 2,
|
|
9
|
+
conflict: 3,
|
|
10
|
+
stalePlan: 4
|
|
11
|
+
};
|
|
12
|
+
function isDiagnostic(error) {
|
|
13
|
+
return error instanceof Error && typeof Reflect.get(error, "code") === "string" && typeof Reflect.get(error, "why") === "string";
|
|
14
|
+
}
|
|
15
|
+
function toSetupError(error) {
|
|
16
|
+
const diagnostic = isDiagnostic(error) ? error : cliErrorDiagnostics.CLI_SETUP_FAILED({ message: error instanceof Error ? error.message : String(error) });
|
|
17
|
+
const why = diagnostic.why.replace(/^\[vitehub\] /u, "");
|
|
18
|
+
return {
|
|
19
|
+
code: diagnostic.code,
|
|
20
|
+
message: /^.*?[.!?](?=\s|$)/u.exec(why)?.[0] ?? why,
|
|
21
|
+
why,
|
|
22
|
+
...diagnostic.fix ? { fix: diagnostic.fix } : {},
|
|
23
|
+
...diagnostic.docs ? { docs: diagnostic.docs } : {}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Prints one JSON document with `schemaVersion: 1` on stdout. */
|
|
27
|
+
function writeSetupJson(context, data) {
|
|
28
|
+
context.stdout.write(`${JSON.stringify({
|
|
29
|
+
schemaVersion: 1,
|
|
30
|
+
...data
|
|
31
|
+
})}\n`);
|
|
32
|
+
}
|
|
33
|
+
/** Adds the exit code and the missing input of a setup command to its diagnostic. */
|
|
34
|
+
function setupFailure(diagnostic, exitCode, details = {}) {
|
|
35
|
+
return Object.assign(diagnostic, {
|
|
36
|
+
details,
|
|
37
|
+
exitCode
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Whether `error` is a diagnostic that `setupFailure()` gave an exit code. */
|
|
41
|
+
function isSetupFailure(error) {
|
|
42
|
+
if (!(error instanceof Error)) return false;
|
|
43
|
+
const details = Reflect.get(error, "details");
|
|
44
|
+
return typeof Reflect.get(error, "exitCode") === "number" && typeof details === "object" && details !== null;
|
|
45
|
+
}
|
|
46
|
+
function formatMissing(missing) {
|
|
47
|
+
return missing.map((item) => {
|
|
48
|
+
const choices = item.choices ?? [];
|
|
49
|
+
if (choices.every((choice) => typeof choice === "string")) return `Missing: ${item.field}${choices.length ? ` (${choices.join(", ")})` : ""}\n`;
|
|
50
|
+
return `Missing: ${item.field}\n${choices.map((choice) => typeof choice === "string" ? ` ${choice}\n` : ` ${choice.id}${choice.name ? ` ${choice.name}` : ""}\n`).join("")}`;
|
|
51
|
+
}).join("");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Reports `error` as one JSON document on stdout with `--json`, else on stderr, and returns its exit code.
|
|
55
|
+
* A `SetupFailure` adds `missing`, `rerun`, and its `data` to the document. Any other error exits with 1.
|
|
56
|
+
*/
|
|
57
|
+
function writeSetupError(context, json, error) {
|
|
58
|
+
if (isSetupFailure(error)) {
|
|
59
|
+
const { data, missing, rerun } = error.details;
|
|
60
|
+
if (json) writeSetupJson(context, {
|
|
61
|
+
...data,
|
|
62
|
+
error: toSetupError(error),
|
|
63
|
+
...missing ? { missing } : {},
|
|
64
|
+
...rerun ? { rerun } : {}
|
|
65
|
+
});
|
|
66
|
+
else context.stderr.write(`${formatRuntimeDiagnosticError(error)}\n${formatMissing(missing ?? [])}${rerun ? `Run: ${rerun}\n` : ""}`);
|
|
67
|
+
return error.exitCode;
|
|
68
|
+
}
|
|
69
|
+
if (json) writeSetupJson(context, { error: toSetupError(error) });
|
|
70
|
+
else context.stderr.write(`${formatRuntimeDiagnosticError(error)}\n`);
|
|
71
|
+
return setupExitCodes.error;
|
|
72
|
+
}
|
|
73
|
+
/** Reads `--json` and `--help`. Throws `CLI_R0003` for any other argument. */
|
|
74
|
+
function readSetupArgs(args, usage) {
|
|
75
|
+
const unknown = args.find((arg) => arg !== "--json" && arg !== "-h" && arg !== "--help");
|
|
76
|
+
if (unknown !== void 0) throw cliErrorDiagnostics.CLI_R0003({ message: `[vitehub] Unknown argument ${JSON.stringify(unknown)}. Usage: ${usage}` });
|
|
77
|
+
return {
|
|
78
|
+
help: args.includes("-h") || args.includes("--help"),
|
|
79
|
+
json: args.includes("--json")
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** Rows as plain text columns, two spaces apart. */
|
|
83
|
+
function table(rows) {
|
|
84
|
+
const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
|
|
85
|
+
return rows.map((row) => row.map((cell, column) => cell.padEnd(widths[column])).join(" ").trimEnd()).join("\n");
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { table as a, setupFailure as i, readSetupArgs as n, writeSetupError as o, setupExitCodes as r, writeSetupJson as s, isSetupFailure as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { a as ProvisionProvider, c as HostCliRun, i as ViteHubCliProvision, n as ViteHubCliCommandNamespace, t as ViteHubCliCommand } from "./provision-C9p1wSzq.js";
|
|
1
2
|
//#region src/index.d.ts
|
|
2
3
|
interface ViteHubCliSpawnResult {
|
|
3
4
|
exitCode: number | null;
|
|
4
5
|
signal?: NodeJS.Signals | null;
|
|
6
|
+
stdout?: string;
|
|
5
7
|
}
|
|
6
8
|
interface ViteHubCliSpawnOptions {
|
|
7
9
|
cwd?: string;
|
|
8
10
|
env?: NodeJS.ProcessEnv;
|
|
9
11
|
stderr?: "inherit" | "pipe";
|
|
10
|
-
|
|
12
|
+
stdin?: "ignore" | "inherit";
|
|
13
|
+
stdout?: "inherit" | "pipe" | "stderr";
|
|
11
14
|
}
|
|
12
15
|
type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
|
|
13
16
|
interface ViteHubCliStreams {
|
|
@@ -16,7 +19,7 @@ interface ViteHubCliStreams {
|
|
|
16
19
|
}
|
|
17
20
|
interface ViteHubCliStream {
|
|
18
21
|
flush?: () => unknown;
|
|
19
|
-
write: (chunk: string | Uint8Array) => unknown;
|
|
22
|
+
write: (chunk: string | Uint8Array, encoding?: BufferEncoding | ((error?: Error | null) => void), callback?: (error?: Error | null) => void) => unknown;
|
|
20
23
|
}
|
|
21
24
|
type ViteHubCliEntrypointStream = {
|
|
22
25
|
flush: () => unknown;
|
|
@@ -26,16 +29,42 @@ type ViteHubCliEntrypointStream = {
|
|
|
26
29
|
write: (chunk: string | Uint8Array) => void | PromiseLike<unknown>;
|
|
27
30
|
};
|
|
28
31
|
interface ViteHubCliLoadedConfig {
|
|
32
|
+
/** The Nitro config that the plugins wrote. `vitehub inspect routes` reads its `handlers`. */
|
|
33
|
+
nitro?: unknown;
|
|
29
34
|
plugins: readonly unknown[];
|
|
30
35
|
root: string;
|
|
31
36
|
vitehubConfigResolved?: true;
|
|
32
37
|
}
|
|
33
|
-
interface RunViteHubCliOptions {
|
|
38
|
+
export interface RunViteHubCliOptions {
|
|
34
39
|
args?: string[];
|
|
40
|
+
/** Top-level commands that run before the project config loads, such as `vitehub status`. Defaults to the setup commands and `drain`. */
|
|
41
|
+
commands?: readonly ViteHubCliCommand[];
|
|
35
42
|
cwd?: string;
|
|
36
43
|
env?: NodeJS.ProcessEnv;
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
/** Namespaces that run without loading the project config, for example inside a deployed container. */
|
|
45
|
+
runtimeNamespaces?: ViteHubCliCommandNamespace[];
|
|
46
|
+
/**
|
|
47
|
+
* Features that run without loading the project config, for example commands that only talk to a server.
|
|
48
|
+
* Other features of a project namespace with the same name still load the config.
|
|
49
|
+
*/
|
|
50
|
+
runtimeFeatures?: ViteHubCliCommandNamespace[];
|
|
51
|
+
/**
|
|
52
|
+
* Project namespaces whose help needs no project, by name. `vitehub <namespace> --help` and
|
|
53
|
+
* `vitehub <namespace> <feature> --help` answer from them without loading the config, which takes seconds in a Nuxt
|
|
54
|
+
* app. Every feature of such a namespace must print its help for `-h` or `--help` before it reads the project.
|
|
55
|
+
*/
|
|
56
|
+
helpNamespaces?: Record<string, () => Promise<ViteHubCliCommandNamespace | undefined>>;
|
|
57
|
+
/** Optional guard for runtime features that have a project-level opt-out. */
|
|
58
|
+
runtimeFeatureGuard?: (namespace: string, feature: string, cwd: string) => boolean | Promise<boolean>;
|
|
59
|
+
/** Replaces `fetch` in commands that call a running app or a host API. */
|
|
60
|
+
fetch?: typeof fetch;
|
|
61
|
+
/** Replaces the host CLI runner of setup and provision commands, such as for `wrangler auth token`. */
|
|
62
|
+
runHostCli?: HostCliRun;
|
|
63
|
+
/** Replaces how `vitehub deploy` loads the Provision Steps of the project config for a host. */
|
|
64
|
+
loadProvision?: (host: ProvisionProvider) => Promise<ViteHubCliProvision>;
|
|
65
|
+
loadConfig?: (rootDir: string, command: "build" | "serve", mode?: string) => Promise<ViteHubCliLoadedConfig>;
|
|
66
|
+
loadNuxtViteConfig?: (rootDir: string, command: "build" | "serve", mode?: string) => Promise<{
|
|
67
|
+
nitro?: unknown;
|
|
39
68
|
plugins: readonly unknown[];
|
|
40
69
|
root?: string;
|
|
41
70
|
} | undefined>;
|
|
@@ -43,11 +72,10 @@ interface RunViteHubCliOptions {
|
|
|
43
72
|
stderr?: ViteHubCliStreams["stderr"];
|
|
44
73
|
stdout?: ViteHubCliStreams["stdout"];
|
|
45
74
|
}
|
|
46
|
-
interface RunViteHubCliEntrypointOptions extends Omit<RunViteHubCliOptions, "stderr" | "stdout"> {
|
|
75
|
+
export interface RunViteHubCliEntrypointOptions extends Omit<RunViteHubCliOptions, "stderr" | "stdout"> {
|
|
47
76
|
stderr?: ViteHubCliEntrypointStream;
|
|
48
77
|
stdout?: ViteHubCliEntrypointStream;
|
|
49
78
|
}
|
|
50
|
-
declare function runViteHubCli(options?: RunViteHubCliOptions): Promise<number>;
|
|
51
|
-
declare function runViteHubCliEntrypoint(options?: RunViteHubCliEntrypointOptions): void;
|
|
52
|
-
//#endregion
|
|
53
|
-
export { RunViteHubCliEntrypointOptions, RunViteHubCliOptions, runViteHubCli, runViteHubCliEntrypoint };
|
|
79
|
+
export declare function runViteHubCli(options?: RunViteHubCliOptions): Promise<number>;
|
|
80
|
+
export declare function runViteHubCliEntrypoint(options?: RunViteHubCliEntrypointOptions): void;
|
|
81
|
+
//#endregion
|