@lunora/cli 1.0.0-alpha.3 → 1.0.0-alpha.30
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/__assets__/package-og.svg +1 -1
- package/dist/bin.mjs +1 -1
- package/dist/index.d.mts +243 -114
- package/dist/index.d.ts +243 -114
- package/dist/index.mjs +7 -7
- package/dist/packem_chunks/handler.mjs +89 -7
- package/dist/packem_chunks/handler10.mjs +8 -14
- package/dist/packem_chunks/handler11.mjs +19 -189
- package/dist/packem_chunks/handler12.mjs +176 -115
- package/dist/packem_chunks/handler13.mjs +118 -52
- package/dist/packem_chunks/handler14.mjs +50 -43
- package/dist/packem_chunks/handler15.mjs +46 -67
- package/dist/packem_chunks/handler16.mjs +73 -37
- package/dist/packem_chunks/handler17.mjs +38 -100
- package/dist/packem_chunks/handler18.mjs +87 -154
- package/dist/packem_chunks/handler19.mjs +148 -67
- package/dist/packem_chunks/handler2.mjs +2 -2
- package/dist/packem_chunks/handler20.mjs +71 -76
- package/dist/packem_chunks/handler21.mjs +71 -288
- package/dist/packem_chunks/handler3.mjs +1 -1
- package/dist/packem_chunks/handler4.mjs +1 -1
- package/dist/packem_chunks/handler5.mjs +2 -2
- package/dist/packem_chunks/handler6.mjs +2 -2
- package/dist/packem_chunks/handler7.mjs +1 -1
- package/dist/packem_chunks/handler8.mjs +1 -1
- package/dist/packem_chunks/handler9.mjs +311 -12
- package/dist/packem_chunks/planDevCommand.mjs +46 -49
- package/dist/packem_chunks/runCodegenCommand.mjs +2 -2
- package/dist/packem_chunks/runDeployCommand.mjs +105 -15
- package/dist/packem_chunks/runInitCommand.mjs +1980 -77
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +5 -5
- package/dist/packem_chunks/runResetCommand.mjs +4 -4
- package/dist/packem_chunks/runRpcCommand.mjs +1 -1
- package/dist/packem_shared/{COMMANDS-CHw4zOZ9.mjs → COMMANDS-B0ftFD_3.mjs} +47 -21
- package/dist/packem_shared/{command-BDXcJCCJ.mjs → command-D3lB_4Az.mjs} +6 -1
- package/dist/packem_shared/{commands-DIQ3nf0C.mjs → commands-B-gR09Z_.mjs} +124 -22
- package/dist/packem_shared/{createLogger-CHPNjFw2.mjs → createLogger-B40gPzQo.mjs} +9 -4
- package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +61 -0
- package/dist/packem_shared/{diffSnapshots-RR2ZE8Ya.mjs → diffSnapshots-BeDvvNiF.mjs} +1 -1
- package/dist/packem_shared/{insertSchemaExtension-BuzF6-t2.mjs → insertSchemaExtension-DAqbfr9Z.mjs} +15 -10
- package/dist/packem_shared/{output-format-7gyGR3h8.mjs → output-format-wUvAN6AL.mjs} +1 -1
- package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +9 -0
- package/dist/packem_shared/runAddCommand-bnY6-HKb.mjs +4 -0
- package/dist/packem_shared/{schemaIrToSnapshot-aBTo7TM5.mjs → schemaIrToSnapshot-DdsljJT-.mjs} +1 -1
- package/dist/packem_shared/storage-BIsph-Vk.mjs +84 -0
- package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +658 -0
- package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +47 -0
- package/package.json +12 -11
- package/skills/lunora-setup-storage/SKILL.md +7 -3
- package/dist/packem_shared/features-ocSSpZtS.mjs +0 -24
- package/dist/packem_shared/runAddCommand-3I3JFZUG.mjs +0 -4
- /package/dist/packem_shared/{defaultSpawner-DxI3mebw.mjs → createRecordingSpawner-DxI3mebw.mjs} +0 -0
|
@@ -1,94 +1,89 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { runCodegen } from '@lunora/codegen';
|
|
4
|
+
import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
|
|
5
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
6
|
+
import { v as validateOutputFormat, i as isJsonFormat, p as printJson, l as loggerForFormat } from '../packem_shared/output-format-wUvAN6AL.mjs';
|
|
7
|
+
import { r as runSchemaDriftGate } from '../packem_shared/schema-drift-gate-BtBt0as0.mjs';
|
|
8
|
+
import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
|
|
9
|
+
import { validateWranglerProject } from '@lunora/config';
|
|
6
10
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
for (const candidate of ["wrangler.jsonc", "wrangler.json"]) {
|
|
11
|
-
const fullPath = join(projectRoot, candidate);
|
|
12
|
-
if (existsSync(fullPath)) {
|
|
13
|
-
return fullPath;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return void 0;
|
|
17
|
-
};
|
|
18
|
-
const readWrangler = (projectRoot) => {
|
|
19
|
-
const file = findWranglerFile(projectRoot);
|
|
20
|
-
if (!file) {
|
|
21
|
-
return void 0;
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
const parsed = parse(readFileSync(file, "utf8"));
|
|
25
|
-
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
26
|
-
} catch {
|
|
27
|
-
return void 0;
|
|
11
|
+
const runTypecheckStep = async (cwd, spawner) => {
|
|
12
|
+
if (!existsSync(join(cwd, "tsconfig.json"))) {
|
|
13
|
+
return { warning: "no tsconfig.json found — skipping TypeScript type-check" };
|
|
28
14
|
}
|
|
15
|
+
const result = await spawner({ args: ["exec", "tsc", "--noEmit", "-p", "tsconfig.json"], command: "pnpm", cwd });
|
|
16
|
+
return result.code === 0 ? {} : { error: `type errors: tsc --noEmit exited ${String(result.code)}` };
|
|
29
17
|
};
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
|
|
18
|
+
const reportVerifyResult = (logger, errors, warnings, wranglerPath) => {
|
|
19
|
+
if (errors.length === 0 && warnings.length === 0) {
|
|
20
|
+
logger.success("verify: project is valid");
|
|
21
|
+
return { code: 0, errors: [], warnings: [], wranglerPath };
|
|
33
22
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
return port;
|
|
23
|
+
if (warnings.length > 0) {
|
|
24
|
+
logger.warn("verify: warnings:");
|
|
25
|
+
for (const warning of warnings) {
|
|
26
|
+
logger.warn(` - ${warning}`);
|
|
39
27
|
}
|
|
40
28
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
return void 0;
|
|
46
|
-
}
|
|
47
|
-
const { routes } = wrangler;
|
|
48
|
-
if (Array.isArray(routes) && routes.length > 0) {
|
|
49
|
-
const first = routes[0];
|
|
50
|
-
if (typeof first === "string") {
|
|
51
|
-
return `https://${first.split("/")[0] ?? first}${STUDIO_PATH}`;
|
|
52
|
-
}
|
|
53
|
-
if (first !== null && typeof first === "object") {
|
|
54
|
-
const { pattern } = first;
|
|
55
|
-
if (typeof pattern === "string" && pattern.length > 0) {
|
|
56
|
-
return `https://${pattern.split("/")[0] ?? pattern}${STUDIO_PATH}`;
|
|
57
|
-
}
|
|
29
|
+
if (errors.length > 0) {
|
|
30
|
+
logger.error("verify: errors:");
|
|
31
|
+
for (const error of errors) {
|
|
32
|
+
logger.error(` - ${error}`);
|
|
58
33
|
}
|
|
34
|
+
return { code: 1, errors, warnings, wranglerPath };
|
|
59
35
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return `https://${name}.workers.dev${STUDIO_PATH}`;
|
|
63
|
-
}
|
|
64
|
-
return void 0;
|
|
36
|
+
logger.success("verify: project is valid (with warnings)");
|
|
37
|
+
return { code: 0, errors: [], warnings, wranglerPath };
|
|
65
38
|
};
|
|
66
|
-
const
|
|
39
|
+
const runVerifyCommand = async (options) => {
|
|
67
40
|
const cwd = options.cwd ?? process.cwd();
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!url) {
|
|
74
|
-
logger.error("view --remote: could not determine the remote URL from wrangler config (set `routes` or `name`).");
|
|
75
|
-
return { code: 1, url: void 0 };
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
url = `http://localhost:${String(resolveDevPort(wrangler))}${STUDIO_PATH}`;
|
|
41
|
+
const logger = loggerForFormat(options.format, options.logger);
|
|
42
|
+
const formatError = validateOutputFormat("verify", options.format);
|
|
43
|
+
if (formatError !== void 0) {
|
|
44
|
+
options.logger.error(formatError);
|
|
45
|
+
return { code: 1, error: formatError, errors: [], warnings: [], wranglerPath: void 0 };
|
|
79
46
|
}
|
|
80
|
-
|
|
47
|
+
const validation = validateWranglerProject({ projectRoot: cwd });
|
|
48
|
+
const errors = [...validation.report.errors];
|
|
49
|
+
const warnings = [...validation.report.warnings];
|
|
81
50
|
try {
|
|
82
|
-
|
|
51
|
+
const codegen = runCodegen({ apiSpec: options.apiSpec, dryRun: true, projectRoot: cwd });
|
|
52
|
+
const gate = runSchemaDriftGate({ allowDrift: options.allowSchemaDrift === true, codegen, logger, readOnly: true });
|
|
53
|
+
if (gate.blocked) {
|
|
54
|
+
errors.push(gate.reason);
|
|
55
|
+
}
|
|
83
56
|
} catch (error) {
|
|
84
57
|
const message = error instanceof Error ? error.message : String(error);
|
|
85
|
-
|
|
86
|
-
|
|
58
|
+
errors.push(`codegen failed: ${message}`);
|
|
59
|
+
}
|
|
60
|
+
if (options.typecheck !== false) {
|
|
61
|
+
const typecheck = await runTypecheckStep(cwd, options.spawner ?? defaultSpawner);
|
|
62
|
+
if (typecheck.error !== void 0) {
|
|
63
|
+
errors.push(typecheck.error);
|
|
64
|
+
}
|
|
65
|
+
if (typecheck.warning !== void 0) {
|
|
66
|
+
warnings.push(typecheck.warning);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const result = reportVerifyResult(logger, errors, warnings, validation.wranglerPath);
|
|
70
|
+
if (isJsonFormat(options.format)) {
|
|
71
|
+
printJson(result);
|
|
87
72
|
}
|
|
88
|
-
return
|
|
73
|
+
return result;
|
|
89
74
|
};
|
|
90
|
-
const execute = defineHandler(
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
const execute = defineHandler(async ({ cwd, logger, options }) => {
|
|
76
|
+
const result = await runVerifyCommand({
|
|
77
|
+
allowSchemaDrift: options.allowSchemaDrift === true,
|
|
78
|
+
apiSpec: parseApiSpec(options.apiSpec),
|
|
79
|
+
cwd,
|
|
80
|
+
format: options.format,
|
|
81
|
+
logger,
|
|
82
|
+
// `--no-typecheck` is declared as a `no-*` option but cerebro exposes it
|
|
83
|
+
// under the negated `typecheck` key (false when passed, true when absent).
|
|
84
|
+
typecheck: options.typecheck === false ? false : void 0
|
|
85
|
+
});
|
|
86
|
+
return { code: result.code };
|
|
87
|
+
});
|
|
93
88
|
|
|
94
|
-
export { execute,
|
|
89
|
+
export { execute, runVerifyCommand };
|
|
@@ -1,311 +1,94 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
5
|
-
import {
|
|
6
|
-
import { execFile } from 'node:child_process';
|
|
3
|
+
import { parse } from 'jsonc-parser';
|
|
4
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
5
|
+
import { o as openUrl } from '../packem_shared/open-url-Dfq6fAyT.mjs';
|
|
7
6
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const DEFAULT_DEV_PORT = 8787;
|
|
8
|
+
const STUDIO_PATH = "/_lunora/studio";
|
|
9
|
+
const findWranglerFile = (projectRoot) => {
|
|
10
|
+
for (const candidate of ["wrangler.jsonc", "wrangler.json"]) {
|
|
11
|
+
const fullPath = join(projectRoot, candidate);
|
|
12
|
+
if (existsSync(fullPath)) {
|
|
13
|
+
return fullPath;
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
|
-
return
|
|
16
|
+
return void 0;
|
|
13
17
|
};
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
const parseSecretNames = (stdout) => {
|
|
20
|
-
let parsed;
|
|
21
|
-
try {
|
|
22
|
-
parsed = JSON.parse(stdout);
|
|
23
|
-
} catch {
|
|
18
|
+
const readWrangler = (projectRoot) => {
|
|
19
|
+
const file = findWranglerFile(projectRoot);
|
|
20
|
+
if (!file) {
|
|
24
21
|
return void 0;
|
|
25
22
|
}
|
|
26
|
-
|
|
23
|
+
try {
|
|
24
|
+
const parsed = parse(readFileSync(file, "utf8"));
|
|
25
|
+
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
26
|
+
} catch {
|
|
27
27
|
return void 0;
|
|
28
28
|
}
|
|
29
|
-
const names = parsed.map((entry) => entry !== null && typeof entry === "object" ? entry.name : void 0).filter((name) => typeof name === "string" && name.length > 0);
|
|
30
|
-
return [...names].toSorted((a, b) => a.localeCompare(b));
|
|
31
|
-
};
|
|
32
|
-
const listRemoteSecrets = async (inputs) => {
|
|
33
|
-
const args = ["exec", "wrangler", "secret", "list", "--format", "json"];
|
|
34
|
-
if (inputs.env !== void 0) {
|
|
35
|
-
args.push("--env", inputs.env);
|
|
36
|
-
}
|
|
37
|
-
if (inputs.temporary) {
|
|
38
|
-
args.push("--temporary");
|
|
39
|
-
}
|
|
40
|
-
const runner = inputs.runner ?? defaultRunner;
|
|
41
|
-
const result = await runner("pnpm", args, inputs.cwd);
|
|
42
|
-
if (result.code !== 0) {
|
|
43
|
-
return { error: result.stderr.trim() || `wrangler secret list exited ${String(result.code)}`, names: [], ok: false };
|
|
44
|
-
}
|
|
45
|
-
const names = parseSecretNames(result.stdout);
|
|
46
|
-
if (names === void 0) {
|
|
47
|
-
return { error: "could not parse `wrangler secret list --format json` output", names: [], ok: false };
|
|
48
|
-
}
|
|
49
|
-
return { names, ok: true };
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const NEWLINE_PRESENT = /[\r\n]/u;
|
|
53
|
-
const UNREPRESENTABLE_PRESENT = /["\\]/u;
|
|
54
|
-
const parseDevVariables = (content) => {
|
|
55
|
-
const map = /* @__PURE__ */ new Map();
|
|
56
|
-
for (const entry of parseDevVariableEntries(content)) {
|
|
57
|
-
map.set(entry.key, entry);
|
|
58
|
-
}
|
|
59
|
-
return map;
|
|
60
|
-
};
|
|
61
|
-
const serializeDevVariables = (map) => {
|
|
62
|
-
const lines = [];
|
|
63
|
-
for (const entry of map.values()) {
|
|
64
|
-
lines.push(`${entry.key}="${entry.value}"`);
|
|
65
|
-
}
|
|
66
|
-
return `${lines.join("\n")}
|
|
67
|
-
`;
|
|
68
29
|
};
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
return `${value.slice(0, 4)}${"*".repeat(Math.min(8, value.length - 4))}`;
|
|
74
|
-
};
|
|
75
|
-
const loadDevVariables = (devVariablesPath) => {
|
|
76
|
-
if (!existsSync(devVariablesPath)) {
|
|
77
|
-
return /* @__PURE__ */ new Map();
|
|
78
|
-
}
|
|
79
|
-
return parseDevVariables(readFileSync(devVariablesPath, "utf8"));
|
|
80
|
-
};
|
|
81
|
-
const runEnvList = (context) => {
|
|
82
|
-
const map = loadDevVariables(context.devVariablesPath);
|
|
83
|
-
if (map.size === 0) {
|
|
84
|
-
context.logger.info(`${DEV_VARS_FILE}: (empty)`);
|
|
85
|
-
return { code: 0, descriptors: [] };
|
|
86
|
-
}
|
|
87
|
-
for (const entry of map.values()) {
|
|
88
|
-
context.logger.info(`${entry.key}=${redact(entry.value)}`);
|
|
89
|
-
}
|
|
90
|
-
return { code: 0, descriptors: [] };
|
|
91
|
-
};
|
|
92
|
-
const runEnvGet = (context) => {
|
|
93
|
-
const { devVariablesPath, logger, options } = context;
|
|
94
|
-
if (!options.key) {
|
|
95
|
-
logger.error("env get requires a key. Usage: lunora env get <KEY>");
|
|
96
|
-
return { code: 1, descriptors: [] };
|
|
97
|
-
}
|
|
98
|
-
const entry = loadDevVariables(devVariablesPath).get(options.key);
|
|
99
|
-
if (!entry) {
|
|
100
|
-
logger.error(`env: ${options.key} is not set in ${DEV_VARS_FILE}`);
|
|
101
|
-
return { code: 1, descriptors: [] };
|
|
102
|
-
}
|
|
103
|
-
process.stdout.write(`${entry.value}
|
|
104
|
-
`);
|
|
105
|
-
return { code: 0, descriptors: [] };
|
|
106
|
-
};
|
|
107
|
-
const runEnvSet = (context) => {
|
|
108
|
-
const { devVariablesPath, logger, options } = context;
|
|
109
|
-
if (!options.key) {
|
|
110
|
-
logger.error("env set requires a key. Usage: lunora env set <KEY> <VALUE>");
|
|
111
|
-
return { code: 1, descriptors: [] };
|
|
112
|
-
}
|
|
113
|
-
if (!DEV_VARS_KEY_PATTERN.test(options.key)) {
|
|
114
|
-
logger.error(`env: invalid key "${options.key}" — must match [A-Za-z_][A-Za-z0-9_]*`);
|
|
115
|
-
return { code: 1, descriptors: [] };
|
|
116
|
-
}
|
|
117
|
-
if (options.value === void 0) {
|
|
118
|
-
logger.error("env set requires a value. Usage: lunora env set <KEY> <VALUE>");
|
|
119
|
-
return { code: 1, descriptors: [] };
|
|
120
|
-
}
|
|
121
|
-
if (NEWLINE_PRESENT.test(options.value)) {
|
|
122
|
-
logger.error(`env: value for "${options.key}" contains a newline, which .dev.vars cannot represent`);
|
|
123
|
-
return { code: 1, descriptors: [] };
|
|
124
|
-
}
|
|
125
|
-
if (UNREPRESENTABLE_PRESENT.test(options.value)) {
|
|
126
|
-
logger.error(`env: value for "${options.key}" contains a double-quote or backslash, which .dev.vars cannot round-trip`);
|
|
127
|
-
return { code: 1, descriptors: [] };
|
|
30
|
+
const resolveDevPort = (wrangler) => {
|
|
31
|
+
if (!wrangler) {
|
|
32
|
+
return DEFAULT_DEV_PORT;
|
|
128
33
|
}
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
const runEnvUnset = (context) => {
|
|
136
|
-
const { devVariablesPath, logger, options } = context;
|
|
137
|
-
if (!options.key) {
|
|
138
|
-
logger.error("env unset requires a key. Usage: lunora env unset <KEY>");
|
|
139
|
-
return { code: 1, descriptors: [] };
|
|
140
|
-
}
|
|
141
|
-
const map = loadDevVariables(devVariablesPath);
|
|
142
|
-
if (!map.delete(options.key)) {
|
|
143
|
-
logger.warn(`env: ${options.key} was not set in ${DEV_VARS_FILE}`);
|
|
144
|
-
return { code: 0, descriptors: [] };
|
|
34
|
+
const { dev } = wrangler;
|
|
35
|
+
if (dev !== null && typeof dev === "object") {
|
|
36
|
+
const { port } = dev;
|
|
37
|
+
if (typeof port === "number" && Number.isFinite(port)) {
|
|
38
|
+
return port;
|
|
39
|
+
}
|
|
145
40
|
}
|
|
146
|
-
|
|
147
|
-
logger.success(`env: unset ${options.key} in ${DEV_VARS_FILE}`);
|
|
148
|
-
return { code: 0, descriptors: [] };
|
|
41
|
+
return DEFAULT_DEV_PORT;
|
|
149
42
|
};
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
logger.error("env push uploads secrets to Cloudflare. Re-run with --yes to confirm.");
|
|
154
|
-
return { code: 1, descriptors: [] };
|
|
155
|
-
}
|
|
156
|
-
const map = loadDevVariables(devVariablesPath);
|
|
157
|
-
if (map.size === 0) {
|
|
158
|
-
logger.warn(`${DEV_VARS_FILE}: nothing to push (empty)`);
|
|
159
|
-
return { code: 0, descriptors: [] };
|
|
43
|
+
const resolveRemoteUrl = (wrangler) => {
|
|
44
|
+
if (!wrangler) {
|
|
45
|
+
return void 0;
|
|
160
46
|
}
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
args.push("--env", "production");
|
|
167
|
-
}
|
|
168
|
-
if (options.temporary) {
|
|
169
|
-
args.push("--temporary");
|
|
47
|
+
const { routes } = wrangler;
|
|
48
|
+
if (Array.isArray(routes) && routes.length > 0) {
|
|
49
|
+
const first = routes[0];
|
|
50
|
+
if (typeof first === "string") {
|
|
51
|
+
return `https://${first.split("/")[0] ?? first}${STUDIO_PATH}`;
|
|
170
52
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// pipe it through the spawner's `input` channel so the secret
|
|
177
|
-
// never lands on the command line, in env, or in shell history.
|
|
178
|
-
input: entry.value
|
|
179
|
-
};
|
|
180
|
-
descriptors.push(descriptor);
|
|
181
|
-
logger.info(`pushing ${entry.key} -> wrangler secret${options.prod ? " (production)" : ""}`);
|
|
182
|
-
const result = await spawner(descriptor);
|
|
183
|
-
if (result.code !== 0) {
|
|
184
|
-
logger.error(`env push: failed at ${entry.key} (exit ${String(result.code)})`);
|
|
185
|
-
return { code: result.code, descriptors };
|
|
53
|
+
if (first !== null && typeof first === "object") {
|
|
54
|
+
const { pattern } = first;
|
|
55
|
+
if (typeof pattern === "string" && pattern.length > 0) {
|
|
56
|
+
return `https://${pattern.split("/")[0] ?? pattern}${STUDIO_PATH}`;
|
|
57
|
+
}
|
|
186
58
|
}
|
|
187
59
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
const fetchRemoteSecretNames = (context) => {
|
|
192
|
-
const lister = context.options.secretLister ?? listRemoteSecrets;
|
|
193
|
-
return lister({
|
|
194
|
-
cwd: context.cwd,
|
|
195
|
-
env: context.options.prod ? "production" : void 0,
|
|
196
|
-
temporary: context.options.temporary
|
|
197
|
-
});
|
|
198
|
-
};
|
|
199
|
-
const runEnvDiff = async (context) => {
|
|
200
|
-
const { devVariablesPath, logger } = context;
|
|
201
|
-
const remote = await fetchRemoteSecretNames(context);
|
|
202
|
-
if (!remote.ok) {
|
|
203
|
-
logger.error(`env diff: ${remote.error ?? "failed to list remote secrets"}`);
|
|
204
|
-
return { code: 1, descriptors: [] };
|
|
205
|
-
}
|
|
206
|
-
const localKeys = new Set(loadDevVariables(devVariablesPath).keys());
|
|
207
|
-
const remoteKeys = new Set(remote.names);
|
|
208
|
-
const localOnly = [...localKeys].filter((key) => !remoteKeys.has(key)).toSorted((a, b) => a.localeCompare(b));
|
|
209
|
-
const remoteOnly = remote.names.filter((name) => !localKeys.has(name));
|
|
210
|
-
const both = [...localKeys].filter((key) => remoteKeys.has(key)).toSorted((a, b) => a.localeCompare(b));
|
|
211
|
-
for (const key of localOnly) {
|
|
212
|
-
logger.info(`local only (run \`lunora env push\`): ${key}`);
|
|
213
|
-
}
|
|
214
|
-
for (const key of remoteOnly) {
|
|
215
|
-
logger.info(`remote only (in Cloudflare, not ${DEV_VARS_FILE}): ${key}`);
|
|
216
|
-
}
|
|
217
|
-
logger.info(`in both: ${String(both.length)} secret(s)`);
|
|
218
|
-
if (localOnly.length === 0 && remoteOnly.length === 0) {
|
|
219
|
-
logger.success("env diff: local and remote secret names match");
|
|
220
|
-
}
|
|
221
|
-
return { code: 0, descriptors: [] };
|
|
222
|
-
};
|
|
223
|
-
const runEnvDoctor = (context) => {
|
|
224
|
-
const { cwd, devVariablesPath, logger } = context;
|
|
225
|
-
const examplePath = join(cwd, DEV_VARS_EXAMPLE_FILE);
|
|
226
|
-
if (!existsSync(examplePath)) {
|
|
227
|
-
logger.info(`env doctor: no ${DEV_VARS_EXAMPLE_FILE} to check against — nothing to validate.`);
|
|
228
|
-
return { code: 0, descriptors: [] };
|
|
229
|
-
}
|
|
230
|
-
const exampleKeys = parseDevVariableEntries(readFileSync(examplePath, "utf8")).map((entry) => entry.key);
|
|
231
|
-
const current = loadDevVariables(devVariablesPath);
|
|
232
|
-
if (!existsSync(devVariablesPath)) {
|
|
233
|
-
logger.error(`env doctor: ${DEV_VARS_FILE} is missing. Run \`lunora dev\` to scaffold it, or \`lunora env set <KEY> <VALUE>\`.`);
|
|
234
|
-
logger.info(`expected (from ${DEV_VARS_EXAMPLE_FILE}): ${exampleKeys.join(", ")}`);
|
|
235
|
-
return { code: 1, descriptors: [] };
|
|
60
|
+
const { name } = wrangler;
|
|
61
|
+
if (typeof name === "string" && name.length > 0) {
|
|
62
|
+
return `https://${name}.workers.dev${STUDIO_PATH}`;
|
|
236
63
|
}
|
|
237
|
-
|
|
238
|
-
const placeholders = [...current.values()].filter((entry) => isPlaceholderValue(entry.value)).map((entry) => entry.key);
|
|
239
|
-
const exampleKeySet = new Set(exampleKeys);
|
|
240
|
-
const extra = [...current.keys()].filter((key) => !exampleKeySet.has(key));
|
|
241
|
-
for (const key of missing) {
|
|
242
|
-
logger.error(`missing: ${key} is in ${DEV_VARS_EXAMPLE_FILE} but not ${DEV_VARS_FILE}`);
|
|
243
|
-
}
|
|
244
|
-
for (const key of placeholders) {
|
|
245
|
-
logger.error(`unset: ${key} still has a placeholder value`);
|
|
246
|
-
}
|
|
247
|
-
for (const key of extra) {
|
|
248
|
-
logger.info(`extra: ${key} is set locally but not listed in ${DEV_VARS_EXAMPLE_FILE}`);
|
|
249
|
-
}
|
|
250
|
-
if (missing.length === 0 && placeholders.length === 0) {
|
|
251
|
-
logger.success(`env doctor: ${DEV_VARS_FILE} looks good (${String(current.size)} var(s)).`);
|
|
252
|
-
return { code: 0, descriptors: [] };
|
|
253
|
-
}
|
|
254
|
-
return { code: 1, descriptors: [] };
|
|
64
|
+
return void 0;
|
|
255
65
|
};
|
|
256
|
-
const
|
|
66
|
+
const runViewCommand = async (options) => {
|
|
257
67
|
const cwd = options.cwd ?? process.cwd();
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return runEnvDiff(context);
|
|
267
|
-
}
|
|
268
|
-
case "doctor": {
|
|
269
|
-
return runEnvDoctor(context);
|
|
270
|
-
}
|
|
271
|
-
case "get": {
|
|
272
|
-
return runEnvGet(context);
|
|
273
|
-
}
|
|
274
|
-
case "list": {
|
|
275
|
-
return runEnvList(context);
|
|
276
|
-
}
|
|
277
|
-
case "push": {
|
|
278
|
-
return runEnvPush(context);
|
|
279
|
-
}
|
|
280
|
-
case "set": {
|
|
281
|
-
return runEnvSet(context);
|
|
282
|
-
}
|
|
283
|
-
case "unset": {
|
|
284
|
-
return runEnvUnset(context);
|
|
285
|
-
}
|
|
286
|
-
default: {
|
|
287
|
-
options.logger.error(`env: unknown subcommand "${options.subcommand}"`);
|
|
288
|
-
return { code: 1, descriptors: [] };
|
|
68
|
+
const wrangler = readWrangler(cwd);
|
|
69
|
+
const { logger } = options;
|
|
70
|
+
let url;
|
|
71
|
+
if (options.remote) {
|
|
72
|
+
url = resolveRemoteUrl(wrangler);
|
|
73
|
+
if (!url) {
|
|
74
|
+
logger.error("view --remote: could not determine the remote URL from wrangler config (set `routes` or `name`).");
|
|
75
|
+
return { code: 1, url: void 0 };
|
|
289
76
|
}
|
|
77
|
+
} else {
|
|
78
|
+
url = `http://localhost:${String(resolveDevPort(wrangler))}${STUDIO_PATH}`;
|
|
290
79
|
}
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
logger.error(`
|
|
297
|
-
return { code: 1 };
|
|
80
|
+
logger.info(`opening ${url}`);
|
|
81
|
+
try {
|
|
82
|
+
await openUrl(url, { opener: options.opener });
|
|
83
|
+
} catch (error) {
|
|
84
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
85
|
+
logger.error(`view: failed to open URL: ${message}`);
|
|
86
|
+
return { code: 1, url };
|
|
298
87
|
}
|
|
299
|
-
return
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
subcommand: sub,
|
|
305
|
-
temporary: options.temporary === true,
|
|
306
|
-
value: argument[2],
|
|
307
|
-
yes: options.yes === true
|
|
308
|
-
});
|
|
309
|
-
});
|
|
88
|
+
return { code: 0, url };
|
|
89
|
+
};
|
|
90
|
+
const execute = defineHandler(
|
|
91
|
+
({ cwd, logger, options }) => runViewCommand({ cwd, logger, remote: options.remote === true })
|
|
92
|
+
);
|
|
310
93
|
|
|
311
|
-
export { execute,
|
|
94
|
+
export { execute, runViewCommand };
|
|
@@ -2,7 +2,7 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { r as resolveAdminBaseUrl } from '../packem_shared/admin-url-4UzT-CI4.mjs';
|
|
5
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
5
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
6
6
|
import { a as resolveProductionWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
|
|
7
7
|
import { runExportCommand, runImportCommand } from '../packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs';
|
|
8
8
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
|
|
2
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
2
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
3
3
|
import { runDeployCommand } from './runDeployCommand.mjs';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_OUT_DIR = ".lunora/build";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
1
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
2
2
|
import { i as isDockerAvailable } from '../packem_shared/docker-hMQ97KSQ.mjs';
|
|
3
|
-
import { defaultSpawner } from '../packem_shared/
|
|
3
|
+
import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
|
|
4
4
|
|
|
5
5
|
const SUBCOMMANDS = /* @__PURE__ */ new Set(["build", "delete", "images", "info", "list", "push"]);
|
|
6
6
|
const NEEDS_DOCKER = /* @__PURE__ */ new Set(["build", "push"]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
2
|
-
import { defaultSpawner } from '../packem_shared/
|
|
1
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
2
|
+
import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
|
|
3
3
|
|
|
4
4
|
const withEnv = (args, env) => {
|
|
5
5
|
if (env !== void 0) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
1
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
2
2
|
import { o as openUrl } from '../packem_shared/open-url-Dfq6fAyT.mjs';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_DOCS_URL = "https://lunora.anolilab.dev/docs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { findWranglerFile, readWranglerJsonc, validateWranglerConfig, isPlaceholderValue, DEV_VARS_FILE, parseDevVariableEntries, inferLunoraBindings } from '@lunora/config';
|
|
4
|
-
import { d as defineHandler } from '../packem_shared/command-
|
|
4
|
+
import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
|
|
5
5
|
|
|
6
6
|
const SECRET_KEY_PATTERN = /(?:KEY|PASSWORD|SECRET|TOKEN)$/u;
|
|
7
7
|
const isD1PlaceholderId = (databaseId) => {
|