@nzyme/cli 0.14.0 → 0.15.1

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 (137) hide show
  1. package/bin/cli.js +3 -0
  2. package/dist/Command.d.ts +48 -5
  3. package/dist/Command.js +69 -6
  4. package/dist/Command.js.map +1 -1
  5. package/dist/Command.test.d.ts +1 -0
  6. package/dist/Command.test.js +77 -0
  7. package/dist/Command.test.js.map +1 -0
  8. package/dist/cli.d.ts +1 -1
  9. package/dist/cli.js +23 -3
  10. package/dist/cli.js.map +1 -1
  11. package/dist/codeIndex/IndexSettings.d.ts +60 -0
  12. package/dist/codeIndex/IndexSettings.js +59 -0
  13. package/dist/codeIndex/IndexSettings.js.map +1 -0
  14. package/dist/codeIndex/IndexSymbol.d.ts +32 -0
  15. package/dist/codeIndex/IndexSymbol.js +2 -0
  16. package/dist/codeIndex/IndexSymbol.js.map +1 -0
  17. package/dist/codeIndex/NzymeIndexConfig.d.ts +72 -0
  18. package/dist/codeIndex/NzymeIndexConfig.js +101 -0
  19. package/dist/codeIndex/NzymeIndexConfig.js.map +1 -0
  20. package/dist/codeIndex/NzymeIndexConfig.test.d.ts +1 -0
  21. package/dist/codeIndex/NzymeIndexConfig.test.js +56 -0
  22. package/dist/codeIndex/NzymeIndexConfig.test.js.map +1 -0
  23. package/dist/codeIndex/collectIndexSourceFiles.d.ts +8 -0
  24. package/dist/codeIndex/collectIndexSourceFiles.js +57 -0
  25. package/dist/codeIndex/collectIndexSourceFiles.js.map +1 -0
  26. package/dist/codeIndex/collectSymbols.d.ts +27 -0
  27. package/dist/codeIndex/collectSymbols.js +151 -0
  28. package/dist/codeIndex/collectSymbols.js.map +1 -0
  29. package/dist/codeIndex/collectSymbols.test.d.ts +1 -0
  30. package/dist/codeIndex/collectSymbols.test.js +204 -0
  31. package/dist/codeIndex/collectSymbols.test.js.map +1 -0
  32. package/dist/codeIndex/extractComponent.d.ts +25 -0
  33. package/dist/codeIndex/extractComponent.js +38 -0
  34. package/dist/codeIndex/extractComponent.js.map +1 -0
  35. package/dist/codeIndex/extractComponent.test.d.ts +1 -0
  36. package/dist/codeIndex/extractComponent.test.js +65 -0
  37. package/dist/codeIndex/extractComponent.test.js.map +1 -0
  38. package/dist/codeIndex/extractDefineSymbol.d.ts +30 -0
  39. package/dist/codeIndex/extractDefineSymbol.js +86 -0
  40. package/dist/codeIndex/extractDefineSymbol.js.map +1 -0
  41. package/dist/codeIndex/extractDefineSymbol.test.d.ts +1 -0
  42. package/dist/codeIndex/extractDefineSymbol.test.js +142 -0
  43. package/dist/codeIndex/extractDefineSymbol.test.js.map +1 -0
  44. package/dist/codeIndex/extractEntity.d.ts +29 -0
  45. package/dist/codeIndex/extractEntity.js +63 -0
  46. package/dist/codeIndex/extractEntity.js.map +1 -0
  47. package/dist/codeIndex/extractEntity.test.d.ts +1 -0
  48. package/dist/codeIndex/extractEntity.test.js +79 -0
  49. package/dist/codeIndex/extractEntity.test.js.map +1 -0
  50. package/dist/codeIndex/extractUtil.d.ts +27 -0
  51. package/dist/codeIndex/extractUtil.js +98 -0
  52. package/dist/codeIndex/extractUtil.js.map +1 -0
  53. package/dist/codeIndex/extractUtil.test.d.ts +1 -0
  54. package/dist/codeIndex/extractUtil.test.js +111 -0
  55. package/dist/codeIndex/extractUtil.test.js.map +1 -0
  56. package/dist/codeIndex/importPathOf.d.ts +18 -0
  57. package/dist/codeIndex/importPathOf.js +17 -0
  58. package/dist/codeIndex/importPathOf.js.map +1 -0
  59. package/dist/codeIndex/importPathOf.test.d.ts +1 -0
  60. package/dist/codeIndex/importPathOf.test.js +40 -0
  61. package/dist/codeIndex/importPathOf.test.js.map +1 -0
  62. package/dist/codeIndex/jsdocSummary.d.ts +9 -0
  63. package/dist/codeIndex/jsdocSummary.js +18 -0
  64. package/dist/codeIndex/jsdocSummary.js.map +1 -0
  65. package/dist/codeIndex/jsdocSummary.test.d.ts +1 -0
  66. package/dist/codeIndex/jsdocSummary.test.js +33 -0
  67. package/dist/codeIndex/jsdocSummary.test.js.map +1 -0
  68. package/dist/codeIndex/renderMarkdown.d.ts +27 -0
  69. package/dist/codeIndex/renderMarkdown.js +171 -0
  70. package/dist/codeIndex/renderMarkdown.js.map +1 -0
  71. package/dist/codeIndex/renderMarkdown.test.d.ts +1 -0
  72. package/dist/codeIndex/renderMarkdown.test.js +291 -0
  73. package/dist/codeIndex/renderMarkdown.test.js.map +1 -0
  74. package/dist/commands/DepcheckCommand.d.ts +17 -0
  75. package/dist/commands/DepcheckCommand.js +229 -42
  76. package/dist/commands/DepcheckCommand.js.map +1 -1
  77. package/dist/commands/FormatMarkdownCommand.d.ts +22 -0
  78. package/dist/commands/FormatMarkdownCommand.js +256 -0
  79. package/dist/commands/FormatMarkdownCommand.js.map +1 -0
  80. package/dist/commands/FormatMarkdownCommand.test.d.ts +1 -0
  81. package/dist/commands/FormatMarkdownCommand.test.js +82 -0
  82. package/dist/commands/FormatMarkdownCommand.test.js.map +1 -0
  83. package/dist/commands/IndexCommand.d.ts +20 -0
  84. package/dist/commands/IndexCommand.js +81 -0
  85. package/dist/commands/IndexCommand.js.map +1 -0
  86. package/dist/commands/IndexCommand.test.d.ts +1 -0
  87. package/dist/commands/IndexCommand.test.js +126 -0
  88. package/dist/commands/IndexCommand.test.js.map +1 -0
  89. package/dist/commands/LocaliseCommand.d.ts +23 -0
  90. package/dist/commands/LocaliseCommand.js +125 -0
  91. package/dist/commands/LocaliseCommand.js.map +1 -0
  92. package/dist/commands/MonorepoCommand.d.ts +14 -0
  93. package/dist/commands/MonorepoCommand.js +243 -144
  94. package/dist/commands/MonorepoCommand.js.map +1 -1
  95. package/dist/commands/QuietRunCommand.d.ts +27 -0
  96. package/dist/commands/QuietRunCommand.js +140 -0
  97. package/dist/commands/QuietRunCommand.js.map +1 -0
  98. package/dist/commands/QuietRunCommand.test.d.ts +1 -0
  99. package/dist/commands/QuietRunCommand.test.js +48 -0
  100. package/dist/commands/QuietRunCommand.test.js.map +1 -0
  101. package/dist/commands/SubmoduleBumpCommand.d.ts +27 -0
  102. package/dist/commands/SubmoduleBumpCommand.js +77 -0
  103. package/dist/commands/SubmoduleBumpCommand.js.map +1 -0
  104. package/dist/execute.d.ts +7 -2
  105. package/dist/execute.js +4 -2
  106. package/dist/execute.js.map +1 -1
  107. package/dist/index.d.ts +1 -1
  108. package/dist/index.js +1 -1
  109. package/dist/index.js.map +1 -1
  110. package/dist/initialize.d.ts +1 -15
  111. package/dist/initialize.js +4 -8
  112. package/dist/initialize.js.map +1 -1
  113. package/dist/quietRun/quietRunReport.d.ts +70 -0
  114. package/dist/quietRun/quietRunReport.js +128 -0
  115. package/dist/quietRun/quietRunReport.js.map +1 -0
  116. package/dist/quietRun/quietRunReport.test.d.ts +1 -0
  117. package/dist/quietRun/quietRunReport.test.js +87 -0
  118. package/dist/quietRun/quietRunReport.test.js.map +1 -0
  119. package/dist/submodule/GitRepository.d.ts +70 -0
  120. package/dist/submodule/GitRepository.js +129 -0
  121. package/dist/submodule/GitRepository.js.map +1 -0
  122. package/dist/submodule/bumpSubmodule.d.ts +45 -0
  123. package/dist/submodule/bumpSubmodule.js +52 -0
  124. package/dist/submodule/bumpSubmodule.js.map +1 -0
  125. package/dist/submodule/renderBumpSummary.d.ts +12 -0
  126. package/dist/submodule/renderBumpSummary.js +50 -0
  127. package/dist/submodule/renderBumpSummary.js.map +1 -0
  128. package/dist/submodule/renderBumpSummary.test.d.ts +1 -0
  129. package/dist/submodule/renderBumpSummary.test.js +55 -0
  130. package/dist/submodule/renderBumpSummary.test.js.map +1 -0
  131. package/dist/submodule/submodule.test.d.ts +1 -0
  132. package/dist/submodule/submodule.test.js +155 -0
  133. package/dist/submodule/submodule.test.js.map +1 -0
  134. package/package.json +55 -50
  135. package/dist/commands/BuildCommand.d.ts +0 -15
  136. package/dist/commands/BuildCommand.js +0 -49
  137. package/dist/commands/BuildCommand.js.map +0 -1
package/bin/cli.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bun
2
+
3
+ await import('../dist/cli.js');
package/dist/Command.d.ts CHANGED
@@ -1,16 +1,59 @@
1
- import { BaseContext, Command as ClipanionCommand, CommandClass as ClipanionCommandClass } from 'clipanion';
2
- import { Container } from '@nzyme/ioc';
1
+ import type { BaseContext, CommandClass as ClipanionCommandClass } from 'clipanion';
2
+ import { Command as ClipanionCommand } from 'clipanion';
3
+ import type { Container } from '@nzyme/ioc/Container.js';
4
+ import { Logger } from '@nzyme/logging/Logger.js';
5
+ /**
6
+ * Rewrites an error a command threw before it is reported — e.g. to turn an opaque library failure
7
+ * into an actionable message. Returns (or resolves to) the error to report in its place, or
8
+ * `null`/`undefined` to report the original unchanged.
9
+ */
10
+ export type CommandErrorHandler = (error: unknown) => unknown;
11
+ /** Clipanion command context extended with an IoC container. */
3
12
  export interface CommandContext extends BaseContext {
13
+ /** The IoC container available to all commands. */
4
14
  container: Container;
15
+ /** Applied by {@link Command.catch} to every error a command throws, before it is reported. */
16
+ onError?: CommandErrorHandler;
5
17
  }
18
+ /** Scope identifier for command-level IoC container isolation. */
6
19
  export declare const CommandScope: Readonly<{
7
20
  name: string;
8
21
  }>;
22
+ /** A Clipanion command class with the CommandContext. */
9
23
  export type CommandClass = ClipanionCommandClass<CommandContext>;
24
+ /** Base class for CLI commands with IoC container, logging, and lifecycle events. */
10
25
  export declare abstract class Command extends ClipanionCommand<CommandContext> {
11
26
  #private;
12
- protected get container(): Container;
13
- execute(): Promise<void>;
27
+ /**
28
+ * Event emitter for the before run event
29
+ */
30
+ get beforeRun(): import("@nzyme/utils/createEventEmitter.js").EventEmitter<[]>;
31
+ /**
32
+ * Event emitter for the after run event
33
+ */
34
+ get afterRun(): import("@nzyme/utils/createEventEmitter.js").EventEmitter<[]>;
35
+ /**
36
+ * Event emitter for the cleanup event
37
+ */
38
+ get cleanup(): import("@nzyme/utils/createEventEmitter.js").EventEmitter<[]>;
39
+ /** The command's scoped IoC container. Throws if accessed before setup. */
40
+ get container(): Container;
41
+ /** The command's logger instance. Throws if accessed before setup. */
42
+ get logger(): Logger;
43
+ private readonly beforeRunEvent;
44
+ private readonly afterRunEvent;
45
+ private readonly cleanupEvent;
46
+ /** Runs the command lifecycle: setup, beforeRun, run, afterRun, cleanup. */
47
+ execute(): Promise<void | number>;
48
+ /**
49
+ * Logs the error and exits the process with code 1. The error is first passed through the
50
+ * context's `onError` handler, so one handler set on `execute()` covers every command — clipanion
51
+ * routes every command failure through `catch()`, making it the single place to apply it.
52
+ * Parameter is intentionally not named `error`/`err` — that shape makes
53
+ * eslint-plugin-promise's `no-promise-in-callback` heuristic mistake this override for a
54
+ * Node-style error-first callback and flag the awaited handler below.
55
+ */
56
+ catch(commandError: unknown): Promise<void>;
14
57
  protected setup(): Promise<void>;
15
- protected abstract run(): Promise<void>;
58
+ protected abstract run(): number | Promise<number | void> | void;
16
59
  }
package/dist/Command.js CHANGED
@@ -1,23 +1,86 @@
1
- import { Command as ClipanionCommand, } from 'clipanion';
2
- import { defineScope } from '@nzyme/ioc';
3
- import { Logger } from '@nzyme/logging';
4
- import { PrettyLogger } from '@nzyme/logging';
1
+ import { Command as ClipanionCommand } from 'clipanion';
2
+ import { defineScope } from '@nzyme/ioc/ContainerScope.js';
3
+ import { Logger } from '@nzyme/logging/Logger.js';
4
+ import { PrettyCliLoggerTransport } from '@nzyme/logging/PrettyCliLoggerTransport.js';
5
+ import { createEventEmitter } from '@nzyme/utils/createEventEmitter.js';
6
+ import { getClassName } from '@nzyme/utils/getClassName.js';
7
+ /** Scope identifier for command-level IoC container isolation. */
5
8
  export const CommandScope = defineScope('command');
9
+ /** Base class for CLI commands with IoC container, logging, and lifecycle events. */
6
10
  export class Command extends ClipanionCommand {
11
+ /**
12
+ * Event emitter for the before run event
13
+ */
14
+ get beforeRun() {
15
+ return this.beforeRunEvent.event;
16
+ }
17
+ /**
18
+ * Event emitter for the after run event
19
+ */
20
+ get afterRun() {
21
+ return this.afterRunEvent.event;
22
+ }
23
+ /**
24
+ * Event emitter for the cleanup event
25
+ */
26
+ get cleanup() {
27
+ return this.cleanupEvent.event;
28
+ }
29
+ /** The command's scoped IoC container. Throws if accessed before setup. */
7
30
  get container() {
8
31
  if (!this.#container) {
9
32
  throw new Error('Not initialized yet');
10
33
  }
11
34
  return this.#container;
12
35
  }
36
+ /** The command's logger instance. Throws if accessed before setup. */
37
+ get logger() {
38
+ if (!this.#logger) {
39
+ throw new Error('Not initialized yet');
40
+ }
41
+ return this.#logger;
42
+ }
43
+ beforeRunEvent = createEventEmitter();
44
+ afterRunEvent = createEventEmitter();
45
+ cleanupEvent = createEventEmitter();
13
46
  #container = null;
47
+ #logger = null;
48
+ /** Runs the command lifecycle: setup, beforeRun, run, afterRun, cleanup. */
14
49
  async execute() {
15
50
  await this.setup();
16
- await this.run();
51
+ try {
52
+ await this.beforeRunEvent.emitAsync();
53
+ const result = await this.run();
54
+ await this.afterRunEvent.emitAsync();
55
+ return result;
56
+ }
57
+ finally {
58
+ await this.cleanupEvent.emitAsync();
59
+ }
60
+ }
61
+ /**
62
+ * Logs the error and exits the process with code 1. The error is first passed through the
63
+ * context's `onError` handler, so one handler set on `execute()` covers every command — clipanion
64
+ * routes every command failure through `catch()`, making it the single place to apply it.
65
+ * Parameter is intentionally not named `error`/`err` — that shape makes
66
+ * eslint-plugin-promise's `no-promise-in-callback` heuristic mistake this override for a
67
+ * Node-style error-first callback and flag the awaited handler below.
68
+ */
69
+ async catch(commandError) {
70
+ const reported = (await this.context.onError?.(commandError)) ?? commandError;
71
+ if (this.#logger) {
72
+ this.#logger.error('❌ Command execution failed', { error: reported });
73
+ }
74
+ else {
75
+ console.error('❌ Command execution failed', { error: reported });
76
+ }
77
+ process.exit(1);
17
78
  }
18
79
  setup() {
19
80
  this.#container = this.context.container.createChild(CommandScope);
20
- this.#container.set(Logger, PrettyLogger);
81
+ this.#container.register(PrettyCliLoggerTransport);
82
+ const transport = this.#container.resolve(PrettyCliLoggerTransport);
83
+ this.#logger = Logger.create({ name: getClassName(this), transport });
21
84
  return Promise.resolve();
22
85
  }
23
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Command.js","sourceRoot":"","sources":["../src/Command.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,OAAO,IAAI,gBAAgB,GAE9B,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAa,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAM9C,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;AAGnD,MAAM,OAAgB,OAAQ,SAAQ,gBAAgC;IAClE,IAAc,SAAS;QACnB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,UAAU,GAAqB,IAAI,CAAC;IAE3B,KAAK,CAAC,OAAO;QAClB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;IACrB,CAAC;IAES,KAAK;QACX,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACnE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAE1C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CAGJ"}
1
+ {"version":3,"file":"Command.js","sourceRoot":"","sources":["../src/Command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;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 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
1
+ import { PassThrough } from 'node:stream';
2
+ import { afterEach, beforeEach, expect, spyOn, test } from 'bun:test';
3
+ import { Cli } from 'clipanion';
4
+ import { createContainer } from '@nzyme/ioc/Container.js';
5
+ import { Command } from './Command.js';
6
+ const thrown = new Error('the original failure');
7
+ /**
8
+ * Fails on every run, so every run reaches `catch()`. Fails before `setup()` creates the logger, so
9
+ * the base handler reports through `console.error` with the error object itself, observable as is.
10
+ */
11
+ class FailingCommand extends Command {
12
+ static paths = [['fail']];
13
+ async execute() {
14
+ await Promise.resolve();
15
+ throw thrown;
16
+ }
17
+ run() { }
18
+ }
19
+ /** Thrown in place of a real `process.exit`, so the base handler's exit code stays observable. */
20
+ class ProcessExited extends Error {
21
+ code;
22
+ constructor(code) {
23
+ super(`process.exit(${String(code)})`);
24
+ this.code = code;
25
+ }
26
+ }
27
+ /** The details the base handler passed to `console.error`, one entry per report. */
28
+ let reported = [];
29
+ let exitCodes = [];
30
+ const spies = [];
31
+ beforeEach(() => {
32
+ reported = [];
33
+ exitCodes = [];
34
+ spies.push(spyOn(process, 'exit').mockImplementation(code => {
35
+ exitCodes.push(code);
36
+ throw new ProcessExited(code);
37
+ }), spyOn(console, 'error').mockImplementation((_message, details) => {
38
+ reported.push(details);
39
+ }));
40
+ });
41
+ afterEach(() => {
42
+ for (const spy of spies) {
43
+ spy.mockRestore();
44
+ }
45
+ spies.length = 0;
46
+ });
47
+ test('the context `onError` handler rewrites the error a command reports, and it still exits 1', async () => {
48
+ const received = [];
49
+ const rewritten = new Error('the rewritten failure');
50
+ // Async on purpose: the handler's result is awaited. (Not named `error` — see `Command.catch`.)
51
+ await runFailing(async (failure) => {
52
+ received.push(failure);
53
+ await Promise.resolve();
54
+ return rewritten;
55
+ });
56
+ expect(received).toEqual([thrown]);
57
+ expect(reported).toEqual([{ error: rewritten }]);
58
+ expect(exitCodes).toEqual([1]);
59
+ });
60
+ test('a handler returning nothing leaves the original error to be reported', async () => {
61
+ await runFailing(() => null);
62
+ expect(reported).toEqual([{ error: thrown }]);
63
+ expect(exitCodes).toEqual([1]);
64
+ });
65
+ test('without a handler the original error is reported', async () => {
66
+ await runFailing(undefined);
67
+ expect(reported).toEqual([{ error: thrown }]);
68
+ expect(exitCodes).toEqual([1]);
69
+ });
70
+ /** Runs {@link FailingCommand} through clipanion, the same path `execute()` takes. */
71
+ async function runFailing(onError) {
72
+ const cli = new Cli();
73
+ cli.register(FailingCommand);
74
+ // The mocked `process.exit` throws, which clipanion reports to `stdout` — swallow it there.
75
+ await cli.run(['fail'], { container: createContainer(), onError, stdout: new PassThrough() });
76
+ }
77
+ //# sourceMappingURL=Command.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Command.test.js","sourceRoot":"","sources":["../src/Command.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAEjD;;;GAGG;AACH,MAAM,cAAe,SAAQ,OAAO;IAChC,MAAM,CAAmB,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAEnC,KAAK,CAAC,OAAO;QAClB,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,MAAM,CAAC;IACjB,CAAC;IAEkB,GAAG,KAAI,CAAC;CAC9B;AAED,kGAAkG;AAClG,MAAM,aAAc,SAAQ,KAAK;IACR,IAAI;IAAzB,YAAqB,IAAwC;QACzD,KAAK,CAAC,gBAAgB,MA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AAW,EAAE,EAAE,CAAC,CAAC;AAClG,CAAC"}
package/dist/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env -S bun --enable-source-maps --conditions=source
2
2
  export {};
package/dist/cli.js CHANGED
@@ -1,14 +1,34 @@
1
- #!/usr/bin/env node
2
- import { BuildCommand } from './commands/BuildCommand.js';
1
+ #!/usr/bin/env -S bun --enable-source-maps --conditions=source
2
+ import { loadEnvVariables } from '@nzyme/project-utils/loadEnvVariables.js';
3
3
  import { DepcheckCommand } from './commands/DepcheckCommand.js';
4
+ import { FormatMarkdownCommand } from './commands/FormatMarkdownCommand.js';
5
+ import { IndexCommand } from './commands/IndexCommand.js';
6
+ import { LocaliseCommand } from './commands/LocaliseCommand.js';
4
7
  import { MonorepoCommand } from './commands/MonorepoCommand.js';
8
+ import { QuietRunCommand } from './commands/QuietRunCommand.js';
9
+ import { SubmoduleBumpCommand } from './commands/SubmoduleBumpCommand.js';
5
10
  import { execute } from './execute.js';
6
11
  import { initialize } from './initialize.js';
12
+ // `quiet-run` wraps an arbitrary command: it hands that command the environment untouched (the
13
+ // command loads its own `.env` if it wants one) and prints nothing beyond its own summary.
14
+ // `submodule` needs no `.env`, and its stdout is a contract workflows parse — so nothing else may
15
+ // be printed there (loading a `.env` logs a line to stdout).
16
+ if (process.argv[2] !== 'quiet-run' && process.argv[2] !== 'submodule') {
17
+ loadEnvVariables();
18
+ }
7
19
  // Initialize the CLI environment
8
20
  initialize();
9
21
  // Execute the CLI program
10
22
  await execute({
11
23
  name: 'nzyme',
12
- commands: [BuildCommand, MonorepoCommand, DepcheckCommand],
24
+ commands: [
25
+ MonorepoCommand,
26
+ DepcheckCommand,
27
+ LocaliseCommand,
28
+ FormatMarkdownCommand,
29
+ IndexCommand,
30
+ QuietRunCommand,
31
+ SubmoduleBumpCommand,
32
+ ],
13
33
  });
14
34
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,iCAAiC;AACjC,UAAU,EAAE,CAAC;AAEb,0BAA0B;AAC1B,MAAM,OAAO,CAAC;IACV,IAAI,EAAE,OAAO;IACb,QAAQ,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,eAAe,CAAC;CAC7D,CAAC,CAAC"}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAE5E,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,+FAA+F;AAC/F,2FAA2F;AAC3F,kGAAkG;AAClG,6DAA6D;AAC7D,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW,EAAE,CAAC;IACrE,gBAAgB,EAAE,CAAC;AACvB,CAAC;AAED,iCAAiC;AACjC,UAAU,EAAE,CAAC;AAEb,0BAA0B;AAC1B,MAAM,OAAO,CAAC;IACV,IAAI,EAAE,OAAO;IACb,QAAQ,EAAE;QACN,eAAe;QACf,eAAe;QACf,eAAe;QACf,qBAAqB;QACrB,YAAY;QACZ,eAAe;QACf,oBAAoB;KACvB;CACJ,CAAC,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { NzymeIndexConfig } from './NzymeIndexConfig.js';
2
+ /**
3
+ * Declarative description of one `defineX(...)` DSL call the indexer extracts — how to spot it
4
+ * (`callee`), where its internal name lives in the object literal (`nameKey`), and where it renders
5
+ * (`section`/`order`). Kept data-driven (rather than a switch per kind) so adding a new `defineX` DSL
6
+ * is a table row, not a new code path through the extractor.
7
+ */
8
+ export interface DefineSymbolKind {
9
+ /** Identifier of the kind, e.g. 'service'. */
10
+ kind: string;
11
+ /** Per-package INDEX.md heading this kind renders under, e.g. 'Services'. */
12
+ section: string;
13
+ /** The CallExpression identifier that marks this kind, e.g. 'defineService'. */
14
+ callee: string;
15
+ /** Object-literal key holding the internal name — also the label it renders with, e.g. 'name'. */
16
+ nameKey: string;
17
+ /** Ascending sort order among sections within a package's INDEX.md. */
18
+ order: number;
19
+ }
20
+ /** Everything the crawl and the rendering need to know beyond the packages themselves. */
21
+ export interface IndexSettings {
22
+ /** Every `defineX` kind to extract — the built-in ones plus the configured ones — by ascending order. */
23
+ defineKinds: readonly DefineSymbolKind[];
24
+ /** Packages whose `@util` helpers feed the root `UTILS.md`; empty means no `UTILS.md`. */
25
+ globalUtilPackages: ReadonlySet<string>;
26
+ /** Table-builder functions marking entities, and the packages they count in (null = all); null = no entities. */
27
+ entities: {
28
+ tableFunctions: ReadonlySet<string>;
29
+ packages: ReadonlySet<string> | null;
30
+ } | null;
31
+ }
32
+ /**
33
+ * The `defineX` DSL kinds every repo gets: those of the nzyme framework itself (`defineService`,
34
+ * `defineCommand`, `defineFactory`, `defineEndpoint`). Orders leave gaps so configured kinds can
35
+ * slot in between.
36
+ */
37
+ export declare const BUILTIN_DEFINE_KINDS: readonly DefineSymbolKind[];
38
+ /** Section title + render order for the kinds that aren't `defineX` DSL calls. */
39
+ export declare const EXTRA_SECTIONS: {
40
+ readonly component: {
41
+ readonly section: 'Components';
42
+ readonly order: 60;
43
+ };
44
+ readonly entity: {
45
+ readonly section: 'Entities';
46
+ readonly order: 70;
47
+ };
48
+ readonly util: {
49
+ readonly section: 'Utils';
50
+ readonly order: 80;
51
+ };
52
+ };
53
+ /**
54
+ * Resolves a repo's {@link NzymeIndexConfig} into the settings the indexer runs on: defaults
55
+ * applied, configured `defineX` kinds merged after the built-in ones, lists turned into sets.
56
+ * Throws when a configured kind clashes with a built-in kind or callee, which would otherwise
57
+ * silently shadow it.
58
+ * @__NO_SIDE_EFFECTS__
59
+ */
60
+ export declare function getIndexSettings(config: NzymeIndexConfig): IndexSettings;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The `defineX` DSL kinds every repo gets: those of the nzyme framework itself (`defineService`,
3
+ * `defineCommand`, `defineFactory`, `defineEndpoint`). Orders leave gaps so configured kinds can
4
+ * slot in between.
5
+ */
6
+ export const BUILTIN_DEFINE_KINDS = [
7
+ { kind: 'service', section: 'Services', callee: 'defineService', nameKey: 'name', order: 10 },
8
+ { kind: 'command', section: 'Commands', callee: 'defineCommand', nameKey: 'name', order: 20 },
9
+ { kind: 'factory', section: 'Factories', callee: 'defineFactory', nameKey: 'name', order: 30 },
10
+ { kind: 'endpoint', section: 'Endpoints', callee: 'defineEndpoint', nameKey: 'name', order: 50 },
11
+ ];
12
+ /** Section title + render order for the kinds that aren't `defineX` DSL calls. */
13
+ export const EXTRA_SECTIONS = {
14
+ component: { section: 'Components', order: 60 },
15
+ entity: { section: 'Entities', order: 70 },
16
+ util: { section: 'Utils', order: 80 },
17
+ };
18
+ /** Where a configured `defineX` kind renders when its config gives no order: after Endpoints. */
19
+ const DEFAULT_DEFINE_KIND_ORDER = 55;
20
+ /** Kinds a configured `defineX` kind may not reuse — they already mean something else. */
21
+ const RESERVED_KINDS = new Set([...BUILTIN_DEFINE_KINDS.map(kind => kind.kind), ...Object.keys(EXTRA_SECTIONS)]);
22
+ /**
23
+ * Resolves a repo's {@link NzymeIndexConfig} into the settings the indexer runs on: defaults
24
+ * applied, configured `defineX` kinds merged after the built-in ones, lists turned into sets.
25
+ * Throws when a configured kind clashes with a built-in kind or callee, which would otherwise
26
+ * silently shadow it.
27
+ * @__NO_SIDE_EFFECTS__
28
+ */
29
+ export function getIndexSettings(config) {
30
+ const defineKinds = [...BUILTIN_DEFINE_KINDS];
31
+ const callees = new Set(BUILTIN_DEFINE_KINDS.map(kind => kind.callee));
32
+ for (const kind of config.defineKinds ?? []) {
33
+ if (RESERVED_KINDS.has(kind.kind) || defineKinds.some(existing => existing.kind === kind.kind)) {
34
+ throw new Error(`Code index kind "${kind.kind}" is already defined.`);
35
+ }
36
+ if (callees.has(kind.callee)) {
37
+ throw new Error(`Code index callee "${kind.callee}" is already indexed.`);
38
+ }
39
+ callees.add(kind.callee);
40
+ defineKinds.push({
41
+ kind: kind.kind,
42
+ section: kind.section,
43
+ callee: kind.callee,
44
+ nameKey: kind.nameKey ?? 'name',
45
+ order: kind.order ?? DEFAULT_DEFINE_KIND_ORDER,
46
+ });
47
+ }
48
+ return {
49
+ defineKinds: defineKinds.toSorted((a, b) => a.order - b.order),
50
+ globalUtilPackages: new Set(config.globalUtilPackages ?? []),
51
+ entities: config.entities
52
+ ? {
53
+ tableFunctions: new Set(config.entities.tableFunctions),
54
+ packages: config.entities.packages ? new Set(config.entities.packages) : null,
55
+ }
56
+ : null,
57
+ };
58
+ }
59
+ //# sourceMappingURL=IndexSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexSettings.js","sourceRoot":"","sources":["../../src/codeIndex/IndexSettings.ts"],"names":[],"mappings":"AAkCA;;;;G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C,QAAQ;YACrB,CAAC,CAAC;gBACI,cAAc,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC;gBACvD,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI;aAChF;YACH,CAAC,CAAC,IAAI;KACb,CAAC;AACN,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The symbol kinds the indexer always knows, each with its own detection strategy: a `defineX` DSL
3
+ * callee (`service`/`command`/`factory`/`endpoint`), a `.vue` file (`component`), a table-builder
4
+ * call (`entity`, only when configured) or a `@util` JSDoc tag (`util`). A repo adds further
5
+ * `defineX` kinds through its `nzyme.index.defineKinds` config, which is why
6
+ * {@link IndexSymbol.kind} is an open string rather than this union.
7
+ */
8
+ export type BuiltinIndexSymbolKind = 'command' | 'component' | 'endpoint' | 'entity' | 'factory' | 'service' | 'util';
9
+ /**
10
+ * A single exported symbol discovered while walking the monorepo — the shared record every
11
+ * extractor produces and every renderer consumes. Kept intentionally flat (no per-kind subtypes) so
12
+ * renderers can treat all kinds uniformly and only branch on `kind` for the handful of fields that
13
+ * are kind-specific.
14
+ */
15
+ export interface IndexSymbol {
16
+ /** A {@link BuiltinIndexSymbolKind} or a configured `defineX` kind, e.g. 'actor'. */
17
+ kind: string;
18
+ /** Owning workspace package name, e.g. '@acme/database'. */
19
+ packageName: string;
20
+ /** Exported const/component identifier, e.g. 'PaymentClient'. */
21
+ exportName: string;
22
+ /** Deep import specifier a consumer would write, e.g. '@acme/payments/PaymentClient.js'. */
23
+ importPath: string;
24
+ /** Internal name the DSL carries (`name:` of a service/command/endpoint, a table name), else null. */
25
+ internalName: string | null;
26
+ /** One-line description (JSDoc summary / Vue leading comment), else null. */
27
+ description: string | null;
28
+ /** Rendered signature — only used for kind 'util', else null. */
29
+ signature: string | null;
30
+ /** Repo-relative declaring file path — stable sort key. */
31
+ relPath: string;
32
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IndexSymbol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexSymbol.js","sourceRoot":"","sources":["../../src/codeIndex/IndexSymbol.ts"],"names":[],"mappings":""}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Configuration of `nzyme index`, read from the `nzyme.index` field of the repo's root
3
+ * `package.json`. Everything is optional: the generic kinds (services, commands, factories,
4
+ * endpoints, components, `@util` helpers) are always indexed, and this only adds what is specific to
5
+ * one repo — which packages feed the global `UTILS.md`, extra `defineX` DSLs, and database entities.
6
+ *
7
+ * @example
8
+ * ```json
9
+ * {
10
+ * "nzyme": {
11
+ * "index": {
12
+ * "globalUtilPackages": ["@acme/utils", "@nzyme/utils"],
13
+ * "defineKinds": [
14
+ * { "kind": "actor", "section": "Actors", "callee": "defineActor", "nameKey": "type", "order": 40 }
15
+ * ],
16
+ * "entities": { "packages": ["@acme/database"], "tableFunctions": ["pgTable"] }
17
+ * }
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ export interface NzymeIndexConfig {
23
+ /**
24
+ * Packages whose `@util` helpers are context-agnostic enough to also be listed in the root
25
+ * `UTILS.md`. Every package's `@util` helpers still appear in that package's own `INDEX.md`; only
26
+ * these foundational packages additionally surface in the repo-wide catalogue. Without any, no
27
+ * `UTILS.md` is written.
28
+ */
29
+ globalUtilPackages?: string[];
30
+ /** Further `defineX` DSLs to index, beside the built-in services, commands, factories and endpoints. */
31
+ defineKinds?: NzymeIndexDefineKindConfig[];
32
+ /** Database entities — exported table definitions — to index. Not indexed when absent. */
33
+ entities?: NzymeIndexEntitiesConfig;
34
+ }
35
+ /**
36
+ * An extra `export const X = defineX({ ... })` DSL to index, e.g. `defineActor` — a table row rather
37
+ * than code, because every `defineX` kind is matched the same way.
38
+ */
39
+ export interface NzymeIndexDefineKindConfig {
40
+ /** Identifier of the kind, e.g. 'actor'. Must not clash with a built-in kind. */
41
+ kind: string;
42
+ /** Heading of the per-package `INDEX.md` section listing these symbols, e.g. 'Actors'. */
43
+ section: string;
44
+ /** The function whose call marks the symbol, e.g. 'defineActor'. */
45
+ callee: string;
46
+ /** Key of the first-argument object literal holding the internal name. Defaults to 'name'. */
47
+ nameKey?: string;
48
+ /**
49
+ * Position of the section within a package's `INDEX.md`; the built-in sections are Services 10,
50
+ * Commands 20, Factories 30, Endpoints 50, Components 60, Entities 70 and Utils 80. Defaults to 55.
51
+ */
52
+ order?: number;
53
+ }
54
+ /** Which exported table definitions count as database entities, e.g. Drizzle's `pgTable(...)`. */
55
+ export interface NzymeIndexEntitiesConfig {
56
+ /** Functions whose call defines a table, e.g. ['pgTable']; the table name is their first argument. */
57
+ tableFunctions: string[];
58
+ /** Packages whose tables are indexed — keeps look-alike calls elsewhere out. Every package when absent. */
59
+ packages?: string[];
60
+ }
61
+ /**
62
+ * Reads {@link NzymeIndexConfig} from the `nzyme.index` field of `<root>/package.json`, so a repo
63
+ * configures the index next to its other tooling rather than in a separate file. A missing field is
64
+ * an empty config; a malformed one throws, naming the offending path.
65
+ */
66
+ export declare function readIndexConfig(root: string): Promise<NzymeIndexConfig>;
67
+ /**
68
+ * Validates a raw `nzyme.index` value into an {@link NzymeIndexConfig}. Hand-rolled rather than
69
+ * schema-based: the shape is small and this keeps the CLI free of a validation dependency.
70
+ * @__NO_SIDE_EFFECTS__
71
+ */
72
+ export declare function parseIndexConfig(value: unknown): NzymeIndexConfig;
@@ -0,0 +1,101 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { isPlainObject } from '@nzyme/utils/isPlainObject.js';
4
+ /**
5
+ * Reads {@link NzymeIndexConfig} from the `nzyme.index` field of `<root>/package.json`, so a repo
6
+ * configures the index next to its other tooling rather than in a separate file. A missing field is
7
+ * an empty config; a malformed one throws, naming the offending path.
8
+ */
9
+ export async function readIndexConfig(root) {
10
+ const packageJson = JSON.parse(await readFile(join(root, 'package.json'), 'utf8'));
11
+ const nzyme = isPlainObject(packageJson) ? packageJson.nzyme : undefined;
12
+ const index = isPlainObject(nzyme) ? nzyme.index : undefined;
13
+ return parseIndexConfig(index);
14
+ }
15
+ /**
16
+ * Validates a raw `nzyme.index` value into an {@link NzymeIndexConfig}. Hand-rolled rather than
17
+ * schema-based: the shape is small and this keeps the CLI free of a validation dependency.
18
+ * @__NO_SIDE_EFFECTS__
19
+ */
20
+ export function parseIndexConfig(value) {
21
+ if (value === undefined) {
22
+ return {};
23
+ }
24
+ if (!isPlainObject(value)) {
25
+ throw configError('nzyme.index', 'an object');
26
+ }
27
+ const config = {};
28
+ if (value.globalUtilPackages !== undefined) {
29
+ config.globalUtilPackages = parseStringArray(value.globalUtilPackages, 'nzyme.index.globalUtilPackages');
30
+ }
31
+ if (value.defineKinds !== undefined) {
32
+ if (!Array.isArray(value.defineKinds)) {
33
+ throw configError('nzyme.index.defineKinds', 'an array');
34
+ }
35
+ config.defineKinds = [];
36
+ for (const [index, entry] of value.defineKinds.entries()) {
37
+ config.defineKinds.push(parseDefineKind(entry, `nzyme.index.defineKinds[${index}]`));
38
+ }
39
+ }
40
+ if (value.entities !== undefined) {
41
+ config.entities = parseEntities(value.entities, 'nzyme.index.entities');
42
+ }
43
+ return config;
44
+ }
45
+ /** Validates one `defineKinds` entry. */
46
+ function parseDefineKind(value, path) {
47
+ if (!isPlainObject(value)) {
48
+ throw configError(path, 'an object');
49
+ }
50
+ const kind = {
51
+ kind: parseString(value.kind, `${path}.kind`),
52
+ section: parseString(value.section, `${path}.section`),
53
+ callee: parseString(value.callee, `${path}.callee`),
54
+ };
55
+ if (value.nameKey !== undefined) {
56
+ kind.nameKey = parseString(value.nameKey, `${path}.nameKey`);
57
+ }
58
+ if (value.order !== undefined) {
59
+ if (typeof value.order !== 'number' || !Number.isFinite(value.order)) {
60
+ throw configError(`${path}.order`, 'a number');
61
+ }
62
+ kind.order = value.order;
63
+ }
64
+ return kind;
65
+ }
66
+ /** Validates the `entities` object. */
67
+ function parseEntities(value, path) {
68
+ if (!isPlainObject(value)) {
69
+ throw configError(path, 'an object');
70
+ }
71
+ const entities = {
72
+ tableFunctions: parseStringArray(value.tableFunctions, `${path}.tableFunctions`),
73
+ };
74
+ if (value.packages !== undefined) {
75
+ entities.packages = parseStringArray(value.packages, `${path}.packages`);
76
+ }
77
+ return entities;
78
+ }
79
+ /** Validates an array of non-empty strings. */
80
+ function parseStringArray(value, path) {
81
+ if (!Array.isArray(value)) {
82
+ throw configError(path, 'an array of strings');
83
+ }
84
+ const strings = [];
85
+ for (const [index, item] of value.entries()) {
86
+ strings.push(parseString(item, `${path}[${index}]`));
87
+ }
88
+ return strings;
89
+ }
90
+ /** Validates a non-empty string. */
91
+ function parseString(value, path) {
92
+ if (typeof value !== 'string' || value === '') {
93
+ throw configError(path, 'a non-empty string');
94
+ }
95
+ return value;
96
+ }
97
+ /** The error for a config value of the wrong shape. */
98
+ function configError(path, expected) {
99
+ return new Error(`Invalid code index config in package.json: \`${path}\` must be ${expected}.`);
100
+ }
101
+ //# sourceMappingURL=NzymeIndexConfig.js.map