@pragmatic-divops/cli 1.13.15 → 1.13.17

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.
@@ -1,10 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import yargs from 'yargs';
3
- import { format } from 'util';
4
- import { resolve, normalize } from 'path';
5
- import { readFileSync, writeFile, statSync } from 'fs';
6
- import 'assert';
7
- import { fileURLToPath } from 'url';
3
+ import { hideBin } from 'yargs/helpers';
8
4
  import updateNotifier from 'update-notifier';
9
5
  import { questionNames as questionNames$1, scaffold as scaffold$2 } from '@form8ion/project';
10
6
  import { packageManagers } from '@form8ion/javascript-core';
@@ -27,1450 +23,10 @@ import { scaffold as scaffold$1 } from '@form8ion/codecov';
27
23
  import { lift as lift$1 } from '@form8ion/lift';
28
24
  import { scaffold as scaffold$3 } from '@form8ion/cucumber-scaffolder';
29
25
 
30
- function getProcessArgvBinIndex() {
31
- if (isBundledElectronApp())
32
- return 0;
33
- return 1;
34
- }
35
- function isBundledElectronApp() {
36
- return isElectronApp() && !process.defaultApp;
37
- }
38
- function isElectronApp() {
39
- return !!process.versions.electron;
40
- }
41
- function hideBin(argv) {
42
- return argv.slice(getProcessArgvBinIndex() + 1);
43
- }
44
-
45
- /**
46
- * @license
47
- * Copyright (c) 2016, Contributors
48
- * SPDX-License-Identifier: ISC
49
- */
50
- function camelCase(str) {
51
- // Handle the case where an argument is provided as camel case, e.g., fooBar.
52
- // by ensuring that the string isn't already mixed case:
53
- const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase();
54
- if (!isCamelCase) {
55
- str = str.toLowerCase();
56
- }
57
- if (str.indexOf('-') === -1 && str.indexOf('_') === -1) {
58
- return str;
59
- }
60
- else {
61
- let camelcase = '';
62
- let nextChrUpper = false;
63
- const leadingHyphens = str.match(/^-+/);
64
- for (let i = leadingHyphens ? leadingHyphens[0].length : 0; i < str.length; i++) {
65
- let chr = str.charAt(i);
66
- if (nextChrUpper) {
67
- nextChrUpper = false;
68
- chr = chr.toUpperCase();
69
- }
70
- if (i !== 0 && (chr === '-' || chr === '_')) {
71
- nextChrUpper = true;
72
- }
73
- else if (chr !== '-' && chr !== '_') {
74
- camelcase += chr;
75
- }
76
- }
77
- return camelcase;
78
- }
79
- }
80
- function decamelize(str, joinString) {
81
- const lowercase = str.toLowerCase();
82
- joinString = joinString || '-';
83
- let notCamelcase = '';
84
- for (let i = 0; i < str.length; i++) {
85
- const chrLower = lowercase.charAt(i);
86
- const chrString = str.charAt(i);
87
- if (chrLower !== chrString && i > 0) {
88
- notCamelcase += `${joinString}${lowercase.charAt(i)}`;
89
- }
90
- else {
91
- notCamelcase += chrString;
92
- }
93
- }
94
- return notCamelcase;
95
- }
96
- function looksLikeNumber(x) {
97
- if (x === null || x === undefined)
98
- return false;
99
- // if loaded from config, may already be a number.
100
- if (typeof x === 'number')
101
- return true;
102
- // hexadecimal.
103
- if (/^0x[0-9a-f]+$/i.test(x))
104
- return true;
105
- // don't treat 0123 as a number; as it drops the leading '0'.
106
- if (/^0[^.]/.test(x))
107
- return false;
108
- return /^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
109
- }
110
-
111
- /**
112
- * @license
113
- * Copyright (c) 2016, Contributors
114
- * SPDX-License-Identifier: ISC
115
- */
116
- // take an un-split argv string and tokenize it.
117
- function tokenizeArgString(argString) {
118
- if (Array.isArray(argString)) {
119
- return argString.map(e => typeof e !== 'string' ? e + '' : e);
120
- }
121
- argString = argString.trim();
122
- let i = 0;
123
- let prevC = null;
124
- let c = null;
125
- let opening = null;
126
- const args = [];
127
- for (let ii = 0; ii < argString.length; ii++) {
128
- prevC = c;
129
- c = argString.charAt(ii);
130
- // split on spaces unless we're in quotes.
131
- if (c === ' ' && !opening) {
132
- if (!(prevC === ' ')) {
133
- i++;
134
- }
135
- continue;
136
- }
137
- // don't split the string if we're in matching
138
- // opening or closing single and double quotes.
139
- if (c === opening) {
140
- opening = null;
141
- }
142
- else if ((c === "'" || c === '"') && !opening) {
143
- opening = c;
144
- }
145
- if (!args[i])
146
- args[i] = '';
147
- args[i] += c;
148
- }
149
- return args;
150
- }
151
-
152
- /**
153
- * @license
154
- * Copyright (c) 2016, Contributors
155
- * SPDX-License-Identifier: ISC
156
- */
157
- var DefaultValuesForTypeKey;
158
- (function (DefaultValuesForTypeKey) {
159
- DefaultValuesForTypeKey["BOOLEAN"] = "boolean";
160
- DefaultValuesForTypeKey["STRING"] = "string";
161
- DefaultValuesForTypeKey["NUMBER"] = "number";
162
- DefaultValuesForTypeKey["ARRAY"] = "array";
163
- })(DefaultValuesForTypeKey || (DefaultValuesForTypeKey = {}));
164
-
165
- /**
166
- * @license
167
- * Copyright (c) 2016, Contributors
168
- * SPDX-License-Identifier: ISC
169
- */
170
- let mixin;
171
- class YargsParser {
172
- constructor(_mixin) {
173
- mixin = _mixin;
174
- }
175
- parse(argsInput, options) {
176
- const opts = Object.assign({
177
- alias: undefined,
178
- array: undefined,
179
- boolean: undefined,
180
- config: undefined,
181
- configObjects: undefined,
182
- configuration: undefined,
183
- coerce: undefined,
184
- count: undefined,
185
- default: undefined,
186
- envPrefix: undefined,
187
- narg: undefined,
188
- normalize: undefined,
189
- string: undefined,
190
- number: undefined,
191
- __: undefined,
192
- key: undefined
193
- }, options);
194
- // allow a string argument to be passed in rather
195
- // than an argv array.
196
- const args = tokenizeArgString(argsInput);
197
- // tokenizeArgString adds extra quotes to args if argsInput is a string
198
- // only strip those extra quotes in processValue if argsInput is a string
199
- const inputIsString = typeof argsInput === 'string';
200
- // aliases might have transitive relationships, normalize this.
201
- const aliases = combineAliases(Object.assign(Object.create(null), opts.alias));
202
- const configuration = Object.assign({
203
- 'boolean-negation': true,
204
- 'camel-case-expansion': true,
205
- 'combine-arrays': false,
206
- 'dot-notation': true,
207
- 'duplicate-arguments-array': true,
208
- 'flatten-duplicate-arrays': true,
209
- 'greedy-arrays': true,
210
- 'halt-at-non-option': false,
211
- 'nargs-eats-options': false,
212
- 'negation-prefix': 'no-',
213
- 'parse-numbers': true,
214
- 'parse-positional-numbers': true,
215
- 'populate--': false,
216
- 'set-placeholder-key': false,
217
- 'short-option-groups': true,
218
- 'strip-aliased': false,
219
- 'strip-dashed': false,
220
- 'unknown-options-as-args': false
221
- }, opts.configuration);
222
- const defaults = Object.assign(Object.create(null), opts.default);
223
- const configObjects = opts.configObjects || [];
224
- const envPrefix = opts.envPrefix;
225
- const notFlagsOption = configuration['populate--'];
226
- const notFlagsArgv = notFlagsOption ? '--' : '_';
227
- const newAliases = Object.create(null);
228
- const defaulted = Object.create(null);
229
- // allow a i18n handler to be passed in, default to a fake one (util.format).
230
- const __ = opts.__ || mixin.format;
231
- const flags = {
232
- aliases: Object.create(null),
233
- arrays: Object.create(null),
234
- bools: Object.create(null),
235
- strings: Object.create(null),
236
- numbers: Object.create(null),
237
- counts: Object.create(null),
238
- normalize: Object.create(null),
239
- configs: Object.create(null),
240
- nargs: Object.create(null),
241
- coercions: Object.create(null),
242
- keys: []
243
- };
244
- const negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
245
- const negatedBoolean = new RegExp('^--' + configuration['negation-prefix'] + '(.+)');
246
- [].concat(opts.array || []).filter(Boolean).forEach(function (opt) {
247
- const key = typeof opt === 'object' ? opt.key : opt;
248
- // assign to flags[bools|strings|numbers]
249
- const assignment = Object.keys(opt).map(function (key) {
250
- const arrayFlagKeys = {
251
- boolean: 'bools',
252
- string: 'strings',
253
- number: 'numbers'
254
- };
255
- return arrayFlagKeys[key];
256
- }).filter(Boolean).pop();
257
- // assign key to be coerced
258
- if (assignment) {
259
- flags[assignment][key] = true;
260
- }
261
- flags.arrays[key] = true;
262
- flags.keys.push(key);
263
- });
264
- [].concat(opts.boolean || []).filter(Boolean).forEach(function (key) {
265
- flags.bools[key] = true;
266
- flags.keys.push(key);
267
- });
268
- [].concat(opts.string || []).filter(Boolean).forEach(function (key) {
269
- flags.strings[key] = true;
270
- flags.keys.push(key);
271
- });
272
- [].concat(opts.number || []).filter(Boolean).forEach(function (key) {
273
- flags.numbers[key] = true;
274
- flags.keys.push(key);
275
- });
276
- [].concat(opts.count || []).filter(Boolean).forEach(function (key) {
277
- flags.counts[key] = true;
278
- flags.keys.push(key);
279
- });
280
- [].concat(opts.normalize || []).filter(Boolean).forEach(function (key) {
281
- flags.normalize[key] = true;
282
- flags.keys.push(key);
283
- });
284
- if (typeof opts.narg === 'object') {
285
- Object.entries(opts.narg).forEach(([key, value]) => {
286
- if (typeof value === 'number') {
287
- flags.nargs[key] = value;
288
- flags.keys.push(key);
289
- }
290
- });
291
- }
292
- if (typeof opts.coerce === 'object') {
293
- Object.entries(opts.coerce).forEach(([key, value]) => {
294
- if (typeof value === 'function') {
295
- flags.coercions[key] = value;
296
- flags.keys.push(key);
297
- }
298
- });
299
- }
300
- if (typeof opts.config !== 'undefined') {
301
- if (Array.isArray(opts.config) || typeof opts.config === 'string') {
302
- [].concat(opts.config).filter(Boolean).forEach(function (key) {
303
- flags.configs[key] = true;
304
- });
305
- }
306
- else if (typeof opts.config === 'object') {
307
- Object.entries(opts.config).forEach(([key, value]) => {
308
- if (typeof value === 'boolean' || typeof value === 'function') {
309
- flags.configs[key] = value;
310
- }
311
- });
312
- }
313
- }
314
- // create a lookup table that takes into account all
315
- // combinations of aliases: {f: ['foo'], foo: ['f']}
316
- extendAliases(opts.key, aliases, opts.default, flags.arrays);
317
- // apply default values to all aliases.
318
- Object.keys(defaults).forEach(function (key) {
319
- (flags.aliases[key] || []).forEach(function (alias) {
320
- defaults[alias] = defaults[key];
321
- });
322
- });
323
- let error = null;
324
- checkConfiguration();
325
- let notFlags = [];
326
- const argv = Object.assign(Object.create(null), { _: [] });
327
- // TODO(bcoe): for the first pass at removing object prototype we didn't
328
- // remove all prototypes from objects returned by this API, we might want
329
- // to gradually move towards doing so.
330
- const argvReturn = {};
331
- for (let i = 0; i < args.length; i++) {
332
- const arg = args[i];
333
- const truncatedArg = arg.replace(/^-{3,}/, '---');
334
- let broken;
335
- let key;
336
- let letters;
337
- let m;
338
- let next;
339
- let value;
340
- // any unknown option (except for end-of-options, "--")
341
- if (arg !== '--' && /^-/.test(arg) && isUnknownOptionAsArg(arg)) {
342
- pushPositional(arg);
343
- // ---, ---=, ----, etc,
344
- }
345
- else if (truncatedArg.match(/^---+(=|$)/)) {
346
- // options without key name are invalid.
347
- pushPositional(arg);
348
- continue;
349
- // -- separated by =
350
- }
351
- else if (arg.match(/^--.+=/) || (!configuration['short-option-groups'] && arg.match(/^-.+=/))) {
352
- // Using [\s\S] instead of . because js doesn't support the
353
- // 'dotall' regex modifier. See:
354
- // http://stackoverflow.com/a/1068308/13216
355
- m = arg.match(/^--?([^=]+)=([\s\S]*)$/);
356
- // arrays format = '--f=a b c'
357
- if (m !== null && Array.isArray(m) && m.length >= 3) {
358
- if (checkAllAliases(m[1], flags.arrays)) {
359
- i = eatArray(i, m[1], args, m[2]);
360
- }
361
- else if (checkAllAliases(m[1], flags.nargs) !== false) {
362
- // nargs format = '--f=monkey washing cat'
363
- i = eatNargs(i, m[1], args, m[2]);
364
- }
365
- else {
366
- setArg(m[1], m[2], true);
367
- }
368
- }
369
- }
370
- else if (arg.match(negatedBoolean) && configuration['boolean-negation']) {
371
- m = arg.match(negatedBoolean);
372
- if (m !== null && Array.isArray(m) && m.length >= 2) {
373
- key = m[1];
374
- setArg(key, checkAllAliases(key, flags.arrays) ? [false] : false);
375
- }
376
- // -- separated by space.
377
- }
378
- else if (arg.match(/^--.+/) || (!configuration['short-option-groups'] && arg.match(/^-[^-]+/))) {
379
- m = arg.match(/^--?(.+)/);
380
- if (m !== null && Array.isArray(m) && m.length >= 2) {
381
- key = m[1];
382
- if (checkAllAliases(key, flags.arrays)) {
383
- // array format = '--foo a b c'
384
- i = eatArray(i, key, args);
385
- }
386
- else if (checkAllAliases(key, flags.nargs) !== false) {
387
- // nargs format = '--foo a b c'
388
- // should be truthy even if: flags.nargs[key] === 0
389
- i = eatNargs(i, key, args);
390
- }
391
- else {
392
- next = args[i + 1];
393
- if (next !== undefined && (!next.match(/^-/) ||
394
- next.match(negative)) &&
395
- !checkAllAliases(key, flags.bools) &&
396
- !checkAllAliases(key, flags.counts)) {
397
- setArg(key, next);
398
- i++;
399
- }
400
- else if (/^(true|false)$/.test(next)) {
401
- setArg(key, next);
402
- i++;
403
- }
404
- else {
405
- setArg(key, defaultValue(key));
406
- }
407
- }
408
- }
409
- // dot-notation flag separated by '='.
410
- }
411
- else if (arg.match(/^-.\..+=/)) {
412
- m = arg.match(/^-([^=]+)=([\s\S]*)$/);
413
- if (m !== null && Array.isArray(m) && m.length >= 3) {
414
- setArg(m[1], m[2]);
415
- }
416
- // dot-notation flag separated by space.
417
- }
418
- else if (arg.match(/^-.\..+/) && !arg.match(negative)) {
419
- next = args[i + 1];
420
- m = arg.match(/^-(.\..+)/);
421
- if (m !== null && Array.isArray(m) && m.length >= 2) {
422
- key = m[1];
423
- if (next !== undefined && !next.match(/^-/) &&
424
- !checkAllAliases(key, flags.bools) &&
425
- !checkAllAliases(key, flags.counts)) {
426
- setArg(key, next);
427
- i++;
428
- }
429
- else {
430
- setArg(key, defaultValue(key));
431
- }
432
- }
433
- }
434
- else if (arg.match(/^-[^-]+/) && !arg.match(negative)) {
435
- letters = arg.slice(1, -1).split('');
436
- broken = false;
437
- for (let j = 0; j < letters.length; j++) {
438
- next = arg.slice(j + 2);
439
- if (letters[j + 1] && letters[j + 1] === '=') {
440
- value = arg.slice(j + 3);
441
- key = letters[j];
442
- if (checkAllAliases(key, flags.arrays)) {
443
- // array format = '-f=a b c'
444
- i = eatArray(i, key, args, value);
445
- }
446
- else if (checkAllAliases(key, flags.nargs) !== false) {
447
- // nargs format = '-f=monkey washing cat'
448
- i = eatNargs(i, key, args, value);
449
- }
450
- else {
451
- setArg(key, value);
452
- }
453
- broken = true;
454
- break;
455
- }
456
- if (next === '-') {
457
- setArg(letters[j], next);
458
- continue;
459
- }
460
- // current letter is an alphabetic character and next value is a number
461
- if (/[A-Za-z]/.test(letters[j]) &&
462
- /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next) &&
463
- checkAllAliases(next, flags.bools) === false) {
464
- setArg(letters[j], next);
465
- broken = true;
466
- break;
467
- }
468
- if (letters[j + 1] && letters[j + 1].match(/\W/)) {
469
- setArg(letters[j], next);
470
- broken = true;
471
- break;
472
- }
473
- else {
474
- setArg(letters[j], defaultValue(letters[j]));
475
- }
476
- }
477
- key = arg.slice(-1)[0];
478
- if (!broken && key !== '-') {
479
- if (checkAllAliases(key, flags.arrays)) {
480
- // array format = '-f a b c'
481
- i = eatArray(i, key, args);
482
- }
483
- else if (checkAllAliases(key, flags.nargs) !== false) {
484
- // nargs format = '-f a b c'
485
- // should be truthy even if: flags.nargs[key] === 0
486
- i = eatNargs(i, key, args);
487
- }
488
- else {
489
- next = args[i + 1];
490
- if (next !== undefined && (!/^(-|--)[^-]/.test(next) ||
491
- next.match(negative)) &&
492
- !checkAllAliases(key, flags.bools) &&
493
- !checkAllAliases(key, flags.counts)) {
494
- setArg(key, next);
495
- i++;
496
- }
497
- else if (/^(true|false)$/.test(next)) {
498
- setArg(key, next);
499
- i++;
500
- }
501
- else {
502
- setArg(key, defaultValue(key));
503
- }
504
- }
505
- }
506
- }
507
- else if (arg.match(/^-[0-9]$/) &&
508
- arg.match(negative) &&
509
- checkAllAliases(arg.slice(1), flags.bools)) {
510
- // single-digit boolean alias, e.g: xargs -0
511
- key = arg.slice(1);
512
- setArg(key, defaultValue(key));
513
- }
514
- else if (arg === '--') {
515
- notFlags = args.slice(i + 1);
516
- break;
517
- }
518
- else if (configuration['halt-at-non-option']) {
519
- notFlags = args.slice(i);
520
- break;
521
- }
522
- else {
523
- pushPositional(arg);
524
- }
525
- }
526
- // order of precedence:
527
- // 1. command line arg
528
- // 2. value from env var
529
- // 3. value from config file
530
- // 4. value from config objects
531
- // 5. configured default value
532
- applyEnvVars(argv, true); // special case: check env vars that point to config file
533
- applyEnvVars(argv, false);
534
- setConfig(argv);
535
- setConfigObjects();
536
- applyDefaultsAndAliases(argv, flags.aliases, defaults, true);
537
- applyCoercions(argv);
538
- if (configuration['set-placeholder-key'])
539
- setPlaceholderKeys(argv);
540
- // for any counts either not in args or without an explicit default, set to 0
541
- Object.keys(flags.counts).forEach(function (key) {
542
- if (!hasKey(argv, key.split('.')))
543
- setArg(key, 0);
544
- });
545
- // '--' defaults to undefined.
546
- if (notFlagsOption && notFlags.length)
547
- argv[notFlagsArgv] = [];
548
- notFlags.forEach(function (key) {
549
- argv[notFlagsArgv].push(key);
550
- });
551
- if (configuration['camel-case-expansion'] && configuration['strip-dashed']) {
552
- Object.keys(argv).filter(key => key !== '--' && key.includes('-')).forEach(key => {
553
- delete argv[key];
554
- });
555
- }
556
- if (configuration['strip-aliased']) {
557
- [].concat(...Object.keys(aliases).map(k => aliases[k])).forEach(alias => {
558
- if (configuration['camel-case-expansion'] && alias.includes('-')) {
559
- delete argv[alias.split('.').map(prop => camelCase(prop)).join('.')];
560
- }
561
- delete argv[alias];
562
- });
563
- }
564
- // Push argument into positional array, applying numeric coercion:
565
- function pushPositional(arg) {
566
- const maybeCoercedNumber = maybeCoerceNumber('_', arg);
567
- if (typeof maybeCoercedNumber === 'string' || typeof maybeCoercedNumber === 'number') {
568
- argv._.push(maybeCoercedNumber);
569
- }
570
- }
571
- // how many arguments should we consume, based
572
- // on the nargs option?
573
- function eatNargs(i, key, args, argAfterEqualSign) {
574
- let ii;
575
- let toEat = checkAllAliases(key, flags.nargs);
576
- // NaN has a special meaning for the array type, indicating that one or
577
- // more values are expected.
578
- toEat = typeof toEat !== 'number' || isNaN(toEat) ? 1 : toEat;
579
- if (toEat === 0) {
580
- if (!isUndefined(argAfterEqualSign)) {
581
- error = Error(__('Argument unexpected for: %s', key));
582
- }
583
- setArg(key, defaultValue(key));
584
- return i;
585
- }
586
- let available = isUndefined(argAfterEqualSign) ? 0 : 1;
587
- if (configuration['nargs-eats-options']) {
588
- // classic behavior, yargs eats positional and dash arguments.
589
- if (args.length - (i + 1) + available < toEat) {
590
- error = Error(__('Not enough arguments following: %s', key));
591
- }
592
- available = toEat;
593
- }
594
- else {
595
- // nargs will not consume flag arguments, e.g., -abc, --foo,
596
- // and terminates when one is observed.
597
- for (ii = i + 1; ii < args.length; ii++) {
598
- if (!args[ii].match(/^-[^0-9]/) || args[ii].match(negative) || isUnknownOptionAsArg(args[ii]))
599
- available++;
600
- else
601
- break;
602
- }
603
- if (available < toEat)
604
- error = Error(__('Not enough arguments following: %s', key));
605
- }
606
- let consumed = Math.min(available, toEat);
607
- if (!isUndefined(argAfterEqualSign) && consumed > 0) {
608
- setArg(key, argAfterEqualSign);
609
- consumed--;
610
- }
611
- for (ii = i + 1; ii < (consumed + i + 1); ii++) {
612
- setArg(key, args[ii]);
613
- }
614
- return (i + consumed);
615
- }
616
- // if an option is an array, eat all non-hyphenated arguments
617
- // following it... YUM!
618
- // e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
619
- function eatArray(i, key, args, argAfterEqualSign) {
620
- let argsToSet = [];
621
- let next = argAfterEqualSign || args[i + 1];
622
- // If both array and nargs are configured, enforce the nargs count:
623
- const nargsCount = checkAllAliases(key, flags.nargs);
624
- if (checkAllAliases(key, flags.bools) && !(/^(true|false)$/.test(next))) {
625
- argsToSet.push(true);
626
- }
627
- else if (isUndefined(next) ||
628
- (isUndefined(argAfterEqualSign) && /^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))) {
629
- // for keys without value ==> argsToSet remains an empty []
630
- // set user default value, if available
631
- if (defaults[key] !== undefined) {
632
- const defVal = defaults[key];
633
- argsToSet = Array.isArray(defVal) ? defVal : [defVal];
634
- }
635
- }
636
- else {
637
- // value in --option=value is eaten as is
638
- if (!isUndefined(argAfterEqualSign)) {
639
- argsToSet.push(processValue(key, argAfterEqualSign, true));
640
- }
641
- for (let ii = i + 1; ii < args.length; ii++) {
642
- if ((!configuration['greedy-arrays'] && argsToSet.length > 0) ||
643
- (nargsCount && typeof nargsCount === 'number' && argsToSet.length >= nargsCount))
644
- break;
645
- next = args[ii];
646
- if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))
647
- break;
648
- i = ii;
649
- argsToSet.push(processValue(key, next, inputIsString));
650
- }
651
- }
652
- // If both array and nargs are configured, create an error if less than
653
- // nargs positionals were found. NaN has special meaning, indicating
654
- // that at least one value is required (more are okay).
655
- if (typeof nargsCount === 'number' && ((nargsCount && argsToSet.length < nargsCount) ||
656
- (isNaN(nargsCount) && argsToSet.length === 0))) {
657
- error = Error(__('Not enough arguments following: %s', key));
658
- }
659
- setArg(key, argsToSet);
660
- return i;
661
- }
662
- function setArg(key, val, shouldStripQuotes = inputIsString) {
663
- if (/-/.test(key) && configuration['camel-case-expansion']) {
664
- const alias = key.split('.').map(function (prop) {
665
- return camelCase(prop);
666
- }).join('.');
667
- addNewAlias(key, alias);
668
- }
669
- const value = processValue(key, val, shouldStripQuotes);
670
- const splitKey = key.split('.');
671
- setKey(argv, splitKey, value);
672
- // handle populating aliases of the full key
673
- if (flags.aliases[key]) {
674
- flags.aliases[key].forEach(function (x) {
675
- const keyProperties = x.split('.');
676
- setKey(argv, keyProperties, value);
677
- });
678
- }
679
- // handle populating aliases of the first element of the dot-notation key
680
- if (splitKey.length > 1 && configuration['dot-notation']) {
681
- (flags.aliases[splitKey[0]] || []).forEach(function (x) {
682
- let keyProperties = x.split('.');
683
- // expand alias with nested objects in key
684
- const a = [].concat(splitKey);
685
- a.shift(); // nuke the old key.
686
- keyProperties = keyProperties.concat(a);
687
- // populate alias only if is not already an alias of the full key
688
- // (already populated above)
689
- if (!(flags.aliases[key] || []).includes(keyProperties.join('.'))) {
690
- setKey(argv, keyProperties, value);
691
- }
692
- });
693
- }
694
- // Set normalize getter and setter when key is in 'normalize' but isn't an array
695
- if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {
696
- const keys = [key].concat(flags.aliases[key] || []);
697
- keys.forEach(function (key) {
698
- Object.defineProperty(argvReturn, key, {
699
- enumerable: true,
700
- get() {
701
- return val;
702
- },
703
- set(value) {
704
- val = typeof value === 'string' ? mixin.normalize(value) : value;
705
- }
706
- });
707
- });
708
- }
709
- }
710
- function addNewAlias(key, alias) {
711
- if (!(flags.aliases[key] && flags.aliases[key].length)) {
712
- flags.aliases[key] = [alias];
713
- newAliases[alias] = true;
714
- }
715
- if (!(flags.aliases[alias] && flags.aliases[alias].length)) {
716
- addNewAlias(alias, key);
717
- }
718
- }
719
- function processValue(key, val, shouldStripQuotes) {
720
- // strings may be quoted, clean this up as we assign values.
721
- if (shouldStripQuotes) {
722
- val = stripQuotes(val);
723
- }
724
- // handle parsing boolean arguments --foo=true --bar false.
725
- if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
726
- if (typeof val === 'string')
727
- val = val === 'true';
728
- }
729
- let value = Array.isArray(val)
730
- ? val.map(function (v) { return maybeCoerceNumber(key, v); })
731
- : maybeCoerceNumber(key, val);
732
- // increment a count given as arg (either no value or value parsed as boolean)
733
- if (checkAllAliases(key, flags.counts) && (isUndefined(value) || typeof value === 'boolean')) {
734
- value = increment();
735
- }
736
- // Set normalized value when key is in 'normalize' and in 'arrays'
737
- if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) {
738
- if (Array.isArray(val))
739
- value = val.map((val) => { return mixin.normalize(val); });
740
- else
741
- value = mixin.normalize(val);
742
- }
743
- return value;
744
- }
745
- function maybeCoerceNumber(key, value) {
746
- if (!configuration['parse-positional-numbers'] && key === '_')
747
- return value;
748
- if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.bools) && !Array.isArray(value)) {
749
- const shouldCoerceNumber = looksLikeNumber(value) && configuration['parse-numbers'] && (Number.isSafeInteger(Math.floor(parseFloat(`${value}`))));
750
- if (shouldCoerceNumber || (!isUndefined(value) && checkAllAliases(key, flags.numbers))) {
751
- value = Number(value);
752
- }
753
- }
754
- return value;
755
- }
756
- // set args from config.json file, this should be
757
- // applied last so that defaults can be applied.
758
- function setConfig(argv) {
759
- const configLookup = Object.create(null);
760
- // expand defaults/aliases, in-case any happen to reference
761
- // the config.json file.
762
- applyDefaultsAndAliases(configLookup, flags.aliases, defaults);
763
- Object.keys(flags.configs).forEach(function (configKey) {
764
- const configPath = argv[configKey] || configLookup[configKey];
765
- if (configPath) {
766
- try {
767
- let config = null;
768
- const resolvedConfigPath = mixin.resolve(mixin.cwd(), configPath);
769
- const resolveConfig = flags.configs[configKey];
770
- if (typeof resolveConfig === 'function') {
771
- try {
772
- config = resolveConfig(resolvedConfigPath);
773
- }
774
- catch (e) {
775
- config = e;
776
- }
777
- if (config instanceof Error) {
778
- error = config;
779
- return;
780
- }
781
- }
782
- else {
783
- config = mixin.require(resolvedConfigPath);
784
- }
785
- setConfigObject(config);
786
- }
787
- catch (ex) {
788
- // Deno will receive a PermissionDenied error if an attempt is
789
- // made to load config without the --allow-read flag:
790
- if (ex.name === 'PermissionDenied')
791
- error = ex;
792
- else if (argv[configKey])
793
- error = Error(__('Invalid JSON config file: %s', configPath));
794
- }
795
- }
796
- });
797
- }
798
- // set args from config object.
799
- // it recursively checks nested objects.
800
- function setConfigObject(config, prev) {
801
- Object.keys(config).forEach(function (key) {
802
- const value = config[key];
803
- const fullKey = prev ? prev + '.' + key : key;
804
- // if the value is an inner object and we have dot-notation
805
- // enabled, treat inner objects in config the same as
806
- // heavily nested dot notations (foo.bar.apple).
807
- if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) {
808
- // if the value is an object but not an array, check nested object
809
- setConfigObject(value, fullKey);
810
- }
811
- else {
812
- // setting arguments via CLI takes precedence over
813
- // values within the config file.
814
- if (!hasKey(argv, fullKey.split('.')) || (checkAllAliases(fullKey, flags.arrays) && configuration['combine-arrays'])) {
815
- setArg(fullKey, value);
816
- }
817
- }
818
- });
819
- }
820
- // set all config objects passed in opts
821
- function setConfigObjects() {
822
- if (typeof configObjects !== 'undefined') {
823
- configObjects.forEach(function (configObject) {
824
- setConfigObject(configObject);
825
- });
826
- }
827
- }
828
- function applyEnvVars(argv, configOnly) {
829
- if (typeof envPrefix === 'undefined')
830
- return;
831
- const prefix = typeof envPrefix === 'string' ? envPrefix : '';
832
- const env = mixin.env();
833
- Object.keys(env).forEach(function (envVar) {
834
- if (prefix === '' || envVar.lastIndexOf(prefix, 0) === 0) {
835
- // get array of nested keys and convert them to camel case
836
- const keys = envVar.split('__').map(function (key, i) {
837
- if (i === 0) {
838
- key = key.substring(prefix.length);
839
- }
840
- return camelCase(key);
841
- });
842
- if (((configOnly && flags.configs[keys.join('.')]) || !configOnly) && !hasKey(argv, keys)) {
843
- setArg(keys.join('.'), env[envVar]);
844
- }
845
- }
846
- });
847
- }
848
- function applyCoercions(argv) {
849
- let coerce;
850
- const applied = new Set();
851
- Object.keys(argv).forEach(function (key) {
852
- if (!applied.has(key)) { // If we haven't already coerced this option via one of its aliases
853
- coerce = checkAllAliases(key, flags.coercions);
854
- if (typeof coerce === 'function') {
855
- try {
856
- const value = maybeCoerceNumber(key, coerce(argv[key]));
857
- ([].concat(flags.aliases[key] || [], key)).forEach(ali => {
858
- applied.add(ali);
859
- argv[ali] = value;
860
- });
861
- }
862
- catch (err) {
863
- error = err;
864
- }
865
- }
866
- }
867
- });
868
- }
869
- function setPlaceholderKeys(argv) {
870
- flags.keys.forEach((key) => {
871
- // don't set placeholder keys for dot notation options 'foo.bar'.
872
- if (~key.indexOf('.'))
873
- return;
874
- if (typeof argv[key] === 'undefined')
875
- argv[key] = undefined;
876
- });
877
- return argv;
878
- }
879
- function applyDefaultsAndAliases(obj, aliases, defaults, canLog = false) {
880
- Object.keys(defaults).forEach(function (key) {
881
- if (!hasKey(obj, key.split('.'))) {
882
- setKey(obj, key.split('.'), defaults[key]);
883
- if (canLog)
884
- defaulted[key] = true;
885
- (aliases[key] || []).forEach(function (x) {
886
- if (hasKey(obj, x.split('.')))
887
- return;
888
- setKey(obj, x.split('.'), defaults[key]);
889
- });
890
- }
891
- });
892
- }
893
- function hasKey(obj, keys) {
894
- let o = obj;
895
- if (!configuration['dot-notation'])
896
- keys = [keys.join('.')];
897
- keys.slice(0, -1).forEach(function (key) {
898
- o = (o[key] || {});
899
- });
900
- const key = keys[keys.length - 1];
901
- if (typeof o !== 'object')
902
- return false;
903
- else
904
- return key in o;
905
- }
906
- function setKey(obj, keys, value) {
907
- let o = obj;
908
- if (!configuration['dot-notation'])
909
- keys = [keys.join('.')];
910
- keys.slice(0, -1).forEach(function (key) {
911
- // TODO(bcoe): in the next major version of yargs, switch to
912
- // Object.create(null) for dot notation:
913
- key = sanitizeKey(key);
914
- if (typeof o === 'object' && o[key] === undefined) {
915
- o[key] = {};
916
- }
917
- if (typeof o[key] !== 'object' || Array.isArray(o[key])) {
918
- // ensure that o[key] is an array, and that the last item is an empty object.
919
- if (Array.isArray(o[key])) {
920
- o[key].push({});
921
- }
922
- else {
923
- o[key] = [o[key], {}];
924
- }
925
- // we want to update the empty object at the end of the o[key] array, so set o to that object
926
- o = o[key][o[key].length - 1];
927
- }
928
- else {
929
- o = o[key];
930
- }
931
- });
932
- // TODO(bcoe): in the next major version of yargs, switch to
933
- // Object.create(null) for dot notation:
934
- const key = sanitizeKey(keys[keys.length - 1]);
935
- const isTypeArray = checkAllAliases(keys.join('.'), flags.arrays);
936
- const isValueArray = Array.isArray(value);
937
- let duplicate = configuration['duplicate-arguments-array'];
938
- // nargs has higher priority than duplicate
939
- if (!duplicate && checkAllAliases(key, flags.nargs)) {
940
- duplicate = true;
941
- if ((!isUndefined(o[key]) && flags.nargs[key] === 1) || (Array.isArray(o[key]) && o[key].length === flags.nargs[key])) {
942
- o[key] = undefined;
943
- }
944
- }
945
- if (value === increment()) {
946
- o[key] = increment(o[key]);
947
- }
948
- else if (Array.isArray(o[key])) {
949
- if (duplicate && isTypeArray && isValueArray) {
950
- o[key] = configuration['flatten-duplicate-arrays'] ? o[key].concat(value) : (Array.isArray(o[key][0]) ? o[key] : [o[key]]).concat([value]);
951
- }
952
- else if (!duplicate && Boolean(isTypeArray) === Boolean(isValueArray)) {
953
- o[key] = value;
954
- }
955
- else {
956
- o[key] = o[key].concat([value]);
957
- }
958
- }
959
- else if (o[key] === undefined && isTypeArray) {
960
- o[key] = isValueArray ? value : [value];
961
- }
962
- else if (duplicate && !(o[key] === undefined ||
963
- checkAllAliases(key, flags.counts) ||
964
- checkAllAliases(key, flags.bools))) {
965
- o[key] = [o[key], value];
966
- }
967
- else {
968
- o[key] = value;
969
- }
970
- }
971
- // extend the aliases list with inferred aliases.
972
- function extendAliases(...args) {
973
- args.forEach(function (obj) {
974
- Object.keys(obj || {}).forEach(function (key) {
975
- // short-circuit if we've already added a key
976
- // to the aliases array, for example it might
977
- // exist in both 'opts.default' and 'opts.key'.
978
- if (flags.aliases[key])
979
- return;
980
- flags.aliases[key] = [].concat(aliases[key] || []);
981
- // For "--option-name", also set argv.optionName
982
- flags.aliases[key].concat(key).forEach(function (x) {
983
- if (/-/.test(x) && configuration['camel-case-expansion']) {
984
- const c = camelCase(x);
985
- if (c !== key && flags.aliases[key].indexOf(c) === -1) {
986
- flags.aliases[key].push(c);
987
- newAliases[c] = true;
988
- }
989
- }
990
- });
991
- // For "--optionName", also set argv['option-name']
992
- flags.aliases[key].concat(key).forEach(function (x) {
993
- if (x.length > 1 && /[A-Z]/.test(x) && configuration['camel-case-expansion']) {
994
- const c = decamelize(x, '-');
995
- if (c !== key && flags.aliases[key].indexOf(c) === -1) {
996
- flags.aliases[key].push(c);
997
- newAliases[c] = true;
998
- }
999
- }
1000
- });
1001
- flags.aliases[key].forEach(function (x) {
1002
- flags.aliases[x] = [key].concat(flags.aliases[key].filter(function (y) {
1003
- return x !== y;
1004
- }));
1005
- });
1006
- });
1007
- });
1008
- }
1009
- function checkAllAliases(key, flag) {
1010
- const toCheck = [].concat(flags.aliases[key] || [], key);
1011
- const keys = Object.keys(flag);
1012
- const setAlias = toCheck.find(key => keys.includes(key));
1013
- return setAlias ? flag[setAlias] : false;
1014
- }
1015
- function hasAnyFlag(key) {
1016
- const flagsKeys = Object.keys(flags);
1017
- const toCheck = [].concat(flagsKeys.map(k => flags[k]));
1018
- return toCheck.some(function (flag) {
1019
- return Array.isArray(flag) ? flag.includes(key) : flag[key];
1020
- });
1021
- }
1022
- function hasFlagsMatching(arg, ...patterns) {
1023
- const toCheck = [].concat(...patterns);
1024
- return toCheck.some(function (pattern) {
1025
- const match = arg.match(pattern);
1026
- return match && hasAnyFlag(match[1]);
1027
- });
1028
- }
1029
- // based on a simplified version of the short flag group parsing logic
1030
- function hasAllShortFlags(arg) {
1031
- // if this is a negative number, or doesn't start with a single hyphen, it's not a short flag group
1032
- if (arg.match(negative) || !arg.match(/^-[^-]+/)) {
1033
- return false;
1034
- }
1035
- let hasAllFlags = true;
1036
- let next;
1037
- const letters = arg.slice(1).split('');
1038
- for (let j = 0; j < letters.length; j++) {
1039
- next = arg.slice(j + 2);
1040
- if (!hasAnyFlag(letters[j])) {
1041
- hasAllFlags = false;
1042
- break;
1043
- }
1044
- if ((letters[j + 1] && letters[j + 1] === '=') ||
1045
- next === '-' ||
1046
- (/[A-Za-z]/.test(letters[j]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) ||
1047
- (letters[j + 1] && letters[j + 1].match(/\W/))) {
1048
- break;
1049
- }
1050
- }
1051
- return hasAllFlags;
1052
- }
1053
- function isUnknownOptionAsArg(arg) {
1054
- return configuration['unknown-options-as-args'] && isUnknownOption(arg);
1055
- }
1056
- function isUnknownOption(arg) {
1057
- arg = arg.replace(/^-{3,}/, '--');
1058
- // ignore negative numbers
1059
- if (arg.match(negative)) {
1060
- return false;
1061
- }
1062
- // if this is a short option group and all of them are configured, it isn't unknown
1063
- if (hasAllShortFlags(arg)) {
1064
- return false;
1065
- }
1066
- // e.g. '--count=2'
1067
- const flagWithEquals = /^-+([^=]+?)=[\s\S]*$/;
1068
- // e.g. '-a' or '--arg'
1069
- const normalFlag = /^-+([^=]+?)$/;
1070
- // e.g. '-a-'
1071
- const flagEndingInHyphen = /^-+([^=]+?)-$/;
1072
- // e.g. '-abc123'
1073
- const flagEndingInDigits = /^-+([^=]+?\d+)$/;
1074
- // e.g. '-a/usr/local'
1075
- const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/;
1076
- // check the different types of flag styles, including negatedBoolean, a pattern defined near the start of the parse method
1077
- return !hasFlagsMatching(arg, flagWithEquals, negatedBoolean, normalFlag, flagEndingInHyphen, flagEndingInDigits, flagEndingInNonWordCharacters);
1078
- }
1079
- // make a best effort to pick a default value
1080
- // for an option based on name and type.
1081
- function defaultValue(key) {
1082
- if (!checkAllAliases(key, flags.bools) &&
1083
- !checkAllAliases(key, flags.counts) &&
1084
- `${key}` in defaults) {
1085
- return defaults[key];
1086
- }
1087
- else {
1088
- return defaultForType(guessType(key));
1089
- }
1090
- }
1091
- // return a default value, given the type of a flag.,
1092
- function defaultForType(type) {
1093
- const def = {
1094
- [DefaultValuesForTypeKey.BOOLEAN]: true,
1095
- [DefaultValuesForTypeKey.STRING]: '',
1096
- [DefaultValuesForTypeKey.NUMBER]: undefined,
1097
- [DefaultValuesForTypeKey.ARRAY]: []
1098
- };
1099
- return def[type];
1100
- }
1101
- // given a flag, enforce a default type.
1102
- function guessType(key) {
1103
- let type = DefaultValuesForTypeKey.BOOLEAN;
1104
- if (checkAllAliases(key, flags.strings))
1105
- type = DefaultValuesForTypeKey.STRING;
1106
- else if (checkAllAliases(key, flags.numbers))
1107
- type = DefaultValuesForTypeKey.NUMBER;
1108
- else if (checkAllAliases(key, flags.bools))
1109
- type = DefaultValuesForTypeKey.BOOLEAN;
1110
- else if (checkAllAliases(key, flags.arrays))
1111
- type = DefaultValuesForTypeKey.ARRAY;
1112
- return type;
1113
- }
1114
- function isUndefined(num) {
1115
- return num === undefined;
1116
- }
1117
- // check user configuration settings for inconsistencies
1118
- function checkConfiguration() {
1119
- // count keys should not be set as array/narg
1120
- Object.keys(flags.counts).find(key => {
1121
- if (checkAllAliases(key, flags.arrays)) {
1122
- error = Error(__('Invalid configuration: %s, opts.count excludes opts.array.', key));
1123
- return true;
1124
- }
1125
- else if (checkAllAliases(key, flags.nargs)) {
1126
- error = Error(__('Invalid configuration: %s, opts.count excludes opts.narg.', key));
1127
- return true;
1128
- }
1129
- return false;
1130
- });
1131
- }
1132
- return {
1133
- aliases: Object.assign({}, flags.aliases),
1134
- argv: Object.assign(argvReturn, argv),
1135
- configuration: configuration,
1136
- defaulted: Object.assign({}, defaulted),
1137
- error: error,
1138
- newAliases: Object.assign({}, newAliases)
1139
- };
1140
- }
1141
- }
1142
- // if any aliases reference each other, we should
1143
- // merge them together.
1144
- function combineAliases(aliases) {
1145
- const aliasArrays = [];
1146
- const combined = Object.create(null);
1147
- let change = true;
1148
- // turn alias lookup hash {key: ['alias1', 'alias2']} into
1149
- // a simple array ['key', 'alias1', 'alias2']
1150
- Object.keys(aliases).forEach(function (key) {
1151
- aliasArrays.push([].concat(aliases[key], key));
1152
- });
1153
- // combine arrays until zero changes are
1154
- // made in an iteration.
1155
- while (change) {
1156
- change = false;
1157
- for (let i = 0; i < aliasArrays.length; i++) {
1158
- for (let ii = i + 1; ii < aliasArrays.length; ii++) {
1159
- const intersect = aliasArrays[i].filter(function (v) {
1160
- return aliasArrays[ii].indexOf(v) !== -1;
1161
- });
1162
- if (intersect.length) {
1163
- aliasArrays[i] = aliasArrays[i].concat(aliasArrays[ii]);
1164
- aliasArrays.splice(ii, 1);
1165
- change = true;
1166
- break;
1167
- }
1168
- }
1169
- }
1170
- }
1171
- // map arrays back to the hash-lookup (de-dupe while
1172
- // we're at it).
1173
- aliasArrays.forEach(function (aliasArray) {
1174
- aliasArray = aliasArray.filter(function (v, i, self) {
1175
- return self.indexOf(v) === i;
1176
- });
1177
- const lastAlias = aliasArray.pop();
1178
- if (lastAlias !== undefined && typeof lastAlias === 'string') {
1179
- combined[lastAlias] = aliasArray;
1180
- }
1181
- });
1182
- return combined;
1183
- }
1184
- // this function should only be called when a count is given as an arg
1185
- // it is NOT called to set a default value
1186
- // thus we can start the count at 1 instead of 0
1187
- function increment(orig) {
1188
- return orig !== undefined ? orig + 1 : 1;
1189
- }
1190
- // TODO(bcoe): in the next major version of yargs, switch to
1191
- // Object.create(null) for dot notation:
1192
- function sanitizeKey(key) {
1193
- if (key === '__proto__')
1194
- return '___proto___';
1195
- return key;
1196
- }
1197
- function stripQuotes(val) {
1198
- return (typeof val === 'string' &&
1199
- (val[0] === "'" || val[0] === '"') &&
1200
- val[val.length - 1] === val[0])
1201
- ? val.substring(1, val.length - 1)
1202
- : val;
1203
- }
1204
-
1205
- /**
1206
- * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
1207
- * CJS and ESM environments.
1208
- *
1209
- * @license
1210
- * Copyright (c) 2016, Contributors
1211
- * SPDX-License-Identifier: ISC
1212
- */
1213
- var _a, _b, _c;
1214
- // See https://github.com/yargs/yargs-parser#supported-nodejs-versions for our
1215
- // version support policy. The YARGS_MIN_NODE_VERSION is used for testing only.
1216
- const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
1217
- ? Number(process.env.YARGS_MIN_NODE_VERSION)
1218
- : 12;
1219
- const nodeVersion = (_b = (_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : (_c = process === null || process === void 0 ? void 0 : process.version) === null || _c === void 0 ? void 0 : _c.slice(1);
1220
- if (nodeVersion) {
1221
- const major = Number(nodeVersion.match(/^([^.]+)/)[1]);
1222
- if (major < minNodeVersion) {
1223
- throw Error(`yargs parser supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`);
1224
- }
1225
- }
1226
- // Creates a yargs-parser instance using Node.js standard libraries:
1227
- const env = process ? process.env : {};
1228
- new YargsParser({
1229
- cwd: process.cwd,
1230
- env: () => {
1231
- return env;
1232
- },
1233
- format,
1234
- normalize,
1235
- resolve,
1236
- // TODO: figure out a way to combine ESM and CJS coverage, such that
1237
- // we can exercise all the lines below:
1238
- require: (path) => {
1239
- if (typeof require !== 'undefined') {
1240
- return require(path);
1241
- }
1242
- else if (path.match(/\.json$/)) {
1243
- // Addresses: https://github.com/yargs/yargs/issues/2040
1244
- return JSON.parse(readFileSync(path, 'utf8'));
1245
- }
1246
- else {
1247
- throw Error('only .json config files are supported in ESM');
1248
- }
1249
- }
1250
- });
1251
-
1252
- var shim$1 = {
1253
- fs: {
1254
- readFileSync,
1255
- writeFile
1256
- },
1257
- format,
1258
- resolve,
1259
- exists: (file) => {
1260
- try {
1261
- return statSync(file).isFile();
1262
- }
1263
- catch (err) {
1264
- return false;
1265
- }
1266
- }
1267
- };
1268
-
1269
- let shim;
1270
- class Y18N {
1271
- constructor(opts) {
1272
- // configurable options.
1273
- opts = opts || {};
1274
- this.directory = opts.directory || './locales';
1275
- this.updateFiles = typeof opts.updateFiles === 'boolean' ? opts.updateFiles : true;
1276
- this.locale = opts.locale || 'en';
1277
- this.fallbackToLanguage = typeof opts.fallbackToLanguage === 'boolean' ? opts.fallbackToLanguage : true;
1278
- // internal stuff.
1279
- this.cache = Object.create(null);
1280
- this.writeQueue = [];
1281
- }
1282
- __(...args) {
1283
- if (typeof arguments[0] !== 'string') {
1284
- return this._taggedLiteral(arguments[0], ...arguments);
1285
- }
1286
- const str = args.shift();
1287
- let cb = function () { }; // start with noop.
1288
- if (typeof args[args.length - 1] === 'function')
1289
- cb = args.pop();
1290
- cb = cb || function () { }; // noop.
1291
- if (!this.cache[this.locale])
1292
- this._readLocaleFile();
1293
- // we've observed a new string, update the language file.
1294
- if (!this.cache[this.locale][str] && this.updateFiles) {
1295
- this.cache[this.locale][str] = str;
1296
- // include the current directory and locale,
1297
- // since these values could change before the
1298
- // write is performed.
1299
- this._enqueueWrite({
1300
- directory: this.directory,
1301
- locale: this.locale,
1302
- cb
1303
- });
1304
- }
1305
- else {
1306
- cb();
1307
- }
1308
- return shim.format.apply(shim.format, [this.cache[this.locale][str] || str].concat(args));
1309
- }
1310
- __n() {
1311
- const args = Array.prototype.slice.call(arguments);
1312
- const singular = args.shift();
1313
- const plural = args.shift();
1314
- const quantity = args.shift();
1315
- let cb = function () { }; // start with noop.
1316
- if (typeof args[args.length - 1] === 'function')
1317
- cb = args.pop();
1318
- if (!this.cache[this.locale])
1319
- this._readLocaleFile();
1320
- let str = quantity === 1 ? singular : plural;
1321
- if (this.cache[this.locale][singular]) {
1322
- const entry = this.cache[this.locale][singular];
1323
- str = entry[quantity === 1 ? 'one' : 'other'];
1324
- }
1325
- // we've observed a new string, update the language file.
1326
- if (!this.cache[this.locale][singular] && this.updateFiles) {
1327
- this.cache[this.locale][singular] = {
1328
- one: singular,
1329
- other: plural
1330
- };
1331
- // include the current directory and locale,
1332
- // since these values could change before the
1333
- // write is performed.
1334
- this._enqueueWrite({
1335
- directory: this.directory,
1336
- locale: this.locale,
1337
- cb
1338
- });
1339
- }
1340
- else {
1341
- cb();
1342
- }
1343
- // if a %d placeholder is provided, add quantity
1344
- // to the arguments expanded by util.format.
1345
- const values = [str];
1346
- if (~str.indexOf('%d'))
1347
- values.push(quantity);
1348
- return shim.format.apply(shim.format, values.concat(args));
1349
- }
1350
- setLocale(locale) {
1351
- this.locale = locale;
1352
- }
1353
- getLocale() {
1354
- return this.locale;
1355
- }
1356
- updateLocale(obj) {
1357
- if (!this.cache[this.locale])
1358
- this._readLocaleFile();
1359
- for (const key in obj) {
1360
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
1361
- this.cache[this.locale][key] = obj[key];
1362
- }
1363
- }
1364
- }
1365
- _taggedLiteral(parts, ...args) {
1366
- let str = '';
1367
- parts.forEach(function (part, i) {
1368
- const arg = args[i + 1];
1369
- str += part;
1370
- if (typeof arg !== 'undefined') {
1371
- str += '%s';
1372
- }
1373
- });
1374
- return this.__.apply(this, [str].concat([].slice.call(args, 1)));
1375
- }
1376
- _enqueueWrite(work) {
1377
- this.writeQueue.push(work);
1378
- if (this.writeQueue.length === 1)
1379
- this._processWriteQueue();
1380
- }
1381
- _processWriteQueue() {
1382
- const _this = this;
1383
- const work = this.writeQueue[0];
1384
- // destructure the enqueued work.
1385
- const directory = work.directory;
1386
- const locale = work.locale;
1387
- const cb = work.cb;
1388
- const languageFile = this._resolveLocaleFile(directory, locale);
1389
- const serializedLocale = JSON.stringify(this.cache[locale], null, 2);
1390
- shim.fs.writeFile(languageFile, serializedLocale, 'utf-8', function (err) {
1391
- _this.writeQueue.shift();
1392
- if (_this.writeQueue.length > 0)
1393
- _this._processWriteQueue();
1394
- cb(err);
1395
- });
1396
- }
1397
- _readLocaleFile() {
1398
- let localeLookup = {};
1399
- const languageFile = this._resolveLocaleFile(this.directory, this.locale);
1400
- try {
1401
- // When using a bundler such as webpack, readFileSync may not be defined:
1402
- if (shim.fs.readFileSync) {
1403
- localeLookup = JSON.parse(shim.fs.readFileSync(languageFile, 'utf-8'));
1404
- }
1405
- }
1406
- catch (err) {
1407
- if (err instanceof SyntaxError) {
1408
- err.message = 'syntax error in ' + languageFile;
1409
- }
1410
- if (err.code === 'ENOENT')
1411
- localeLookup = {};
1412
- else
1413
- throw err;
1414
- }
1415
- this.cache[this.locale] = localeLookup;
1416
- }
1417
- _resolveLocaleFile(directory, locale) {
1418
- let file = shim.resolve(directory, './', locale + '.json');
1419
- if (this.fallbackToLanguage && !this._fileExistsSync(file) && ~locale.lastIndexOf('_')) {
1420
- // attempt fallback to language only
1421
- const languageFile = shim.resolve(directory, './', locale.split('_')[0] + '.json');
1422
- if (this._fileExistsSync(languageFile))
1423
- file = languageFile;
1424
- }
1425
- return file;
1426
- }
1427
- _fileExistsSync(file) {
1428
- return shim.exists(file);
1429
- }
1430
- }
1431
- function y18n$1(opts, _shim) {
1432
- shim = _shim;
1433
- const y18n = new Y18N(opts);
1434
- return {
1435
- __: y18n.__.bind(y18n),
1436
- __n: y18n.__n.bind(y18n),
1437
- setLocale: y18n.setLocale.bind(y18n),
1438
- getLocale: y18n.getLocale.bind(y18n),
1439
- updateLocale: y18n.updateLocale.bind(y18n),
1440
- locale: y18n.locale
1441
- };
1442
- }
1443
-
1444
- const y18n = (opts) => {
1445
- return y18n$1(opts, shim$1)
1446
- };
1447
-
1448
- let __dirname$1;
1449
- try {
1450
- __dirname$1 = fileURLToPath(import.meta.url);
1451
- } catch (e) {
1452
- __dirname$1 = process.cwd();
1453
- }
1454
- const mainFilename = __dirname$1.substring(0, __dirname$1.lastIndexOf('node_modules'));
1455
-
1456
- ({
1457
- mainFilename: mainFilename || process.cwd(),
1458
- process: {
1459
- cwd: process.cwd,
1460
- exit: process.exit,
1461
- nextTick: process.nextTick,
1462
- stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null
1463
- },
1464
- y18n: y18n({
1465
- directory: resolve(__dirname$1, '../../../locales'),
1466
- updateFiles: false
1467
- })
1468
- });
1469
-
1470
26
  var name = "@pragmatic-divops/cli";
1471
27
  var description = "cli for various organization tools";
1472
28
  var license = "MIT";
1473
- var version = "1.13.15";
29
+ var version = "1.13.17";
1474
30
  var type = "module";
1475
31
  var author = "Matt Travi <npm@travi.org> (https://matt.travi.org/)";
1476
32
  var repository = "pragmatic-divops/cli";
@@ -1516,11 +72,11 @@ var publishConfig = {
1516
72
  access: "public",
1517
73
  provenance: true
1518
74
  };
1519
- var packageManager = "npm@11.7.0+sha512.c22099a6fff8d5b2286c2a09df5352b4858a7c0c716320f58989d60ad8b29ecf2ce6fdfe97ccb41c23ffb1272e1fa079f868487dd6b81d02a2a9e199c095a117";
75
+ var packageManager = "npm@11.11.0+sha512.f36811c4aae1fde639527368ae44c571d050006a608d67a191f195a801a52637a312d259186254aa3a3799b05335b7390539cf28656d18f0591a1125ba35f973";
1520
76
  var dependencies = {
1521
77
  "@form8ion/cli-core": "1.1.0",
1522
78
  "@form8ion/codecov": "6.2.2",
1523
- "@form8ion/core": "4.11.0",
79
+ "@form8ion/core": "4.11.1",
1524
80
  "@form8ion/cucumber-scaffolder": "5.1.0",
1525
81
  "@form8ion/eslint-config-extender": "10.0.3",
1526
82
  "@form8ion/gatsby": "1.0.3",
@@ -1531,16 +87,16 @@ var dependencies = {
1531
87
  "@form8ion/javascript-core": "12.4.0",
1532
88
  "@form8ion/lift": "11.0.0",
1533
89
  "@form8ion/mocha-scaffolder": "6.1.1",
1534
- "@form8ion/project": "21.1.0",
90
+ "@form8ion/project": "21.1.1",
1535
91
  "@form8ion/renovate-scaffolder": "3.0.0",
1536
92
  "@travi/netlify-scaffolder": "1.6.0",
1537
93
  "update-notifier": "7.3.1",
1538
- yargs: "17.7.2"
94
+ yargs: "18.0.0"
1539
95
  };
1540
96
  var devDependencies = {
1541
- "@cucumber/cucumber": "12.5.0",
97
+ "@cucumber/cucumber": "12.7.0",
1542
98
  "@form8ion/config-file": "1.3.0",
1543
- "@form8ion/eslint-config-vitest": "1.0.0",
99
+ "@form8ion/eslint-config-vitest": "1.1.0",
1544
100
  "@pragmatic-divops/commitlint-config": "1.0.69",
1545
101
  "@pragmatic-divops/eslint-config": "1.0.97",
1546
102
  "@pragmatic-divops/eslint-config-cucumber": "1.0.1",
@@ -1549,7 +105,7 @@ var devDependencies = {
1549
105
  "@rollup/plugin-node-resolve": "16.0.3",
1550
106
  "@travi/any": "3.1.3",
1551
107
  "ban-sensitive-files": "1.10.11",
1552
- c8: "10.1.3",
108
+ c8: "11.0.0",
1553
109
  chai: "6.2.2",
1554
110
  "cross-env": "10.1.0",
1555
111
  "cz-conventional-changelog": "3.3.0",
@@ -1558,19 +114,19 @@ var devDependencies = {
1558
114
  "gherkin-lint": "4.2.4",
1559
115
  "http-status-codes": "2.3.0",
1560
116
  husky: "9.1.7",
1561
- "lockfile-lint": "4.14.1",
117
+ "lockfile-lint": "5.0.0",
1562
118
  "mock-fs": "5.5.0",
1563
- msw: "2.12.7",
119
+ msw: "2.12.10",
1564
120
  "npm-run-all2": "8.0.4",
1565
- publint: "0.3.16",
121
+ publint: "0.3.18",
1566
122
  "remark-cli": "12.0.1",
1567
123
  "remark-toc": "9.0.0",
1568
- rimraf: "6.1.2",
1569
- rollup: "4.54.0",
124
+ rimraf: "6.1.3",
125
+ rollup: "4.59.0",
1570
126
  "rollup-plugin-auto-external": "2.0.0",
1571
127
  "rollup-plugin-executable": "1.6.3",
1572
128
  testdouble: "3.20.2",
1573
- vitest: "4.0.16",
129
+ vitest: "4.0.18",
1574
130
  "vitest-when": "0.10.0"
1575
131
  };
1576
132
  var pkg = {
@@ -1731,10 +287,10 @@ const command$2 = 'scaffold';
1731
287
  const describe$2 = 'Scaffold a new project';
1732
288
 
1733
289
  var scaffoldCommand = /*#__PURE__*/Object.freeze({
1734
- __proto__: null,
1735
- command: command$2,
1736
- describe: describe$2,
1737
- handler: handler$2
290
+ __proto__: null,
291
+ command: command$2,
292
+ describe: describe$2,
293
+ handler: handler$2
1738
294
  });
1739
295
 
1740
296
  function handler$1({decisions}) {
@@ -1753,10 +309,10 @@ const command$1 = 'lift';
1753
309
  const describe$1 = 'Lift an existing project with additional functionality';
1754
310
 
1755
311
  var liftCommand = /*#__PURE__*/Object.freeze({
1756
- __proto__: null,
1757
- command: command$1,
1758
- describe: describe$1,
1759
- handler: handler$1
312
+ __proto__: null,
313
+ command: command$1,
314
+ describe: describe$1,
315
+ handler: handler$1
1760
316
  });
1761
317
 
1762
318
  function handler(providedDecisions) {
@@ -1767,10 +323,10 @@ const command = 'extend-eslint-config';
1767
323
  const describe = 'Extend a @form8ion shareable ESLint config';
1768
324
 
1769
325
  var extendEslintConfigCommand = /*#__PURE__*/Object.freeze({
1770
- __proto__: null,
1771
- command: command,
1772
- describe: describe,
1773
- handler: handler
326
+ __proto__: null,
327
+ command: command,
328
+ describe: describe,
329
+ handler: handler
1774
330
  });
1775
331
 
1776
332
  function cli(yargs) {