@lunora/cli 1.0.0-alpha.35 → 1.0.0-alpha.350

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.
Files changed (130) hide show
  1. package/LICENSE.md +33 -0
  2. package/README.md +1 -1
  3. package/dist/bin.mjs +2 -10
  4. package/dist/index.d.mts +1007 -372
  5. package/dist/index.d.ts +1007 -372
  6. package/dist/index.mjs +1 -19
  7. package/dist/packem_chunks/dispatch.mjs +1 -0
  8. package/dist/packem_chunks/handler.mjs +1 -160
  9. package/dist/packem_chunks/handler10.mjs +2 -16
  10. package/dist/packem_chunks/handler11.mjs +1 -22
  11. package/dist/packem_chunks/handler12.mjs +1 -192
  12. package/dist/packem_chunks/handler13.mjs +1 -131
  13. package/dist/packem_chunks/handler14.mjs +1 -65
  14. package/dist/packem_chunks/handler15.mjs +3 -58
  15. package/dist/packem_chunks/handler16.mjs +1 -80
  16. package/dist/packem_chunks/handler17.mjs +1 -43
  17. package/dist/packem_chunks/handler18.mjs +1 -105
  18. package/dist/packem_chunks/handler19.mjs +7 -170
  19. package/dist/packem_chunks/handler2.mjs +1 -114
  20. package/dist/packem_chunks/handler20.mjs +1 -94
  21. package/dist/packem_chunks/handler21.mjs +1 -94
  22. package/dist/packem_chunks/handler22.mjs +3 -0
  23. package/dist/packem_chunks/handler23.mjs +3 -0
  24. package/dist/packem_chunks/handler24.mjs +1 -0
  25. package/dist/packem_chunks/handler25.mjs +2 -0
  26. package/dist/packem_chunks/handler26.mjs +1 -0
  27. package/dist/packem_chunks/handler27.mjs +99 -0
  28. package/dist/packem_chunks/handler28.mjs +10 -0
  29. package/dist/packem_chunks/handler3.mjs +1 -204
  30. package/dist/packem_chunks/handler4.mjs +1 -33
  31. package/dist/packem_chunks/handler5.mjs +1 -49
  32. package/dist/packem_chunks/handler6.mjs +3 -91
  33. package/dist/packem_chunks/handler7.mjs +1 -42
  34. package/dist/packem_chunks/handler8.mjs +1 -174
  35. package/dist/packem_chunks/handler9.mjs +1 -315
  36. package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
  37. package/dist/packem_chunks/runDeployCommand.mjs +7 -594
  38. package/dist/packem_chunks/runDevCommand.mjs +2 -0
  39. package/dist/packem_chunks/runInitCommand.mjs +164 -1432
  40. package/dist/packem_chunks/runResetCommand.mjs +1 -41
  41. package/dist/packem_chunks/runRpcCommand.mjs +1 -68
  42. package/dist/packem_shared/COMMANDS-DRMcVnnw.mjs +1 -0
  43. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-CyIsI3S1.mjs +1 -0
  44. package/dist/packem_shared/EXIT_CODE-D_XCixv8.mjs +1 -0
  45. package/dist/packem_shared/admin-token-VdUnvnKW.mjs +1 -0
  46. package/dist/packem_shared/admin-url-DJB8P6Jh.mjs +1 -0
  47. package/dist/packem_shared/binding-manifest-file-CQ1eQYy1.mjs +2 -0
  48. package/dist/packem_shared/buildRegistryIndex-Dc8D8AR6.mjs +1 -0
  49. package/dist/packem_shared/catalog-CahzmDLV.mjs +1 -0
  50. package/dist/packem_shared/cli-CG_JgNKu.mjs +2 -0
  51. package/dist/packem_shared/codegen-error-AmH54ofi.mjs +3 -0
  52. package/dist/packem_shared/command-CAXl2A1S.mjs +1 -0
  53. package/dist/packem_shared/commands-Cg06JNO2.mjs +13 -0
  54. package/dist/packem_shared/createLogger-Cl18I8AX.mjs +2 -0
  55. package/dist/packem_shared/createRecordingSpawner-Ch7zuQQE.mjs +1 -0
  56. package/dist/packem_shared/deploy-target-DCWwiuAe.mjs +1 -0
  57. package/dist/packem_shared/diffSnapshots-WWwx-KvZ.mjs +5 -0
  58. package/dist/packem_shared/docker-DpVxvYpL.mjs +1 -0
  59. package/dist/packem_shared/health-probe-Bw9JFfIy.mjs +1 -0
  60. package/dist/packem_shared/import-BRM1hs7j.mjs +12 -0
  61. package/dist/packem_shared/index-oHZBGBwB.mjs +1 -0
  62. package/dist/packem_shared/insertSchemaExtension-DuiV6cba.mjs +8 -0
  63. package/dist/packem_shared/lint-ignore-report-DKZagpqk.mjs +2 -0
  64. package/dist/packem_shared/open-url-EnKy--w-.mjs +1 -0
  65. package/dist/packem_shared/output-format-B4eQHi5y.mjs +2 -0
  66. package/dist/packem_shared/parseManifest-CwPTKdtS.mjs +1 -0
  67. package/dist/packem_shared/path-containment-CgxYZggb.mjs +1 -0
  68. package/dist/packem_shared/plan-Cod9Cgll.mjs +5 -0
  69. package/dist/packem_shared/planDevCommand-1uuaH06D.mjs +1 -0
  70. package/dist/packem_shared/platform-diagnostics-Cn2g6Jh-.mjs +4 -0
  71. package/dist/packem_shared/prompt-cancelled-BvsNxg_Q.mjs +1 -0
  72. package/dist/packem_shared/render-lunora-error-C3OJY5wk.mjs +2 -0
  73. package/dist/packem_shared/resolve-DUCSc7jQ.mjs +5 -0
  74. package/dist/packem_shared/resolve-target-C_ZloTvd.mjs +1 -0
  75. package/dist/packem_shared/runAddCommand-BsOrlyfD.mjs +1 -0
  76. package/dist/packem_shared/runExportCommand-slAq5BCF.mjs +5 -0
  77. package/dist/packem_shared/runMigrateGenerateCommand-Ii_WMZEA.mjs +11 -0
  78. package/dist/packem_shared/schemaIrToSnapshot-BjK-0IRo.mjs +1 -0
  79. package/dist/packem_shared/secret-key-DsMeUoEg.mjs +1 -0
  80. package/dist/packem_shared/shared-D-zCOmgY.mjs +1 -0
  81. package/dist/packem_shared/storage-ChJtQ9E4.mjs +1 -0
  82. package/dist/packem_shared/tui-prompts-B3YwUhGw.mjs +4 -0
  83. package/dist/packem_shared/variables-acxcvVQa.mjs +1 -0
  84. package/dist/packem_shared/wrangler-name-Dsk5K1f-.mjs +1 -0
  85. package/dist/packem_shared/wrangler-secrets-3chIVv3H.mjs +1 -0
  86. package/package.json +39 -19
  87. package/skills/README.md +35 -17
  88. package/skills/lunora/SKILL.md +123 -9
  89. package/skills/lunora-create-package/SKILL.md +4 -3
  90. package/skills/lunora-deploy/SKILL.md +50 -11
  91. package/skills/lunora-functions/SKILL.md +215 -15
  92. package/skills/lunora-migration-helper/SKILL.md +74 -21
  93. package/skills/lunora-performance-audit/SKILL.md +78 -9
  94. package/skills/lunora-quickstart/SKILL.md +95 -27
  95. package/skills/lunora-realtime/SKILL.md +73 -39
  96. package/skills/lunora-setup-auth/SKILL.md +33 -6
  97. package/skills/lunora-setup-hyperdrive/SKILL.md +33 -13
  98. package/skills/lunora-setup-hyperdrive-global/SKILL.md +5 -0
  99. package/skills/lunora-setup-mail/SKILL.md +34 -28
  100. package/skills/lunora-setup-scheduler/SKILL.md +18 -14
  101. package/skills/lunora-setup-storage/SKILL.md +187 -27
  102. package/dist/packem_chunks/planDevCommand.mjs +0 -541
  103. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +0 -397
  104. package/dist/packem_shared/COMMANDS-B0ftFD_3.mjs +0 -948
  105. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
  106. package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
  107. package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
  108. package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
  109. package/dist/packem_shared/codegen-error-DJG-ghs_.mjs +0 -31
  110. package/dist/packem_shared/command-D3lB_4Az.mjs +0 -19
  111. package/dist/packem_shared/commands-B-gR09Z_.mjs +0 -845
  112. package/dist/packem_shared/createLogger-B40gPzQo.mjs +0 -78
  113. package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +0 -43
  114. package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
  115. package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +0 -161
  116. package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
  117. package/dist/packem_shared/insertSchemaExtension-DAqbfr9Z.mjs +0 -64
  118. package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
  119. package/dist/packem_shared/output-format-wUvAN6AL.mjs +0 -17
  120. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
  121. package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
  122. package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +0 -9
  123. package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
  124. package/dist/packem_shared/runAddCommand-bnY6-HKb.mjs +0 -4
  125. package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
  126. package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +0 -43
  127. package/dist/packem_shared/storage-BIsph-Vk.mjs +0 -84
  128. package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +0 -658
  129. package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
  130. package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +0 -47
@@ -1,315 +1 @@
1
- import { writeFileSync, existsSync, readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { DEV_VARS_FILE, DEV_VARS_KEY_PATTERN, generateSecretValue, DEV_VARS_EXAMPLE_FILE, parseDevVariableEntries, isPlaceholderValue, packageNamesFromBindings, inferLunoraBindings, requiredSecrets, isMintableSecretKey } from '@lunora/config';
4
- import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
5
- import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
6
- import { l as listRemoteSecrets } from '../packem_shared/wrangler-secrets-P2_ZUR-k.mjs';
7
-
8
- const NEWLINE_PRESENT = /[\r\n]/u;
9
- const UNREPRESENTABLE_PRESENT = /["\\]/u;
10
- const parseDevVariables = (content) => {
11
- const map = /* @__PURE__ */ new Map();
12
- for (const entry of parseDevVariableEntries(content)) {
13
- map.set(entry.key, entry);
14
- }
15
- return map;
16
- };
17
- const serializeDevVariables = (map) => {
18
- const lines = [];
19
- for (const entry of map.values()) {
20
- lines.push(`${entry.key}="${entry.value}"`);
21
- }
22
- return `${lines.join("\n")}
23
- `;
24
- };
25
- const redact = (value) => {
26
- if (value.length <= 4) {
27
- return "****";
28
- }
29
- return `${value.slice(0, 4)}${"*".repeat(Math.min(8, value.length - 4))}`;
30
- };
31
- const loadDevVariables = (devVariablesPath) => {
32
- if (!existsSync(devVariablesPath)) {
33
- return /* @__PURE__ */ new Map();
34
- }
35
- return parseDevVariables(readFileSync(devVariablesPath, "utf8"));
36
- };
37
- const runEnvList = (context) => {
38
- const map = loadDevVariables(context.devVariablesPath);
39
- if (map.size === 0) {
40
- context.logger.info(`${DEV_VARS_FILE}: (empty)`);
41
- return { code: 0, descriptors: [] };
42
- }
43
- for (const entry of map.values()) {
44
- context.logger.info(`${entry.key}=${redact(entry.value)}`);
45
- }
46
- return { code: 0, descriptors: [] };
47
- };
48
- const runEnvGet = (context) => {
49
- const { devVariablesPath, logger, options } = context;
50
- if (!options.key) {
51
- logger.error("env get requires a key. Usage: lunora env get <KEY>");
52
- return { code: 1, descriptors: [] };
53
- }
54
- const entry = loadDevVariables(devVariablesPath).get(options.key);
55
- if (!entry) {
56
- logger.error(`env: ${options.key} is not set in ${DEV_VARS_FILE}`);
57
- return { code: 1, descriptors: [] };
58
- }
59
- process.stdout.write(`${entry.value}
60
- `);
61
- return { code: 0, descriptors: [] };
62
- };
63
- const runEnvSet = (context) => {
64
- const { devVariablesPath, logger, options } = context;
65
- if (!options.key) {
66
- logger.error("env set requires a key. Usage: lunora env set <KEY> <VALUE>");
67
- return { code: 1, descriptors: [] };
68
- }
69
- if (!DEV_VARS_KEY_PATTERN.test(options.key)) {
70
- logger.error(`env: invalid key "${options.key}" — must match [A-Za-z_][A-Za-z0-9_]*`);
71
- return { code: 1, descriptors: [] };
72
- }
73
- if (options.value === void 0) {
74
- logger.error("env set requires a value. Usage: lunora env set <KEY> <VALUE>");
75
- return { code: 1, descriptors: [] };
76
- }
77
- if (NEWLINE_PRESENT.test(options.value)) {
78
- logger.error(`env: value for "${options.key}" contains a newline, which .dev.vars cannot represent`);
79
- return { code: 1, descriptors: [] };
80
- }
81
- if (UNREPRESENTABLE_PRESENT.test(options.value)) {
82
- logger.error(`env: value for "${options.key}" contains a double-quote or backslash, which .dev.vars cannot round-trip`);
83
- return { code: 1, descriptors: [] };
84
- }
85
- const map = loadDevVariables(devVariablesPath);
86
- map.set(options.key, { key: options.key, value: options.value });
87
- writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
88
- logger.success(`env: set ${options.key} (${redact(options.value)}) in ${DEV_VARS_FILE}`);
89
- return { code: 0, descriptors: [] };
90
- };
91
- const runEnvUnset = (context) => {
92
- const { devVariablesPath, logger, options } = context;
93
- if (!options.key) {
94
- logger.error("env unset requires a key. Usage: lunora env unset <KEY>");
95
- return { code: 1, descriptors: [] };
96
- }
97
- const map = loadDevVariables(devVariablesPath);
98
- if (!map.delete(options.key)) {
99
- logger.warn(`env: ${options.key} was not set in ${DEV_VARS_FILE}`);
100
- return { code: 0, descriptors: [] };
101
- }
102
- writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
103
- logger.success(`env: unset ${options.key} in ${DEV_VARS_FILE}`);
104
- return { code: 0, descriptors: [] };
105
- };
106
- const runEnvPush = async (context) => {
107
- const { devVariablesPath, logger, options } = context;
108
- if (!options.yes) {
109
- logger.error("env push uploads secrets to Cloudflare. Re-run with --yes to confirm.");
110
- return { code: 1, descriptors: [] };
111
- }
112
- const map = loadDevVariables(devVariablesPath);
113
- if (map.size === 0) {
114
- logger.warn(`${DEV_VARS_FILE}: nothing to push (empty)`);
115
- return { code: 0, descriptors: [] };
116
- }
117
- const spawner = options.spawner ?? defaultSpawner;
118
- const descriptors = [];
119
- for (const entry of map.values()) {
120
- const args = ["exec", "wrangler", "secret", "put", entry.key];
121
- if (options.prod) {
122
- args.push("--env", "production");
123
- }
124
- if (options.temporary) {
125
- args.push("--temporary");
126
- }
127
- const descriptor = {
128
- args,
129
- command: "pnpm",
130
- cwd: options.cwd ?? process.cwd(),
131
- // `wrangler secret put <name>` reads the value from stdin. We
132
- // pipe it through the spawner's `input` channel so the secret
133
- // never lands on the command line, in env, or in shell history.
134
- input: entry.value
135
- };
136
- descriptors.push(descriptor);
137
- logger.info(`pushing ${entry.key} -> wrangler secret${options.prod ? " (production)" : ""}`);
138
- const result = await spawner(descriptor);
139
- if (result.code !== 0) {
140
- logger.error(`env push: failed at ${entry.key} (exit ${String(result.code)})`);
141
- return { code: result.code, descriptors };
142
- }
143
- }
144
- logger.success(`env: pushed ${String(map.size)} secret(s)`);
145
- return { code: 0, descriptors };
146
- };
147
- const fetchRemoteSecretNames = (context) => {
148
- const lister = context.options.secretLister ?? listRemoteSecrets;
149
- return lister({
150
- cwd: context.cwd,
151
- env: context.options.prod ? "production" : void 0,
152
- temporary: context.options.temporary
153
- });
154
- };
155
- const runEnvDiff = async (context) => {
156
- const { devVariablesPath, logger } = context;
157
- const remote = await fetchRemoteSecretNames(context);
158
- if (!remote.ok) {
159
- logger.error(`env diff: ${remote.error ?? "failed to list remote secrets"}`);
160
- return { code: 1, descriptors: [] };
161
- }
162
- const localKeys = new Set(loadDevVariables(devVariablesPath).keys());
163
- const remoteKeys = new Set(remote.names);
164
- const localOnly = [...localKeys].filter((key) => !remoteKeys.has(key)).toSorted((a, b) => a.localeCompare(b));
165
- const remoteOnly = remote.names.filter((name) => !localKeys.has(name));
166
- const both = [...localKeys].filter((key) => remoteKeys.has(key)).toSorted((a, b) => a.localeCompare(b));
167
- for (const key of localOnly) {
168
- logger.info(`local only (run \`lunora env push\`): ${key}`);
169
- }
170
- for (const key of remoteOnly) {
171
- logger.info(`remote only (in Cloudflare, not ${DEV_VARS_FILE}): ${key}`);
172
- }
173
- logger.info(`in both: ${String(both.length)} secret(s)`);
174
- if (localOnly.length === 0 && remoteOnly.length === 0) {
175
- logger.success("env diff: local and remote secret names match");
176
- }
177
- return { code: 0, descriptors: [] };
178
- };
179
- const runEnvDoctor = (context) => {
180
- const { cwd, devVariablesPath, logger } = context;
181
- const examplePath = join(cwd, DEV_VARS_EXAMPLE_FILE);
182
- if (!existsSync(examplePath)) {
183
- logger.info(`env doctor: no ${DEV_VARS_EXAMPLE_FILE} to check against — nothing to validate.`);
184
- return { code: 0, descriptors: [] };
185
- }
186
- const exampleKeys = parseDevVariableEntries(readFileSync(examplePath, "utf8")).map((entry) => entry.key);
187
- const current = loadDevVariables(devVariablesPath);
188
- if (!existsSync(devVariablesPath)) {
189
- logger.error(`env doctor: ${DEV_VARS_FILE} is missing. Run \`lunora dev\` to scaffold it, or \`lunora env set <KEY> <VALUE>\`.`);
190
- logger.info(`expected (from ${DEV_VARS_EXAMPLE_FILE}): ${exampleKeys.join(", ")}`);
191
- return { code: 1, descriptors: [] };
192
- }
193
- const missing = exampleKeys.filter((key) => !current.has(key));
194
- const placeholders = [...current.values()].filter((entry) => isPlaceholderValue(entry.value)).map((entry) => entry.key);
195
- const exampleKeySet = new Set(exampleKeys);
196
- const extra = [...current.keys()].filter((key) => !exampleKeySet.has(key));
197
- for (const key of missing) {
198
- logger.error(`missing: ${key} is in ${DEV_VARS_EXAMPLE_FILE} but not ${DEV_VARS_FILE}`);
199
- }
200
- for (const key of placeholders) {
201
- logger.error(`unset: ${key} still has a placeholder value`);
202
- }
203
- for (const key of extra) {
204
- logger.info(`extra: ${key} is set locally but not listed in ${DEV_VARS_EXAMPLE_FILE}`);
205
- }
206
- if (missing.length === 0 && placeholders.length === 0) {
207
- logger.success(`env doctor: ${DEV_VARS_FILE} looks good (${String(current.size)} var(s)).`);
208
- return { code: 0, descriptors: [] };
209
- }
210
- return { code: 1, descriptors: [] };
211
- };
212
- const resolveMintableKeys = async (context) => {
213
- let packages = [];
214
- try {
215
- packages = packageNamesFromBindings(await inferLunoraBindings({ projectRoot: context.cwd }));
216
- } catch {
217
- }
218
- const fromPackages = requiredSecrets(packages).map((entry) => entry.key).filter((key) => isMintableSecretKey(key));
219
- const fromLocal = [...loadDevVariables(context.devVariablesPath).keys()].filter((key) => isMintableSecretKey(key));
220
- return [.../* @__PURE__ */ new Set([...fromPackages, ...fromLocal])];
221
- };
222
- const runEnvGenerate = async (context) => {
223
- const { devVariablesPath, logger, options } = context;
224
- let keys;
225
- if (options.key === void 0) {
226
- keys = await resolveMintableKeys(context);
227
- if (keys.length === 0) {
228
- logger.info("env generate: no locally-generatable secrets for this project. Name one explicitly: lunora env generate <KEY>");
229
- return { code: 0, descriptors: [] };
230
- }
231
- } else {
232
- if (!DEV_VARS_KEY_PATTERN.test(options.key)) {
233
- logger.error(`env: invalid key "${options.key}" — must match [A-Za-z_][A-Za-z0-9_]*`);
234
- return { code: 1, descriptors: [] };
235
- }
236
- keys = [options.key];
237
- }
238
- const generated = keys.map((key) => {
239
- return { key, value: generateSecretValue() };
240
- });
241
- if (options.set === true) {
242
- const map = loadDevVariables(devVariablesPath);
243
- for (const entry of generated) {
244
- map.set(entry.key, entry);
245
- }
246
- writeFileSync(devVariablesPath, serializeDevVariables(map), "utf8");
247
- logger.success(`env: generated ${String(generated.length)} secret(s) into ${DEV_VARS_FILE}: ${generated.map((entry) => entry.key).join(", ")}`);
248
- return { code: 0, descriptors: [] };
249
- }
250
- for (const entry of generated) {
251
- process.stdout.write(`${entry.key}=${entry.value}
252
- `);
253
- }
254
- return { code: 0, descriptors: [] };
255
- };
256
- const runEnvCommand = async (options) => {
257
- const cwd = options.cwd ?? process.cwd();
258
- const context = {
259
- cwd,
260
- devVariablesPath: join(cwd, DEV_VARS_FILE),
261
- logger: options.logger,
262
- options
263
- };
264
- switch (options.subcommand) {
265
- case "diff": {
266
- return runEnvDiff(context);
267
- }
268
- case "doctor": {
269
- return runEnvDoctor(context);
270
- }
271
- case "generate": {
272
- return runEnvGenerate(context);
273
- }
274
- case "get": {
275
- return runEnvGet(context);
276
- }
277
- case "list": {
278
- return runEnvList(context);
279
- }
280
- case "push": {
281
- return runEnvPush(context);
282
- }
283
- case "set": {
284
- return runEnvSet(context);
285
- }
286
- case "unset": {
287
- return runEnvUnset(context);
288
- }
289
- default: {
290
- options.logger.error(`env: unknown subcommand "${options.subcommand}"`);
291
- return { code: 1, descriptors: [] };
292
- }
293
- }
294
- };
295
- const isEnvSubcommand = (value) => value === "list" || value === "get" || value === "set" || value === "unset" || value === "push" || value === "diff" || value === "doctor" || value === "generate";
296
- const execute = defineHandler(({ argument, cwd, logger, options }) => {
297
- const sub = argument[0];
298
- if (!isEnvSubcommand(sub)) {
299
- logger.error(`env: unknown subcommand "${sub ?? ""}" — expected list | get | set | unset | push | diff | doctor | generate`);
300
- return { code: 1 };
301
- }
302
- return runEnvCommand({
303
- cwd,
304
- key: argument[1],
305
- logger,
306
- prod: options.prod === true,
307
- set: options.set === true,
308
- subcommand: sub,
309
- temporary: options.temporary === true,
310
- value: argument[2],
311
- yes: options.yes === true
312
- });
313
- });
314
-
315
- export { execute, runEnvCommand };
1
+ import{readFileSync as m,existsSync as u}from"node:fs";import{join as g}from"node:path";import{discoverSchema as h}from"@lunora/codegen";import{readLinkedProject as p}from"@lunora/config";import{findWranglerFile as $}from"@lunora/config/cloudflare";import{parse as v}from"jsonc-parser";import{Project as k}from"ts-morph";import{w,d as b}from"../packem_shared/binding-manifest-file-CQ1eQYy1.mjs";import{d as j}from"../packem_shared/command-CAXl2A1S.mjs";import{EXIT_CODE as d}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";const f=(n,e)=>{if(n===null||typeof n!="object")return;const i=n[e];return typeof i=="string"&&i.length>0?i:void 0},S=(n,e)=>{if(n===null||typeof n!="object")return[];const i=n[e];return Array.isArray(i)?i:[]},x=(n,e)=>{const{manifest:i}=b(e);return{bindings:(i?.bindings??[]).map(r=>`${r.type}:${r.binding}`),compatibilityDate:f(n,"compatibility_date"),compatibilityFlags:S(n,"compatibility_flags").filter(r=>typeof r=="string"),main:f(n,"main"),name:f(n,"name")}},E=n=>({tables:n.tables.map(e=>{let i="root";return e.shardMode==="global"?i="global":typeof e.shardMode=="object"&&(i=`shardBy(${e.shardMode.field})`),{indexes:e.indexes.length,name:e.name,shard:i}}),vectorIndexes:n.vectorIndexes.length}),F=n=>{const e=g(n,"package.json");if(!u(e))return[];let i;try{i=JSON.parse(m(e,"utf8"))}catch{return[]}if(i===null||typeof i!="object")return[];const r=["dependencies","devDependencies","peerDependencies","optionalDependencies"],s=new Map;for(const a of r){const t=i[a];if(!(t===null||typeof t!="object"))for(const[o,c]of Object.entries(t))o.startsWith("@lunora/")&&typeof c=="string"&&!s.has(o)&&s.set(o,c)}return[...s.entries()].toSorted(([a],[t])=>a.localeCompare(t)).map(([a,t])=>({name:a,version:t}))},P=n=>{const e=F(n),i=$(n);let r;if(i)try{r=x(v(m(i,"utf8")),n)}catch{r=void 0}const s=g(n,"lunora","schema.ts");let a,t;if(u(s))try{const o=new k({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1});a=E(h(o,s))}catch(o){t=o instanceof Error?o.message:String(o)}return{link:p(n),lunoraPackages:e,projectRoot:n,schema:a,schemaError:t,wrangler:r,wranglerPath:i}},I=(n,e)=>{if(e.info(`project: ${n.projectRoot}`),e.info(""),e.info("@lunora/* packages:"),n.lunoraPackages.length===0)e.info(" (none found in package.json)");else for(const i of n.lunoraPackages)e.info(` ${i.name}@${i.version}`);if(e.info(""),n.wrangler?(e.info(`wrangler: ${n.wranglerPath??""}`),e.info(` name: ${n.wrangler.name??"<unset>"}`),e.info(` main: ${n.wrangler.main??"<unset>"}`),e.info(` compatibility_date: ${n.wrangler.compatibilityDate??"<unset>"}`),e.info(` compatibility_flags: ${n.wrangler.compatibilityFlags.join(", ")||"<none>"}`),e.info(` bindings: ${n.wrangler.bindings.join(", ")||"<none>"}`)):e.info("wrangler: (not found)"),e.info(""),n.link?(e.info(`link: ${n.link.workerName??"(unnamed)"} -> ${n.link.workerUrl??"<no url>"}`),n.link.env!==void 0&&e.info(` env: ${n.link.env}`)):e.info("link: (not linked — run `lunora link --url <https://your-worker>`)"),e.info(""),n.schemaError!==void 0)e.warn(`schema: parse error — ${n.schemaError}`);else if(n.schema){e.info(`schema: ${String(n.schema.tables.length)} table(s), ${String(n.schema.vectorIndexes)} vector index(es)`);for(const i of n.schema.tables)e.info(` ${i.name} [${i.shard}, ${String(i.indexes)} index(es)]`)}else e.info("schema: (no lunora/schema.ts)")},M=n=>{const{cwd:e,json:i,logger:r,out:s}=n;if(s!==void 0){const{error:o}=w({destination:s,logger:r,projectRoot:e});return o!==void 0?(r.error(o),{code:d.USAGE,error:o}):{code:0}}const{error:a,manifest:t}=b(e);if(t===void 0){const o=a??"could not derive the binding manifest";return r.error(o),{code:d.USAGE,error:o}}if(i)return{code:0,data:t};if(t.bindings.length===0)r.info("No bindings declared.");else{const o=Math.max(...t.bindings.map(c=>c.type.length));r.info(`${String(t.bindings.length)} binding(s):`);for(const c of t.bindings){const l=[c.resource,c.className,c.resourceId].filter(y=>y!==void 0).join(" ");r.info(` ${c.type.padEnd(o)} ${c.binding}${l===""?"":` ${l}`}`)}}return t.crons.length>0&&r.info(`${String(t.crons.length)} cron trigger(s): ${t.crons.join(", ")}`),t.vars.length>0&&r.info(`${String(t.vars.length)} var(s): ${t.vars.join(", ")}`),t.unknown.length>0&&r.warn(`not modelled by the manifest: ${t.unknown.join(", ")} — anything they bind must be provisioned by hand.`),{code:0,data:t}},A=n=>{const e=n.cwd??process.cwd(),i=n.format==="json",{logger:r}=n;if(n.bindings===!0)return M({cwd:e,json:i,logger:r,out:n.out});if(n.out!==void 0){const a="--out only applies with --bindings; the full info snapshot prints to stdout under --format json.";return r.error(a),{code:d.USAGE,error:a}}const s=P(e);return i||I(s,r),{code:0,data:s,snapshot:s}},L=j(({cwd:n,format:e,logger:i,options:r})=>A({bindings:r.bindings===!0,cwd:n,format:e,logger:i,out:r.out}));export{P as collectInfo,L as execute,A as runInfoCommand};
@@ -1,52 +1,4 @@
1
- import { runCodegen } from '@lunora/codegen';
2
- import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
3
- import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
4
- import { v as validateOutputFormat, p as printJson, l as loggerForFormat, i as isJsonFormat } from '../packem_shared/output-format-wUvAN6AL.mjs';
5
-
6
- const CRON_TRIGGER_LIMIT = 3;
7
- const runCodegenCommand = (options) => {
8
- const projectRoot = options.cwd ?? process.cwd();
9
- const json = isJsonFormat(options.format);
10
- const logger = loggerForFormat(options.format, options.logger);
11
- const formatError = validateOutputFormat("codegen", options.format);
12
- if (formatError !== void 0) {
13
- options.logger.error(formatError);
14
- return { advisories: [], cronTriggers: [], error: formatError, outputDirectory: "" };
15
- }
16
- const result = runCodegen({ apiSpec: options.apiSpec, projectRoot });
17
- const commandResult = {
18
- advisories: result.advisories.map((advisory) => {
19
- return {
20
- detail: advisory.detail,
21
- level: advisory.level,
22
- name: advisory.name,
23
- remediation: advisory.remediation
24
- };
25
- }),
26
- cronTriggers: result.cronTriggers,
27
- outputDirectory: result.outputDirectory
28
- };
29
- logger.success(`codegen wrote dataModel.ts, api.ts, server.ts to ${result.outputDirectory}`);
30
- if (result.advisories.length > 0) {
31
- const count = result.advisories.length;
32
- const lines = result.advisories.map((advisory) => ` [${advisory.level}] ${advisory.name} — ${advisory.detail}
33
- ↳ ${advisory.remediation}`);
34
- logger.warn(`${count.toString()} schema ${count === 1 ? "advisory" : "advisories"}:
35
- ${lines.join("\n")}`);
36
- }
37
- if (result.cronTriggers.length > CRON_TRIGGER_LIMIT) {
38
- logger.warn(
39
- `${result.cronTriggers.length.toString()} distinct cron expressions declared — Cloudflare allows at most ${CRON_TRIGGER_LIMIT.toString()} Cron Triggers per Worker. Consolidate schedules (jobs can share one expression) or move finer-grained work to Durable Object alarms via @lunora/scheduler (runAfter/runAt).`
40
- );
41
- }
42
- if (json) {
43
- printJson(commandResult);
44
- }
45
- return commandResult;
46
- };
47
- const execute = defineHandler(({ cwd, logger, options }) => {
48
- const result = runCodegenCommand({ apiSpec: parseApiSpec(options.apiSpec), cwd, format: options.format, logger });
49
- return { code: result.error === void 0 ? 0 : 1 };
50
- });
51
-
52
- export { execute, runCodegenCommand };
1
+ import{runCodegen as v}from"@lunora/codegen";import{applyLintIgnores as h,detectLintTools as w,inferLunoraBindings as y,resolveSchemaDirectory as $}from"@lunora/config";import{warnCloudflareCliConfigOnce as A,collectWranglerSecretVariables as S,collectExportGaps as T}from"@lunora/config/cloudflare";import{r as D,a as x,e as C}from"../packem_shared/platform-diagnostics-Cn2g6Jh-.mjs";import{p as k,r as b}from"../packem_shared/deploy-target-DCWwiuAe.mjs";import{d as E}from"../packem_shared/command-CAXl2A1S.mjs";import{EXIT_CODE as I}from"../packem_shared/EXIT_CODE-D_XCixv8.mjs";import{r as L}from"../packem_shared/lint-ignore-report-DKZagpqk.mjs";const u=3,O=r=>{const s=r.cwd??process.cwd(),{logger:i}=r,e=D(r),o=b(s,r.target);if(o.target===void 0)return r.logger.error(o.error??"unknown deploy target"),{advisories:[],code:I.USAGE,cronTriggers:[],error:o.error??"unknown deploy target",failedAdvisories:0,outputDirectory:""};const{target:a}=o,t=v({apiSpec:r.apiSpec,projectRoot:s,target:a,wranglerVariables:S(s)}),l={advisories:t.advisories.map(n=>({detail:n.detail,level:n.level,name:n.name,remediation:n.remediation})),cronTriggers:t.cronTriggers,failedAdvisories:0,outputDirectory:t.outputDirectory};if(i.success(`codegen wrote ${t.writtenFiles.join(", ")} to ${t.outputDirectory}`),t.advisories.length>0){const n=t.advisories.length,f=t.advisories.map(c=>` [${c.level}] ${c.name} — ${c.detail}
2
+ ↳ ${c.remediation}`);i.warn(`${n.toString()} schema ${n===1?"advisory":"advisories"}:
3
+ ${f.join(`
4
+ `)}`)}const g=x(t.platformDiagnostics,i);g.errors.length>0&&(l.error=g.errors.join("; "));const{errorAdvisories:d,names:p,shouldBlock:m}=C(l.advisories,e);return m&&i.error(`${d.length.toString()} ERROR-level ${d.length===1?"advisory":"advisories"} (${p.join(", ")}). Codegen wrote its output; this exit code is the gate. Pass --no-strict-advisories to downgrade it to a warning.`),t.cronTriggers.length>u&&i.warn(`${t.cronTriggers.length.toString()} distinct cron expressions declared — Cloudflare allows at most ${u.toString()} Cron Triggers per Worker. Consolidate schedules (jobs can share one expression) or move finer-grained work to Durable Object alarms via @lunora/scheduler (runAfter/runAt).`),{...l,failedAdvisories:e?d.length:0}},R=async(r,s)=>{let i;try{i=T(await y({projectRoot:r,schemaDir:$(r)}))}catch(e){s.warn(`could not check whether declared containers/workflows/agents are re-exported by the worker entry: ${e instanceof Error?e.message:String(e)}. Run \`lunora doctor\` to check explicitly.`);return}for(const e of i)s.warn(`${e.kind} "${e.exportName}" is declared but ${e.className} is not exported by the worker entry — add \`export * from "./lunora/_generated/${e.module}"\` so wrangler can provision its binding. Until then it deploys with nothing to run.`)},G=(r,s)=>{try{L(h(r,w(r)),s)}catch{}},F=E(async({cwd:r,format:s,logger:i,options:e})=>{const o=O({apiSpec:k(e.apiSpec),cwd:r,format:s,logger:i,strictAdvisories:e.strictAdvisories,target:e.target});if(o.outputDirectory!==""){const a=i;G(r,a),await R(r,a),A(r,t=>{a.warn(t)})}return{code:o.code??(o.error===void 0&&o.failedAdvisories===0?0:1),data:{advisories:o.advisories,cronTriggers:o.cronTriggers,failedAdvisories:o.failedAdvisories,outputDirectory:o.outputDirectory},error:o.error}});export{F as execute,O as runCodegenCommand};