@akanjs/cli 2.4.0-rc.9 → 2.4.1-rc.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.
Files changed (69) hide show
  1. package/agent.command-h4afc69n.js +26 -0
  2. package/application.command-4ctkfdan.js +165 -0
  3. package/applicationBuildRunner-esa1kj7v.js +284 -0
  4. package/applicationReleasePackager-brvth6rs.js +245 -0
  5. package/capacitorApp-y0h6cgft.js +58 -0
  6. package/cloud.command-rpztn4fh.js +94 -0
  7. package/commandManifest.json +1 -0
  8. package/context.command-nqbtak4f.js +82 -0
  9. package/dependencyScanner-m4x5maek.js +9 -0
  10. package/guideline.command-ya0dh44f.js +356 -0
  11. package/incrementalBuilder.proc.js +89 -17394
  12. package/index-1xdrsbry.js +1447 -0
  13. package/index-45aj5ry0.js +990 -0
  14. package/index-5vvwc0cz.js +559 -0
  15. package/index-61keag0s.js +40 -0
  16. package/index-6pz1j0zj.js +62 -0
  17. package/index-73pr2cmy.js +534 -0
  18. package/index-76rn3g2c.js +76 -0
  19. package/index-85msc0wg.js +161 -0
  20. package/index-8pkbzj26.js +840 -0
  21. package/index-8rc0bm04.js +514 -0
  22. package/index-9sp6fsc5.js +1884 -0
  23. package/index-a6sbyy0b.js +2769 -0
  24. package/index-b0brjbp3.js +83 -0
  25. package/index-fgc8r6dj.js +33 -0
  26. package/index-h6ca6qg0.js +2777 -0
  27. package/index-hdqztm58.js +758 -0
  28. package/index-hwzpw9c1.js +202 -0
  29. package/index-pmm9e2jf.js +120 -0
  30. package/index-qaq13qk3.js +80 -0
  31. package/index-qhtr07v8.js +1072 -0
  32. package/index-r24hmh0q.js +4 -0
  33. package/index-ss469dec.js +11 -0
  34. package/index-swf4bmbg.js +25 -0
  35. package/index-w7fyqjrw.js +462 -0
  36. package/index-wnp7hwq7.js +193 -0
  37. package/index-wq8jwx8z.js +224 -0
  38. package/index-x53a5nya.js +301 -0
  39. package/index-xmc2w32q.js +4359 -0
  40. package/index-y3hdhy4p.js +229 -0
  41. package/index.js +54 -23340
  42. package/library.command-r15zdqvp.js +33 -0
  43. package/localRegistry.command-5tcahs3f.js +178 -0
  44. package/module.command-qrj3kmyz.js +54 -0
  45. package/package.command-r8sq5kzp.js +43 -0
  46. package/package.json +2 -2
  47. package/page.command-c6xdx0xm.js +24 -0
  48. package/primitive.command-pv9ssmtf.js +62 -0
  49. package/quality.command-es67wvdp.js +809 -0
  50. package/repair.command-677675vw.js +67 -0
  51. package/routeSourceValidator-wbhmbwpj.js +132 -0
  52. package/scalar.command-kabkd6wd.js +35 -0
  53. package/templates/app/page/_layout.tsx +19 -1
  54. package/templates/app/public/fonts/Pretendard-Black.woff2 +0 -0
  55. package/templates/app/public/fonts/Pretendard-Bold.woff2 +0 -0
  56. package/templates/app/public/fonts/Pretendard-ExtraBold.woff2 +0 -0
  57. package/templates/app/public/fonts/Pretendard-ExtraLight.woff2 +0 -0
  58. package/templates/app/public/fonts/Pretendard-Light.woff2 +0 -0
  59. package/templates/app/public/fonts/Pretendard-Medium.woff2 +0 -0
  60. package/templates/app/public/fonts/Pretendard-Regular.woff2 +0 -0
  61. package/templates/app/public/fonts/Pretendard-SemiBold.woff2 +0 -0
  62. package/templates/app/public/fonts/Pretendard-Thin.woff2 +0 -0
  63. package/templates/facetIndex/index.ts +1 -1
  64. package/typeChecker-kravn7ns.js +8 -0
  65. package/typecheck.proc.js +4 -194
  66. package/workflow.command-64r6cw0w.js +108 -0
  67. package/workspace.command-vrws0rgx.js +435 -0
  68. package/README.ko.md +0 -72
  69. package/README.md +0 -85
@@ -0,0 +1,758 @@
1
+ // @bun
2
+ import {
3
+ AppExecutor,
4
+ Executor,
5
+ LibExecutor,
6
+ ModuleExecutor,
7
+ PkgExecutor,
8
+ WorkspaceExecutor,
9
+ getDirname
10
+ } from "./index-a6sbyy0b.js";
11
+ import {
12
+ FileSys
13
+ } from "./index-61keag0s.js";
14
+
15
+ // pkgs/@akanjs/devkit/commandDecorators/targetMeta.ts
16
+ var COMMAND_META = Symbol("akan.command.meta");
17
+ var getTargetMetas = (command) => {
18
+ const targetMetaMap = command[COMMAND_META];
19
+ if (!targetMetaMap)
20
+ throw new Error(`TargetMeta is not defined for ${command.name}`);
21
+ return [...targetMetaMap.values()];
22
+ };
23
+ var camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
24
+ var getTargetCommandNames = (targetMeta) => {
25
+ const kebabKey = camelToKebabCase(targetMeta.key);
26
+ if (targetMeta.targetOption.short !== true)
27
+ return [kebabKey];
28
+ return [
29
+ kebabKey,
30
+ kebabKey.split("-").map((s) => s.slice(0, 1)).join("")
31
+ ];
32
+ };
33
+
34
+ // pkgs/@akanjs/devkit/commandDecorators/argMeta.ts
35
+ var getArgMetas = (command, key) => {
36
+ const allArgMetas = [...command[COMMAND_META]?.get(key)?.args ?? []];
37
+ const argMetas = allArgMetas.filter((argMeta) => argMeta.type === "Option");
38
+ const internalArgMetas = allArgMetas.filter((argMeta) => argMeta.type !== "Option");
39
+ return [allArgMetas, argMetas, internalArgMetas];
40
+ };
41
+ var createInternalArgToken = (type) => ({ type });
42
+ var normalizePrimitiveArgType = (type) => {
43
+ if (type === String)
44
+ return "string";
45
+ if (type === Number)
46
+ return "number";
47
+ if (type === Boolean)
48
+ return "boolean";
49
+ throw new Error(`Invalid primitive argument type: ${type}`);
50
+ };
51
+ var App = createInternalArgToken("App");
52
+ var Lib = createInternalArgToken("Lib");
53
+ var Sys = createInternalArgToken("Sys");
54
+ var Exec = createInternalArgToken("Exec");
55
+ var Pkg = createInternalArgToken("Pkg");
56
+ var Module = createInternalArgToken("Module");
57
+ var Workspace = createInternalArgToken("Workspace");
58
+
59
+ // pkgs/@akanjs/devkit/commandDecorators/command.ts
60
+ import path from "path";
61
+ import { confirm, input, select } from "@inquirer/prompts";
62
+ import { Logger } from "akanjs/common";
63
+ import chalk2 from "chalk";
64
+ import { program } from "commander";
65
+
66
+ // pkgs/@akanjs/devkit/commandDecorators/dependencyBuilder.ts
67
+ var capitalize = (value) => value.slice(0, 1).toUpperCase() + value.slice(1);
68
+ var createDependencyKey = (refName, kind) => `${refName}${capitalize(kind)}`;
69
+
70
+ class CommandContainer {
71
+ static #instances = new Map;
72
+ static #resolving = new Set;
73
+ static get(dep) {
74
+ const instance = CommandContainer.#instances.get(dep);
75
+ if (instance)
76
+ return instance;
77
+ if (CommandContainer.#resolving.has(dep))
78
+ throw new Error(`Circular command dependency: ${dep.name}`);
79
+ CommandContainer.#resolving.add(dep);
80
+ try {
81
+ const nextInstance = new dep;
82
+ CommandContainer.#instances.set(dep, nextInstance);
83
+ return nextInstance;
84
+ } finally {
85
+ CommandContainer.#resolving.delete(dep);
86
+ }
87
+ }
88
+ static clear() {
89
+ CommandContainer.#instances.clear();
90
+ CommandContainer.#resolving.clear();
91
+ }
92
+ }
93
+ var getDependencyKey = (dep) => dep.dependencyKey;
94
+ var assertUniqueDependencies = (deps) => {
95
+ const keys = new Map;
96
+ const classes = new Set;
97
+ for (const dep of deps) {
98
+ if (classes.has(dep))
99
+ throw new Error(`Duplicate command dependency class: ${dep.name}`);
100
+ classes.add(dep);
101
+ const key = getDependencyKey(dep);
102
+ const existing = keys.get(key);
103
+ if (existing)
104
+ throw new Error(`Duplicate command dependency key "${key}": ${existing.name}, ${dep.name}`);
105
+ keys.set(key, dep);
106
+ }
107
+ };
108
+ var injectDependencies = (target, deps) => {
109
+ assertUniqueDependencies(deps);
110
+ for (const dep of deps) {
111
+ Object.defineProperty(target, getDependencyKey(dep), {
112
+ configurable: true,
113
+ enumerable: false,
114
+ value: CommandContainer.get(dep),
115
+ writable: false
116
+ });
117
+ }
118
+ return target;
119
+ };
120
+ var runner = (refName) => {
121
+
122
+ class RunnerBase {
123
+ static refName = refName;
124
+ static dependencyKind = "runner";
125
+ static dependencyKey = createDependencyKey(refName, "runner");
126
+ }
127
+ return RunnerBase;
128
+ };
129
+ var script = (refName, deps = []) => {
130
+ assertUniqueDependencies(deps);
131
+
132
+ class ScriptBase {
133
+ static refName = refName;
134
+ static dependencyKind = "script";
135
+ static dependencyKey = createDependencyKey(refName, "script");
136
+ constructor() {
137
+ injectDependencies(this, deps);
138
+ }
139
+ }
140
+ return ScriptBase;
141
+ };
142
+
143
+ // pkgs/@akanjs/devkit/commandDecorators/helpFormatter.ts
144
+ import chalk from "chalk";
145
+ var camelToKebabCase2 = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
146
+ var formatChoice = (choice) => typeof choice === "object" ? choice.label : choice.toString();
147
+ var groupCommands = (commands) => {
148
+ const groups = new Map;
149
+ for (const command of commands) {
150
+ const className = command.name.replace("Command", "");
151
+ const groupName = className;
152
+ if (!groups.has(groupName)) {
153
+ groups.set(groupName, { name: groupName, commands: [] });
154
+ }
155
+ const targetMetas = getTargetMetas(command);
156
+ for (const targetMeta of targetMetas) {
157
+ if (targetMeta.targetOption.devOnly)
158
+ continue;
159
+ const [allArgMetas] = getArgMetas(command, targetMeta.key);
160
+ const args = allArgMetas.filter((arg) => arg.type !== "Option").map((arg) => {
161
+ if (arg.type === "Workspace")
162
+ return "";
163
+ if (arg.type === "Module")
164
+ return "[sys:module]";
165
+ if (arg.type === "Argument") {
166
+ return `[${arg.name}]`;
167
+ }
168
+ return `[${arg.type.toLowerCase()}]`;
169
+ }).filter(Boolean);
170
+ const group = groups.get(groupName);
171
+ if (group) {
172
+ group.commands.push({
173
+ key: camelToKebabCase2(targetMeta.key),
174
+ args,
175
+ desc: targetMeta.targetOption.desc
176
+ });
177
+ }
178
+ }
179
+ }
180
+ return groups;
181
+ };
182
+ var formatHelp = (commands, version) => {
183
+ const groups = groupCommands(commands);
184
+ const lines = [];
185
+ lines.push("");
186
+ lines.push(chalk.bold.cyan(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"));
187
+ lines.push(chalk.bold.cyan(" \u2551") + chalk.bold.white(" Akan.js Framework CLI ") + chalk.bold.cyan(" \u2551"));
188
+ lines.push(chalk.bold.cyan(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
189
+ lines.push("");
190
+ lines.push(chalk.gray(` Version: ${version}`));
191
+ lines.push("");
192
+ lines.push(chalk.bold.yellow(" USAGE"));
193
+ lines.push("");
194
+ lines.push(chalk.gray(" $ ") + chalk.white("akan") + chalk.gray(" <command> [options]"));
195
+ lines.push("");
196
+ lines.push(chalk.bold.yellow(" COMMANDS"));
197
+ lines.push("");
198
+ for (const [groupName, group] of groups) {
199
+ if (group.commands.length === 0)
200
+ continue;
201
+ lines.push(chalk.bold.magenta(` ${groupName}`));
202
+ lines.push("");
203
+ for (const cmd of group.commands) {
204
+ const cmdName = chalk.green(cmd.key);
205
+ const cmdArgs = cmd.args.length > 0 ? chalk.gray(` ${cmd.args.join(" ")}`) : "";
206
+ if (cmd.desc) {
207
+ const maxLineLength = 70;
208
+ const cmdPrefix = ` ${cmdName}${cmdArgs}`;
209
+ const indent = " ";
210
+ if (cmdPrefix.length + cmd.desc.length + 3 < maxLineLength) {
211
+ lines.push(`${cmdPrefix} ${chalk.gray(cmd.desc)}`);
212
+ } else {
213
+ lines.push(cmdPrefix);
214
+ lines.push(`${indent}${chalk.gray(cmd.desc)}`);
215
+ }
216
+ } else {
217
+ lines.push(` ${cmdName}${cmdArgs}`);
218
+ }
219
+ }
220
+ lines.push("");
221
+ }
222
+ lines.push(chalk.bold.yellow(" OPTIONS"));
223
+ lines.push("");
224
+ lines.push(` ${chalk.green("-v, --verbose")} ${chalk.gray("Enable verbose output")}`);
225
+ lines.push(` ${chalk.green("-h, --help")} ${chalk.gray("Display this help message")}`);
226
+ lines.push(` ${chalk.green("-V, --version")} ${chalk.gray("Output version number")}`);
227
+ lines.push("");
228
+ lines.push(chalk.bold.yellow(" EXAMPLES"));
229
+ lines.push("");
230
+ lines.push(chalk.gray(" # Create a new workspace"));
231
+ lines.push(chalk.white(" $ akan create-workspace myproject"));
232
+ lines.push("");
233
+ lines.push(chalk.gray(" # Start development server"));
234
+ lines.push(chalk.white(" $ akan start myapp"));
235
+ lines.push("");
236
+ lines.push(chalk.gray(" # Create a new module"));
237
+ lines.push(chalk.white(" $ akan create-module userProfile"));
238
+ lines.push("");
239
+ lines.push(chalk.gray(" Documentation: ") + chalk.cyan("https://akanjs.com/docs"));
240
+ lines.push(chalk.gray(" Report issues: ") + chalk.cyan("https://github.com/akan-team/akanjs/issues"));
241
+ lines.push("");
242
+ return lines.join(`
243
+ `);
244
+ };
245
+ var formatCommandHelp = (command, key) => {
246
+ const [allArgMetas, argMetas] = getArgMetas(command, key);
247
+ const kebabKey = camelToKebabCase2(key);
248
+ const lines = [];
249
+ const targetMetas = getTargetMetas(command);
250
+ const targetMeta = targetMetas.find((t) => t.key === key);
251
+ const commandDesc = targetMeta?.targetOption.desc;
252
+ lines.push("");
253
+ lines.push(chalk.bold.cyan(` Command: ${kebabKey}`));
254
+ if (commandDesc) {
255
+ lines.push(chalk.gray(` ${commandDesc}`));
256
+ }
257
+ lines.push("");
258
+ const args = allArgMetas.filter((arg) => arg.type !== "Option").map((arg) => {
259
+ if (arg.type === "Workspace")
260
+ return "";
261
+ if (arg.type === "Module")
262
+ return "[sys:module]";
263
+ if (arg.type === "Argument") {
264
+ return `[${camelToKebabCase2(arg.name)}]`;
265
+ }
266
+ return `[${arg.type.toLowerCase()}]`;
267
+ }).filter(Boolean).join(" ");
268
+ lines.push(chalk.bold.yellow(" USAGE"));
269
+ lines.push("");
270
+ lines.push(chalk.gray(" $ ") + chalk.white(`akan ${kebabKey}`) + (args ? chalk.gray(` ${args}`) : ""));
271
+ lines.push("");
272
+ const nonOptionArgs = allArgMetas.filter((arg) => arg.type !== "Option");
273
+ if (nonOptionArgs.length > 0) {
274
+ lines.push(chalk.bold.yellow(" ARGUMENTS"));
275
+ lines.push("");
276
+ for (const arg of nonOptionArgs) {
277
+ if (arg.type === "Workspace")
278
+ continue;
279
+ let argName;
280
+ let argDesc;
281
+ let example = "";
282
+ if (arg.type === "Argument") {
283
+ argName = camelToKebabCase2(arg.name);
284
+ argDesc = arg.argsOption.desc ?? "";
285
+ example = arg.argsOption.example ? chalk.gray(` (e.g., ${String(arg.argsOption.example)})`) : "";
286
+ } else if (arg.type === "Module") {
287
+ argName = "sys:module";
288
+ argDesc = "Module in format: app-name:module-name or lib-name:module-name";
289
+ } else {
290
+ argName = arg.type.toLowerCase();
291
+ argDesc = `${arg.type} name in this workspace`;
292
+ }
293
+ lines.push(` ${chalk.green(argName)} ${chalk.gray(argDesc)}${example}`);
294
+ }
295
+ lines.push("");
296
+ }
297
+ const optionArgs = argMetas.filter((a) => a.type === "Option");
298
+ if (optionArgs.length > 0) {
299
+ lines.push(chalk.bold.yellow(" OPTIONS"));
300
+ lines.push("");
301
+ for (const arg of optionArgs) {
302
+ const opt = arg.argsOption;
303
+ const flag = opt.flag ? `-${opt.flag}, ` : "";
304
+ const kebabName = camelToKebabCase2(arg.name);
305
+ const optName = `${flag}--${kebabName}`;
306
+ const optDesc = opt.desc ?? "";
307
+ const defaultVal = opt.default !== undefined ? chalk.gray(` [default: ${String(opt.default)}]`) : "";
308
+ const choices = opt.enum ? chalk.gray(typeof opt.enum === "function" ? " ([dynamic choices])" : ` (${opt.enum.map(formatChoice).join(", ")})`) : "";
309
+ lines.push(` ${chalk.green(optName)} ${chalk.gray(optDesc)}${defaultVal}${choices}`);
310
+ }
311
+ lines.push("");
312
+ }
313
+ return lines.join(`
314
+ `);
315
+ };
316
+
317
+ // pkgs/@akanjs/devkit/commandDecorators/command.ts
318
+ var camelToKebabCase3 = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
319
+ var loggedCliErrorObjects = new WeakSet;
320
+ var loggedCliErrorMessages = new Set;
321
+ var formatCliError = (error) => {
322
+ if (error instanceof Error)
323
+ return error.message || error.name;
324
+ if (typeof error === "string")
325
+ return error.trim() || "Unknown error";
326
+ if (error === null || error === undefined)
327
+ return "Unknown error";
328
+ try {
329
+ const json = JSON.stringify(error);
330
+ if (json)
331
+ return json;
332
+ } catch {
333
+ return String(error);
334
+ }
335
+ return String(error) || "Unknown error";
336
+ };
337
+ var printCliError = (error) => {
338
+ if (typeof error === "object" && error !== null) {
339
+ if (loggedCliErrorObjects.has(error))
340
+ return;
341
+ loggedCliErrorObjects.add(error);
342
+ }
343
+ const message = formatCliError(error);
344
+ if (loggedCliErrorMessages.has(message))
345
+ return;
346
+ loggedCliErrorMessages.add(message);
347
+ Logger.rawLog(`
348
+ ${chalk2.red(message)}`);
349
+ };
350
+ var handleOption = (programCommand, argMeta) => {
351
+ const {
352
+ type,
353
+ flag = argMeta.name.slice(0, 1).toLowerCase(),
354
+ desc = argMeta.name,
355
+ example,
356
+ enum: enumChoices,
357
+ ask
358
+ } = argMeta.argsOption;
359
+ const kebabName = camelToKebabCase3(argMeta.name);
360
+ const choices = enumChoices && typeof enumChoices !== "function" ? normalizeEnumChoices(enumChoices) : null;
361
+ programCommand.option(`-${flag}, --${kebabName}${type === "boolean" ? " [boolean]" : ` <${kebabName}>`}`, `${desc}${ask ? ` (${ask})` : ""}${example ? ` (example: ${example})` : ""}${choices ? ` (choices: ${choices.map((choice) => choice.name).join(", ")})` : ""}`);
362
+ return programCommand;
363
+ };
364
+ var handleArgument = (programCommand, argMeta) => {
365
+ const kebabName = camelToKebabCase3(argMeta.name);
366
+ programCommand.argument(`[${kebabName}]`, `${argMeta.argsOption.desc}${argMeta.argsOption.example ? ` (example: ${argMeta.argsOption.example})` : ""}`);
367
+ return programCommand;
368
+ };
369
+ var convertArgValue = (value, type) => {
370
+ if (type === "string")
371
+ return value;
372
+ else if (type === "number")
373
+ return Number(value);
374
+ else
375
+ return value === true || value === "true";
376
+ };
377
+ var normalizeEnumChoices = (enumChoices) => enumChoices.map((choice) => typeof choice === "object" ? { value: choice.value, name: choice.label } : { value: choice, name: choice.toString() });
378
+ var resolveEnumChoices = async (argMeta, context) => {
379
+ const enumChoices = argMeta.argsOption.enum;
380
+ if (!enumChoices)
381
+ return null;
382
+ if (typeof enumChoices === "function")
383
+ return await enumChoices(context);
384
+ return enumChoices;
385
+ };
386
+ var getOptionValue = async (argMeta, opt, context) => {
387
+ const {
388
+ name,
389
+ argsOption: { enum: enumChoices, default: defaultValue, type, desc, nullable, example, ask }
390
+ } = argMeta;
391
+ if (opt[argMeta.name] !== undefined)
392
+ return convertArgValue(opt[argMeta.name], type ?? "string");
393
+ else if (defaultValue !== undefined)
394
+ return defaultValue;
395
+ if (enumChoices) {
396
+ const choices = normalizeEnumChoices(await resolveEnumChoices(argMeta, context) ?? []);
397
+ if (choices.length === 1)
398
+ return choices[0]?.value;
399
+ const choice = await select({ message: ask ?? desc ?? `Select the ${name} value`, choices });
400
+ return choice;
401
+ } else if (nullable)
402
+ return null;
403
+ else if (type === "boolean") {
404
+ const message = ask ?? desc ?? `Do you want to set ${name}? ${desc ? ` (${desc})` : ""}: `;
405
+ return await confirm({ message });
406
+ } else {
407
+ const message = ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
408
+ if (argMeta.argsOption.nullable)
409
+ return await input({ message });
410
+ else
411
+ return convertArgValue(await input({ message }), type ?? "string");
412
+ }
413
+ };
414
+ var getArgumentValue = async (argMeta, value) => {
415
+ const {
416
+ name,
417
+ argsOption: { default: defaultValue, type, desc, nullable, example, ask }
418
+ } = argMeta;
419
+ if (value !== undefined)
420
+ return convertArgValue(value, type ?? "string");
421
+ else if (defaultValue !== undefined)
422
+ return defaultValue;
423
+ else if (nullable)
424
+ return null;
425
+ const message = ask ? `${ask}: ` : desc ? `${desc}: ` : `Enter the ${name} value${example ? ` (example: ${example})` : ""}: `;
426
+ return convertArgValue(await input({ message }), type ?? "string");
427
+ };
428
+ var assignCommandContext = (context, argMeta, value) => {
429
+ if (value instanceof AppExecutor)
430
+ context.app = value;
431
+ else if (value instanceof LibExecutor)
432
+ context.lib = value;
433
+ else if (value instanceof PkgExecutor)
434
+ context.pkg = value;
435
+ else if (value instanceof ModuleExecutor)
436
+ context.module = value;
437
+ else if (value instanceof Executor)
438
+ context.exec = value;
439
+ if (argMeta.type === "Argument" || argMeta.type === "Option")
440
+ context.values[argMeta.name] = value;
441
+ else
442
+ context.values[argMeta.type.toLowerCase()] = value;
443
+ };
444
+ var assertCurrentDirectoryIsWorkspaceRoot = async () => {
445
+ const cwd = process.cwd();
446
+ const [hasPackageJson, hasTsConfig, hasEnv] = await Promise.all([
447
+ FileSys.fileExists(`${cwd}/package.json`),
448
+ FileSys.fileExists(`${cwd}/tsconfig.json`),
449
+ FileSys.fileExists(`${cwd}/.env`)
450
+ ]);
451
+ if (hasPackageJson && hasTsConfig && hasEnv)
452
+ return;
453
+ throw new Error([
454
+ "Akan CLI commands must be run from the workspace root.",
455
+ `Current directory: ${cwd}`,
456
+ "Move to the directory that contains package.json, tsconfig.json, and .env, then run the command again."
457
+ ].join(`
458
+ `));
459
+ };
460
+ var getInternalArgumentValue = async (argMeta, value, workspace) => {
461
+ if (argMeta.type === "Workspace")
462
+ return workspace;
463
+ const sysType = argMeta.type.toLowerCase();
464
+ const [appNames, libNames, pkgNames] = await workspace.getExecs();
465
+ if (sysType === "sys") {
466
+ if (value && appNames.includes(value))
467
+ return AppExecutor.from(workspace, value);
468
+ else if (value && libNames.includes(value))
469
+ return LibExecutor.from(workspace, value);
470
+ else {
471
+ const sysName = await select({
472
+ message: `Select the App or Lib name`,
473
+ choices: [...appNames, ...libNames]
474
+ });
475
+ if (appNames.includes(sysName))
476
+ return AppExecutor.from(workspace, sysName);
477
+ else if (libNames.includes(sysName))
478
+ return LibExecutor.from(workspace, sysName);
479
+ else
480
+ throw new Error(`Invalid system name: ${sysName}`);
481
+ }
482
+ } else if (sysType === "exec") {
483
+ if (value && appNames.includes(value))
484
+ return AppExecutor.from(workspace, value);
485
+ else if (value && libNames.includes(value))
486
+ return LibExecutor.from(workspace, value);
487
+ else if (value && pkgNames.includes(value))
488
+ return PkgExecutor.from(workspace, value);
489
+ else {
490
+ const execName = await select({
491
+ message: `Select the App or Lib or Pkg name`,
492
+ choices: [...appNames, ...libNames, ...pkgNames]
493
+ });
494
+ if (appNames.includes(execName))
495
+ return AppExecutor.from(workspace, execName);
496
+ else if (libNames.includes(execName))
497
+ return LibExecutor.from(workspace, execName);
498
+ else if (pkgNames.includes(execName))
499
+ return PkgExecutor.from(workspace, execName);
500
+ else
501
+ throw new Error(`Invalid system name: ${execName}`);
502
+ }
503
+ } else if (sysType === "app") {
504
+ if (value && appNames.includes(value))
505
+ return AppExecutor.from(workspace, value);
506
+ if (!value && appNames.length === 1 && appNames[0])
507
+ return AppExecutor.from(workspace, appNames[0]);
508
+ const appName = await select({ message: `Select the ${sysType} name`, choices: appNames });
509
+ return AppExecutor.from(workspace, appName);
510
+ } else if (sysType === "lib") {
511
+ if (value && libNames.includes(value))
512
+ return LibExecutor.from(workspace, value);
513
+ const libName = await select({ message: `Select the ${sysType} name`, choices: libNames });
514
+ return LibExecutor.from(workspace, libName);
515
+ } else if (sysType === "pkg") {
516
+ const pkgs = await workspace.getPkgs();
517
+ if (value && pkgs.includes(value))
518
+ return PkgExecutor.from(workspace, value);
519
+ const pkgName = await select({ message: `Select the ${sysType} name`, choices: pkgs });
520
+ return PkgExecutor.from(workspace, pkgName);
521
+ } else if (sysType === "module") {
522
+ if (value) {
523
+ const [sysName, moduleName2] = value.split(":");
524
+ if (!sysName || !moduleName2)
525
+ throw new Error(`Invalid module name: ${value}`);
526
+ if (appNames.includes(sysName)) {
527
+ const app = AppExecutor.from(workspace, sysName);
528
+ const modules2 = await app.getModules();
529
+ if (modules2.includes(moduleName2))
530
+ return ModuleExecutor.from(app, moduleName2);
531
+ else
532
+ throw new Error(`Invalid module name: ${moduleName2}`);
533
+ } else if (libNames.includes(sysName)) {
534
+ const lib = LibExecutor.from(workspace, sysName);
535
+ const modules2 = await lib.getModules();
536
+ if (modules2.includes(moduleName2))
537
+ return ModuleExecutor.from(lib, moduleName2);
538
+ } else
539
+ throw new Error(`Invalid system name: ${sysName}`);
540
+ }
541
+ const { type, name } = await select({
542
+ message: `select the App or Lib name`,
543
+ choices: [
544
+ ...appNames.map((name2) => ({ name: name2, value: { type: "app", name: name2 } })),
545
+ ...libNames.map((name2) => ({ name: name2, value: { type: "lib", name: name2 } }))
546
+ ]
547
+ });
548
+ const executor = type === "app" ? AppExecutor.from(workspace, name) : LibExecutor.from(workspace, name);
549
+ const modules = await executor.getModules();
550
+ const moduleName = await select({
551
+ message: `Select the module name`,
552
+ choices: modules.map((name2) => ({ name: `${executor.name}:${name2}`, value: name2 }))
553
+ });
554
+ return ModuleExecutor.from(executor, moduleName);
555
+ } else
556
+ throw new Error(`Invalid system type: ${argMeta.type}`);
557
+ };
558
+ var runCommands = async (...commands) => {
559
+ process.on("unhandledRejection", (error) => {
560
+ printCliError(error);
561
+ process.exit(1);
562
+ });
563
+ const __dirname2 = getDirname(import.meta.url);
564
+ const packageJsonCandidates = [`${path.dirname(Bun.main)}/package.json`, `${__dirname2}/../package.json`];
565
+ let cliPackageJson = null;
566
+ for (const packageJsonPath of packageJsonCandidates) {
567
+ if (!await FileSys.fileExists(packageJsonPath))
568
+ continue;
569
+ const packageJson = await FileSys.readJson(packageJsonPath);
570
+ if (packageJson.name === "@akanjs/cli" || packageJson.name === "@akanjs/devkit") {
571
+ cliPackageJson = packageJson;
572
+ break;
573
+ }
574
+ }
575
+ process.env.AKAN_VERSION = cliPackageJson?.version ?? "0.0.1";
576
+ const hasHelpFlag = process.argv.includes("--help") || process.argv.includes("-h");
577
+ const hasCommand = process.argv.length > 2 && !process.argv[2]?.startsWith("-");
578
+ if (hasHelpFlag || !hasCommand) {
579
+ if (process.argv.length === 2 || process.argv.length === 3 && hasHelpFlag) {
580
+ Logger.rawLog(formatHelp(commands, process.env.AKAN_VERSION));
581
+ process.exit(0);
582
+ }
583
+ }
584
+ program.version(process.env.AKAN_VERSION).description("Akan CLI").configureHelp({
585
+ helpWidth: 100
586
+ });
587
+ const installedAkanPackageJson = await FileSys.fileExists("./node_modules/akanjs/package.json") ? await FileSys.readJson("./node_modules/akanjs/package.json") : null;
588
+ if (installedAkanPackageJson && installedAkanPackageJson.version !== process.env.AKAN_VERSION) {
589
+ Logger.rawLog(chalk2.yellow(`
590
+ Akan CLI version is mismatch with installed package. ${process.env.AKAN_VERSION} (global) vs ${installedAkanPackageJson.version} (akanjs)
591
+ It may cause unexpected behavior. Run \`akan update\` to update latest akanjs.`));
592
+ }
593
+ for (const command of commands) {
594
+ const targetMetas = getTargetMetas(command);
595
+ for (const targetMeta of targetMetas) {
596
+ const commandNames = getTargetCommandNames(targetMeta);
597
+ for (const commandName of commandNames) {
598
+ let programCommand = program.command(commandName, {
599
+ hidden: targetMeta.targetOption.devOnly
600
+ });
601
+ const [allArgMetas] = getArgMetas(command, targetMeta.key);
602
+ for (const argMeta of allArgMetas) {
603
+ if (argMeta.type === "Option")
604
+ programCommand = handleOption(programCommand, argMeta);
605
+ else if (argMeta.type === "Argument")
606
+ programCommand = handleArgument(programCommand, argMeta);
607
+ else if (argMeta.type === "Workspace")
608
+ continue;
609
+ else if (argMeta.type === "Module") {
610
+ programCommand = programCommand.argument(`[sys-name:module-name]`, `${argMeta.type} in this workspace (apps|libs)/<sys-name>/lib/<module-name>`);
611
+ } else {
612
+ const sysType = argMeta.type.toLowerCase();
613
+ programCommand = programCommand.argument(`[${sysType}]`, `${sysType} in this workspace ${sysType}s/<${sysType}Name>`);
614
+ }
615
+ }
616
+ programCommand = programCommand.option(`-v, --verbose [boolean]`, `verbose output`);
617
+ programCommand.helpInformation = () => {
618
+ return formatCommandHelp(command, targetMeta.key);
619
+ };
620
+ programCommand.action(async (...args) => {
621
+ if (!targetMeta.targetOption.stdio)
622
+ Logger.rawLog();
623
+ const cmdArgs = args.slice(0, args.length - 2);
624
+ const opt = args[args.length - 2];
625
+ const commandArgs = [];
626
+ if (targetMeta.targetOption.runsOnWorkspaceRoot)
627
+ await assertCurrentDirectoryIsWorkspaceRoot();
628
+ const workspace = WorkspaceExecutor.fromRoot();
629
+ const commandContext = { values: {} };
630
+ for (const argMeta of allArgMetas) {
631
+ if (argMeta.type === "Option")
632
+ commandArgs[argMeta.idx] = await getOptionValue(argMeta, opt, commandContext);
633
+ else if (argMeta.type === "Argument")
634
+ commandArgs[argMeta.idx] = await getArgumentValue(argMeta, cmdArgs[argMeta.idx]);
635
+ else
636
+ commandArgs[argMeta.idx] = await getInternalArgumentValue(argMeta, cmdArgs[argMeta.idx], workspace);
637
+ if (commandArgs[argMeta.idx] instanceof AppExecutor)
638
+ process.env.AKAN_PUBLIC_APP_NAME = commandArgs[argMeta.idx].name;
639
+ assignCommandContext(commandContext, argMeta, commandArgs[argMeta.idx]);
640
+ if (opt.verbose)
641
+ Executor.setVerbose(true);
642
+ }
643
+ const cmd = CommandContainer.get(command);
644
+ try {
645
+ await targetMeta.handler.call(cmd, ...commandArgs);
646
+ if (!targetMeta.targetOption.stdio)
647
+ Logger.rawLog();
648
+ } catch (e) {
649
+ printCliError(e);
650
+ throw e;
651
+ }
652
+ });
653
+ }
654
+ }
655
+ }
656
+ await program.parseAsync(process.argv);
657
+ };
658
+
659
+ // pkgs/@akanjs/devkit/commandDecorators/commandBuilder.ts
660
+ class TargetBuilder {
661
+ targetOption;
662
+ #args;
663
+ constructor(targetOption, args = []) {
664
+ this.targetOption = targetOption;
665
+ this.#args = args;
666
+ }
667
+ arg(name, type, argsOption = {}) {
668
+ return new TargetBuilder(this.targetOption, [
669
+ ...this.#args,
670
+ {
671
+ name,
672
+ argsOption: { ...argsOption, type: normalizePrimitiveArgType(type) },
673
+ key: "",
674
+ idx: this.#args.length,
675
+ type: "Argument"
676
+ }
677
+ ]);
678
+ }
679
+ option(name, type, argsOption = {}) {
680
+ return new TargetBuilder(this.targetOption, [
681
+ ...this.#args,
682
+ {
683
+ name,
684
+ argsOption: { ...argsOption, type: normalizePrimitiveArgType(type) },
685
+ key: "",
686
+ idx: this.#args.length,
687
+ type: "Option"
688
+ }
689
+ ]);
690
+ }
691
+ with(...tokens) {
692
+ return new TargetBuilder(this.targetOption, [
693
+ ...this.#args,
694
+ ...tokens.map((token, offset) => ({
695
+ key: "",
696
+ idx: this.#args.length + offset,
697
+ type: token.type
698
+ }))
699
+ ]);
700
+ }
701
+ exec(handler) {
702
+ return {
703
+ args: this.#args,
704
+ handler,
705
+ targetOption: this.targetOption
706
+ };
707
+ }
708
+ }
709
+ var createTarget = (type) => (targetOption = {}) => new TargetBuilder({ runsOnWorkspaceRoot: true, ...targetOption, type });
710
+ var createContext = () => ({
711
+ public: createTarget("public"),
712
+ cloud: createTarget("cloud"),
713
+ dev: createTarget("dev"),
714
+ arg: (name, type, argsOption) => ({
715
+ name,
716
+ argsOption: { ...argsOption ?? {}, type: normalizePrimitiveArgType(type) },
717
+ key: "",
718
+ idx: -1,
719
+ type: "Argument"
720
+ }),
721
+ option: (name, type, argsOption) => ({
722
+ name,
723
+ argsOption: { ...argsOption ?? {}, type: normalizePrimitiveArgType(type) },
724
+ key: "",
725
+ idx: -1,
726
+ type: "Option"
727
+ })
728
+ });
729
+ var buildCommandMeta = (definitions) => {
730
+ const commandMeta = new Map;
731
+ for (const [key, definition] of Object.entries(definitions)) {
732
+ commandMeta.set(key, {
733
+ key,
734
+ args: definition.args.map((arg) => ({ ...arg, key })),
735
+ handler: definition.handler,
736
+ targetOption: definition.targetOption
737
+ });
738
+ }
739
+ return commandMeta;
740
+ };
741
+ function command(refName, depsOrBuilder, builder) {
742
+ const deps = Array.isArray(depsOrBuilder) ? depsOrBuilder : [];
743
+ const commandBuilder = Array.isArray(depsOrBuilder) ? builder : depsOrBuilder;
744
+ assertUniqueDependencies(deps);
745
+ const commandMeta = buildCommandMeta(commandBuilder(createContext()));
746
+
747
+ class CommandBase {
748
+ static refName = refName;
749
+ static dependencyKind = "command";
750
+ static dependencyKey = `${refName}Command`;
751
+ static [COMMAND_META] = commandMeta;
752
+ constructor() {
753
+ injectDependencies(this, deps);
754
+ }
755
+ }
756
+ return CommandBase;
757
+ }
758
+ export { getTargetMetas, getTargetCommandNames, App, Lib, Sys, Exec, Pkg, Module, Workspace, CommandContainer, runner, script, runCommands, command };