@prism-d1/cli 1.0.57 → 1.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/index.js CHANGED
@@ -1,44 +1,82 @@
1
- import { readdirSync, statSync } from 'node:fs';
1
+ import { readdirSync, statSync, existsSync } from 'node:fs';
2
2
  import { resolve, dirname, basename } from 'node:path';
3
3
  import { fileURLToPath, pathToFileURL } from 'node:url';
4
4
  const __dirname = dirname(fileURLToPath(import.meta.url));
5
5
  const commandsDir = resolve(__dirname, 'commands');
6
+ function attach(program, category, command, def) {
7
+ // Reuse an existing category command if it was already created
8
+ let categoryCmd = program.commands.find((c) => c.name() === category);
9
+ if (!categoryCmd)
10
+ categoryCmd = program.command(category).description(`${category} commands`);
11
+ const sub = categoryCmd.command(command).description(def.description || command);
12
+ if (def.options) {
13
+ for (const opt of def.options)
14
+ sub.option(opt.flags, opt.description, opt.default);
15
+ }
16
+ sub.action((opts) => def.action(opts));
17
+ }
6
18
  /**
7
- * Auto-discovers and registers commands from the filesystem.
8
- *
9
- * Structure:
10
- * commands/
11
- * <category>/ → becomes `prism-cli <category>`
12
- * <command>.js → becomes `prism-cli <category> <command>`
13
- *
14
- * Each command file must export a default object:
15
- * { description: string, options?: [{flags, description, default?}], action: (options) => void }
19
+ * Fast path: import and register ONLY the `<category> <command>` module being
20
+ * invoked. Returns false if the module can't be found (so we can fall back).
21
+ * Supports both compiled `.js` (published) and `.ts` (tsx dev) layouts.
16
22
  */
17
- export async function registerCommands(program) {
23
+ async function registerOne(program, category, command) {
24
+ const categoryDir = resolve(commandsDir, category);
25
+ if (!existsSync(categoryDir) || !statSync(categoryDir).isDirectory())
26
+ return false;
27
+ let file = '';
28
+ for (const candidate of [`${command}.js`, `${command}.ts`]) {
29
+ const p = resolve(categoryDir, candidate);
30
+ if (existsSync(p)) {
31
+ file = p;
32
+ break;
33
+ }
34
+ }
35
+ if (!file)
36
+ return false;
37
+ const mod = await import(pathToFileURL(file).href);
38
+ attach(program, category, command, mod.default || mod);
39
+ return true;
40
+ }
41
+ /** Full registration — imports every command module. Used for --help and unmatched invocations. */
42
+ async function registerAll(program) {
18
43
  const categories = readdirSync(commandsDir).filter((entry) => {
19
44
  return statSync(resolve(commandsDir, entry)).isDirectory();
20
45
  });
21
46
  for (const category of categories) {
22
47
  const categoryDir = resolve(commandsDir, category);
23
- const categoryCmd = program
24
- .command(category)
25
- .description(`${category} commands`);
26
48
  const files = readdirSync(categoryDir).filter((f) => f.endsWith('.js') && !f.endsWith('.d.ts'));
27
49
  for (const file of files) {
28
50
  const commandName = basename(file, '.js');
29
51
  const modulePath = pathToFileURL(resolve(categoryDir, file)).href;
30
52
  const mod = await import(modulePath);
31
- const def = mod.default || mod;
32
- const sub = categoryCmd
33
- .command(commandName)
34
- .description(def.description || commandName);
35
- if (def.options) {
36
- for (const opt of def.options) {
37
- sub.option(opt.flags, opt.description, opt.default);
38
- }
39
- }
40
- sub.action((opts) => def.action(opts));
53
+ attach(program, category, commandName, mod.default || mod);
41
54
  }
42
55
  }
43
56
  }
57
+ /**
58
+ * Auto-discovers and registers commands from the filesystem.
59
+ *
60
+ * Structure:
61
+ * commands/
62
+ * <category>/ → becomes `prism-cli <category>`
63
+ * <command>.js → becomes `prism-cli <category> <command>`
64
+ *
65
+ * Each command file must export a default object:
66
+ * { description: string, options?: [{flags, description, default?}], action: (options) => void }
67
+ *
68
+ * Performance: when invoked as `prism-cli <category> <command>`, only that one
69
+ * module is imported (lazy fast path). This keeps latency-sensitive callers
70
+ * such as the prepare-commit-msg git hook from eagerly loading the entire
71
+ * command tree (including heavy assessment/CDK modules). All other invocations
72
+ * (--help, --version, bare category, unknown commands) register everything.
73
+ */
74
+ export async function registerCommands(program) {
75
+ const [category, command] = process.argv.slice(2);
76
+ if (category && command && !category.startsWith('-') && !command.startsWith('-')) {
77
+ if (await registerOne(program, category, command))
78
+ return;
79
+ }
80
+ await registerAll(program);
81
+ }
44
82
  //# sourceMappingURL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C,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAAY;IACjD,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClD,IAAI,QAAQ,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACjF,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC;YAAE,OAAO;IAC5D,CAAC;IACD,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prism-d1/cli",
3
- "version": "1.0.57",
3
+ "version": "1.0.59",
4
4
  "description": "PRISM D1 Velocity CLI — AI development lifecycle assessment tool",
5
5
  "author": "andklee",
6
6
  "engines": {