juisy 2.0.0-beta.0 → 2.0.0-beta.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 (110) hide show
  1. package/bin/cli/cli.js +6 -4
  2. package/bin/cli/cmds/index.js +10 -10
  3. package/bin/cli/cmds/private/docs/generate-api.js +31 -0
  4. package/bin/cli/cmds/{docs → private/docs}/index.js +4 -6
  5. package/bin/cli/cmds/{print-globals.js → public/print-globals.js} +0 -1
  6. package/bin/scripts/prepare.js +22 -0
  7. package/dist/DataExporter.d.ts +6 -0
  8. package/dist/cli/CLIFactory.d.ts +48 -11
  9. package/dist/cli/Command.d.ts +23 -13
  10. package/dist/cli/GlobalSettings.schema.json +1 -0
  11. package/dist/cli/InterfaceUtils.d.ts +8 -2
  12. package/dist/cli/OutputUtils.d.ts +3 -3
  13. package/dist/cli/Plugin.d.ts +21 -0
  14. package/dist/cli/extract-usage.d.ts +7 -1
  15. package/dist/cli/index.d.ts +19 -6
  16. package/dist/cli/index.js +1160 -138
  17. package/dist/cli/plugins/command-handler-injections/augment.d.ts +29 -0
  18. package/dist/cli/{command-visitors → plugins/command-handler-injections/command-visitors}/command-handler-injections.d.ts +1 -1
  19. package/dist/cli/plugins/command-handler-injections/index.d.ts +3 -0
  20. package/dist/cli/plugins/command-meta/augment.d.ts +23 -0
  21. package/dist/cli/{command-visitors/get-command-meta.d.ts → plugins/command-meta/command-visitors/command-meta.d.ts} +1 -1
  22. package/dist/cli/plugins/command-meta/index.d.ts +3 -0
  23. package/dist/cli/plugins/default-command-fallbacks/augment.d.ts +3 -0
  24. package/dist/cli/plugins/default-command-fallbacks/command-visitors/default-command-fallbacks.d.ts +10 -0
  25. package/dist/cli/plugins/default-command-fallbacks/index.d.ts +3 -0
  26. package/dist/cli/plugins/load-env-file/augment.d.ts +9 -0
  27. package/dist/cli/plugins/load-env-file/index.d.ts +3 -0
  28. package/dist/cli/plugins/private-commands/augment.d.ts +6 -0
  29. package/dist/cli/{command-visitors → plugins/private-commands/command-visitors}/private-command.d.ts +1 -1
  30. package/dist/cli/plugins/private-commands/index.d.ts +3 -0
  31. package/dist/cli/plugins/register-changelog-command/augment.d.ts +110 -0
  32. package/dist/cli/plugins/register-changelog-command/cmds/index.d.ts +3 -0
  33. package/dist/cli/plugins/register-changelog-command/index.d.ts +3 -0
  34. package/dist/cli/plugins/register-docs-commands/augment.d.ts +18 -0
  35. package/dist/cli/plugins/register-docs-commands/cmds/generate-api.d.ts +3 -0
  36. package/dist/cli/plugins/register-docs-commands/cmds/generate-cli.d.ts +3 -0
  37. package/dist/cli/plugins/register-docs-commands/cmds/generate-readme.d.ts +3 -0
  38. package/dist/cli/plugins/register-docs-commands/cmds/index.d.ts +3 -0
  39. package/dist/cli/plugins/register-docs-commands/index.d.ts +3 -0
  40. package/dist/cli/plugins/register-git-hooks-commands/augment.d.ts +40 -0
  41. package/dist/cli/plugins/register-git-hooks-commands/cmds/index.d.ts +3 -0
  42. package/dist/cli/plugins/register-git-hooks-commands/cmds/reset.d.ts +3 -0
  43. package/dist/cli/plugins/register-git-hooks-commands/cmds/sync.d.ts +3 -0
  44. package/dist/cli/plugins/register-git-hooks-commands/index.d.ts +3 -0
  45. package/dist/cli/plugins/register-lint-commands/augment.d.ts +39 -0
  46. package/dist/cli/plugins/register-lint-commands/cmds/commit.d.ts +3 -0
  47. package/dist/cli/plugins/register-lint-commands/cmds/default.d.ts +3 -0
  48. package/dist/cli/plugins/register-lint-commands/cmds/markdown.d.ts +3 -0
  49. package/dist/cli/plugins/register-lint-commands/cmds/staged.d.ts +3 -0
  50. package/dist/cli/plugins/register-lint-commands/index.d.ts +3 -0
  51. package/dist/cli/plugins/register-lint-commands/settings.d.ts +11 -0
  52. package/dist/cli/plugins/register-lint-commands/types.d.ts +26 -0
  53. package/dist/cli/plugins/register-release-command/augment.d.ts +9 -0
  54. package/dist/cli/plugins/register-release-command/cmds/index.d.ts +3 -0
  55. package/dist/cli/plugins/register-release-command/index.d.ts +3 -0
  56. package/dist/cli/plugins/register-test-command/augment.d.ts +3 -0
  57. package/dist/cli/plugins/register-test-command/cmds/index.d.ts +3 -0
  58. package/dist/cli/plugins/register-test-command/index.d.ts +3 -0
  59. package/dist/cli/types.d.ts +73 -44
  60. package/dist/cli/utils.d.ts +3 -3
  61. package/dist/eject.d.ts +11 -4
  62. package/dist/index.d.ts +8 -2
  63. package/dist/index.js +80 -76
  64. package/dist/project-globals.d.ts +9 -0
  65. package/dist/templater/index.d.ts +6 -1
  66. package/dist/templater/index.js +27 -40
  67. package/dist/templater/markdown-templater/ReadmeTemplater.d.ts +28 -28
  68. package/dist/templater/markdown-templater/index.d.ts +3 -0
  69. package/dist/templater/types.d.ts +6 -0
  70. package/dist/utils/misc.d.ts +1 -1
  71. package/package.json +69 -55
  72. package/README.md +0 -211
  73. package/bin/cli/cmds/changelog.js +0 -41
  74. package/bin/cli/cmds/docs/generate-api.js +0 -22
  75. package/bin/cli/cmds/docs/generate-cli.js +0 -11
  76. package/bin/cli/cmds/docs/generate-readme.js +0 -11
  77. package/bin/cli/cmds/eject.js +0 -28
  78. package/bin/cli/cmds/git-hooks/index.js +0 -20
  79. package/bin/cli/cmds/git-hooks/reset.js +0 -48
  80. package/bin/cli/cmds/git-hooks/sync.js +0 -19
  81. package/bin/cli/cmds/release.js +0 -231
  82. package/bin/cli/lib/docs/generate-api-doc.js +0 -78
  83. package/bin/cli/lib/version/update-version.js +0 -52
  84. package/bin/scripts/commit-msg.js +0 -32
  85. package/bin/scripts/pre-commit.js +0 -24
  86. package/dist/cli/command-visitors/index.d.ts +0 -9
  87. package/src/index.js +0 -507
  88. package/template/CHANGELOG.md +0 -0
  89. package/template/bin/cli/cli.js +0 -27
  90. package/template/bin/cli/cmds/changelog.js +0 -71
  91. package/template/bin/cli/cmds/docs.js +0 -30
  92. package/template/bin/cli/cmds/docs_cmds/generate-api.js +0 -75
  93. package/template/bin/cli/cmds/docs_cmds/generate-readme.js +0 -51
  94. package/template/bin/cli/cmds/git-hooks.js +0 -30
  95. package/template/bin/cli/cmds/git_hooks_cmds/reset.js +0 -76
  96. package/template/bin/cli/cmds/git_hooks_cmds/sync.js +0 -44
  97. package/template/bin/cli/cmds/release.js +0 -219
  98. package/template/bin/cli/index.js +0 -7
  99. package/template/bin/cli/lib/docs/generate-api-doc.js +0 -33
  100. package/template/bin/cli/lib/release/generate-release-note.js +0 -3
  101. package/template/bin/cli/lib/version/update-version.js +0 -51
  102. package/template/bin/scripts/commit-msg.js +0 -42
  103. package/template/bin/scripts/pre-commit.js +0 -32
  104. package/template/docs/api/docs.config.js +0 -10
  105. package/template/docs/readme/config.js +0 -22
  106. package/template/docs/readme/readme.js +0 -70
  107. package/template/docs/readme/template.md +0 -53
  108. /package/bin/cli/cmds/{docs → private/docs}/lint.js +0 -0
  109. /package/bin/cli/cmds/{test.js → private/test.js} +0 -0
  110. /package/bin/cli/cmds/{squeeze.js → public/squeeze.js} +0 -0
package/dist/cli/index.js CHANGED
@@ -1,21 +1,317 @@
1
1
  /*!
2
- * juisy v1.4.0
2
+ * juisy v2.0.0-beta.0
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
6
6
  import { hideBin } from 'yargs/helpers';
7
- import execa from 'execa';
7
+ import deepmerge from 'deepmerge';
8
+ import { pathToFileURL } from 'node:url';
9
+ import fs from 'fs-extra';
10
+ import Yargs from 'yargs/yargs';
11
+ import { findUpSync } from 'find-up';
12
+ import { importSingleTs } from 'import-single-ts';
13
+ import lodashGet from 'lodash.get';
14
+ import { execa } from 'execa';
8
15
  import _prompts from 'prompts';
9
16
  import chalk from 'chalk';
10
17
  import indent from 'indent-string';
11
18
  import _stripAnsi from 'strip-ansi';
12
- import Yargs from 'yargs/yargs';
13
- import deepmerge from 'deepmerge';
19
+ import dotenv from '@dotenvx/dotenvx';
20
+ import kebabcase from 'lodash.kebabcase';
21
+ import { ReadmeTemplater } from 'juisy/templater';
22
+ import path from 'node:path';
23
+ import { getPackageInfo } from 'juisy';
24
+ import { ESLint } from 'eslint';
25
+ import fs$1 from 'node:fs';
26
+ import yargsParser from 'yargs-parser';
27
+
28
+ class Plugin {
29
+ constructor(name, pluginObject) {
30
+ this.name = name;
31
+ if (pluginObject.beforeCreate) {
32
+ this.beforeCreate = pluginObject.beforeCreate;
33
+ } else {
34
+ this.beforeCreate = () => {
35
+ };
36
+ }
37
+ if (pluginObject.created) {
38
+ this.created = pluginObject.created;
39
+ } else {
40
+ this.created = () => {
41
+ };
42
+ }
43
+ }
44
+ /**
45
+ * The plugin unique name
46
+ */
47
+ name;
48
+ /**
49
+ * The beforeCreate hook (can be async)
50
+ */
51
+ beforeCreate;
52
+ /**
53
+ * The created hook (must be sync)
54
+ */
55
+ created;
56
+ }
57
+
58
+ function createEngine(yargs) {
59
+ const xargs = yargs;
60
+ xargs._isPrivate = false;
61
+ xargs._globalCommandVisitors = {};
62
+ xargs._globalCommandVisitorsEnabled = /* @__PURE__ */ new Set([]);
63
+ xargs._disabledDefaultCommands = /* @__PURE__ */ new Set([]);
64
+ xargs._meta = {
65
+ private: false
66
+ };
67
+ xargs._settings = {};
68
+ const originalCommandMethod = xargs.command;
69
+ xargs.originalCommand = originalCommandMethod;
70
+ xargs.command = command;
71
+ xargs.disableDefaultCommand = disableDefaultCommand;
72
+ xargs.hasDefaultCommand = hasDefaultCommand;
73
+ xargs.globalCommandVisitor = globalCommandVisitor;
74
+ xargs.globalCommandVisitorOptions = globalCommandVisitorOptions;
75
+ xargs.hasGlobalCommandVisitor = hasGlobalCommandVisitor;
76
+ xargs.disableGlobalCommandVisitors = disableGlobalCommandVisitors;
77
+ xargs.enableGlobalCommandVisitors = enableGlobalCommandVisitors;
78
+ xargs.isPrivate = isPrivate;
79
+ xargs.getSettings = getSettings;
80
+ return xargs.strict().help();
81
+ }
82
+ function command(...args) {
83
+ const self = this;
84
+ if (args.length === 1) {
85
+ const visit = (cmdModule) => {
86
+ const cmdObj = {
87
+ ...cmdModule
88
+ };
89
+ let failOnFalsyReturn;
90
+ for (const name of self._globalCommandVisitorsEnabled) {
91
+ const globalVisitor = self._globalCommandVisitors[name];
92
+ if (!globalVisitor(cmdObj, self, globalVisitor.options)) {
93
+ failOnFalsyReturn = true;
94
+ }
95
+ }
96
+ return failOnFalsyReturn ? false : cmdObj;
97
+ };
98
+ if (args[0] instanceof Array) {
99
+ const cmdsArray = [];
100
+ for (const commandModule of args[0]) {
101
+ const visited = visit(commandModule);
102
+ if (visited)
103
+ cmdsArray.push(visited);
104
+ }
105
+ return self.originalCommand(cmdsArray);
106
+ } else {
107
+ const visited = visit(args[0]);
108
+ return visited ? self.originalCommand(visited) : self;
109
+ }
110
+ } else {
111
+ return self.originalCommand(...args);
112
+ }
113
+ }
114
+ function disableDefaultCommand(signature) {
115
+ if (getDefaultCommand(signature)) {
116
+ this._disabledDefaultCommands.add(signature);
117
+ } else {
118
+ throw new Error('Default command: "' + signature + '" does not exist.');
119
+ }
120
+ return this;
121
+ }
122
+ function hasDefaultCommand(signature) {
123
+ return !this._disabledDefaultCommands.has(signature);
124
+ }
125
+ function globalCommandVisitor(name, visitor, defaultOptions = {}) {
126
+ this._globalCommandVisitors[name] = visitor;
127
+ return this.enableGlobalCommandVisitors([name]).globalCommandVisitorOptions(name, defaultOptions);
128
+ }
129
+ function globalCommandVisitorOptions(name, options) {
130
+ this._globalCommandVisitors[name].options = {
131
+ ...this._globalCommandVisitors[name].options,
132
+ ...options
133
+ };
134
+ return this;
135
+ }
136
+ function hasGlobalCommandVisitor(name) {
137
+ return Object.keys(this._globalCommandVisitors).includes(name);
138
+ }
139
+ function disableGlobalCommandVisitors(visitors = []) {
140
+ for (const name of visitors) {
141
+ if (this.hasGlobalCommandVisitor(name)) {
142
+ this._globalCommandVisitorsEnabled.delete(name);
143
+ } else {
144
+ throw new Error('Global command visitor: "' + name + '" not defined.');
145
+ }
146
+ }
147
+ return this;
148
+ }
149
+ function enableGlobalCommandVisitors(visitors = []) {
150
+ for (const name of visitors) {
151
+ if (this.hasGlobalCommandVisitor(name)) {
152
+ this._globalCommandVisitorsEnabled.add(name);
153
+ } else {
154
+ throw new Error('Global command visitor: "' + name + '" not defined.');
155
+ }
156
+ }
157
+ return this;
158
+ }
159
+ function isPrivate() {
160
+ return this._isPrivate;
161
+ }
162
+ function getSettings(path) {
163
+ return path ? lodashGet(this._settings, path) : this._settings;
164
+ }
165
+
166
+ const proxify = (target) => {
167
+ const tmp = new Proxy(target instanceof Array ? [] : {}, {
168
+ // Overwrite Object type getter to 'observe'
169
+ get: (obj, prop) => {
170
+ if (prop in obj) {
171
+ if (resolveSettingsCallbacks[prop]) {
172
+ return resolveSettingsCallbacks[prop](obj[prop]);
173
+ }
174
+ return obj[prop];
175
+ }
176
+ return undefined;
177
+ }
178
+ });
179
+ for (const property in target) {
180
+ tmp[property] = target[property];
181
+ }
182
+ return tmp;
183
+ };
184
+ const defaultGlobalSettings = {
185
+ release: {
186
+ git: {
187
+ commitMessage: "chore(release): v${version}",
188
+ requireBranch: "main",
189
+ tagAnnotation: "v${version}"
190
+ }
191
+ }
192
+ };
193
+ const defaultCommands = [];
194
+ const registeredPlugins = [];
195
+ function defineDefaultCommand(command) {
196
+ defaultCommands.push(command);
197
+ }
198
+ const findCommandIn = (fullSignature, commands) => {
199
+ for (const command of commands) {
200
+ if (command.fullSignature === fullSignature) {
201
+ return command;
202
+ } else {
203
+ if (command.children?.length) {
204
+ const found = findCommandIn(fullSignature, command.children);
205
+ if (found)
206
+ return found;
207
+ }
208
+ }
209
+ }
210
+ };
211
+ const getDefaultCommand = (fullSignature) => {
212
+ return findCommandIn(fullSignature, defaultCommands);
213
+ };
214
+ const resolveSettingsCallbacks = {
215
+ // ...
216
+ };
217
+ function defineSettings(target, settings, options) {
218
+ if (options?.resolve) {
219
+ resolveSettingsCallbacks[target] = options.resolve;
220
+ }
221
+ defaultGlobalSettings[target] = settings;
222
+ }
223
+ async function CLIFactory(builder, options) {
224
+ let settingsPath;
225
+ let globalSettings;
226
+ for (const plugin of registeredPlugins) {
227
+ await plugin.beforeCreate({
228
+ defineDefaultCommand,
229
+ defineSettings,
230
+ builder,
231
+ factoryOptions: options || {}
232
+ });
233
+ }
234
+ if (options?.settingsPath) {
235
+ settingsPath = options.settingsPath;
236
+ }
237
+ const configPath = findUpSync(settingsPath ? [settingsPath] : [
238
+ "dev.config.ts",
239
+ "dev.config.js",
240
+ "dev.config.json",
241
+ "cli.config.ts",
242
+ "cli.config.js",
243
+ "cli.config.json",
244
+ ".clirc.ts",
245
+ ".clirc.js",
246
+ ".clirc.json"
247
+ ]);
248
+ if (settingsPath && !configPath) {
249
+ throw new Error("Unable to find file: " + settingsPath);
250
+ } else if (configPath) {
251
+ if (configPath.endsWith(".ts")) {
252
+ globalSettings = deepmerge(defaultGlobalSettings, await importSingleTs(configPath).then((mod) => mod.default || mod));
253
+ } else if (configPath.endsWith(".json")) {
254
+ globalSettings = deepmerge(defaultGlobalSettings, JSON.parse(fs.readFileSync(configPath).toString()));
255
+ } else {
256
+ globalSettings = deepmerge(defaultGlobalSettings, await import(pathToFileURL(configPath).toString()).then((mod) => mod.default || mod));
257
+ }
258
+ } else {
259
+ globalSettings = defaultGlobalSettings;
260
+ }
261
+ const cli = function(argv) {
262
+ let engine = createEngine(Yargs(argv));
263
+ engine._settings = proxify(globalSettings);
264
+ for (const plugin of registeredPlugins) {
265
+ plugin.created({
266
+ engine,
267
+ builder,
268
+ factoryOptions: options || {}
269
+ });
270
+ }
271
+ engine = builder(engine);
272
+ const rootHandlers = engine.getInternalMethods().getCommandInstance().handlers;
273
+ for (const key in rootHandlers) {
274
+ const handler = rootHandlers[key];
275
+ if (defaultCommands.find((cmdObj) => cmdObj.fullSignature === handler.original)) {
276
+ engine.disableDefaultCommand(handler.original);
277
+ }
278
+ }
279
+ for (const defaultCommand of defaultCommands) {
280
+ if (engine.hasDefaultCommand(defaultCommand.fullSignature)) {
281
+ engine.command({
282
+ // @ts-ignore
283
+ aliases: defaultCommand.commandObject.aliases,
284
+ command: defaultCommand.commandObject.command,
285
+ describe: defaultCommand.commandObject.describe,
286
+ builder: (cli2) => {
287
+ return defaultCommand.commandObject.builder(cli2);
288
+ },
289
+ handler: defaultCommand.commandObject.handler,
290
+ meta: defaultCommand.commandObject.meta,
291
+ middlewares: defaultCommand.commandObject.middlewares
292
+ });
293
+ }
294
+ }
295
+ return engine;
296
+ };
297
+ return cli;
298
+ }
299
+ CLIFactory.use = function(plugin) {
300
+ if (plugin instanceof Plugin) {
301
+ if (registeredPlugins.find((rp) => rp.name === plugin.name)) {
302
+ throw new Error(`CLI plugin "${plugin.name}" is already used`);
303
+ } else {
304
+ registeredPlugins.push(plugin);
305
+ }
306
+ } else {
307
+ throw new Error(`Provided plugin is not an instance of Plugin`);
308
+ }
309
+ };
14
310
 
15
311
  class Command {
16
312
  /**
17
- * Creates a Command instance from object (CommandModule)
18
- * @param {CommandModule} commandObject - The command definition object
313
+ * Creates a Command instance from object (CommandObject)
314
+ * @param {CommandObject} commandObject - The command definition object
19
315
  */
20
316
  constructor(commandObject) {
21
317
  this.command = commandObject.command;
@@ -25,6 +321,7 @@ class Command {
25
321
  this.meta = commandObject.meta;
26
322
  this.builder = commandObject.builder || ((cli) => cli);
27
323
  this.handler = commandObject.handler;
324
+ this.middlewares = commandObject.middlewares;
28
325
  }
29
326
  /**
30
327
  * The command
@@ -53,7 +350,12 @@ class Command {
53
350
  /**
54
351
  * Command handler
55
352
  */
353
+ // @ts-ignore
56
354
  handler;
355
+ /**
356
+ * Command middlewares
357
+ */
358
+ middlewares;
57
359
  }
58
360
 
59
361
  const loading = {
@@ -115,7 +417,7 @@ class OutputUtils {
115
417
  static formatOutputMessage(msg, options = {}) {
116
418
  let formatted = `${msg}`;
117
419
  if (options.indentChar) {
118
- if (options.indent === void 0) {
420
+ if (options.indent === undefined) {
119
421
  options.indent = 1;
120
422
  }
121
423
  } else {
@@ -160,7 +462,7 @@ class OutputUtils {
160
462
  }
161
463
  /**
162
464
  * @param msg - The message to display
163
- * @param {Error} [err] - If provided, throw the error
465
+ * @param err - If provided, throw the error
164
466
  * @description
165
467
  * Display error message. Throws `err` if provided.
166
468
  * @example
@@ -168,9 +470,9 @@ class OutputUtils {
168
470
  * error('No configuration file') // => '[31m⨉ ERROR: No configuration file[0m'
169
471
  * error('No configuration file', error) // => Log and throws error
170
472
  */
171
- static error(msg, err = void 0) {
473
+ static error(msg, err) {
172
474
  OutputUtils.log(OutputUtils.$style.red(`⨉ ERROR: ${msg}`));
173
- if (err !== void 0) {
475
+ if (err !== undefined) {
174
476
  OutputUtils.log();
175
477
  throw err;
176
478
  }
@@ -186,7 +488,7 @@ class OutputUtils {
186
488
  */
187
489
  static step(msg, options = {}) {
188
490
  OutputUtils.stepsCache.index++;
189
- if (options.index === void 0) {
491
+ if (options.index === undefined) {
190
492
  options.index = OutputUtils.stepsCache.index;
191
493
  }
192
494
  OutputUtils.log(`${options.index !== null ? options.index + " - " : ""}${msg}`, { indentChar: "● " });
@@ -242,6 +544,7 @@ class InterfaceUtils {
242
544
  * @param {string[]} args - Same as execa second arg
243
545
  * @param {object} [opts] - Options
244
546
  * @returns {Promise<object>} The `execa` Promise
547
+ * @throws {RunError}
245
548
  * @description
246
549
  * Run command (child_process). See also `execa` package documentation
247
550
  * @example
@@ -307,6 +610,783 @@ class InterfaceUtils {
307
610
  static prompts = _prompts;
308
611
  }
309
612
 
613
+ const LoadEnvFile = new Plugin("built-in:load-env-file", {
614
+ beforeCreate({ defineDefaultCommand, defineSettings, builder, factoryOptions }) {
615
+ if (factoryOptions.loadEnv !== false) {
616
+ dotenv.config({
617
+ // Default to not verbose, can be overridden
618
+ debug: false,
619
+ verbose: false,
620
+ quiet: true
621
+ });
622
+ }
623
+ }
624
+ });
625
+
626
+ const changelog = new Command({
627
+ command: "changelog",
628
+ describe: "Generate CHANGELOG file",
629
+ meta: {
630
+ private: true
631
+ },
632
+ builder: function(cli) {
633
+ return cli;
634
+ },
635
+ async handler(argv) {
636
+ const { $style, step, substep, error, wait } = OutputUtils;
637
+ const { run } = InterfaceUtils;
638
+ step("Generating changelog");
639
+ const { onReleaseConfig, ...commandOptions } = this.engine.getSettings("changelog");
640
+ const flattenOptions = (options) => {
641
+ const _array = [];
642
+ for (const key in options) {
643
+ if (typeof options[key] === "boolean") {
644
+ _array.push("--" + kebabcase(key));
645
+ } else {
646
+ _array.push("--" + kebabcase(key));
647
+ _array.push(String(options[key]));
648
+ }
649
+ }
650
+ return _array;
651
+ };
652
+ await wait("Generating", async () => {
653
+ try {
654
+ await run("npx", [
655
+ "conventional-changelog",
656
+ ...flattenOptions(commandOptions)
657
+ ], { stdio: "inherit" });
658
+ } catch (e) {
659
+ error("Unable to generate changelog", e);
660
+ }
661
+ });
662
+ substep($style.green("✔ Success"), { last: true });
663
+ this.log();
664
+ }
665
+ });
666
+
667
+ const RegisterChangelogCommand = new Plugin("built-in:register-changelog-command", {
668
+ beforeCreate({ defineDefaultCommand, defineSettings, builder, factoryOptions }) {
669
+ defineSettings("changelog", {
670
+ infile: "CHANGELOG.md",
671
+ preset: "angular",
672
+ sameFile: true
673
+ });
674
+ defineDefaultCommand({
675
+ fullSignature: "changelog",
676
+ commandObject: changelog,
677
+ children: []
678
+ });
679
+ }
680
+ });
681
+
682
+ const docs = new Command({
683
+ command: "docs <command>",
684
+ describe: "Manage project documentation",
685
+ meta: {
686
+ private: true
687
+ },
688
+ builder(cli) {
689
+ return cli.demandCommand(1, "Command is missing. See help to learn more.");
690
+ },
691
+ handler(argv) {
692
+ }
693
+ });
694
+
695
+ const docsGenerateAPI = new Command({
696
+ command: "generate:api",
697
+ describe: "Generate API docs from source code",
698
+ async handler(argv) {
699
+ const { $style } = OutputUtils;
700
+ this.log($style.yellow("Command not implemented. Read the doc and build your own!"));
701
+ this.log();
702
+ }
703
+ });
704
+
705
+ const docsGenerateCLI = new Command({
706
+ command: "generate:cli",
707
+ describe: "Generate CLI docs",
708
+ builder(cli) {
709
+ cli.option("config", {
710
+ alias: "c",
711
+ describe: "Path to config file",
712
+ type: "string",
713
+ default: "./docs/cli/config.js"
714
+ });
715
+ cli.config(cli.getSettings("docs.cli"));
716
+ return cli;
717
+ },
718
+ async handler(argv) {
719
+ const templater = new ReadmeTemplater(argv.config);
720
+ await templater.generate();
721
+ }
722
+ });
723
+
724
+ const docsGenerateReadme = new Command({
725
+ command: "generate:readme",
726
+ describe: "Generate README.md",
727
+ builder(cli) {
728
+ cli.option("config", {
729
+ alias: "c",
730
+ describe: "Path to config file",
731
+ type: "string",
732
+ default: "./docs/readme/config.js"
733
+ });
734
+ cli.config(cli.getSettings("docs.readme"));
735
+ return cli;
736
+ },
737
+ async handler(argv) {
738
+ const templater = new ReadmeTemplater(argv.config);
739
+ await templater.generate();
740
+ }
741
+ });
742
+
743
+ const RegisterDocsCommands = new Plugin("built-in:register-docs-commands", {
744
+ beforeCreate({ defineDefaultCommand, defineSettings, builder, factoryOptions }) {
745
+ defineSettings("docs", {
746
+ readme: {
747
+ config: "./docs/readme/config.js"
748
+ },
749
+ cli: {
750
+ config: "./docs/cli/config.js"
751
+ }
752
+ });
753
+ defineDefaultCommand({
754
+ fullSignature: "docs <command>",
755
+ commandObject: docs,
756
+ children: [
757
+ {
758
+ fullSignature: "docs generate:api",
759
+ commandObject: docsGenerateAPI
760
+ },
761
+ {
762
+ fullSignature: "docs generate:cli",
763
+ commandObject: docsGenerateCLI
764
+ },
765
+ {
766
+ fullSignature: "docs generate:readme",
767
+ commandObject: docsGenerateReadme
768
+ }
769
+ ]
770
+ });
771
+ }
772
+ });
773
+
774
+ const gitHooks = new Command({
775
+ command: "git-hooks <command>",
776
+ describe: "Git relative commands",
777
+ meta: {
778
+ private: true
779
+ },
780
+ builder: function(cli) {
781
+ return cli.demandCommand(1, "Command is missing. See help to learn more.");
782
+ },
783
+ handler: async function(argv) {
784
+ }
785
+ });
786
+
787
+ const gitHooksSync = new Command({
788
+ command: "sync",
789
+ describe: "Sync git hooks",
790
+ builder(cli) {
791
+ return cli;
792
+ },
793
+ async handler(argv) {
794
+ const { $style, error, step, substep } = OutputUtils;
795
+ const { run, abort } = InterfaceUtils;
796
+ step("Sync git hooks");
797
+ const gitHooksConfig = getPackageInfo()["simple-git-hooks"] || this.engine.getSettings("gitHooks");
798
+ const tempConfigFilePath = "./__TEMP_SIMPLE_GIT_HOOKS_CONFIG__.json";
799
+ fs.writeFileSync(path.resolve(tempConfigFilePath), JSON.stringify(gitHooksConfig));
800
+ let commandError = false;
801
+ try {
802
+ await run("npx", [
803
+ "simple-git-hooks",
804
+ tempConfigFilePath
805
+ ], { stdio: "pipe" });
806
+ } catch (e) {
807
+ commandError = e;
808
+ }
809
+ fs.unlinkSync(path.resolve(tempConfigFilePath));
810
+ if (commandError) {
811
+ substep($style.red("❌ Unable to sync git hooks."), { last: true });
812
+ error("Unable to sync git hooks.", commandError);
813
+ abort(1);
814
+ } else {
815
+ substep($style.green("✔ Git hooks successfuly sync"), { last: true });
816
+ this.log();
817
+ }
818
+ }
819
+ });
820
+
821
+ const gitHooksReset = new Command({
822
+ command: "reset",
823
+ describe: "Reset git hooks",
824
+ builder(cli) {
825
+ return cli;
826
+ },
827
+ async handler(argv) {
828
+ const { $style, step, substep } = OutputUtils;
829
+ const { rootDir, run, abort } = InterfaceUtils;
830
+ step("Reset git hooks");
831
+ const tempConfigFilePath = "./__TEMP_SIMPLE_GIT_HOOKS_CONFIG__.json";
832
+ fs.writeFileSync(path.resolve(rootDir, tempConfigFilePath), "{}");
833
+ let commandError = false;
834
+ try {
835
+ await run("npx", [
836
+ "simple-git-hooks",
837
+ tempConfigFilePath
838
+ ], { stdio: "pipe" });
839
+ } catch (e) {
840
+ commandError = e;
841
+ }
842
+ fs.unlinkSync(path.resolve(rootDir, tempConfigFilePath));
843
+ if (commandError) {
844
+ substep($style.red("❌ Unable to reset git hooks."), { last: true });
845
+ abort(1);
846
+ } else {
847
+ substep($style.green("✔ Git hooks successfuly reset"), { last: true });
848
+ this.log();
849
+ }
850
+ }
851
+ });
852
+
853
+ const RegisterGitHooksCommands = new Plugin("built-in:register-git-hooks-commands", {
854
+ beforeCreate({ defineDefaultCommand, defineSettings, builder, factoryOptions }) {
855
+ defineSettings("gitHooks", {
856
+ "pre-commit": "node ./bin/scripts/pre-commit.js",
857
+ "commit-msg": "node ./bin/scripts/commit-msg.js ${1}"
858
+ });
859
+ defineDefaultCommand({
860
+ fullSignature: "git-hooks <command>",
861
+ commandObject: gitHooks,
862
+ children: [
863
+ {
864
+ fullSignature: "git-hooks reset",
865
+ commandObject: gitHooksReset
866
+ },
867
+ {
868
+ fullSignature: "git-hooks sync",
869
+ commandObject: gitHooksSync
870
+ }
871
+ ]
872
+ });
873
+ }
874
+ });
875
+
876
+ function resolveESLintSettings(settings = []) {
877
+ return settings;
878
+ }
879
+ function resolveCommitlintSettings(settings = {}) {
880
+ return settings;
881
+ }
882
+ function resolveMarkdownlintSettings(settings = []) {
883
+ const normalizeRootConfig = (config = {}) => {
884
+ return {
885
+ config: {},
886
+ ...config
887
+ };
888
+ };
889
+ const normalizeConfig = (config = {}) => {
890
+ return {
891
+ config: {},
892
+ ...config,
893
+ globs: config.globs
894
+ };
895
+ };
896
+ let resolved = [];
897
+ let rootConfig = {
898
+ config: {}
899
+ };
900
+ const globScopedConfigs = [];
901
+ for (const item of settings) {
902
+ if (!item.globs && typeof rootConfig.config !== "string") {
903
+ rootConfig = deepmerge(rootConfig, item);
904
+ } else if (!(item.globs instanceof Array) || !item.globs.length) {
905
+ throw new Error('lint.markdown configuration: if provided, "globs" property must be a non-empty array');
906
+ } else {
907
+ globScopedConfigs.push(item);
908
+ }
909
+ }
910
+ resolved.push(normalizeRootConfig(rootConfig));
911
+ resolved.push(...globScopedConfigs.map(normalizeConfig));
912
+ return resolved;
913
+ }
914
+ function resolveLintStagedSettings(settings = {}) {
915
+ return settings;
916
+ }
917
+ function resolveSettings(settings = {}) {
918
+ const resolved = {
919
+ default: resolveESLintSettings(settings.default),
920
+ commit: resolveCommitlintSettings(settings.commit),
921
+ markdown: resolveMarkdownlintSettings(settings.markdown),
922
+ staged: resolveLintStagedSettings(settings.staged)
923
+ };
924
+ return resolved;
925
+ }
926
+
927
+ const lint = new Command({
928
+ command: "lint [files]",
929
+ describe: "Lint source code",
930
+ meta: {
931
+ private: true
932
+ },
933
+ builder(cli) {
934
+ cli.option("fix", {
935
+ alias: "f",
936
+ describe: "Automatically fix problems",
937
+ type: "boolean",
938
+ default: false
939
+ }).option("config", {
940
+ alias: "c",
941
+ describe: "Provide configuration file path",
942
+ type: "string",
943
+ requiresArg: true
944
+ });
945
+ const lintSettings = cli.getSettings("lint.default");
946
+ if (lintSettings?.config) {
947
+ cli.config(lintSettings);
948
+ }
949
+ return cli;
950
+ },
951
+ async handler(argv) {
952
+ const { step } = OutputUtils;
953
+ step("Configuring linter");
954
+ const lintSettings = this.engine.getSettings("lint.default") || {};
955
+ const eslintOptions = {
956
+ fix: !!argv.fix
957
+ };
958
+ if (argv.config) {
959
+ eslintOptions.overrideConfigFile = argv.config;
960
+ } else {
961
+ eslintOptions.baseConfig = lintSettings;
962
+ }
963
+ const eslint = new ESLint(eslintOptions);
964
+ step("Linting files");
965
+ const results = await eslint.lintFiles([argv.files || "."]);
966
+ if (argv.fix) {
967
+ step("Fix problems");
968
+ await ESLint.outputFixes(results);
969
+ }
970
+ const formatter = await eslint.loadFormatter("stylish");
971
+ const resultText = formatter.format(results);
972
+ console.log(resultText);
973
+ this.log();
974
+ }
975
+ });
976
+
977
+ const lintCommit = new Command({
978
+ command: "lint:commit [input]",
979
+ describe: "Lint commit message with commitlint. Accepts all options of native commitlint. See also https://github.com/conventional-changelog/commitlint",
980
+ meta: {
981
+ private: true
982
+ },
983
+ builder(cli) {
984
+ cli.strict(false).option("config", {
985
+ // No alias because -c is already used by commitlint cli
986
+ describe: "Provide configuration file path",
987
+ type: "string",
988
+ requiresArg: true
989
+ });
990
+ const lintSettings = cli.getSettings("lint.commit");
991
+ if (lintSettings?.config) {
992
+ cli.config(lintSettings);
993
+ }
994
+ return cli;
995
+ },
996
+ async handler(argv) {
997
+ const { abort, run } = InterfaceUtils;
998
+ const { $style, step, substep, error } = OutputUtils;
999
+ step("Configuring commitlint");
1000
+ const lintSettings = this.engine.getSettings("lint.commit");
1001
+ const commitLintCmdArgs = yargsParser([...process.argv].slice(3), {
1002
+ configuration: {
1003
+ "halt-at-non-option": true,
1004
+ "unknown-options-as-args": true
1005
+ }
1006
+ })._.map(String);
1007
+ const tempConfigFilePath = "./__TEMP_COMMITLINT_CONFIG__.json";
1008
+ let tempConfig;
1009
+ if (!commitLintCmdArgs.includes("--config") && !commitLintCmdArgs.includes("-g")) {
1010
+ if (argv.config) {
1011
+ commitLintCmdArgs.push("--config", argv.config);
1012
+ } else {
1013
+ if (lintSettings) {
1014
+ tempConfig = lintSettings;
1015
+ commitLintCmdArgs.push("--config", tempConfigFilePath);
1016
+ fs$1.writeFileSync(path.resolve(tempConfigFilePath), JSON.stringify(tempConfig));
1017
+ }
1018
+ }
1019
+ }
1020
+ let commandError;
1021
+ try {
1022
+ await run("npx", ["commitlint", ...commitLintCmdArgs], { stdio: "pipe" });
1023
+ } catch (e) {
1024
+ commandError = e;
1025
+ }
1026
+ if (tempConfig) {
1027
+ fs$1.unlinkSync(path.resolve(tempConfigFilePath));
1028
+ }
1029
+ if (commandError) {
1030
+ substep($style.red("❌ An error has occured."), { last: true });
1031
+ error("An error has occured.", commandError);
1032
+ } else {
1033
+ substep($style.green("✔ Commit successfuly linted"), { last: true });
1034
+ this.log();
1035
+ }
1036
+ }
1037
+ });
1038
+
1039
+ const lintMarkdown = new Command({
1040
+ command: "lint:markdown",
1041
+ describe: "Lint markdown files with markdownlint-cli2. See also https://github.com/DavidAnson/markdownlint-cli2",
1042
+ meta: {
1043
+ private: true
1044
+ },
1045
+ builder(cli) {
1046
+ cli.strict(false).option("fix", {
1047
+ alias: "f",
1048
+ describe: "Fix the problems",
1049
+ type: "boolean"
1050
+ });
1051
+ return cli;
1052
+ },
1053
+ async handler(argv) {
1054
+ const { abort, run } = InterfaceUtils;
1055
+ const { $style, step, substep, error } = OutputUtils;
1056
+ step("Configuring markdownlint");
1057
+ const configs = this.engine.getSettings("lint.markdown") || [];
1058
+ const rootConfig = configs.splice(configs.findIndex((config) => !config.globs), 1);
1059
+ let commandError;
1060
+ for (const item of configs) {
1061
+ let tempConfig;
1062
+ const mdLintCmdArgs = [...item.globs];
1063
+ const tempConfigFilePath = "__TEMP_MARKDOWNLINT_CONFIG__.markdownlint-cli2.jsonc";
1064
+ if (!item.config) {
1065
+ tempConfig = rootConfig;
1066
+ } else {
1067
+ tempConfig = item.config;
1068
+ }
1069
+ if (typeof tempConfig === "string") {
1070
+ mdLintCmdArgs.push("--config", tempConfig);
1071
+ } else {
1072
+ mdLintCmdArgs.push("--config", tempConfigFilePath);
1073
+ fs$1.writeFileSync(path.resolve(tempConfigFilePath), JSON.stringify(tempConfig));
1074
+ }
1075
+ if (argv.fix) {
1076
+ mdLintCmdArgs.push("--fix");
1077
+ }
1078
+ try {
1079
+ await run("npx", ["markdownlint-cli2", ...mdLintCmdArgs], { stdio: "pipe" });
1080
+ } catch (e) {
1081
+ commandError = e;
1082
+ if (fs$1.existsSync(path.resolve(tempConfigFilePath))) {
1083
+ fs$1.unlinkSync(path.resolve(tempConfigFilePath));
1084
+ }
1085
+ break;
1086
+ }
1087
+ }
1088
+ if (commandError) {
1089
+ substep($style.red("❌ An error has occured."), { last: true });
1090
+ if (commandError.stderr) {
1091
+ console.error(commandError.stderr);
1092
+ } else {
1093
+ error("An error has occured.", commandError);
1094
+ }
1095
+ } else {
1096
+ substep($style.green("✔ Markdown files successfuly linted"), { last: true });
1097
+ this.log();
1098
+ }
1099
+ }
1100
+ });
1101
+
1102
+ const lintStaged = new Command({
1103
+ command: "lint:staged",
1104
+ describe: "Lint staged files with lint-staged. Accepts all options of native lint-staged command. See also https://github.com/okonet/lint-staged",
1105
+ meta: {
1106
+ private: true
1107
+ },
1108
+ builder(cli) {
1109
+ cli.strict(false).option("config", {
1110
+ alias: "c",
1111
+ describe: "Provide configuration file path",
1112
+ type: "string",
1113
+ requiresArg: true
1114
+ });
1115
+ const lintSettings = cli.getSettings("lint.staged");
1116
+ if (lintSettings?.config) {
1117
+ cli.config(lintSettings);
1118
+ }
1119
+ return cli;
1120
+ },
1121
+ async handler(argv) {
1122
+ const { abort, run } = InterfaceUtils;
1123
+ const { $style, step, substep, error } = OutputUtils;
1124
+ step("Configuring lint-staged");
1125
+ const lintSettings = this.engine.getSettings("lint.staged");
1126
+ const lintStagedCmdArgs = [
1127
+ // Pass all native options to lint-staged command
1128
+ ...argv._.map(String)
1129
+ ];
1130
+ const tempConfigFilePath = "./__TEMP_LINT_STAGED_CONFIG__.json";
1131
+ let tempConfig;
1132
+ if (argv.config) {
1133
+ lintStagedCmdArgs.push("--config", argv.config);
1134
+ } else {
1135
+ if (lintSettings) {
1136
+ tempConfig = lintSettings;
1137
+ lintStagedCmdArgs.push("--config", tempConfigFilePath);
1138
+ fs$1.writeFileSync(path.resolve(tempConfigFilePath), JSON.stringify(tempConfig));
1139
+ }
1140
+ }
1141
+ let commandError = false;
1142
+ try {
1143
+ await run("npx", [
1144
+ "lint-staged",
1145
+ ...lintStagedCmdArgs
1146
+ ], { stdio: "inherit" });
1147
+ } catch (e) {
1148
+ commandError = e;
1149
+ }
1150
+ if (tempConfig) {
1151
+ fs$1.unlinkSync(path.resolve(tempConfigFilePath));
1152
+ }
1153
+ if (commandError) {
1154
+ substep($style.red("❌ An error has occured."), { last: true });
1155
+ error("An error has occured.", commandError);
1156
+ abort(1);
1157
+ } else {
1158
+ substep($style.green("✔ Files successfuly linted"), { last: true });
1159
+ this.log();
1160
+ }
1161
+ }
1162
+ });
1163
+
1164
+ const RegisterLintCommands = new Plugin("built-in:register-lint-commands", {
1165
+ beforeCreate({ defineDefaultCommand, defineSettings, builder, factoryOptions }) {
1166
+ defineSettings("lint", {
1167
+ default: {
1168
+ config: "eslint.config.js"
1169
+ },
1170
+ commit: {
1171
+ extends: [
1172
+ "@commitlint/config-conventional"
1173
+ ]
1174
+ },
1175
+ markdown: [],
1176
+ staged: {
1177
+ "*.{js,cjs,ts}": [
1178
+ "eslint --fix"
1179
+ ]
1180
+ }
1181
+ }, {
1182
+ resolve: resolveSettings
1183
+ });
1184
+ defineDefaultCommand({
1185
+ fullSignature: "lint",
1186
+ commandObject: lint,
1187
+ children: []
1188
+ });
1189
+ defineDefaultCommand({
1190
+ fullSignature: "lint:commit",
1191
+ commandObject: lintCommit,
1192
+ children: []
1193
+ });
1194
+ defineDefaultCommand({
1195
+ fullSignature: "lint:markdown",
1196
+ commandObject: lintMarkdown,
1197
+ children: []
1198
+ });
1199
+ defineDefaultCommand({
1200
+ fullSignature: "lint:staged",
1201
+ commandObject: lintStaged,
1202
+ children: []
1203
+ });
1204
+ }
1205
+ });
1206
+
1207
+ const release = new Command({
1208
+ command: "release",
1209
+ describe: "Make a release",
1210
+ builder(cli) {
1211
+ cli.option("d", {
1212
+ alias: "dry-run",
1213
+ type: "boolean",
1214
+ describe: "Do not touch or write anything, but show the commands"
1215
+ }).option("i", {
1216
+ alias: "increment",
1217
+ type: "string",
1218
+ describe: 'Increment "major", "minor", "patch", or "pre*" version; or specify version',
1219
+ default: "patch",
1220
+ requiresArg: true
1221
+ }).option("ci", {
1222
+ type: "boolean",
1223
+ describe: "No prompts, no user interaction; activated automatically in CI environments"
1224
+ }).option("only-version", {
1225
+ type: "boolean",
1226
+ describe: "Prompt only for version, no further interaction"
1227
+ }).option("release-version", {
1228
+ type: "boolean",
1229
+ describe: "Print version number to be released"
1230
+ }).option("changelog", {
1231
+ type: "boolean",
1232
+ describe: "Print changelog for the version to be released"
1233
+ }).option("v", {
1234
+ alias: "verbose",
1235
+ type: "boolean",
1236
+ describe: "Verbose output (user hooks output)"
1237
+ }).option("V", {
1238
+ alias: "extra-verbose",
1239
+ type: "boolean",
1240
+ describe: "Extra verbose output (also internal commands output)"
1241
+ });
1242
+ return cli;
1243
+ },
1244
+ async handler(argv) {
1245
+ const { $style, step, substep, error, wait } = OutputUtils;
1246
+ const { abort, run } = InterfaceUtils;
1247
+ console.log("argv ? ", argv);
1248
+ abort(1);
1249
+ step("Prepare for release");
1250
+ const tempConfigFilePath = "./__TEMP_RELEASE_IT_CONFIG__.json";
1251
+ const releaseItCmdArgs = [];
1252
+ let tempConfig;
1253
+ let releaseItConfigFound = false;
1254
+ substep($style.green("Resolving configuration"));
1255
+ const releaseSettings = this.engine.getSettings("release");
1256
+ if (getPackageInfo()["release-it"]) {
1257
+ releaseItConfigFound = true;
1258
+ } else {
1259
+ const searchPlaces = [
1260
+ ".release-it.json",
1261
+ ".release-it.js",
1262
+ ".release-it.ts",
1263
+ ".release-it.cjs",
1264
+ ".release-it.yaml",
1265
+ ".release-it.yml",
1266
+ ".release-it.toml"
1267
+ ];
1268
+ for (const fileName of searchPlaces) {
1269
+ if (fs$1.existsSync(path.resolve(fileName))) {
1270
+ releaseItConfigFound = true;
1271
+ break;
1272
+ }
1273
+ }
1274
+ if (!releaseItConfigFound) {
1275
+ if (releaseSettings.config) {
1276
+ if (typeof releaseSettings.config !== "string") {
1277
+ error("release.config must be path to file as string");
1278
+ abort(1);
1279
+ }
1280
+ releaseItCmdArgs.push("--config", releaseSettings.config);
1281
+ } else {
1282
+ const changelogSettings = this.engine.getSettings("changelog");
1283
+ const { onReleaseConfig, preset, infile, context } = changelogSettings;
1284
+ const releaseItChangelogConfig = {
1285
+ infile: onReleaseConfig.infile || infile,
1286
+ header: onReleaseConfig.header,
1287
+ context: onReleaseConfig.context || (context ? JSON.parse(fs$1.readFileSync(path.resolve(context)).toString()) : {}),
1288
+ preset: {
1289
+ name: preset,
1290
+ ...onReleaseConfig.preset || {}
1291
+ },
1292
+ tagOpts: onReleaseConfig.tagOpts,
1293
+ commitsOpts: onReleaseConfig.commitsOpts,
1294
+ whatBump: onReleaseConfig.whatBump,
1295
+ ignoreRecommendedBump: onReleaseConfig.ignoreRecommendedBump,
1296
+ strictSemVer: onReleaseConfig.strictSemVer
1297
+ };
1298
+ tempConfig = {
1299
+ plugins: {
1300
+ "@release-it/conventional-changelog": releaseItChangelogConfig
1301
+ }
1302
+ };
1303
+ releaseItCmdArgs.push("--config", tempConfigFilePath);
1304
+ }
1305
+ }
1306
+ }
1307
+ if (argv["dry-run"]) {
1308
+ releaseItCmdArgs.push("--dry-run");
1309
+ }
1310
+ if (argv.increment) {
1311
+ releaseItCmdArgs.push("--increment");
1312
+ releaseItCmdArgs.push(argv.increment);
1313
+ }
1314
+ if (argv.ci) {
1315
+ releaseItCmdArgs.push("--ci");
1316
+ }
1317
+ if (argv["only-version"]) {
1318
+ releaseItCmdArgs.push("--only-version");
1319
+ }
1320
+ if (argv["release-version"]) {
1321
+ releaseItCmdArgs.push("--release-version");
1322
+ }
1323
+ if (argv.changelog) {
1324
+ releaseItCmdArgs.push("--changelog");
1325
+ }
1326
+ if (argv.verbose) {
1327
+ releaseItCmdArgs.push("--verbose");
1328
+ }
1329
+ if (argv["extra-verbose"]) {
1330
+ releaseItCmdArgs.push("-VV");
1331
+ }
1332
+ if (!releaseItConfigFound) {
1333
+ fs$1.writeFileSync(path.resolve(tempConfigFilePath), JSON.stringify(tempConfig));
1334
+ }
1335
+ let commandError = false;
1336
+ try {
1337
+ await run("npx", [
1338
+ "release-it",
1339
+ ...releaseItCmdArgs
1340
+ ], { stdio: "inherit" });
1341
+ } catch (e) {
1342
+ commandError = e;
1343
+ }
1344
+ if (!releaseItConfigFound) {
1345
+ fs$1.unlinkSync(path.resolve(tempConfigFilePath));
1346
+ }
1347
+ if (commandError) {
1348
+ substep($style.red("❌ Unable to release."), { last: true });
1349
+ abort(1);
1350
+ } else {
1351
+ substep($style.green("✔ Release successfuly created"), { last: true });
1352
+ this.log();
1353
+ }
1354
+ }
1355
+ });
1356
+
1357
+ const RegisterReleaseCommand = new Plugin("built-in:register-release-command", {
1358
+ beforeCreate({ defineDefaultCommand, defineSettings, builder, factoryOptions }) {
1359
+ defineSettings("release", {
1360
+ // ...
1361
+ });
1362
+ defineDefaultCommand({
1363
+ fullSignature: "release",
1364
+ commandObject: release,
1365
+ children: []
1366
+ });
1367
+ }
1368
+ });
1369
+
1370
+ const test = new Command({
1371
+ command: "test",
1372
+ describe: "Run tests",
1373
+ async handler(argv) {
1374
+ const { $style } = OutputUtils;
1375
+ this.log($style.yellow("Command not implemented. Read the doc and build your own!"));
1376
+ this.log();
1377
+ }
1378
+ });
1379
+
1380
+ const RegisterTestCommand = new Plugin("built-in:register-test-command", {
1381
+ beforeCreate({ defineDefaultCommand, defineSettings, builder, factoryOptions }) {
1382
+ defineDefaultCommand({
1383
+ fullSignature: "test",
1384
+ commandObject: test,
1385
+ children: []
1386
+ });
1387
+ }
1388
+ });
1389
+
310
1390
  function wrapCommandBuilder(target, builder) {
311
1391
  const _target = target || ((cli) => cli);
312
1392
  return (cli) => {
@@ -320,6 +1400,41 @@ function wrapCommandhandler(target, handler) {
320
1400
  };
321
1401
  }
322
1402
 
1403
+ const visitor$3 = function(commandObject, cli) {
1404
+ const defaultCommand = getDefaultCommand(commandObject.command);
1405
+ if (defaultCommand) {
1406
+ commandObject.builder = wrapCommandBuilder(commandObject.builder, function(_cli) {
1407
+ if (defaultCommand.children?.length) {
1408
+ for (const child of defaultCommand.children) {
1409
+ if (cli.hasDefaultCommand(child.fullSignature)) {
1410
+ cli.command({
1411
+ // @ts-ignore
1412
+ aliases: child.commandObject.aliases,
1413
+ command: child.commandObject.command,
1414
+ describe: child.commandObject.describe,
1415
+ builder: (__cli) => {
1416
+ return child.commandObject.builder(__cli);
1417
+ },
1418
+ handler: child.commandObject.handler,
1419
+ meta: child.commandObject.meta,
1420
+ middlewares: child.commandObject.middlewares
1421
+ });
1422
+ }
1423
+ }
1424
+ }
1425
+ return _cli;
1426
+ });
1427
+ }
1428
+ return commandObject;
1429
+ };
1430
+ const options$3 = {};
1431
+
1432
+ const DefaultCommandFallbacks = new Plugin("built-in:default-command-fallbacks", {
1433
+ created({ engine, builder, factoryOptions }) {
1434
+ engine.globalCommandVisitor("default-command-fallbacks-visitor", visitor$3, options$3);
1435
+ }
1436
+ });
1437
+
323
1438
  const visitor$2 = function(commandObject, cli) {
324
1439
  commandObject.handler = wrapCommandhandler(commandObject.handler, function(args) {
325
1440
  Object.defineProperty(this, "engine", {
@@ -342,11 +1457,11 @@ const visitor$2 = function(commandObject, cli) {
342
1457
  };
343
1458
  const options$2 = {};
344
1459
 
345
- const commandHandlerInjections = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
346
- __proto__: null,
347
- options: options$2,
348
- visitor: visitor$2
349
- }, Symbol.toStringTag, { value: 'Module' }));
1460
+ const CommandHandlerInjections = new Plugin("built-in:command-handler-injections", {
1461
+ created({ engine, builder, factoryOptions }) {
1462
+ engine.globalCommandVisitor("command-handler-injections-visitor", visitor$2, options$2);
1463
+ }
1464
+ });
350
1465
 
351
1466
  const visitor$1 = function(commandObject, cli) {
352
1467
  if (commandObject.meta) {
@@ -360,11 +1475,14 @@ const visitor$1 = function(commandObject, cli) {
360
1475
  };
361
1476
  const options$1 = {};
362
1477
 
363
- const getCommandMeta = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
364
- __proto__: null,
365
- options: options$1,
366
- visitor: visitor$1
367
- }, Symbol.toStringTag, { value: 'Module' }));
1478
+ const CommandMeta = new Plugin("built-in:command-meta", {
1479
+ created({ engine, builder, factoryOptions }) {
1480
+ engine.getMeta = function() {
1481
+ return this._meta;
1482
+ };
1483
+ engine.globalCommandVisitor("command-meta-visitor", visitor$1, options$1);
1484
+ }
1485
+ });
368
1486
 
369
1487
  const visitor = function(commandObject, engine, options2) {
370
1488
  const { metaProp, envKey } = options2;
@@ -385,130 +1503,23 @@ const options = {
385
1503
  envKey: "CLI_ENV"
386
1504
  };
387
1505
 
388
- const privateCommand = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
389
- __proto__: null,
390
- options,
391
- visitor
392
- }, Symbol.toStringTag, { value: 'Module' }));
393
-
394
- const commandVisitors = {
395
- commandHandlerInjections,
396
- getCommandMeta,
397
- privateCommand
398
- };
399
-
400
- function createEngine(yargs) {
401
- const xargs = yargs;
402
- xargs._isPrivate = false;
403
- xargs._globalCommandVisitors = {};
404
- xargs._globalCommandVisitorsEnabled = /* @__PURE__ */ new Set([]);
405
- xargs._meta = {
406
- private: false
407
- };
408
- const originalCommandMethod = xargs.command;
409
- xargs.originalCommand = originalCommandMethod;
410
- xargs.command = command;
411
- xargs.globalCommandVisitor = globalCommandVisitor;
412
- xargs.globalCommandVisitorOptions = globalCommandVisitorOptions;
413
- xargs.hasGlobalCommandVisitor = hasGlobalCommandVisitor;
414
- xargs.disableGlobalCommandVisitors = disableGlobalCommandVisitors;
415
- xargs.enableGlobalCommandVisitors = enableGlobalCommandVisitors;
416
- xargs.isPrivate = isPrivate;
417
- xargs.getMeta = getMeta;
418
- return xargs.globalCommandVisitor("command-handler-injections-visitor", commandVisitors.commandHandlerInjections.visitor, commandVisitors.commandHandlerInjections.options).globalCommandVisitor("get-meta-command-visitor", commandVisitors.getCommandMeta.visitor, commandVisitors.getCommandMeta.options).globalCommandVisitor("private-command-visitor", commandVisitors.privateCommand.visitor, commandVisitors.privateCommand.options).strict().help();
419
- }
420
- function command(...args) {
421
- const self = this;
422
- if (args.length === 1) {
423
- const visit = (cmdModule) => {
424
- const cmdObj = {
425
- ...cmdModule
426
- };
427
- let failOnFalsyReturn;
428
- for (const name of self._globalCommandVisitorsEnabled) {
429
- const globalVisitor = self._globalCommandVisitors[name];
430
- if (!globalVisitor(cmdObj, self, globalVisitor.options)) {
431
- failOnFalsyReturn = true;
432
- }
433
- }
434
- return failOnFalsyReturn ? false : cmdObj;
435
- };
436
- if (args[0] instanceof Array) {
437
- const cmdsArray = [];
438
- for (const commandModule of args[0]) {
439
- const visited = visit(commandModule);
440
- if (visited)
441
- cmdsArray.push(visited);
442
- }
443
- return self.originalCommand(cmdsArray);
444
- } else {
445
- const visited = visit(args[0]);
446
- return visited ? self.originalCommand(visited) : self;
447
- }
448
- } else {
449
- return self.originalCommand(...args);
450
- }
451
- }
452
- function globalCommandVisitor(name, visitor, defaultOptions = {}) {
453
- this._globalCommandVisitors[name] = visitor;
454
- return this.enableGlobalCommandVisitors([name]).globalCommandVisitorOptions(name, defaultOptions);
455
- }
456
- function globalCommandVisitorOptions(name, options) {
457
- this._globalCommandVisitors[name].options = {
458
- ...this._globalCommandVisitors[name].options,
459
- ...options
460
- };
461
- return this;
462
- }
463
- function hasGlobalCommandVisitor(name) {
464
- return Object.keys(this._globalCommandVisitors).includes(name);
465
- }
466
- function disableGlobalCommandVisitors(visitors = []) {
467
- for (const name of visitors) {
468
- if (this.hasGlobalCommandVisitor(name)) {
469
- this._globalCommandVisitorsEnabled.delete(name);
470
- } else {
471
- throw new Error('Global command visitor: "' + name + '" not defined.');
472
- }
1506
+ const PrivateCommands = new Plugin("built-in:private-commands", {
1507
+ created({ engine, builder, factoryOptions }) {
1508
+ engine.globalCommandVisitor("private-command-visitor", visitor, options);
473
1509
  }
474
- return this;
475
- }
476
- function enableGlobalCommandVisitors(visitors = []) {
477
- for (const name of visitors) {
478
- if (this.hasGlobalCommandVisitor(name)) {
479
- this._globalCommandVisitorsEnabled.add(name);
480
- } else {
481
- throw new Error('Global command visitor: "' + name + '" not defined.');
482
- }
483
- }
484
- return this;
485
- }
486
- function isPrivate() {
487
- return this._isPrivate;
488
- }
489
- function getMeta() {
490
- return this._meta;
491
- }
492
-
493
- function CLIFactory(builder) {
494
- const cli = function(argv) {
495
- const engine = createEngine(Yargs(argv));
496
- return builder(engine);
497
- };
498
- return cli;
499
- }
1510
+ });
500
1511
 
501
1512
  async function extractUsage(factory, recursive = false, args = [""], locale = "en") {
502
1513
  const innerYargs = factory([""]);
503
1514
  innerYargs.locale(locale);
504
1515
  const doclet = {
505
- command: void 0,
506
- args: void 0,
507
- aliases: void 0,
1516
+ command: undefined,
1517
+ args: undefined,
1518
+ aliases: undefined,
508
1519
  deprecated: false,
509
- extractedUsage: void 0,
510
- rawUsage: void 0,
511
- children: recursive ? {} : void 0
1520
+ extractedUsage: undefined,
1521
+ rawUsage: undefined,
1522
+ children: recursive ? {} : undefined
512
1523
  };
513
1524
  const parseCallback = function(err, argv, output) {
514
1525
  if (err)
@@ -555,5 +1566,16 @@ globalThis.CLI = {
555
1566
  InterfaceUtils,
556
1567
  OutputUtils
557
1568
  };
1569
+ CLIFactory.use(LoadEnvFile);
1570
+ CLIFactory.use(RegisterChangelogCommand);
1571
+ CLIFactory.use(RegisterDocsCommands);
1572
+ CLIFactory.use(RegisterGitHooksCommands);
1573
+ CLIFactory.use(RegisterLintCommands);
1574
+ CLIFactory.use(RegisterReleaseCommand);
1575
+ CLIFactory.use(RegisterTestCommand);
1576
+ CLIFactory.use(DefaultCommandFallbacks);
1577
+ CLIFactory.use(CommandHandlerInjections);
1578
+ CLIFactory.use(CommandMeta);
1579
+ CLIFactory.use(PrivateCommands);
558
1580
 
559
1581
  export { CLIFactory, Command, InterfaceUtils, OutputUtils, extractUsage };