juisy 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/LICENSE +1 -1
  2. package/bin/cli/cli.js +14 -0
  3. package/bin/cli/cmds/index.js +6 -4
  4. package/bin/cli/cmds/public/AddExt.js +49 -0
  5. package/bin/cli/cmds/public/RemoveExt.js +49 -0
  6. package/bin/cli/index.js +1 -0
  7. package/bin/cli/init.js +1 -0
  8. package/bin/cli/lib/index.js +71 -0
  9. package/dist/DataExporter.d.ts +1 -0
  10. package/dist/bootstrap.d.ts +1 -0
  11. package/dist/cli/CLIFactory.d.ts +1 -0
  12. package/dist/cli/Command.d.ts +23 -2
  13. package/dist/cli/InterfaceUtils.d.ts +11 -9
  14. package/dist/cli/OutputUtils.d.ts +30 -16
  15. package/dist/cli/Plugin.d.ts +9 -0
  16. package/dist/cli/extract-usage.d.ts +8 -0
  17. package/dist/cli/index.d.ts +1 -0
  18. package/dist/cli/index.js +193 -113
  19. package/dist/cli/plugins/command-meta/augment.d.ts +0 -3
  20. package/dist/cli/plugins/command-meta/index.d.ts +4 -0
  21. package/dist/cli/plugins/default-command-fallbacks/command-visitors/default-command-fallbacks.d.ts +1 -1
  22. package/dist/cli/plugins/default-command-fallbacks/index.d.ts +4 -0
  23. package/dist/cli/plugins/load-env-file/index.d.ts +4 -0
  24. package/dist/cli/plugins/private-commands/augment.d.ts +8 -0
  25. package/dist/cli/plugins/private-commands/command-visitors/private-command.d.ts +7 -3
  26. package/dist/cli/plugins/private-commands/index.d.ts +4 -0
  27. package/dist/cli/plugins/register-bump-version-command/index.d.ts +4 -0
  28. package/dist/cli/plugins/register-changelog-command/index.d.ts +4 -0
  29. package/dist/cli/plugins/register-docs-commands/index.d.ts +4 -0
  30. package/dist/cli/plugins/register-git-hooks-commands/index.d.ts +4 -0
  31. package/dist/cli/plugins/register-lint-commands/index.d.ts +4 -0
  32. package/dist/cli/plugins/register-lint-commands/settings.d.ts +2 -0
  33. package/dist/cli/plugins/register-lint-commands/types.d.ts +5 -9
  34. package/dist/cli/plugins/register-release-command/index.d.ts +4 -0
  35. package/dist/cli/plugins/register-test-command/index.d.ts +4 -0
  36. package/dist/cli/types.d.ts +7 -0
  37. package/dist/cli/utils.d.ts +3 -4
  38. package/dist/eject.d.ts +1 -0
  39. package/dist/get-package-info.d.ts +1 -0
  40. package/dist/index.d.ts +5 -1
  41. package/dist/index.js +167 -11
  42. package/dist/project-globals.d.ts +2 -0
  43. package/dist/shims/shims.d.ts +1440 -0
  44. package/dist/templater/index.d.ts +4 -1
  45. package/dist/templater/index.js +42 -23
  46. package/dist/templater/markdown-templater/ReadmeTemplater.d.ts +8 -10
  47. package/dist/templater/markdown-templater/index.d.ts +10 -1
  48. package/dist/utils/misc.d.ts +69 -8
  49. package/package.json +38 -44
  50. package/bin/cli/cmds/private/docs/generate-api.js +0 -31
  51. package/bin/cli/cmds/private/docs/index.js +0 -20
  52. package/bin/cli/cmds/private/test.js +0 -33
  53. package/dist/vite/plugins/inject-css-variables/index.d.ts +0 -23
  54. package/dist/vite/plugins/inject-css-variables/index.js +0 -60
  55. package/dist/vite/plugins/inject-project-globals/index.d.ts +0 -19
  56. package/dist/vite/plugins/inject-project-globals/index.js +0 -58
package/dist/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v2.2.0
2
+ * juisy v2.3.0
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
@@ -27,6 +27,11 @@ import { ESLint } from 'eslint';
27
27
  import yargsParser from 'yargs-parser';
28
28
 
29
29
  class Plugin {
30
+ /**
31
+ * Creates a Plugin instance
32
+ * @param name - The unique name
33
+ * @param pluginObject - The plugin object
34
+ */
30
35
  constructor(name, pluginObject) {
31
36
  this.name = name;
32
37
  if (pluginObject.beforeCreate) {
@@ -93,13 +98,31 @@ class OutputUtils {
93
98
  index: 0
94
99
  // 0 by default
95
100
  };
101
+ /**
102
+ * The logger instance
103
+ * @ignore
104
+ */
105
+ static _loggerInstance = console;
96
106
  /**
97
107
  * Use `chalk` package to style output in console/stdout
98
108
  * @example
99
- * const { $style } = OutputUtils
100
- * console.log($style.green('Green text!')) // => '[32mGreen text![0m'
109
+ * const { $style, log } = OutputUtils
110
+ * log($style.green('Green text!')) // => '[32mGreen text![0m'
101
111
  */
102
112
  static $style = chalk;
113
+ /**
114
+ * Set logger instance
115
+ * @param loggerInstance - The logger instance to set
116
+ */
117
+ static setLoggerInstance(loggerInstance) {
118
+ this._loggerInstance = loggerInstance;
119
+ }
120
+ /**
121
+ * Get the logger instance
122
+ */
123
+ static getLoggerInstance() {
124
+ return this._loggerInstance;
125
+ }
103
126
  /**
104
127
  * Format a message for console output
105
128
  * @param msg - The message to format
@@ -128,12 +151,11 @@ class OutputUtils {
128
151
  return formatted;
129
152
  }
130
153
  /**
154
+ * Log message in console
131
155
  * @param msg - The message
132
156
  * @param options - (Optional) Options object
133
157
  * @param options.indent - How many repeat indent (see `indent-string` package)
134
158
  * @param options.indentChar - Indent character(s). If `options.indent` not provided, will be repeated only 1 time
135
- * @description
136
- * Log message in console
137
159
  * @example
138
160
  * const { log } = OutputUtils
139
161
  * log() // => blank line
@@ -141,7 +163,7 @@ class OutputUtils {
141
163
  * log('To do:', { indent: 2 }) // => ' To do:'
142
164
  */
143
165
  static log(msg, options = {}) {
144
- const loggerInstance = options.loggerInstance || console;
166
+ const loggerInstance = options.loggerInstance || OutputUtils.getLoggerInstance();
145
167
  if (msg) {
146
168
  loggerInstance.log(OutputUtils.formatOutputMessage(msg, options));
147
169
  } else {
@@ -159,12 +181,11 @@ class OutputUtils {
159
181
  OutputUtils.log(OutputUtils.$style.yellow(`⚠ Warning: ${msg}`));
160
182
  }
161
183
  /**
184
+ * Display error message. Throws `err` if provided.
162
185
  * @param msg - The message to display
163
186
  * @param err - If provided, throw the error
164
- * @description
165
- * Display error message. Throws `err` if provided.
166
187
  * @example
167
- * const { error } = require('@hperchec/juisy').utils
188
+ * const { error } = OutputUtils
168
189
  * error('No configuration file') // => '[31m⨉ ERROR: No configuration file[0m'
169
190
  * error('No configuration file', error) // => Log and throws error
170
191
  */
@@ -181,6 +202,7 @@ class OutputUtils {
181
202
  * @param options - Options object
182
203
  * @param options.index - Custom index. If `null`, no index prepended to string
183
204
  * @example
205
+ * const { step } = OutputUtils
184
206
  * step('Important step') // => '● 1 - Important step'
185
207
  * step('Very important step') // => '● 2 - Very important step'
186
208
  */
@@ -197,7 +219,7 @@ class OutputUtils {
197
219
  * @param options - Options object
198
220
  * @param options.last - Defines if it is the last substep
199
221
  * @example
200
- * const { substep } = require('@hperchec/juisy').utils
222
+ * const { substep } = OutputUtils
201
223
  * substep('Awesome substep') // => '├ Awesome substep'
202
224
  * substep('Last substep', { last: true }) // => '└ Last substep'
203
225
  */
@@ -205,13 +227,11 @@ class OutputUtils {
205
227
  OutputUtils.log(msg, { indentChar: options.last ? "└ " : "├ " });
206
228
  }
207
229
  /**
208
- * @param {string} message - Message to display
209
- * @param {Function} fct - The function to execute
210
- * @returns {Promise<void>}
211
- * @description
212
230
  * Wait function: display loading during 'fct' execution
231
+ * @param message - Message to display
232
+ * @param fct - The function to execute
213
233
  * @example
214
- * const { wait } = require('@hperchec/juisy').utils
234
+ * const { wait } = OutputUtils
215
235
  * await wait('Waiting', async () => {
216
236
  * // Do async logic
217
237
  * })
@@ -231,7 +251,7 @@ class OutputUtils {
231
251
  class Command {
232
252
  /**
233
253
  * Creates a Command instance from object (CommandObject)
234
- * @param {CommandObject} commandObject - The command definition object
254
+ * @param commandObject - The command definition object
235
255
  */
236
256
  constructor(commandObject) {
237
257
  if (commandObject) {
@@ -240,10 +260,8 @@ class Command {
240
260
  this.describe = commandObject.describe;
241
261
  this.deprecated = commandObject.deprecated;
242
262
  this.meta = commandObject.meta;
243
- if (commandObject.builder)
244
- this.builder = commandObject.builder;
245
- if (commandObject.handler)
246
- this.handler = commandObject.handler;
263
+ if (commandObject.builder) this.builder = commandObject.builder;
264
+ if (commandObject.handler) this.handler = commandObject.handler;
247
265
  this.middlewares = commandObject.middlewares;
248
266
  }
249
267
  }
@@ -301,6 +319,12 @@ class Command {
301
319
  getProcessArgv() {
302
320
  return hideBin(process.argv);
303
321
  }
322
+ /**
323
+ * Get the command signature as string
324
+ */
325
+ getSignature() {
326
+ return this.constructor.getSignature(this);
327
+ }
304
328
  /**
305
329
  * Get Command instance as plain object
306
330
  * @returns The command definition object to pass to yargs
@@ -329,10 +353,32 @@ class Command {
329
353
  /**
330
354
  * Static properties
331
355
  */
356
+ /**
357
+ * The CLI engine
358
+ * @ignore
359
+ */
360
+ static _engine;
332
361
  /**
333
362
  * The CLI engine. Will be set by createEngine method
334
363
  */
335
- static engine;
364
+ static get engine() {
365
+ return this._engine;
366
+ }
367
+ /**
368
+ * Set the CLI engine
369
+ * @param engine - The CLI engine
370
+ */
371
+ static setEngine(engine) {
372
+ this._engine = engine;
373
+ OutputUtils.setLoggerInstance(this._engine.getInternalMethods().getLoggerInstance());
374
+ }
375
+ /**
376
+ * Get the command signature as string
377
+ * @param cmdObj - Can be an instance of Command or a command object
378
+ */
379
+ static getSignature(cmdObj) {
380
+ return cmdObj.command ? Array.isArray(cmdObj.command) ? cmdObj.command.join(" ") : cmdObj.command : "";
381
+ }
336
382
  }
337
383
 
338
384
  function createEngine(yargs) {
@@ -357,7 +403,10 @@ function createEngine(yargs) {
357
403
  xargs.enableGlobalCommandVisitors = enableGlobalCommandVisitors;
358
404
  xargs.isPrivate = isPrivate;
359
405
  xargs.getSettings = getSettings;
360
- Command.engine = xargs.strict().help();
406
+ Command.setEngine(
407
+ xargs.strict().help()
408
+ // Enable help
409
+ );
361
410
  return Command.engine;
362
411
  }
363
412
  function command(...args) {
@@ -383,8 +432,7 @@ function command(...args) {
383
432
  const cmdsArray = [];
384
433
  for (const commandModule of args[0]) {
385
434
  const visited = visit((isClass(commandModule) ? new commandModule() : commandModule).toObject());
386
- if (visited)
387
- cmdsArray.push(visited);
435
+ if (visited) cmdsArray.push(visited);
388
436
  }
389
437
  return self.originalCommand(cmdsArray);
390
438
  } else {
@@ -448,18 +496,21 @@ function getSettings(path) {
448
496
  }
449
497
 
450
498
  const proxify = (target) => {
451
- const tmp = new Proxy(target instanceof Array ? [] : {}, {
452
- // Overwrite Object type getter to 'observe'
453
- get: (obj, prop) => {
454
- if (prop in obj) {
455
- if (resolveSettingsCallbacks[prop]) {
456
- return resolveSettingsCallbacks[prop](obj[prop]);
499
+ const tmp = new Proxy(
500
+ target instanceof Array ? [] : {},
501
+ {
502
+ // Overwrite Object type getter to 'observe'
503
+ get: (obj, prop) => {
504
+ if (prop in obj) {
505
+ if (resolveSettingsCallbacks[prop]) {
506
+ return resolveSettingsCallbacks[prop](obj[prop]);
507
+ }
508
+ return obj[prop];
457
509
  }
458
- return obj[prop];
510
+ return void 0;
459
511
  }
460
- return void 0;
461
512
  }
462
- });
513
+ );
463
514
  for (const property in target) {
464
515
  tmp[property] = target[property];
465
516
  }
@@ -480,8 +531,7 @@ const findCommandIn = (fullSignature, commands) => {
480
531
  } else {
481
532
  if (command.children?.length) {
482
533
  const found = findCommandIn(fullSignature, command.children);
483
- if (found)
484
- return found;
534
+ if (found) return found;
485
535
  }
486
536
  }
487
537
  }
@@ -512,17 +562,19 @@ async function CLIFactory(builder, options) {
512
562
  if (options?.settingsPath) {
513
563
  settingsPath = options.settingsPath;
514
564
  }
515
- const configPath = findUpSync(settingsPath ? [settingsPath] : [
516
- "dev.config.ts",
517
- "dev.config.js",
518
- "dev.config.json",
519
- "cli.config.ts",
520
- "cli.config.js",
521
- "cli.config.json",
522
- ".clirc.ts",
523
- ".clirc.js",
524
- ".clirc.json"
525
- ]);
565
+ const configPath = findUpSync(
566
+ settingsPath ? [settingsPath] : [
567
+ "dev.config.ts",
568
+ "dev.config.js",
569
+ "dev.config.json",
570
+ "cli.config.ts",
571
+ "cli.config.js",
572
+ "cli.config.json",
573
+ ".clirc.ts",
574
+ ".clirc.js",
575
+ ".clirc.json"
576
+ ]
577
+ );
526
578
  if (settingsPath && !configPath) {
527
579
  throw new Error("Unable to find file: " + settingsPath);
528
580
  } else if (configPath) {
@@ -621,10 +673,8 @@ class InterfaceUtils {
621
673
  return callExeca();
622
674
  }
623
675
  /**
624
- * @param {number} [code] - Code for process.exit() (default: 0)
625
- * @returns {void}
626
- * @description
627
676
  * Exit process
677
+ * @param [code] - Code for process.exit() (default: 0)
628
678
  * @example
629
679
  * const { abort } = InterfaceUtils
630
680
  * abort() // => exit process with code 0
@@ -635,12 +685,11 @@ class InterfaceUtils {
635
685
  process.exit(code);
636
686
  }
637
687
  /**
688
+ * Demand confirmation with prompts native util. If not confirmed, it will automatically abort the script.
638
689
  * @param question - A prompt question object
639
690
  * @param options - A prompt options object
640
- * @returns {Promise<boolean>} - True if confirmed
641
- * @description
642
- * Demand confirmation with prompts native util. If not confirmed, it will automatically abort the script.
643
691
  * @example
692
+ * const { confirm } = InterfaceUtils
644
693
  * confirm({ message: 'Confirm to continue' }) // Deny it will abort the script
645
694
  */
646
695
  static async confirm(question, options = {}) {
@@ -723,7 +772,9 @@ class BumpVersionCommand extends Command {
723
772
  const { $style, step, substep, error } = OutputUtils;
724
773
  const { confirm, prompts, abort } = InterfaceUtils;
725
774
  const packageJsonPath = argv.file ? path.isAbsolute(argv.file) ? argv.file : path.join(process.cwd(), argv.file) : path.resolve(process.cwd(), "package.json");
726
- const pkg = JSON.parse(fs$1.readFileSync(packageJsonPath, "utf-8"));
775
+ const pkg = JSON.parse(
776
+ fs$1.readFileSync(packageJsonPath, "utf-8")
777
+ );
727
778
  let targetVersion = argv.targetVersion;
728
779
  step("Bump version");
729
780
  if (!targetVersion) {
@@ -759,14 +810,17 @@ class BumpVersionCommand extends Command {
759
810
  } else {
760
811
  targetVersion = release;
761
812
  }
762
- await confirm({
763
- type: "confirm",
764
- name: "yes",
765
- message: `Releasing v${targetVersion}. Confirm?`,
766
- initial: true
767
- }, {
768
- onCancel: () => abort()
769
- });
813
+ await confirm(
814
+ {
815
+ type: "confirm",
816
+ name: "yes",
817
+ message: `Releasing v${targetVersion}. Confirm?`,
818
+ initial: true
819
+ },
820
+ {
821
+ onCancel: () => abort()
822
+ }
823
+ );
770
824
  }
771
825
  let commandError = false;
772
826
  try {
@@ -825,10 +879,14 @@ const changelog = new Command({
825
879
  };
826
880
  await wait("Generating", async () => {
827
881
  try {
828
- await run("npx", [
829
- "conventional-changelog",
830
- ...flattenOptions(commandOptions)
831
- ], { stdio: "inherit" });
882
+ await run(
883
+ "npx",
884
+ [
885
+ "conventional-changelog",
886
+ ...flattenOptions(commandOptions)
887
+ ],
888
+ { stdio: "inherit" }
889
+ );
832
890
  } catch (e) {
833
891
  error("Unable to generate changelog", e);
834
892
  }
@@ -1056,35 +1114,14 @@ function resolveCommitlintSettings(settings = {}) {
1056
1114
  return settings;
1057
1115
  }
1058
1116
  function resolveMarkdownlintSettings(settings = []) {
1059
- const normalizeRootConfig = (config = {}) => {
1060
- return {
1061
- config: {},
1062
- ...config
1063
- };
1064
- };
1065
- const normalizeConfig = (config = {}) => {
1066
- return {
1067
- config: {},
1068
- ...config,
1069
- globs: config.globs
1070
- };
1071
- };
1072
1117
  let resolved = [];
1073
- let rootConfig = {
1074
- config: {}
1075
- };
1076
- const globScopedConfigs = [];
1077
1118
  for (const item of settings) {
1078
- if (!item.globs && typeof rootConfig.config !== "string") {
1079
- rootConfig = deepmerge(rootConfig, item);
1080
- } else if (!(item.globs instanceof Array) || !item.globs.length) {
1119
+ if (item.globs && (!(item.globs instanceof Array) || !item.globs.length)) {
1081
1120
  throw new Error('lint.markdown configuration: if provided, "globs" property must be a non-empty array');
1082
1121
  } else {
1083
- globScopedConfigs.push(item);
1122
+ resolved.push(item);
1084
1123
  }
1085
1124
  }
1086
- resolved.push(normalizeRootConfig(rootConfig));
1087
- resolved.push(...globScopedConfigs.map(normalizeConfig));
1088
1125
  return resolved;
1089
1126
  }
1090
1127
  function resolveLintStagedSettings(settings = {}) {
@@ -1195,7 +1232,11 @@ const lintCommit = new Command({
1195
1232
  }
1196
1233
  let commandError;
1197
1234
  try {
1198
- await run("npx", ["commitlint", ...commitLintCmdArgs], { stdio: "pipe" });
1235
+ await run(
1236
+ "npx",
1237
+ ["commitlint", ...commitLintCmdArgs],
1238
+ { stdio: "pipe" }
1239
+ );
1199
1240
  } catch (e) {
1200
1241
  commandError = e;
1201
1242
  }
@@ -1231,15 +1272,12 @@ const lintMarkdown = new Command({
1231
1272
  const { $style, step, substep, error } = OutputUtils;
1232
1273
  step("Configuring markdownlint");
1233
1274
  const configs = this.engine.getSettings("lint.markdown") || [];
1234
- const rootConfig = configs.splice(configs.findIndex((config) => !config.globs), 1);
1235
1275
  let commandError;
1236
1276
  for (const item of configs) {
1237
1277
  let tempConfig;
1238
1278
  const mdLintCmdArgs = [...item.globs];
1239
1279
  const tempConfigFilePath = "__TEMP_MARKDOWNLINT_CONFIG__.markdownlint-cli2.jsonc";
1240
- if (!item.config) {
1241
- tempConfig = rootConfig;
1242
- } else {
1280
+ if (item.config) {
1243
1281
  tempConfig = item.config;
1244
1282
  }
1245
1283
  if (typeof tempConfig === "string") {
@@ -1252,7 +1290,11 @@ const lintMarkdown = new Command({
1252
1290
  mdLintCmdArgs.push("--fix");
1253
1291
  }
1254
1292
  try {
1255
- await run("npx", ["markdownlint-cli2", ...mdLintCmdArgs], { stdio: "pipe" });
1293
+ await run(
1294
+ "npx",
1295
+ ["markdownlint-cli2", ...mdLintCmdArgs],
1296
+ { stdio: "pipe" }
1297
+ );
1256
1298
  } catch (e) {
1257
1299
  commandError = e;
1258
1300
  if (fs$1.existsSync(path.resolve(tempConfigFilePath))) {
@@ -1260,6 +1302,9 @@ const lintMarkdown = new Command({
1260
1302
  }
1261
1303
  break;
1262
1304
  }
1305
+ if (fs$1.existsSync(path.resolve(tempConfigFilePath))) {
1306
+ fs$1.unlinkSync(path.resolve(tempConfigFilePath));
1307
+ }
1263
1308
  }
1264
1309
  if (commandError) {
1265
1310
  substep($style.red("❌ An error has occured."), { last: true });
@@ -1339,22 +1384,26 @@ const lintStaged = new Command({
1339
1384
 
1340
1385
  const RegisterLintCommands = new Plugin("built-in:register-lint-commands", {
1341
1386
  beforeCreate({ defineDefaultCommand, defineSettings, builder, factoryOptions }) {
1342
- defineSettings("lint", {
1343
- default: {
1344
- config: "eslint.config.js"
1345
- },
1346
- commit: {
1347
- // ...
1387
+ defineSettings(
1388
+ "lint",
1389
+ {
1390
+ default: {
1391
+ config: "eslint.config.js"
1392
+ },
1393
+ commit: {
1394
+ // ...
1395
+ },
1396
+ markdown: [],
1397
+ staged: {
1398
+ "*.{js,cjs,ts}": [
1399
+ "eslint --fix"
1400
+ ]
1401
+ }
1348
1402
  },
1349
- markdown: [],
1350
- staged: {
1351
- "*.{js,cjs,ts}": [
1352
- "eslint --fix"
1353
- ]
1403
+ {
1404
+ resolve: resolveSettings
1354
1405
  }
1355
- }, {
1356
- resolve: resolveSettings
1357
- });
1406
+ );
1358
1407
  defineDefaultCommand({
1359
1408
  fullSignature: "lint",
1360
1409
  commandObject: lint,
@@ -1458,7 +1507,12 @@ const release = new Command({
1458
1507
  releaseItCmdArgs.push("--config", releaseSettings.config);
1459
1508
  } else {
1460
1509
  const changelogSettings = this.engine.getSettings("changelog");
1461
- const { onReleaseConfig, preset, infile, context } = changelogSettings;
1510
+ const {
1511
+ onReleaseConfig,
1512
+ preset,
1513
+ infile,
1514
+ context
1515
+ } = changelogSettings;
1462
1516
  const releaseItChangelogConfig = {
1463
1517
  infile: onReleaseConfig.infile || infile,
1464
1518
  header: onReleaseConfig.header,
@@ -1547,6 +1601,7 @@ const RegisterReleaseCommand = new Plugin("built-in:register-release-command", {
1547
1601
  git: {
1548
1602
  commitMessage: "chore(release): v${version}",
1549
1603
  requireBranch: "main",
1604
+ tagName: "v${version}",
1550
1605
  tagAnnotation: "v${version}"
1551
1606
  }
1552
1607
  });
@@ -1633,9 +1688,23 @@ const CommandMeta = new Plugin("built-in:command-meta", {
1633
1688
  }
1634
1689
  });
1635
1690
 
1691
+ const visitorsCache = [];
1636
1692
  const visitor = function(commandObject, engine, options2) {
1637
1693
  const { metaProp, envKey } = options2;
1638
- if (commandObject.meta?.[metaProp]) {
1694
+ let isMadePrivate = !!commandObject.meta?.[metaProp];
1695
+ for (const localVisitor of visitorsCache) {
1696
+ const result = localVisitor(commandObject);
1697
+ if (result !== void 0) {
1698
+ isMadePrivate = result;
1699
+ }
1700
+ }
1701
+ if (!commandObject.meta) commandObject.meta = {};
1702
+ if (isMadePrivate) {
1703
+ commandObject.meta[metaProp] = true;
1704
+ } else {
1705
+ commandObject.meta[metaProp] = false;
1706
+ }
1707
+ if (commandObject.meta[metaProp]) {
1639
1708
  if (process.env[envKey] === "private") {
1640
1709
  commandObject.builder = wrapCommandBuilder(commandObject.builder, function(cli) {
1641
1710
  cli._isPrivate = true;
@@ -1652,8 +1721,15 @@ const options = {
1652
1721
  envKey: "CLI_ENV"
1653
1722
  };
1654
1723
 
1724
+ function makeCommandPrivate(visitor) {
1725
+ visitorsCache.push(visitor);
1726
+ return this;
1727
+ }
1655
1728
  const PrivateCommands = new Plugin("built-in:private-commands", {
1656
1729
  created({ engine, builder, factoryOptions }) {
1730
+ Object.defineProperty(engine.constructor.prototype, "makeCommandPrivate", {
1731
+ value: makeCommandPrivate
1732
+ });
1657
1733
  engine.globalCommandVisitor("private-command-visitor", visitor, options);
1658
1734
  }
1659
1735
  });
@@ -1671,8 +1747,7 @@ async function extractUsage(factory, recursive = false, args = [""], locale = "e
1671
1747
  children: recursive ? {} : void 0
1672
1748
  };
1673
1749
  const parseCallback = function(err, argv, output) {
1674
- if (err)
1675
- throw err;
1750
+ if (err) throw err;
1676
1751
  const self = this;
1677
1752
  doclet.args = argv._;
1678
1753
  doclet.command = argv._[argv._.length - 1];
@@ -1701,7 +1776,12 @@ async function extractUsage(factory, recursive = false, args = [""], locale = "e
1701
1776
  await innerYargs.parseAsync(args, { help: true }, parseCallback);
1702
1777
  if (recursive) {
1703
1778
  for (const childCommand in doclet.extractedUsage.commands) {
1704
- doclet.children[childCommand] = await extractUsage(factory, true, [...args.filter((a) => a !== ""), childCommand], locale);
1779
+ doclet.children[childCommand] = await extractUsage(
1780
+ factory,
1781
+ true,
1782
+ [...args.filter((a) => a !== ""), childCommand],
1783
+ locale
1784
+ );
1705
1785
  }
1706
1786
  }
1707
1787
  return doclet;
@@ -13,9 +13,6 @@ declare module '../../types' {
13
13
  */
14
14
  getMeta: () => this['_meta'];
15
15
  }
16
- /**
17
- * @group Types
18
- */
19
16
  interface CommandObject {
20
17
  meta?: Partial<CommandMeta>;
21
18
  }
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:command-meta'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;
@@ -1,10 +1,10 @@
1
1
  import { CommandVisitor } from '../../../types';
2
2
  /**
3
3
  * Global command visitor to auto-set command meta
4
- * @ignore
5
4
  * @param commandObject - The command object
6
5
  * @param cli - The CLIEngine instance
7
6
  * @returns The commandObject with wrapped builder to inject CLI instance meta.
7
+ * @ignore
8
8
  */
9
9
  export declare const visitor: CommandVisitor;
10
10
  export declare const options: {};
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:default-command-fallbacks'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:load-env-file'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;
@@ -1,4 +1,12 @@
1
1
  declare module '../../types' {
2
+ interface CLIEngine {
3
+ /**
4
+ * Make a command private or not
5
+ * @param visitor - A simple function that returns true to make private, false to make public, or undefined to do nothing.
6
+ * @returns The CLIEngine instance itself
7
+ */
8
+ makeCommandPrivate(visitor: (cmdObj: CommandObject) => (boolean | undefined)): this;
9
+ }
2
10
  interface CommandMeta {
3
11
  private: boolean;
4
12
  }
@@ -1,13 +1,17 @@
1
- import { CommandVisitor } from '../../../types';
1
+ import { CommandObject, CommandVisitor } from '../../../types';
2
2
  /**
3
+ * A local cache for visitors added via CLIEngine.makeCommandPrivate method
4
+ * @ignore
5
+ */
6
+ export declare const visitorsCache: Array<(cmdObj: CommandObject) => (boolean | undefined)>;
7
+ /**
8
+ * Global command visitor to auto-set command private status
3
9
  * @ignore
4
10
  * @param commandModule - The exported command object
5
11
  * @param engine - The CLI (yargs) instance
6
12
  * @param options - The global command visitor defined options
7
13
  * @returns {object|boolean} False if command is private and env key is set to "private".
8
14
  * Otherwise, returns the commandModule with wrapped builder to tag CLI instance as private.
9
- * @description
10
- * Global command visitor to auto-set command private status
11
15
  */
12
16
  export declare const visitor: CommandVisitor;
13
17
  export declare const options: {
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:private-commands'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:register-bump-version-command'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:register-changelog-command'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;