@form8ion/utils-cli 8.0.0-beta.1 → 8.0.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.
@@ -1,34 +1,1881 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
-
4
- var yargs = require('yargs');
5
- var updateNotifier = require('update-notifier');
6
- require('source-map-support/register');
7
- var project = require('@form8ion/project');
8
- var javascriptCore = require('@form8ion/javascript-core');
9
- var javascript$1 = require('@form8ion/javascript');
10
- var githubScaffolder = require('@travi/github-scaffolder');
11
- var renovateScaffolder = require('@form8ion/renovate-scaffolder');
12
- var githubActionsNodeCi = require('@form8ion/github-actions-node-ci');
13
- var hapiScaffolder = require('@form8ion/hapi-scaffolder');
14
- var remarkPluginScaffolder = require('@form8ion/remark-plugin-scaffolder');
15
- var mochaScaffolder = require('@form8ion/mocha-scaffolder');
16
- var scaffolderScaffolder = require('@form8ion/scaffolder-scaffolder');
17
- var vitest = require('@form8ion/vitest');
18
- var rollup = require('@form8ion/rollup');
19
- var vite = require('@form8ion/vite');
20
- var octoherdScript = require('@form8ion/octoherd-script');
21
- var lift = require('@form8ion/lift');
22
- var cucumberScaffolder = require('@form8ion/cucumber-scaffolder');
23
- var removeGreenkeeper = require('@form8ion/remove-greenkeeper');
24
- var replaceTravisCiWithGithubActions = require('@form8ion/replace-travis-ci-with-github-actions');
25
- var codecov = require('@form8ion/codecov');
26
- var prettier$1 = require('@form8ion/prettier');
2
+ import yargs from 'yargs';
3
+ import { format, inspect } from 'util';
4
+ import { normalize, resolve, dirname, basename, extname, relative } from 'path';
5
+ import { readFileSync, statSync, readdirSync, writeFile } from 'fs';
6
+ import { notStrictEqual, strictEqual } from 'assert';
7
+ import { fileURLToPath } from 'url';
8
+ import updateNotifier from 'update-notifier';
9
+ import { questionNames, scaffold as scaffold$a } from '@form8ion/project';
10
+ import { packageManagers } from '@form8ion/javascript-core';
11
+ import { scaffold, questionNames as questionNames$1, lift, test } from '@form8ion/javascript';
12
+ import { prompt, scaffold as scaffold$b } from '@travi/github-scaffolder';
13
+ import { scaffold as scaffold$c, predicate, lift as lift$2 } from '@form8ion/renovate-scaffolder';
14
+ import { scaffold as scaffold$1, test as test$1, lift as lift$3 } from '@form8ion/github-actions-node-ci';
15
+ import { scaffold as scaffold$2 } from '@form8ion/hapi-scaffolder';
16
+ import { scaffold as scaffold$4 } from '@form8ion/remark-plugin-scaffolder';
17
+ import { scaffold as scaffold$6 } from '@form8ion/mocha-scaffolder';
18
+ import { scaffold as scaffold$3 } from '@form8ion/scaffolder-scaffolder';
19
+ import { scaffold as scaffold$7 } from '@form8ion/vitest';
20
+ import { scaffold as scaffold$8 } from '@form8ion/rollup';
21
+ import { scaffold as scaffold$9 } from '@form8ion/vite';
22
+ import { scaffold as scaffold$5 } from '@form8ion/octoherd-script';
23
+ import { lift as lift$1 } from '@form8ion/lift';
24
+ import { scaffold as scaffold$f } from '@form8ion/cucumber-scaffolder';
25
+ import { removeGreenkeeper } from '@form8ion/remove-greenkeeper';
26
+ import { replace } from '@form8ion/replace-travis-ci-with-github-actions';
27
+ import { scaffold as scaffold$d } from '@form8ion/codecov';
28
+ import { scaffold as scaffold$e } from '@form8ion/prettier';
29
+
30
+ class YError extends Error {
31
+ constructor(msg) {
32
+ super(msg || 'yargs error');
33
+ this.name = 'YError';
34
+ if (Error.captureStackTrace) {
35
+ Error.captureStackTrace(this, YError);
36
+ }
37
+ }
38
+ }
39
+
40
+ function getProcessArgvBinIndex() {
41
+ if (isBundledElectronApp())
42
+ return 0;
43
+ return 1;
44
+ }
45
+ function isBundledElectronApp() {
46
+ return isElectronApp() && !process.defaultApp;
47
+ }
48
+ function isElectronApp() {
49
+ return !!process.versions.electron;
50
+ }
51
+ function hideBin(argv) {
52
+ return argv.slice(getProcessArgvBinIndex() + 1);
53
+ }
54
+ function getProcessArgvBin() {
55
+ return process.argv[getProcessArgvBinIndex()];
56
+ }
57
+
58
+ /**
59
+ * @license
60
+ * Copyright (c) 2016, Contributors
61
+ * SPDX-License-Identifier: ISC
62
+ */
63
+ function camelCase(str) {
64
+ // Handle the case where an argument is provided as camel case, e.g., fooBar.
65
+ // by ensuring that the string isn't already mixed case:
66
+ const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase();
67
+ if (!isCamelCase) {
68
+ str = str.toLowerCase();
69
+ }
70
+ if (str.indexOf('-') === -1 && str.indexOf('_') === -1) {
71
+ return str;
72
+ }
73
+ else {
74
+ let camelcase = '';
75
+ let nextChrUpper = false;
76
+ const leadingHyphens = str.match(/^-+/);
77
+ for (let i = leadingHyphens ? leadingHyphens[0].length : 0; i < str.length; i++) {
78
+ let chr = str.charAt(i);
79
+ if (nextChrUpper) {
80
+ nextChrUpper = false;
81
+ chr = chr.toUpperCase();
82
+ }
83
+ if (i !== 0 && (chr === '-' || chr === '_')) {
84
+ nextChrUpper = true;
85
+ }
86
+ else if (chr !== '-' && chr !== '_') {
87
+ camelcase += chr;
88
+ }
89
+ }
90
+ return camelcase;
91
+ }
92
+ }
93
+ function decamelize(str, joinString) {
94
+ const lowercase = str.toLowerCase();
95
+ joinString = joinString || '-';
96
+ let notCamelcase = '';
97
+ for (let i = 0; i < str.length; i++) {
98
+ const chrLower = lowercase.charAt(i);
99
+ const chrString = str.charAt(i);
100
+ if (chrLower !== chrString && i > 0) {
101
+ notCamelcase += `${joinString}${lowercase.charAt(i)}`;
102
+ }
103
+ else {
104
+ notCamelcase += chrString;
105
+ }
106
+ }
107
+ return notCamelcase;
108
+ }
109
+ function looksLikeNumber(x) {
110
+ if (x === null || x === undefined)
111
+ return false;
112
+ // if loaded from config, may already be a number.
113
+ if (typeof x === 'number')
114
+ return true;
115
+ // hexadecimal.
116
+ if (/^0x[0-9a-f]+$/i.test(x))
117
+ return true;
118
+ // don't treat 0123 as a number; as it drops the leading '0'.
119
+ if (/^0[^.]/.test(x))
120
+ return false;
121
+ return /^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
122
+ }
123
+
124
+ /**
125
+ * @license
126
+ * Copyright (c) 2016, Contributors
127
+ * SPDX-License-Identifier: ISC
128
+ */
129
+ // take an un-split argv string and tokenize it.
130
+ function tokenizeArgString(argString) {
131
+ if (Array.isArray(argString)) {
132
+ return argString.map(e => typeof e !== 'string' ? e + '' : e);
133
+ }
134
+ argString = argString.trim();
135
+ let i = 0;
136
+ let prevC = null;
137
+ let c = null;
138
+ let opening = null;
139
+ const args = [];
140
+ for (let ii = 0; ii < argString.length; ii++) {
141
+ prevC = c;
142
+ c = argString.charAt(ii);
143
+ // split on spaces unless we're in quotes.
144
+ if (c === ' ' && !opening) {
145
+ if (!(prevC === ' ')) {
146
+ i++;
147
+ }
148
+ continue;
149
+ }
150
+ // don't split the string if we're in matching
151
+ // opening or closing single and double quotes.
152
+ if (c === opening) {
153
+ opening = null;
154
+ }
155
+ else if ((c === "'" || c === '"') && !opening) {
156
+ opening = c;
157
+ }
158
+ if (!args[i])
159
+ args[i] = '';
160
+ args[i] += c;
161
+ }
162
+ return args;
163
+ }
164
+
165
+ /**
166
+ * @license
167
+ * Copyright (c) 2016, Contributors
168
+ * SPDX-License-Identifier: ISC
169
+ */
170
+ var DefaultValuesForTypeKey;
171
+ (function (DefaultValuesForTypeKey) {
172
+ DefaultValuesForTypeKey["BOOLEAN"] = "boolean";
173
+ DefaultValuesForTypeKey["STRING"] = "string";
174
+ DefaultValuesForTypeKey["NUMBER"] = "number";
175
+ DefaultValuesForTypeKey["ARRAY"] = "array";
176
+ })(DefaultValuesForTypeKey || (DefaultValuesForTypeKey = {}));
177
+
178
+ /**
179
+ * @license
180
+ * Copyright (c) 2016, Contributors
181
+ * SPDX-License-Identifier: ISC
182
+ */
183
+ let mixin$1;
184
+ class YargsParser {
185
+ constructor(_mixin) {
186
+ mixin$1 = _mixin;
187
+ }
188
+ parse(argsInput, options) {
189
+ const opts = Object.assign({
190
+ alias: undefined,
191
+ array: undefined,
192
+ boolean: undefined,
193
+ config: undefined,
194
+ configObjects: undefined,
195
+ configuration: undefined,
196
+ coerce: undefined,
197
+ count: undefined,
198
+ default: undefined,
199
+ envPrefix: undefined,
200
+ narg: undefined,
201
+ normalize: undefined,
202
+ string: undefined,
203
+ number: undefined,
204
+ __: undefined,
205
+ key: undefined
206
+ }, options);
207
+ // allow a string argument to be passed in rather
208
+ // than an argv array.
209
+ const args = tokenizeArgString(argsInput);
210
+ // tokenizeArgString adds extra quotes to args if argsInput is a string
211
+ // only strip those extra quotes in processValue if argsInput is a string
212
+ const inputIsString = typeof argsInput === 'string';
213
+ // aliases might have transitive relationships, normalize this.
214
+ const aliases = combineAliases(Object.assign(Object.create(null), opts.alias));
215
+ const configuration = Object.assign({
216
+ 'boolean-negation': true,
217
+ 'camel-case-expansion': true,
218
+ 'combine-arrays': false,
219
+ 'dot-notation': true,
220
+ 'duplicate-arguments-array': true,
221
+ 'flatten-duplicate-arrays': true,
222
+ 'greedy-arrays': true,
223
+ 'halt-at-non-option': false,
224
+ 'nargs-eats-options': false,
225
+ 'negation-prefix': 'no-',
226
+ 'parse-numbers': true,
227
+ 'parse-positional-numbers': true,
228
+ 'populate--': false,
229
+ 'set-placeholder-key': false,
230
+ 'short-option-groups': true,
231
+ 'strip-aliased': false,
232
+ 'strip-dashed': false,
233
+ 'unknown-options-as-args': false
234
+ }, opts.configuration);
235
+ const defaults = Object.assign(Object.create(null), opts.default);
236
+ const configObjects = opts.configObjects || [];
237
+ const envPrefix = opts.envPrefix;
238
+ const notFlagsOption = configuration['populate--'];
239
+ const notFlagsArgv = notFlagsOption ? '--' : '_';
240
+ const newAliases = Object.create(null);
241
+ const defaulted = Object.create(null);
242
+ // allow a i18n handler to be passed in, default to a fake one (util.format).
243
+ const __ = opts.__ || mixin$1.format;
244
+ const flags = {
245
+ aliases: Object.create(null),
246
+ arrays: Object.create(null),
247
+ bools: Object.create(null),
248
+ strings: Object.create(null),
249
+ numbers: Object.create(null),
250
+ counts: Object.create(null),
251
+ normalize: Object.create(null),
252
+ configs: Object.create(null),
253
+ nargs: Object.create(null),
254
+ coercions: Object.create(null),
255
+ keys: []
256
+ };
257
+ const negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
258
+ const negatedBoolean = new RegExp('^--' + configuration['negation-prefix'] + '(.+)');
259
+ [].concat(opts.array || []).filter(Boolean).forEach(function (opt) {
260
+ const key = typeof opt === 'object' ? opt.key : opt;
261
+ // assign to flags[bools|strings|numbers]
262
+ const assignment = Object.keys(opt).map(function (key) {
263
+ const arrayFlagKeys = {
264
+ boolean: 'bools',
265
+ string: 'strings',
266
+ number: 'numbers'
267
+ };
268
+ return arrayFlagKeys[key];
269
+ }).filter(Boolean).pop();
270
+ // assign key to be coerced
271
+ if (assignment) {
272
+ flags[assignment][key] = true;
273
+ }
274
+ flags.arrays[key] = true;
275
+ flags.keys.push(key);
276
+ });
277
+ [].concat(opts.boolean || []).filter(Boolean).forEach(function (key) {
278
+ flags.bools[key] = true;
279
+ flags.keys.push(key);
280
+ });
281
+ [].concat(opts.string || []).filter(Boolean).forEach(function (key) {
282
+ flags.strings[key] = true;
283
+ flags.keys.push(key);
284
+ });
285
+ [].concat(opts.number || []).filter(Boolean).forEach(function (key) {
286
+ flags.numbers[key] = true;
287
+ flags.keys.push(key);
288
+ });
289
+ [].concat(opts.count || []).filter(Boolean).forEach(function (key) {
290
+ flags.counts[key] = true;
291
+ flags.keys.push(key);
292
+ });
293
+ [].concat(opts.normalize || []).filter(Boolean).forEach(function (key) {
294
+ flags.normalize[key] = true;
295
+ flags.keys.push(key);
296
+ });
297
+ if (typeof opts.narg === 'object') {
298
+ Object.entries(opts.narg).forEach(([key, value]) => {
299
+ if (typeof value === 'number') {
300
+ flags.nargs[key] = value;
301
+ flags.keys.push(key);
302
+ }
303
+ });
304
+ }
305
+ if (typeof opts.coerce === 'object') {
306
+ Object.entries(opts.coerce).forEach(([key, value]) => {
307
+ if (typeof value === 'function') {
308
+ flags.coercions[key] = value;
309
+ flags.keys.push(key);
310
+ }
311
+ });
312
+ }
313
+ if (typeof opts.config !== 'undefined') {
314
+ if (Array.isArray(opts.config) || typeof opts.config === 'string') {
315
+ [].concat(opts.config).filter(Boolean).forEach(function (key) {
316
+ flags.configs[key] = true;
317
+ });
318
+ }
319
+ else if (typeof opts.config === 'object') {
320
+ Object.entries(opts.config).forEach(([key, value]) => {
321
+ if (typeof value === 'boolean' || typeof value === 'function') {
322
+ flags.configs[key] = value;
323
+ }
324
+ });
325
+ }
326
+ }
327
+ // create a lookup table that takes into account all
328
+ // combinations of aliases: {f: ['foo'], foo: ['f']}
329
+ extendAliases(opts.key, aliases, opts.default, flags.arrays);
330
+ // apply default values to all aliases.
331
+ Object.keys(defaults).forEach(function (key) {
332
+ (flags.aliases[key] || []).forEach(function (alias) {
333
+ defaults[alias] = defaults[key];
334
+ });
335
+ });
336
+ let error = null;
337
+ checkConfiguration();
338
+ let notFlags = [];
339
+ const argv = Object.assign(Object.create(null), { _: [] });
340
+ // TODO(bcoe): for the first pass at removing object prototype we didn't
341
+ // remove all prototypes from objects returned by this API, we might want
342
+ // to gradually move towards doing so.
343
+ const argvReturn = {};
344
+ for (let i = 0; i < args.length; i++) {
345
+ const arg = args[i];
346
+ const truncatedArg = arg.replace(/^-{3,}/, '---');
347
+ let broken;
348
+ let key;
349
+ let letters;
350
+ let m;
351
+ let next;
352
+ let value;
353
+ // any unknown option (except for end-of-options, "--")
354
+ if (arg !== '--' && /^-/.test(arg) && isUnknownOptionAsArg(arg)) {
355
+ pushPositional(arg);
356
+ // ---, ---=, ----, etc,
357
+ }
358
+ else if (truncatedArg.match(/^---+(=|$)/)) {
359
+ // options without key name are invalid.
360
+ pushPositional(arg);
361
+ continue;
362
+ // -- separated by =
363
+ }
364
+ else if (arg.match(/^--.+=/) || (!configuration['short-option-groups'] && arg.match(/^-.+=/))) {
365
+ // Using [\s\S] instead of . because js doesn't support the
366
+ // 'dotall' regex modifier. See:
367
+ // http://stackoverflow.com/a/1068308/13216
368
+ m = arg.match(/^--?([^=]+)=([\s\S]*)$/);
369
+ // arrays format = '--f=a b c'
370
+ if (m !== null && Array.isArray(m) && m.length >= 3) {
371
+ if (checkAllAliases(m[1], flags.arrays)) {
372
+ i = eatArray(i, m[1], args, m[2]);
373
+ }
374
+ else if (checkAllAliases(m[1], flags.nargs) !== false) {
375
+ // nargs format = '--f=monkey washing cat'
376
+ i = eatNargs(i, m[1], args, m[2]);
377
+ }
378
+ else {
379
+ setArg(m[1], m[2], true);
380
+ }
381
+ }
382
+ }
383
+ else if (arg.match(negatedBoolean) && configuration['boolean-negation']) {
384
+ m = arg.match(negatedBoolean);
385
+ if (m !== null && Array.isArray(m) && m.length >= 2) {
386
+ key = m[1];
387
+ setArg(key, checkAllAliases(key, flags.arrays) ? [false] : false);
388
+ }
389
+ // -- separated by space.
390
+ }
391
+ else if (arg.match(/^--.+/) || (!configuration['short-option-groups'] && arg.match(/^-[^-]+/))) {
392
+ m = arg.match(/^--?(.+)/);
393
+ if (m !== null && Array.isArray(m) && m.length >= 2) {
394
+ key = m[1];
395
+ if (checkAllAliases(key, flags.arrays)) {
396
+ // array format = '--foo a b c'
397
+ i = eatArray(i, key, args);
398
+ }
399
+ else if (checkAllAliases(key, flags.nargs) !== false) {
400
+ // nargs format = '--foo a b c'
401
+ // should be truthy even if: flags.nargs[key] === 0
402
+ i = eatNargs(i, key, args);
403
+ }
404
+ else {
405
+ next = args[i + 1];
406
+ if (next !== undefined && (!next.match(/^-/) ||
407
+ next.match(negative)) &&
408
+ !checkAllAliases(key, flags.bools) &&
409
+ !checkAllAliases(key, flags.counts)) {
410
+ setArg(key, next);
411
+ i++;
412
+ }
413
+ else if (/^(true|false)$/.test(next)) {
414
+ setArg(key, next);
415
+ i++;
416
+ }
417
+ else {
418
+ setArg(key, defaultValue(key));
419
+ }
420
+ }
421
+ }
422
+ // dot-notation flag separated by '='.
423
+ }
424
+ else if (arg.match(/^-.\..+=/)) {
425
+ m = arg.match(/^-([^=]+)=([\s\S]*)$/);
426
+ if (m !== null && Array.isArray(m) && m.length >= 3) {
427
+ setArg(m[1], m[2]);
428
+ }
429
+ // dot-notation flag separated by space.
430
+ }
431
+ else if (arg.match(/^-.\..+/) && !arg.match(negative)) {
432
+ next = args[i + 1];
433
+ m = arg.match(/^-(.\..+)/);
434
+ if (m !== null && Array.isArray(m) && m.length >= 2) {
435
+ key = m[1];
436
+ if (next !== undefined && !next.match(/^-/) &&
437
+ !checkAllAliases(key, flags.bools) &&
438
+ !checkAllAliases(key, flags.counts)) {
439
+ setArg(key, next);
440
+ i++;
441
+ }
442
+ else {
443
+ setArg(key, defaultValue(key));
444
+ }
445
+ }
446
+ }
447
+ else if (arg.match(/^-[^-]+/) && !arg.match(negative)) {
448
+ letters = arg.slice(1, -1).split('');
449
+ broken = false;
450
+ for (let j = 0; j < letters.length; j++) {
451
+ next = arg.slice(j + 2);
452
+ if (letters[j + 1] && letters[j + 1] === '=') {
453
+ value = arg.slice(j + 3);
454
+ key = letters[j];
455
+ if (checkAllAliases(key, flags.arrays)) {
456
+ // array format = '-f=a b c'
457
+ i = eatArray(i, key, args, value);
458
+ }
459
+ else if (checkAllAliases(key, flags.nargs) !== false) {
460
+ // nargs format = '-f=monkey washing cat'
461
+ i = eatNargs(i, key, args, value);
462
+ }
463
+ else {
464
+ setArg(key, value);
465
+ }
466
+ broken = true;
467
+ break;
468
+ }
469
+ if (next === '-') {
470
+ setArg(letters[j], next);
471
+ continue;
472
+ }
473
+ // current letter is an alphabetic character and next value is a number
474
+ if (/[A-Za-z]/.test(letters[j]) &&
475
+ /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next) &&
476
+ checkAllAliases(next, flags.bools) === false) {
477
+ setArg(letters[j], next);
478
+ broken = true;
479
+ break;
480
+ }
481
+ if (letters[j + 1] && letters[j + 1].match(/\W/)) {
482
+ setArg(letters[j], next);
483
+ broken = true;
484
+ break;
485
+ }
486
+ else {
487
+ setArg(letters[j], defaultValue(letters[j]));
488
+ }
489
+ }
490
+ key = arg.slice(-1)[0];
491
+ if (!broken && key !== '-') {
492
+ if (checkAllAliases(key, flags.arrays)) {
493
+ // array format = '-f a b c'
494
+ i = eatArray(i, key, args);
495
+ }
496
+ else if (checkAllAliases(key, flags.nargs) !== false) {
497
+ // nargs format = '-f a b c'
498
+ // should be truthy even if: flags.nargs[key] === 0
499
+ i = eatNargs(i, key, args);
500
+ }
501
+ else {
502
+ next = args[i + 1];
503
+ if (next !== undefined && (!/^(-|--)[^-]/.test(next) ||
504
+ next.match(negative)) &&
505
+ !checkAllAliases(key, flags.bools) &&
506
+ !checkAllAliases(key, flags.counts)) {
507
+ setArg(key, next);
508
+ i++;
509
+ }
510
+ else if (/^(true|false)$/.test(next)) {
511
+ setArg(key, next);
512
+ i++;
513
+ }
514
+ else {
515
+ setArg(key, defaultValue(key));
516
+ }
517
+ }
518
+ }
519
+ }
520
+ else if (arg.match(/^-[0-9]$/) &&
521
+ arg.match(negative) &&
522
+ checkAllAliases(arg.slice(1), flags.bools)) {
523
+ // single-digit boolean alias, e.g: xargs -0
524
+ key = arg.slice(1);
525
+ setArg(key, defaultValue(key));
526
+ }
527
+ else if (arg === '--') {
528
+ notFlags = args.slice(i + 1);
529
+ break;
530
+ }
531
+ else if (configuration['halt-at-non-option']) {
532
+ notFlags = args.slice(i);
533
+ break;
534
+ }
535
+ else {
536
+ pushPositional(arg);
537
+ }
538
+ }
539
+ // order of precedence:
540
+ // 1. command line arg
541
+ // 2. value from env var
542
+ // 3. value from config file
543
+ // 4. value from config objects
544
+ // 5. configured default value
545
+ applyEnvVars(argv, true); // special case: check env vars that point to config file
546
+ applyEnvVars(argv, false);
547
+ setConfig(argv);
548
+ setConfigObjects();
549
+ applyDefaultsAndAliases(argv, flags.aliases, defaults, true);
550
+ applyCoercions(argv);
551
+ if (configuration['set-placeholder-key'])
552
+ setPlaceholderKeys(argv);
553
+ // for any counts either not in args or without an explicit default, set to 0
554
+ Object.keys(flags.counts).forEach(function (key) {
555
+ if (!hasKey(argv, key.split('.')))
556
+ setArg(key, 0);
557
+ });
558
+ // '--' defaults to undefined.
559
+ if (notFlagsOption && notFlags.length)
560
+ argv[notFlagsArgv] = [];
561
+ notFlags.forEach(function (key) {
562
+ argv[notFlagsArgv].push(key);
563
+ });
564
+ if (configuration['camel-case-expansion'] && configuration['strip-dashed']) {
565
+ Object.keys(argv).filter(key => key !== '--' && key.includes('-')).forEach(key => {
566
+ delete argv[key];
567
+ });
568
+ }
569
+ if (configuration['strip-aliased']) {
570
+ [].concat(...Object.keys(aliases).map(k => aliases[k])).forEach(alias => {
571
+ if (configuration['camel-case-expansion'] && alias.includes('-')) {
572
+ delete argv[alias.split('.').map(prop => camelCase(prop)).join('.')];
573
+ }
574
+ delete argv[alias];
575
+ });
576
+ }
577
+ // Push argument into positional array, applying numeric coercion:
578
+ function pushPositional(arg) {
579
+ const maybeCoercedNumber = maybeCoerceNumber('_', arg);
580
+ if (typeof maybeCoercedNumber === 'string' || typeof maybeCoercedNumber === 'number') {
581
+ argv._.push(maybeCoercedNumber);
582
+ }
583
+ }
584
+ // how many arguments should we consume, based
585
+ // on the nargs option?
586
+ function eatNargs(i, key, args, argAfterEqualSign) {
587
+ let ii;
588
+ let toEat = checkAllAliases(key, flags.nargs);
589
+ // NaN has a special meaning for the array type, indicating that one or
590
+ // more values are expected.
591
+ toEat = typeof toEat !== 'number' || isNaN(toEat) ? 1 : toEat;
592
+ if (toEat === 0) {
593
+ if (!isUndefined(argAfterEqualSign)) {
594
+ error = Error(__('Argument unexpected for: %s', key));
595
+ }
596
+ setArg(key, defaultValue(key));
597
+ return i;
598
+ }
599
+ let available = isUndefined(argAfterEqualSign) ? 0 : 1;
600
+ if (configuration['nargs-eats-options']) {
601
+ // classic behavior, yargs eats positional and dash arguments.
602
+ if (args.length - (i + 1) + available < toEat) {
603
+ error = Error(__('Not enough arguments following: %s', key));
604
+ }
605
+ available = toEat;
606
+ }
607
+ else {
608
+ // nargs will not consume flag arguments, e.g., -abc, --foo,
609
+ // and terminates when one is observed.
610
+ for (ii = i + 1; ii < args.length; ii++) {
611
+ if (!args[ii].match(/^-[^0-9]/) || args[ii].match(negative) || isUnknownOptionAsArg(args[ii]))
612
+ available++;
613
+ else
614
+ break;
615
+ }
616
+ if (available < toEat)
617
+ error = Error(__('Not enough arguments following: %s', key));
618
+ }
619
+ let consumed = Math.min(available, toEat);
620
+ if (!isUndefined(argAfterEqualSign) && consumed > 0) {
621
+ setArg(key, argAfterEqualSign);
622
+ consumed--;
623
+ }
624
+ for (ii = i + 1; ii < (consumed + i + 1); ii++) {
625
+ setArg(key, args[ii]);
626
+ }
627
+ return (i + consumed);
628
+ }
629
+ // if an option is an array, eat all non-hyphenated arguments
630
+ // following it... YUM!
631
+ // e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
632
+ function eatArray(i, key, args, argAfterEqualSign) {
633
+ let argsToSet = [];
634
+ let next = argAfterEqualSign || args[i + 1];
635
+ // If both array and nargs are configured, enforce the nargs count:
636
+ const nargsCount = checkAllAliases(key, flags.nargs);
637
+ if (checkAllAliases(key, flags.bools) && !(/^(true|false)$/.test(next))) {
638
+ argsToSet.push(true);
639
+ }
640
+ else if (isUndefined(next) ||
641
+ (isUndefined(argAfterEqualSign) && /^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))) {
642
+ // for keys without value ==> argsToSet remains an empty []
643
+ // set user default value, if available
644
+ if (defaults[key] !== undefined) {
645
+ const defVal = defaults[key];
646
+ argsToSet = Array.isArray(defVal) ? defVal : [defVal];
647
+ }
648
+ }
649
+ else {
650
+ // value in --option=value is eaten as is
651
+ if (!isUndefined(argAfterEqualSign)) {
652
+ argsToSet.push(processValue(key, argAfterEqualSign, true));
653
+ }
654
+ for (let ii = i + 1; ii < args.length; ii++) {
655
+ if ((!configuration['greedy-arrays'] && argsToSet.length > 0) ||
656
+ (nargsCount && typeof nargsCount === 'number' && argsToSet.length >= nargsCount))
657
+ break;
658
+ next = args[ii];
659
+ if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))
660
+ break;
661
+ i = ii;
662
+ argsToSet.push(processValue(key, next, inputIsString));
663
+ }
664
+ }
665
+ // If both array and nargs are configured, create an error if less than
666
+ // nargs positionals were found. NaN has special meaning, indicating
667
+ // that at least one value is required (more are okay).
668
+ if (typeof nargsCount === 'number' && ((nargsCount && argsToSet.length < nargsCount) ||
669
+ (isNaN(nargsCount) && argsToSet.length === 0))) {
670
+ error = Error(__('Not enough arguments following: %s', key));
671
+ }
672
+ setArg(key, argsToSet);
673
+ return i;
674
+ }
675
+ function setArg(key, val, shouldStripQuotes = inputIsString) {
676
+ if (/-/.test(key) && configuration['camel-case-expansion']) {
677
+ const alias = key.split('.').map(function (prop) {
678
+ return camelCase(prop);
679
+ }).join('.');
680
+ addNewAlias(key, alias);
681
+ }
682
+ const value = processValue(key, val, shouldStripQuotes);
683
+ const splitKey = key.split('.');
684
+ setKey(argv, splitKey, value);
685
+ // handle populating aliases of the full key
686
+ if (flags.aliases[key]) {
687
+ flags.aliases[key].forEach(function (x) {
688
+ const keyProperties = x.split('.');
689
+ setKey(argv, keyProperties, value);
690
+ });
691
+ }
692
+ // handle populating aliases of the first element of the dot-notation key
693
+ if (splitKey.length > 1 && configuration['dot-notation']) {
694
+ (flags.aliases[splitKey[0]] || []).forEach(function (x) {
695
+ let keyProperties = x.split('.');
696
+ // expand alias with nested objects in key
697
+ const a = [].concat(splitKey);
698
+ a.shift(); // nuke the old key.
699
+ keyProperties = keyProperties.concat(a);
700
+ // populate alias only if is not already an alias of the full key
701
+ // (already populated above)
702
+ if (!(flags.aliases[key] || []).includes(keyProperties.join('.'))) {
703
+ setKey(argv, keyProperties, value);
704
+ }
705
+ });
706
+ }
707
+ // Set normalize getter and setter when key is in 'normalize' but isn't an array
708
+ if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {
709
+ const keys = [key].concat(flags.aliases[key] || []);
710
+ keys.forEach(function (key) {
711
+ Object.defineProperty(argvReturn, key, {
712
+ enumerable: true,
713
+ get() {
714
+ return val;
715
+ },
716
+ set(value) {
717
+ val = typeof value === 'string' ? mixin$1.normalize(value) : value;
718
+ }
719
+ });
720
+ });
721
+ }
722
+ }
723
+ function addNewAlias(key, alias) {
724
+ if (!(flags.aliases[key] && flags.aliases[key].length)) {
725
+ flags.aliases[key] = [alias];
726
+ newAliases[alias] = true;
727
+ }
728
+ if (!(flags.aliases[alias] && flags.aliases[alias].length)) {
729
+ addNewAlias(alias, key);
730
+ }
731
+ }
732
+ function processValue(key, val, shouldStripQuotes) {
733
+ // strings may be quoted, clean this up as we assign values.
734
+ if (shouldStripQuotes) {
735
+ val = stripQuotes(val);
736
+ }
737
+ // handle parsing boolean arguments --foo=true --bar false.
738
+ if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
739
+ if (typeof val === 'string')
740
+ val = val === 'true';
741
+ }
742
+ let value = Array.isArray(val)
743
+ ? val.map(function (v) { return maybeCoerceNumber(key, v); })
744
+ : maybeCoerceNumber(key, val);
745
+ // increment a count given as arg (either no value or value parsed as boolean)
746
+ if (checkAllAliases(key, flags.counts) && (isUndefined(value) || typeof value === 'boolean')) {
747
+ value = increment();
748
+ }
749
+ // Set normalized value when key is in 'normalize' and in 'arrays'
750
+ if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) {
751
+ if (Array.isArray(val))
752
+ value = val.map((val) => { return mixin$1.normalize(val); });
753
+ else
754
+ value = mixin$1.normalize(val);
755
+ }
756
+ return value;
757
+ }
758
+ function maybeCoerceNumber(key, value) {
759
+ if (!configuration['parse-positional-numbers'] && key === '_')
760
+ return value;
761
+ if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.bools) && !Array.isArray(value)) {
762
+ const shouldCoerceNumber = looksLikeNumber(value) && configuration['parse-numbers'] && (Number.isSafeInteger(Math.floor(parseFloat(`${value}`))));
763
+ if (shouldCoerceNumber || (!isUndefined(value) && checkAllAliases(key, flags.numbers))) {
764
+ value = Number(value);
765
+ }
766
+ }
767
+ return value;
768
+ }
769
+ // set args from config.json file, this should be
770
+ // applied last so that defaults can be applied.
771
+ function setConfig(argv) {
772
+ const configLookup = Object.create(null);
773
+ // expand defaults/aliases, in-case any happen to reference
774
+ // the config.json file.
775
+ applyDefaultsAndAliases(configLookup, flags.aliases, defaults);
776
+ Object.keys(flags.configs).forEach(function (configKey) {
777
+ const configPath = argv[configKey] || configLookup[configKey];
778
+ if (configPath) {
779
+ try {
780
+ let config = null;
781
+ const resolvedConfigPath = mixin$1.resolve(mixin$1.cwd(), configPath);
782
+ const resolveConfig = flags.configs[configKey];
783
+ if (typeof resolveConfig === 'function') {
784
+ try {
785
+ config = resolveConfig(resolvedConfigPath);
786
+ }
787
+ catch (e) {
788
+ config = e;
789
+ }
790
+ if (config instanceof Error) {
791
+ error = config;
792
+ return;
793
+ }
794
+ }
795
+ else {
796
+ config = mixin$1.require(resolvedConfigPath);
797
+ }
798
+ setConfigObject(config);
799
+ }
800
+ catch (ex) {
801
+ // Deno will receive a PermissionDenied error if an attempt is
802
+ // made to load config without the --allow-read flag:
803
+ if (ex.name === 'PermissionDenied')
804
+ error = ex;
805
+ else if (argv[configKey])
806
+ error = Error(__('Invalid JSON config file: %s', configPath));
807
+ }
808
+ }
809
+ });
810
+ }
811
+ // set args from config object.
812
+ // it recursively checks nested objects.
813
+ function setConfigObject(config, prev) {
814
+ Object.keys(config).forEach(function (key) {
815
+ const value = config[key];
816
+ const fullKey = prev ? prev + '.' + key : key;
817
+ // if the value is an inner object and we have dot-notation
818
+ // enabled, treat inner objects in config the same as
819
+ // heavily nested dot notations (foo.bar.apple).
820
+ if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) {
821
+ // if the value is an object but not an array, check nested object
822
+ setConfigObject(value, fullKey);
823
+ }
824
+ else {
825
+ // setting arguments via CLI takes precedence over
826
+ // values within the config file.
827
+ if (!hasKey(argv, fullKey.split('.')) || (checkAllAliases(fullKey, flags.arrays) && configuration['combine-arrays'])) {
828
+ setArg(fullKey, value);
829
+ }
830
+ }
831
+ });
832
+ }
833
+ // set all config objects passed in opts
834
+ function setConfigObjects() {
835
+ if (typeof configObjects !== 'undefined') {
836
+ configObjects.forEach(function (configObject) {
837
+ setConfigObject(configObject);
838
+ });
839
+ }
840
+ }
841
+ function applyEnvVars(argv, configOnly) {
842
+ if (typeof envPrefix === 'undefined')
843
+ return;
844
+ const prefix = typeof envPrefix === 'string' ? envPrefix : '';
845
+ const env = mixin$1.env();
846
+ Object.keys(env).forEach(function (envVar) {
847
+ if (prefix === '' || envVar.lastIndexOf(prefix, 0) === 0) {
848
+ // get array of nested keys and convert them to camel case
849
+ const keys = envVar.split('__').map(function (key, i) {
850
+ if (i === 0) {
851
+ key = key.substring(prefix.length);
852
+ }
853
+ return camelCase(key);
854
+ });
855
+ if (((configOnly && flags.configs[keys.join('.')]) || !configOnly) && !hasKey(argv, keys)) {
856
+ setArg(keys.join('.'), env[envVar]);
857
+ }
858
+ }
859
+ });
860
+ }
861
+ function applyCoercions(argv) {
862
+ let coerce;
863
+ const applied = new Set();
864
+ Object.keys(argv).forEach(function (key) {
865
+ if (!applied.has(key)) { // If we haven't already coerced this option via one of its aliases
866
+ coerce = checkAllAliases(key, flags.coercions);
867
+ if (typeof coerce === 'function') {
868
+ try {
869
+ const value = maybeCoerceNumber(key, coerce(argv[key]));
870
+ ([].concat(flags.aliases[key] || [], key)).forEach(ali => {
871
+ applied.add(ali);
872
+ argv[ali] = value;
873
+ });
874
+ }
875
+ catch (err) {
876
+ error = err;
877
+ }
878
+ }
879
+ }
880
+ });
881
+ }
882
+ function setPlaceholderKeys(argv) {
883
+ flags.keys.forEach((key) => {
884
+ // don't set placeholder keys for dot notation options 'foo.bar'.
885
+ if (~key.indexOf('.'))
886
+ return;
887
+ if (typeof argv[key] === 'undefined')
888
+ argv[key] = undefined;
889
+ });
890
+ return argv;
891
+ }
892
+ function applyDefaultsAndAliases(obj, aliases, defaults, canLog = false) {
893
+ Object.keys(defaults).forEach(function (key) {
894
+ if (!hasKey(obj, key.split('.'))) {
895
+ setKey(obj, key.split('.'), defaults[key]);
896
+ if (canLog)
897
+ defaulted[key] = true;
898
+ (aliases[key] || []).forEach(function (x) {
899
+ if (hasKey(obj, x.split('.')))
900
+ return;
901
+ setKey(obj, x.split('.'), defaults[key]);
902
+ });
903
+ }
904
+ });
905
+ }
906
+ function hasKey(obj, keys) {
907
+ let o = obj;
908
+ if (!configuration['dot-notation'])
909
+ keys = [keys.join('.')];
910
+ keys.slice(0, -1).forEach(function (key) {
911
+ o = (o[key] || {});
912
+ });
913
+ const key = keys[keys.length - 1];
914
+ if (typeof o !== 'object')
915
+ return false;
916
+ else
917
+ return key in o;
918
+ }
919
+ function setKey(obj, keys, value) {
920
+ let o = obj;
921
+ if (!configuration['dot-notation'])
922
+ keys = [keys.join('.')];
923
+ keys.slice(0, -1).forEach(function (key) {
924
+ // TODO(bcoe): in the next major version of yargs, switch to
925
+ // Object.create(null) for dot notation:
926
+ key = sanitizeKey(key);
927
+ if (typeof o === 'object' && o[key] === undefined) {
928
+ o[key] = {};
929
+ }
930
+ if (typeof o[key] !== 'object' || Array.isArray(o[key])) {
931
+ // ensure that o[key] is an array, and that the last item is an empty object.
932
+ if (Array.isArray(o[key])) {
933
+ o[key].push({});
934
+ }
935
+ else {
936
+ o[key] = [o[key], {}];
937
+ }
938
+ // we want to update the empty object at the end of the o[key] array, so set o to that object
939
+ o = o[key][o[key].length - 1];
940
+ }
941
+ else {
942
+ o = o[key];
943
+ }
944
+ });
945
+ // TODO(bcoe): in the next major version of yargs, switch to
946
+ // Object.create(null) for dot notation:
947
+ const key = sanitizeKey(keys[keys.length - 1]);
948
+ const isTypeArray = checkAllAliases(keys.join('.'), flags.arrays);
949
+ const isValueArray = Array.isArray(value);
950
+ let duplicate = configuration['duplicate-arguments-array'];
951
+ // nargs has higher priority than duplicate
952
+ if (!duplicate && checkAllAliases(key, flags.nargs)) {
953
+ duplicate = true;
954
+ if ((!isUndefined(o[key]) && flags.nargs[key] === 1) || (Array.isArray(o[key]) && o[key].length === flags.nargs[key])) {
955
+ o[key] = undefined;
956
+ }
957
+ }
958
+ if (value === increment()) {
959
+ o[key] = increment(o[key]);
960
+ }
961
+ else if (Array.isArray(o[key])) {
962
+ if (duplicate && isTypeArray && isValueArray) {
963
+ o[key] = configuration['flatten-duplicate-arrays'] ? o[key].concat(value) : (Array.isArray(o[key][0]) ? o[key] : [o[key]]).concat([value]);
964
+ }
965
+ else if (!duplicate && Boolean(isTypeArray) === Boolean(isValueArray)) {
966
+ o[key] = value;
967
+ }
968
+ else {
969
+ o[key] = o[key].concat([value]);
970
+ }
971
+ }
972
+ else if (o[key] === undefined && isTypeArray) {
973
+ o[key] = isValueArray ? value : [value];
974
+ }
975
+ else if (duplicate && !(o[key] === undefined ||
976
+ checkAllAliases(key, flags.counts) ||
977
+ checkAllAliases(key, flags.bools))) {
978
+ o[key] = [o[key], value];
979
+ }
980
+ else {
981
+ o[key] = value;
982
+ }
983
+ }
984
+ // extend the aliases list with inferred aliases.
985
+ function extendAliases(...args) {
986
+ args.forEach(function (obj) {
987
+ Object.keys(obj || {}).forEach(function (key) {
988
+ // short-circuit if we've already added a key
989
+ // to the aliases array, for example it might
990
+ // exist in both 'opts.default' and 'opts.key'.
991
+ if (flags.aliases[key])
992
+ return;
993
+ flags.aliases[key] = [].concat(aliases[key] || []);
994
+ // For "--option-name", also set argv.optionName
995
+ flags.aliases[key].concat(key).forEach(function (x) {
996
+ if (/-/.test(x) && configuration['camel-case-expansion']) {
997
+ const c = camelCase(x);
998
+ if (c !== key && flags.aliases[key].indexOf(c) === -1) {
999
+ flags.aliases[key].push(c);
1000
+ newAliases[c] = true;
1001
+ }
1002
+ }
1003
+ });
1004
+ // For "--optionName", also set argv['option-name']
1005
+ flags.aliases[key].concat(key).forEach(function (x) {
1006
+ if (x.length > 1 && /[A-Z]/.test(x) && configuration['camel-case-expansion']) {
1007
+ const c = decamelize(x, '-');
1008
+ if (c !== key && flags.aliases[key].indexOf(c) === -1) {
1009
+ flags.aliases[key].push(c);
1010
+ newAliases[c] = true;
1011
+ }
1012
+ }
1013
+ });
1014
+ flags.aliases[key].forEach(function (x) {
1015
+ flags.aliases[x] = [key].concat(flags.aliases[key].filter(function (y) {
1016
+ return x !== y;
1017
+ }));
1018
+ });
1019
+ });
1020
+ });
1021
+ }
1022
+ function checkAllAliases(key, flag) {
1023
+ const toCheck = [].concat(flags.aliases[key] || [], key);
1024
+ const keys = Object.keys(flag);
1025
+ const setAlias = toCheck.find(key => keys.includes(key));
1026
+ return setAlias ? flag[setAlias] : false;
1027
+ }
1028
+ function hasAnyFlag(key) {
1029
+ const flagsKeys = Object.keys(flags);
1030
+ const toCheck = [].concat(flagsKeys.map(k => flags[k]));
1031
+ return toCheck.some(function (flag) {
1032
+ return Array.isArray(flag) ? flag.includes(key) : flag[key];
1033
+ });
1034
+ }
1035
+ function hasFlagsMatching(arg, ...patterns) {
1036
+ const toCheck = [].concat(...patterns);
1037
+ return toCheck.some(function (pattern) {
1038
+ const match = arg.match(pattern);
1039
+ return match && hasAnyFlag(match[1]);
1040
+ });
1041
+ }
1042
+ // based on a simplified version of the short flag group parsing logic
1043
+ function hasAllShortFlags(arg) {
1044
+ // if this is a negative number, or doesn't start with a single hyphen, it's not a short flag group
1045
+ if (arg.match(negative) || !arg.match(/^-[^-]+/)) {
1046
+ return false;
1047
+ }
1048
+ let hasAllFlags = true;
1049
+ let next;
1050
+ const letters = arg.slice(1).split('');
1051
+ for (let j = 0; j < letters.length; j++) {
1052
+ next = arg.slice(j + 2);
1053
+ if (!hasAnyFlag(letters[j])) {
1054
+ hasAllFlags = false;
1055
+ break;
1056
+ }
1057
+ if ((letters[j + 1] && letters[j + 1] === '=') ||
1058
+ next === '-' ||
1059
+ (/[A-Za-z]/.test(letters[j]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) ||
1060
+ (letters[j + 1] && letters[j + 1].match(/\W/))) {
1061
+ break;
1062
+ }
1063
+ }
1064
+ return hasAllFlags;
1065
+ }
1066
+ function isUnknownOptionAsArg(arg) {
1067
+ return configuration['unknown-options-as-args'] && isUnknownOption(arg);
1068
+ }
1069
+ function isUnknownOption(arg) {
1070
+ arg = arg.replace(/^-{3,}/, '--');
1071
+ // ignore negative numbers
1072
+ if (arg.match(negative)) {
1073
+ return false;
1074
+ }
1075
+ // if this is a short option group and all of them are configured, it isn't unknown
1076
+ if (hasAllShortFlags(arg)) {
1077
+ return false;
1078
+ }
1079
+ // e.g. '--count=2'
1080
+ const flagWithEquals = /^-+([^=]+?)=[\s\S]*$/;
1081
+ // e.g. '-a' or '--arg'
1082
+ const normalFlag = /^-+([^=]+?)$/;
1083
+ // e.g. '-a-'
1084
+ const flagEndingInHyphen = /^-+([^=]+?)-$/;
1085
+ // e.g. '-abc123'
1086
+ const flagEndingInDigits = /^-+([^=]+?\d+)$/;
1087
+ // e.g. '-a/usr/local'
1088
+ const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/;
1089
+ // check the different types of flag styles, including negatedBoolean, a pattern defined near the start of the parse method
1090
+ return !hasFlagsMatching(arg, flagWithEquals, negatedBoolean, normalFlag, flagEndingInHyphen, flagEndingInDigits, flagEndingInNonWordCharacters);
1091
+ }
1092
+ // make a best effort to pick a default value
1093
+ // for an option based on name and type.
1094
+ function defaultValue(key) {
1095
+ if (!checkAllAliases(key, flags.bools) &&
1096
+ !checkAllAliases(key, flags.counts) &&
1097
+ `${key}` in defaults) {
1098
+ return defaults[key];
1099
+ }
1100
+ else {
1101
+ return defaultForType(guessType(key));
1102
+ }
1103
+ }
1104
+ // return a default value, given the type of a flag.,
1105
+ function defaultForType(type) {
1106
+ const def = {
1107
+ [DefaultValuesForTypeKey.BOOLEAN]: true,
1108
+ [DefaultValuesForTypeKey.STRING]: '',
1109
+ [DefaultValuesForTypeKey.NUMBER]: undefined,
1110
+ [DefaultValuesForTypeKey.ARRAY]: []
1111
+ };
1112
+ return def[type];
1113
+ }
1114
+ // given a flag, enforce a default type.
1115
+ function guessType(key) {
1116
+ let type = DefaultValuesForTypeKey.BOOLEAN;
1117
+ if (checkAllAliases(key, flags.strings))
1118
+ type = DefaultValuesForTypeKey.STRING;
1119
+ else if (checkAllAliases(key, flags.numbers))
1120
+ type = DefaultValuesForTypeKey.NUMBER;
1121
+ else if (checkAllAliases(key, flags.bools))
1122
+ type = DefaultValuesForTypeKey.BOOLEAN;
1123
+ else if (checkAllAliases(key, flags.arrays))
1124
+ type = DefaultValuesForTypeKey.ARRAY;
1125
+ return type;
1126
+ }
1127
+ function isUndefined(num) {
1128
+ return num === undefined;
1129
+ }
1130
+ // check user configuration settings for inconsistencies
1131
+ function checkConfiguration() {
1132
+ // count keys should not be set as array/narg
1133
+ Object.keys(flags.counts).find(key => {
1134
+ if (checkAllAliases(key, flags.arrays)) {
1135
+ error = Error(__('Invalid configuration: %s, opts.count excludes opts.array.', key));
1136
+ return true;
1137
+ }
1138
+ else if (checkAllAliases(key, flags.nargs)) {
1139
+ error = Error(__('Invalid configuration: %s, opts.count excludes opts.narg.', key));
1140
+ return true;
1141
+ }
1142
+ return false;
1143
+ });
1144
+ }
1145
+ return {
1146
+ aliases: Object.assign({}, flags.aliases),
1147
+ argv: Object.assign(argvReturn, argv),
1148
+ configuration: configuration,
1149
+ defaulted: Object.assign({}, defaulted),
1150
+ error: error,
1151
+ newAliases: Object.assign({}, newAliases)
1152
+ };
1153
+ }
1154
+ }
1155
+ // if any aliases reference each other, we should
1156
+ // merge them together.
1157
+ function combineAliases(aliases) {
1158
+ const aliasArrays = [];
1159
+ const combined = Object.create(null);
1160
+ let change = true;
1161
+ // turn alias lookup hash {key: ['alias1', 'alias2']} into
1162
+ // a simple array ['key', 'alias1', 'alias2']
1163
+ Object.keys(aliases).forEach(function (key) {
1164
+ aliasArrays.push([].concat(aliases[key], key));
1165
+ });
1166
+ // combine arrays until zero changes are
1167
+ // made in an iteration.
1168
+ while (change) {
1169
+ change = false;
1170
+ for (let i = 0; i < aliasArrays.length; i++) {
1171
+ for (let ii = i + 1; ii < aliasArrays.length; ii++) {
1172
+ const intersect = aliasArrays[i].filter(function (v) {
1173
+ return aliasArrays[ii].indexOf(v) !== -1;
1174
+ });
1175
+ if (intersect.length) {
1176
+ aliasArrays[i] = aliasArrays[i].concat(aliasArrays[ii]);
1177
+ aliasArrays.splice(ii, 1);
1178
+ change = true;
1179
+ break;
1180
+ }
1181
+ }
1182
+ }
1183
+ }
1184
+ // map arrays back to the hash-lookup (de-dupe while
1185
+ // we're at it).
1186
+ aliasArrays.forEach(function (aliasArray) {
1187
+ aliasArray = aliasArray.filter(function (v, i, self) {
1188
+ return self.indexOf(v) === i;
1189
+ });
1190
+ const lastAlias = aliasArray.pop();
1191
+ if (lastAlias !== undefined && typeof lastAlias === 'string') {
1192
+ combined[lastAlias] = aliasArray;
1193
+ }
1194
+ });
1195
+ return combined;
1196
+ }
1197
+ // this function should only be called when a count is given as an arg
1198
+ // it is NOT called to set a default value
1199
+ // thus we can start the count at 1 instead of 0
1200
+ function increment(orig) {
1201
+ return orig !== undefined ? orig + 1 : 1;
1202
+ }
1203
+ // TODO(bcoe): in the next major version of yargs, switch to
1204
+ // Object.create(null) for dot notation:
1205
+ function sanitizeKey(key) {
1206
+ if (key === '__proto__')
1207
+ return '___proto___';
1208
+ return key;
1209
+ }
1210
+ function stripQuotes(val) {
1211
+ return (typeof val === 'string' &&
1212
+ (val[0] === "'" || val[0] === '"') &&
1213
+ val[val.length - 1] === val[0])
1214
+ ? val.substring(1, val.length - 1)
1215
+ : val;
1216
+ }
1217
+
1218
+ /**
1219
+ * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
1220
+ * CJS and ESM environments.
1221
+ *
1222
+ * @license
1223
+ * Copyright (c) 2016, Contributors
1224
+ * SPDX-License-Identifier: ISC
1225
+ */
1226
+ var _a, _b, _c;
1227
+ // See https://github.com/yargs/yargs-parser#supported-nodejs-versions for our
1228
+ // version support policy. The YARGS_MIN_NODE_VERSION is used for testing only.
1229
+ const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
1230
+ ? Number(process.env.YARGS_MIN_NODE_VERSION)
1231
+ : 12;
1232
+ 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);
1233
+ if (nodeVersion) {
1234
+ const major = Number(nodeVersion.match(/^([^.]+)/)[1]);
1235
+ if (major < minNodeVersion) {
1236
+ 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`);
1237
+ }
1238
+ }
1239
+ // Creates a yargs-parser instance using Node.js standard libraries:
1240
+ const env = process ? process.env : {};
1241
+ const parser = new YargsParser({
1242
+ cwd: process.cwd,
1243
+ env: () => {
1244
+ return env;
1245
+ },
1246
+ format,
1247
+ normalize,
1248
+ resolve,
1249
+ // TODO: figure out a way to combine ESM and CJS coverage, such that
1250
+ // we can exercise all the lines below:
1251
+ require: (path) => {
1252
+ if (typeof require !== 'undefined') {
1253
+ return require(path);
1254
+ }
1255
+ else if (path.match(/\.json$/)) {
1256
+ // Addresses: https://github.com/yargs/yargs/issues/2040
1257
+ return JSON.parse(readFileSync(path, 'utf8'));
1258
+ }
1259
+ else {
1260
+ throw Error('only .json config files are supported in ESM');
1261
+ }
1262
+ }
1263
+ });
1264
+ const yargsParser = function Parser(args, opts) {
1265
+ const result = parser.parse(args.slice(), opts);
1266
+ return result.argv;
1267
+ };
1268
+ yargsParser.detailed = function (args, opts) {
1269
+ return parser.parse(args.slice(), opts);
1270
+ };
1271
+ yargsParser.camelCase = camelCase;
1272
+ yargsParser.decamelize = decamelize;
1273
+ yargsParser.looksLikeNumber = looksLikeNumber;
1274
+
1275
+ const align = {
1276
+ right: alignRight,
1277
+ center: alignCenter
1278
+ };
1279
+ const top = 0;
1280
+ const right = 1;
1281
+ const bottom = 2;
1282
+ const left = 3;
1283
+ class UI {
1284
+ constructor(opts) {
1285
+ var _a;
1286
+ this.width = opts.width;
1287
+ this.wrap = (_a = opts.wrap) !== null && _a !== void 0 ? _a : true;
1288
+ this.rows = [];
1289
+ }
1290
+ span(...args) {
1291
+ const cols = this.div(...args);
1292
+ cols.span = true;
1293
+ }
1294
+ resetOutput() {
1295
+ this.rows = [];
1296
+ }
1297
+ div(...args) {
1298
+ if (args.length === 0) {
1299
+ this.div('');
1300
+ }
1301
+ if (this.wrap && this.shouldApplyLayoutDSL(...args) && typeof args[0] === 'string') {
1302
+ return this.applyLayoutDSL(args[0]);
1303
+ }
1304
+ const cols = args.map(arg => {
1305
+ if (typeof arg === 'string') {
1306
+ return this.colFromString(arg);
1307
+ }
1308
+ return arg;
1309
+ });
1310
+ this.rows.push(cols);
1311
+ return cols;
1312
+ }
1313
+ shouldApplyLayoutDSL(...args) {
1314
+ return args.length === 1 && typeof args[0] === 'string' &&
1315
+ /[\t\n]/.test(args[0]);
1316
+ }
1317
+ applyLayoutDSL(str) {
1318
+ const rows = str.split('\n').map(row => row.split('\t'));
1319
+ let leftColumnWidth = 0;
1320
+ // simple heuristic for layout, make sure the
1321
+ // second column lines up along the left-hand.
1322
+ // don't allow the first column to take up more
1323
+ // than 50% of the screen.
1324
+ rows.forEach(columns => {
1325
+ if (columns.length > 1 && mixin.stringWidth(columns[0]) > leftColumnWidth) {
1326
+ leftColumnWidth = Math.min(Math.floor(this.width * 0.5), mixin.stringWidth(columns[0]));
1327
+ }
1328
+ });
1329
+ // generate a table:
1330
+ // replacing ' ' with padding calculations.
1331
+ // using the algorithmically generated width.
1332
+ rows.forEach(columns => {
1333
+ this.div(...columns.map((r, i) => {
1334
+ return {
1335
+ text: r.trim(),
1336
+ padding: this.measurePadding(r),
1337
+ width: (i === 0 && columns.length > 1) ? leftColumnWidth : undefined
1338
+ };
1339
+ }));
1340
+ });
1341
+ return this.rows[this.rows.length - 1];
1342
+ }
1343
+ colFromString(text) {
1344
+ return {
1345
+ text,
1346
+ padding: this.measurePadding(text)
1347
+ };
1348
+ }
1349
+ measurePadding(str) {
1350
+ // measure padding without ansi escape codes
1351
+ const noAnsi = mixin.stripAnsi(str);
1352
+ return [0, noAnsi.match(/\s*$/)[0].length, 0, noAnsi.match(/^\s*/)[0].length];
1353
+ }
1354
+ toString() {
1355
+ const lines = [];
1356
+ this.rows.forEach(row => {
1357
+ this.rowToString(row, lines);
1358
+ });
1359
+ // don't display any lines with the
1360
+ // hidden flag set.
1361
+ return lines
1362
+ .filter(line => !line.hidden)
1363
+ .map(line => line.text)
1364
+ .join('\n');
1365
+ }
1366
+ rowToString(row, lines) {
1367
+ this.rasterize(row).forEach((rrow, r) => {
1368
+ let str = '';
1369
+ rrow.forEach((col, c) => {
1370
+ const { width } = row[c]; // the width with padding.
1371
+ const wrapWidth = this.negatePadding(row[c]); // the width without padding.
1372
+ let ts = col; // temporary string used during alignment/padding.
1373
+ if (wrapWidth > mixin.stringWidth(col)) {
1374
+ ts += ' '.repeat(wrapWidth - mixin.stringWidth(col));
1375
+ }
1376
+ // align the string within its column.
1377
+ if (row[c].align && row[c].align !== 'left' && this.wrap) {
1378
+ const fn = align[row[c].align];
1379
+ ts = fn(ts, wrapWidth);
1380
+ if (mixin.stringWidth(ts) < wrapWidth) {
1381
+ ts += ' '.repeat((width || 0) - mixin.stringWidth(ts) - 1);
1382
+ }
1383
+ }
1384
+ // apply border and padding to string.
1385
+ const padding = row[c].padding || [0, 0, 0, 0];
1386
+ if (padding[left]) {
1387
+ str += ' '.repeat(padding[left]);
1388
+ }
1389
+ str += addBorder(row[c], ts, '| ');
1390
+ str += ts;
1391
+ str += addBorder(row[c], ts, ' |');
1392
+ if (padding[right]) {
1393
+ str += ' '.repeat(padding[right]);
1394
+ }
1395
+ // if prior row is span, try to render the
1396
+ // current row on the prior line.
1397
+ if (r === 0 && lines.length > 0) {
1398
+ str = this.renderInline(str, lines[lines.length - 1]);
1399
+ }
1400
+ });
1401
+ // remove trailing whitespace.
1402
+ lines.push({
1403
+ text: str.replace(/ +$/, ''),
1404
+ span: row.span
1405
+ });
1406
+ });
1407
+ return lines;
1408
+ }
1409
+ // if the full 'source' can render in
1410
+ // the target line, do so.
1411
+ renderInline(source, previousLine) {
1412
+ const match = source.match(/^ */);
1413
+ const leadingWhitespace = match ? match[0].length : 0;
1414
+ const target = previousLine.text;
1415
+ const targetTextWidth = mixin.stringWidth(target.trimRight());
1416
+ if (!previousLine.span) {
1417
+ return source;
1418
+ }
1419
+ // if we're not applying wrapping logic,
1420
+ // just always append to the span.
1421
+ if (!this.wrap) {
1422
+ previousLine.hidden = true;
1423
+ return target + source;
1424
+ }
1425
+ if (leadingWhitespace < targetTextWidth) {
1426
+ return source;
1427
+ }
1428
+ previousLine.hidden = true;
1429
+ return target.trimRight() + ' '.repeat(leadingWhitespace - targetTextWidth) + source.trimLeft();
1430
+ }
1431
+ rasterize(row) {
1432
+ const rrows = [];
1433
+ const widths = this.columnWidths(row);
1434
+ let wrapped;
1435
+ // word wrap all columns, and create
1436
+ // a data-structure that is easy to rasterize.
1437
+ row.forEach((col, c) => {
1438
+ // leave room for left and right padding.
1439
+ col.width = widths[c];
1440
+ if (this.wrap) {
1441
+ wrapped = mixin.wrap(col.text, this.negatePadding(col), { hard: true }).split('\n');
1442
+ }
1443
+ else {
1444
+ wrapped = col.text.split('\n');
1445
+ }
1446
+ if (col.border) {
1447
+ wrapped.unshift('.' + '-'.repeat(this.negatePadding(col) + 2) + '.');
1448
+ wrapped.push("'" + '-'.repeat(this.negatePadding(col) + 2) + "'");
1449
+ }
1450
+ // add top and bottom padding.
1451
+ if (col.padding) {
1452
+ wrapped.unshift(...new Array(col.padding[top] || 0).fill(''));
1453
+ wrapped.push(...new Array(col.padding[bottom] || 0).fill(''));
1454
+ }
1455
+ wrapped.forEach((str, r) => {
1456
+ if (!rrows[r]) {
1457
+ rrows.push([]);
1458
+ }
1459
+ const rrow = rrows[r];
1460
+ for (let i = 0; i < c; i++) {
1461
+ if (rrow[i] === undefined) {
1462
+ rrow.push('');
1463
+ }
1464
+ }
1465
+ rrow.push(str);
1466
+ });
1467
+ });
1468
+ return rrows;
1469
+ }
1470
+ negatePadding(col) {
1471
+ let wrapWidth = col.width || 0;
1472
+ if (col.padding) {
1473
+ wrapWidth -= (col.padding[left] || 0) + (col.padding[right] || 0);
1474
+ }
1475
+ if (col.border) {
1476
+ wrapWidth -= 4;
1477
+ }
1478
+ return wrapWidth;
1479
+ }
1480
+ columnWidths(row) {
1481
+ if (!this.wrap) {
1482
+ return row.map(col => {
1483
+ return col.width || mixin.stringWidth(col.text);
1484
+ });
1485
+ }
1486
+ let unset = row.length;
1487
+ let remainingWidth = this.width;
1488
+ // column widths can be set in config.
1489
+ const widths = row.map(col => {
1490
+ if (col.width) {
1491
+ unset--;
1492
+ remainingWidth -= col.width;
1493
+ return col.width;
1494
+ }
1495
+ return undefined;
1496
+ });
1497
+ // any unset widths should be calculated.
1498
+ const unsetWidth = unset ? Math.floor(remainingWidth / unset) : 0;
1499
+ return widths.map((w, i) => {
1500
+ if (w === undefined) {
1501
+ return Math.max(unsetWidth, _minWidth(row[i]));
1502
+ }
1503
+ return w;
1504
+ });
1505
+ }
1506
+ }
1507
+ function addBorder(col, ts, style) {
1508
+ if (col.border) {
1509
+ if (/[.']-+[.']/.test(ts)) {
1510
+ return '';
1511
+ }
1512
+ if (ts.trim().length !== 0) {
1513
+ return style;
1514
+ }
1515
+ return ' ';
1516
+ }
1517
+ return '';
1518
+ }
1519
+ // calculates the minimum width of
1520
+ // a column, based on padding preferences.
1521
+ function _minWidth(col) {
1522
+ const padding = col.padding || [];
1523
+ const minWidth = 1 + (padding[left] || 0) + (padding[right] || 0);
1524
+ if (col.border) {
1525
+ return minWidth + 4;
1526
+ }
1527
+ return minWidth;
1528
+ }
1529
+ function getWindowWidth() {
1530
+ /* istanbul ignore next: depends on terminal */
1531
+ if (typeof process === 'object' && process.stdout && process.stdout.columns) {
1532
+ return process.stdout.columns;
1533
+ }
1534
+ return 80;
1535
+ }
1536
+ function alignRight(str, width) {
1537
+ str = str.trim();
1538
+ const strWidth = mixin.stringWidth(str);
1539
+ if (strWidth < width) {
1540
+ return ' '.repeat(width - strWidth) + str;
1541
+ }
1542
+ return str;
1543
+ }
1544
+ function alignCenter(str, width) {
1545
+ str = str.trim();
1546
+ const strWidth = mixin.stringWidth(str);
1547
+ /* istanbul ignore next */
1548
+ if (strWidth >= width) {
1549
+ return str;
1550
+ }
1551
+ return ' '.repeat((width - strWidth) >> 1) + str;
1552
+ }
1553
+ let mixin;
1554
+ function cliui(opts, _mixin) {
1555
+ mixin = _mixin;
1556
+ return new UI({
1557
+ width: (opts === null || opts === void 0 ? void 0 : opts.width) || getWindowWidth(),
1558
+ wrap: opts === null || opts === void 0 ? void 0 : opts.wrap
1559
+ });
1560
+ }
1561
+
1562
+ // Minimal replacement for ansi string helpers "wrap-ansi" and "strip-ansi".
1563
+ // to facilitate ESM and Deno modules.
1564
+ // TODO: look at porting https://www.npmjs.com/package/wrap-ansi to ESM.
1565
+ // The npm application
1566
+ // Copyright (c) npm, Inc. and Contributors
1567
+ // Licensed on the terms of The Artistic License 2.0
1568
+ // See: https://github.com/npm/cli/blob/4c65cd952bc8627811735bea76b9b110cc4fc80e/lib/utils/ansi-trim.js
1569
+ const ansi = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|' +
1570
+ '\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g');
1571
+ function stripAnsi(str) {
1572
+ return str.replace(ansi, '');
1573
+ }
1574
+ function wrap(str, width) {
1575
+ const [start, end] = str.match(ansi) || ['', ''];
1576
+ str = stripAnsi(str);
1577
+ let wrapped = '';
1578
+ for (let i = 0; i < str.length; i++) {
1579
+ if (i !== 0 && (i % width) === 0) {
1580
+ wrapped += '\n';
1581
+ }
1582
+ wrapped += str.charAt(i);
1583
+ }
1584
+ if (start && end) {
1585
+ wrapped = `${start}${wrapped}${end}`;
1586
+ }
1587
+ return wrapped;
1588
+ }
1589
+
1590
+ // Bootstrap cliui with CommonJS dependencies:
1591
+
1592
+ function ui (opts) {
1593
+ return cliui(opts, {
1594
+ stringWidth: (str) => {
1595
+ return [...str].length
1596
+ },
1597
+ stripAnsi,
1598
+ wrap
1599
+ })
1600
+ }
1601
+
1602
+ function escalade (start, callback) {
1603
+ let dir = resolve('.', start);
1604
+ let tmp, stats = statSync(dir);
1605
+
1606
+ if (!stats.isDirectory()) {
1607
+ dir = dirname(dir);
1608
+ }
1609
+
1610
+ while (true) {
1611
+ tmp = callback(dir, readdirSync(dir));
1612
+ if (tmp) return resolve(dir, tmp);
1613
+ dir = dirname(tmp = dir);
1614
+ if (tmp === dir) break;
1615
+ }
1616
+ }
1617
+
1618
+ var shim$1 = {
1619
+ fs: {
1620
+ readFileSync,
1621
+ writeFile
1622
+ },
1623
+ format,
1624
+ resolve,
1625
+ exists: (file) => {
1626
+ try {
1627
+ return statSync(file).isFile();
1628
+ }
1629
+ catch (err) {
1630
+ return false;
1631
+ }
1632
+ }
1633
+ };
1634
+
1635
+ let shim;
1636
+ class Y18N {
1637
+ constructor(opts) {
1638
+ // configurable options.
1639
+ opts = opts || {};
1640
+ this.directory = opts.directory || './locales';
1641
+ this.updateFiles = typeof opts.updateFiles === 'boolean' ? opts.updateFiles : true;
1642
+ this.locale = opts.locale || 'en';
1643
+ this.fallbackToLanguage = typeof opts.fallbackToLanguage === 'boolean' ? opts.fallbackToLanguage : true;
1644
+ // internal stuff.
1645
+ this.cache = Object.create(null);
1646
+ this.writeQueue = [];
1647
+ }
1648
+ __(...args) {
1649
+ if (typeof arguments[0] !== 'string') {
1650
+ return this._taggedLiteral(arguments[0], ...arguments);
1651
+ }
1652
+ const str = args.shift();
1653
+ let cb = function () { }; // start with noop.
1654
+ if (typeof args[args.length - 1] === 'function')
1655
+ cb = args.pop();
1656
+ cb = cb || function () { }; // noop.
1657
+ if (!this.cache[this.locale])
1658
+ this._readLocaleFile();
1659
+ // we've observed a new string, update the language file.
1660
+ if (!this.cache[this.locale][str] && this.updateFiles) {
1661
+ this.cache[this.locale][str] = str;
1662
+ // include the current directory and locale,
1663
+ // since these values could change before the
1664
+ // write is performed.
1665
+ this._enqueueWrite({
1666
+ directory: this.directory,
1667
+ locale: this.locale,
1668
+ cb
1669
+ });
1670
+ }
1671
+ else {
1672
+ cb();
1673
+ }
1674
+ return shim.format.apply(shim.format, [this.cache[this.locale][str] || str].concat(args));
1675
+ }
1676
+ __n() {
1677
+ const args = Array.prototype.slice.call(arguments);
1678
+ const singular = args.shift();
1679
+ const plural = args.shift();
1680
+ const quantity = args.shift();
1681
+ let cb = function () { }; // start with noop.
1682
+ if (typeof args[args.length - 1] === 'function')
1683
+ cb = args.pop();
1684
+ if (!this.cache[this.locale])
1685
+ this._readLocaleFile();
1686
+ let str = quantity === 1 ? singular : plural;
1687
+ if (this.cache[this.locale][singular]) {
1688
+ const entry = this.cache[this.locale][singular];
1689
+ str = entry[quantity === 1 ? 'one' : 'other'];
1690
+ }
1691
+ // we've observed a new string, update the language file.
1692
+ if (!this.cache[this.locale][singular] && this.updateFiles) {
1693
+ this.cache[this.locale][singular] = {
1694
+ one: singular,
1695
+ other: plural
1696
+ };
1697
+ // include the current directory and locale,
1698
+ // since these values could change before the
1699
+ // write is performed.
1700
+ this._enqueueWrite({
1701
+ directory: this.directory,
1702
+ locale: this.locale,
1703
+ cb
1704
+ });
1705
+ }
1706
+ else {
1707
+ cb();
1708
+ }
1709
+ // if a %d placeholder is provided, add quantity
1710
+ // to the arguments expanded by util.format.
1711
+ const values = [str];
1712
+ if (~str.indexOf('%d'))
1713
+ values.push(quantity);
1714
+ return shim.format.apply(shim.format, values.concat(args));
1715
+ }
1716
+ setLocale(locale) {
1717
+ this.locale = locale;
1718
+ }
1719
+ getLocale() {
1720
+ return this.locale;
1721
+ }
1722
+ updateLocale(obj) {
1723
+ if (!this.cache[this.locale])
1724
+ this._readLocaleFile();
1725
+ for (const key in obj) {
1726
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1727
+ this.cache[this.locale][key] = obj[key];
1728
+ }
1729
+ }
1730
+ }
1731
+ _taggedLiteral(parts, ...args) {
1732
+ let str = '';
1733
+ parts.forEach(function (part, i) {
1734
+ const arg = args[i + 1];
1735
+ str += part;
1736
+ if (typeof arg !== 'undefined') {
1737
+ str += '%s';
1738
+ }
1739
+ });
1740
+ return this.__.apply(this, [str].concat([].slice.call(args, 1)));
1741
+ }
1742
+ _enqueueWrite(work) {
1743
+ this.writeQueue.push(work);
1744
+ if (this.writeQueue.length === 1)
1745
+ this._processWriteQueue();
1746
+ }
1747
+ _processWriteQueue() {
1748
+ const _this = this;
1749
+ const work = this.writeQueue[0];
1750
+ // destructure the enqueued work.
1751
+ const directory = work.directory;
1752
+ const locale = work.locale;
1753
+ const cb = work.cb;
1754
+ const languageFile = this._resolveLocaleFile(directory, locale);
1755
+ const serializedLocale = JSON.stringify(this.cache[locale], null, 2);
1756
+ shim.fs.writeFile(languageFile, serializedLocale, 'utf-8', function (err) {
1757
+ _this.writeQueue.shift();
1758
+ if (_this.writeQueue.length > 0)
1759
+ _this._processWriteQueue();
1760
+ cb(err);
1761
+ });
1762
+ }
1763
+ _readLocaleFile() {
1764
+ let localeLookup = {};
1765
+ const languageFile = this._resolveLocaleFile(this.directory, this.locale);
1766
+ try {
1767
+ // When using a bundler such as webpack, readFileSync may not be defined:
1768
+ if (shim.fs.readFileSync) {
1769
+ localeLookup = JSON.parse(shim.fs.readFileSync(languageFile, 'utf-8'));
1770
+ }
1771
+ }
1772
+ catch (err) {
1773
+ if (err instanceof SyntaxError) {
1774
+ err.message = 'syntax error in ' + languageFile;
1775
+ }
1776
+ if (err.code === 'ENOENT')
1777
+ localeLookup = {};
1778
+ else
1779
+ throw err;
1780
+ }
1781
+ this.cache[this.locale] = localeLookup;
1782
+ }
1783
+ _resolveLocaleFile(directory, locale) {
1784
+ let file = shim.resolve(directory, './', locale + '.json');
1785
+ if (this.fallbackToLanguage && !this._fileExistsSync(file) && ~locale.lastIndexOf('_')) {
1786
+ // attempt fallback to language only
1787
+ const languageFile = shim.resolve(directory, './', locale.split('_')[0] + '.json');
1788
+ if (this._fileExistsSync(languageFile))
1789
+ file = languageFile;
1790
+ }
1791
+ return file;
1792
+ }
1793
+ _fileExistsSync(file) {
1794
+ return shim.exists(file);
1795
+ }
1796
+ }
1797
+ function y18n$1(opts, _shim) {
1798
+ shim = _shim;
1799
+ const y18n = new Y18N(opts);
1800
+ return {
1801
+ __: y18n.__.bind(y18n),
1802
+ __n: y18n.__n.bind(y18n),
1803
+ setLocale: y18n.setLocale.bind(y18n),
1804
+ getLocale: y18n.getLocale.bind(y18n),
1805
+ updateLocale: y18n.updateLocale.bind(y18n),
1806
+ locale: y18n.locale
1807
+ };
1808
+ }
1809
+
1810
+ const y18n = (opts) => {
1811
+ return y18n$1(opts, shim$1)
1812
+ };
1813
+
1814
+ const REQUIRE_ERROR = 'require is not supported by ESM';
1815
+ const REQUIRE_DIRECTORY_ERROR = 'loading a directory of commands is not supported yet for ESM';
1816
+
1817
+ let __dirname;
1818
+ try {
1819
+ __dirname = fileURLToPath(import.meta.url);
1820
+ } catch (e) {
1821
+ __dirname = process.cwd();
1822
+ }
1823
+ const mainFilename = __dirname.substring(0, __dirname.lastIndexOf('node_modules'));
1824
+
1825
+ ({
1826
+ assert: {
1827
+ notStrictEqual,
1828
+ strictEqual
1829
+ },
1830
+ cliui: ui,
1831
+ findUp: escalade,
1832
+ getEnv: (key) => {
1833
+ return process.env[key]
1834
+ },
1835
+ inspect,
1836
+ getCallerFile: () => {
1837
+ throw new YError(REQUIRE_DIRECTORY_ERROR)
1838
+ },
1839
+ getProcessArgvBin,
1840
+ mainFilename: mainFilename || process.cwd(),
1841
+ Parser: yargsParser,
1842
+ path: {
1843
+ basename,
1844
+ dirname,
1845
+ extname,
1846
+ relative,
1847
+ resolve
1848
+ },
1849
+ process: {
1850
+ argv: () => process.argv,
1851
+ cwd: process.cwd,
1852
+ emitWarning: (warning, type) => process.emitWarning(warning, type),
1853
+ execPath: () => process.execPath,
1854
+ exit: process.exit,
1855
+ nextTick: process.nextTick,
1856
+ stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null
1857
+ },
1858
+ readFileSync,
1859
+ require: () => {
1860
+ throw new YError(REQUIRE_ERROR)
1861
+ },
1862
+ requireDirectory: () => {
1863
+ throw new YError(REQUIRE_DIRECTORY_ERROR)
1864
+ },
1865
+ stringWidth: (str) => {
1866
+ return [...str].length
1867
+ },
1868
+ y18n: y18n({
1869
+ directory: resolve(__dirname, '../../../locales'),
1870
+ updateFiles: false
1871
+ })
1872
+ });
27
1873
 
28
1874
  var name = "@form8ion/utils-cli";
29
1875
  var description = "cli for various tools for the organization";
30
1876
  var license = "MIT";
31
- var version = "8.0.0-beta.1";
1877
+ var version = "8.0.0";
1878
+ var type = "module";
32
1879
  var engines = {
33
1880
  node: "^16.13.0 || >=18"
34
1881
  };
@@ -37,7 +1884,7 @@ var repository = "form8ion/utils-cli";
37
1884
  var bugs = "https://github.com/form8ion/utils-cli/issues";
38
1885
  var homepage = "https://npm.im/@form8ion/utils-cli";
39
1886
  var bin = {
40
- "form8ion-utils": "bin/form8ion-utils.js"
1887
+ "form8ion-utils": "./bin/form8ion-utils.js"
41
1888
  };
42
1889
  var sideEffects = false;
43
1890
  var scripts = {
@@ -45,16 +1892,19 @@ var scripts = {
45
1892
  "test:unit": "cross-env NODE_ENV=test c8 run-s test:unit:base",
46
1893
  "test:unit:base": "DEBUG=any vitest run",
47
1894
  "test:integration": "run-s 'test:integration:base -- --profile noWip'",
48
- "test:integration:base": "NODE_OPTIONS=--enable-source-maps DEBUG=any cucumber-js test/integration --profile base",
1895
+ "test:integration:base": "NODE_OPTIONS=\"--loader=testdouble --enable-source-maps $NODE_OPTIONS\" DEBUG=any cucumber-js test/integration",
49
1896
  "test:integration:debug": "DEBUG=nock.* run-s test:integration",
50
1897
  "test:integration:wip": "run-s 'test:integration:base -- --profile wip'",
51
1898
  "test:integration:focus": "run-s 'test:integration:base -- --profile focus'",
1899
+ "pretest:e2e": "run-s build",
1900
+ "test:e2e": "NODE_OPTIONS=--enable-source-maps node ./test/e2e/smoke-test.js",
52
1901
  "lint:js": "eslint . --cache",
53
1902
  "lint:md": "remark . --frail",
54
1903
  "lint:sensitive": "ban",
55
1904
  "lint:engines": "ls-engines",
56
1905
  "lint:gherkin": "gherkin-lint",
57
1906
  "lint:peer": "npm ls >/dev/null",
1907
+ "lint:lockfile": "lockfile-lint",
58
1908
  clean: "rimraf ./bin",
59
1909
  prebuild: "run-s clean",
60
1910
  build: "npm-run-all --print-label --parallel build:*",
@@ -91,15 +1941,11 @@ var dependencies = {
91
1941
  "@form8ion/vite": "1.3.1",
92
1942
  "@form8ion/vitest": "2.1.0",
93
1943
  "@travi/github-scaffolder": "8.0.4",
94
- "source-map-support": "0.5.21",
95
1944
  "update-notifier": "5.1.0",
96
1945
  yargs: "17.7.1"
97
1946
  };
98
1947
  var devDependencies = {
99
- "@babel/node": "7.20.7",
100
- "@babel/register": "7.21.0",
101
1948
  "@cucumber/cucumber": "9.0.1",
102
- "@form8ion/babel-preset": "1.6.99",
103
1949
  "@form8ion/commitlint-config": "1.0.46",
104
1950
  "@form8ion/core": "2.0.0",
105
1951
  "@form8ion/eslint-config": "5.0.27",
@@ -114,12 +1960,14 @@ var devDependencies = {
114
1960
  "clear-module": "4.1.2",
115
1961
  "cross-env": "7.0.3",
116
1962
  "cz-conventional-changelog": "3.3.0",
1963
+ execa: "7.1.1",
117
1964
  "gherkin-lint": "4.2.2",
118
1965
  "http-status-codes": "2.2.0",
119
1966
  husky: "8.0.3",
120
1967
  "import-fresh": "3.3.0",
121
1968
  "jest-when": "3.5.2",
122
1969
  "js-yaml": "4.1.0",
1970
+ "lockfile-lint": "4.10.1",
123
1971
  "ls-engines": "0.9.0",
124
1972
  "mdast-util-from-markdown": "0.8.5",
125
1973
  "mdast-zone": "4.0.1",
@@ -128,7 +1976,7 @@ var devDependencies = {
128
1976
  "npm-run-all": "4.1.5",
129
1977
  "remark-cli": "11.0.0",
130
1978
  rimraf: "4.4.1",
131
- rollup: "3.20.0",
1979
+ rollup: "3.20.1",
132
1980
  "rollup-plugin-auto-external": "2.0.0",
133
1981
  "rollup-plugin-executable": "1.6.3",
134
1982
  "rollup-plugin-json": "4.0.0",
@@ -141,6 +1989,7 @@ var pkg = {
141
1989
  description: description,
142
1990
  license: license,
143
1991
  version: version,
1992
+ type: type,
144
1993
  engines: engines,
145
1994
  author: author,
146
1995
  repository: repository,
@@ -172,33 +2021,33 @@ const javascriptConfigs = {
172
2021
  };
173
2022
 
174
2023
  function javascriptScaffolderFactory(decisions) {
175
- return options => javascript$1.scaffold({
2024
+ return options => scaffold({
176
2025
  ...options,
177
2026
  configs: javascriptConfigs,
178
2027
  overrides: {npmAccount: 'form8ion'},
179
2028
  ciServices: {
180
- 'GitHub Actions': {scaffolder: githubActionsNodeCi.scaffold, public: true}
2029
+ 'GitHub Actions': {scaffolder: scaffold$1, public: true}
181
2030
  },
182
- applicationTypes: {Hapi: {scaffolder: hapiScaffolder.scaffold}},
2031
+ applicationTypes: {Hapi: {scaffolder: scaffold$2}},
183
2032
  packageTypes: {
184
- 'form8ion Plugin': {scaffolder: scaffolderScaffolder.scaffold},
185
- 'Remark Plugin': {scaffolder: remarkPluginScaffolder.scaffold},
186
- 'Octoherd Script': {scaffolder: octoherdScript.scaffold}
2033
+ 'form8ion Plugin': {scaffolder: scaffold$3},
2034
+ 'Remark Plugin': {scaffolder: scaffold$4},
2035
+ 'Octoherd Script': {scaffolder: scaffold$5}
187
2036
  },
188
2037
  unitTestFrameworks: {
189
- mocha: {scaffolder: mochaScaffolder.scaffold},
190
- vitest: {scaffolder: vitest.scaffold}
2038
+ mocha: {scaffolder: scaffold$6},
2039
+ vitest: {scaffolder: scaffold$7}
191
2040
  },
192
2041
  packageBundlers: {
193
- Rollup: {scaffolder: rollup.scaffold},
194
- Vite: {scaffolder: vite.scaffold}
2042
+ Rollup: {scaffolder: scaffold$8},
2043
+ Vite: {scaffolder: scaffold$9}
195
2044
  },
196
2045
  decisions
197
2046
  });
198
2047
  }
199
2048
 
200
2049
  function githubPromptFactory(decisions) {
201
- return () => githubScaffolder.prompt({account: 'form8ion', decisions});
2050
+ return () => prompt({account: 'form8ion', decisions});
202
2051
  }
203
2052
 
204
2053
  function handler$1(decisions) {
@@ -206,25 +2055,25 @@ function handler$1(decisions) {
206
2055
  const traviName = 'Matt Travi';
207
2056
  const decisionsWithEnhancements = {
208
2057
  ...decisions,
209
- [project.questionNames.COPYRIGHT_HOLDER]: traviName,
210
- [project.questionNames.REPO_HOST]: 'GitHub',
211
- [project.questionNames.REPO_OWNER]: orgName,
212
- [project.questionNames.DEPENDENCY_UPDATER]: 'Renovate',
213
- [javascript$1.questionNames.AUTHOR_NAME]: traviName,
214
- [javascript$1.questionNames.AUTHOR_EMAIL]: 'npm@travi.org',
215
- [javascript$1.questionNames.AUTHOR_URL]: 'https://matt.travi.org',
216
- [javascript$1.questionNames.UNIT_TEST_FRAMEWORK]: 'mocha',
217
- [javascript$1.questionNames.SCOPE]: orgName,
218
- [javascript$1.questionNames.PACKAGE_MANAGER]: javascriptCore.packageManagers.NPM
2058
+ [questionNames.COPYRIGHT_HOLDER]: traviName,
2059
+ [questionNames.REPO_HOST]: 'GitHub',
2060
+ [questionNames.REPO_OWNER]: orgName,
2061
+ [questionNames.DEPENDENCY_UPDATER]: 'Renovate',
2062
+ [questionNames$1.AUTHOR_NAME]: traviName,
2063
+ [questionNames$1.AUTHOR_EMAIL]: 'npm@travi.org',
2064
+ [questionNames$1.AUTHOR_URL]: 'https://matt.travi.org',
2065
+ [questionNames$1.UNIT_TEST_FRAMEWORK]: 'mocha',
2066
+ [questionNames$1.SCOPE]: orgName,
2067
+ [questionNames$1.PACKAGE_MANAGER]: packageManagers.NPM
219
2068
  };
220
2069
 
221
- return project.scaffold({
2070
+ return scaffold$a({
222
2071
  languages: {JavaScript: javascriptScaffolderFactory(decisionsWithEnhancements)},
223
2072
  vcsHosts: {
224
- GitHub: {scaffolder: githubScaffolder.scaffold, prompt: githubPromptFactory(decisionsWithEnhancements), public: true}
2073
+ GitHub: {scaffolder: scaffold$b, prompt: githubPromptFactory(decisionsWithEnhancements), public: true}
225
2074
  },
226
2075
  overrides: {copyrightHolder: traviName},
227
- dependencyUpdaters: {Renovate: {scaffolder: renovateScaffolder.scaffold}},
2076
+ dependencyUpdaters: {Renovate: {scaffolder: scaffold$c}},
228
2077
  decisions: decisionsWithEnhancements
229
2078
  });
230
2079
  }
@@ -233,39 +2082,39 @@ const command$1 = 'scaffold';
233
2082
  const describe$1 = 'Scaffold a new project';
234
2083
 
235
2084
  var scaffoldCommand = /*#__PURE__*/Object.freeze({
236
- __proto__: null,
237
- command: command$1,
238
- describe: describe$1,
239
- handler: handler$1
2085
+ __proto__: null,
2086
+ command: command$1,
2087
+ describe: describe$1,
2088
+ handler: handler$1
240
2089
  });
241
2090
 
242
2091
  function javascript(options) {
243
- return javascript$1.lift({...options, configs: javascriptConfigs});
2092
+ return lift({...options, configs: javascriptConfigs});
244
2093
  }
245
2094
 
246
2095
  function getEnhancedCodecovScaffolder() {
247
- return options => codecov.scaffold({...options, visibility: 'Public'});
2096
+ return options => scaffold$d({...options, visibility: 'Public'});
248
2097
  }
249
2098
 
250
2099
  function prettier(options) {
251
- return prettier$1.scaffold({...options, config: javascriptConfigs.prettier});
2100
+ return scaffold$e({...options, config: javascriptConfigs.prettier});
252
2101
  }
253
2102
 
254
2103
  function handler({decisions}) {
255
- return lift.lift({
2104
+ return lift$1({
256
2105
  decisions,
257
2106
  scaffolders: {
258
- Renovate: renovateScaffolder.scaffold,
259
- Cucumber: cucumberScaffolder.scaffold,
2107
+ Renovate: scaffold$c,
2108
+ Cucumber: scaffold$f,
260
2109
  Codecov: getEnhancedCodecovScaffolder(),
261
2110
  Prettier: prettier,
262
- 'Remove Greenkeeper': removeGreenkeeper.removeGreenkeeper,
263
- 'Replace Travis CI with GitHub Actions': replaceTravisCiWithGithubActions.replace
2111
+ 'Remove Greenkeeper': removeGreenkeeper,
2112
+ 'Replace Travis CI with GitHub Actions': replace
264
2113
  },
265
2114
  enhancers: {
266
- JavaScript: {test: javascript$1.test, lift: javascript},
267
- Renovate: {test: renovateScaffolder.predicate, lift: renovateScaffolder.lift},
268
- 'GitHub Actions CI': {test: githubActionsNodeCi.test, lift: githubActionsNodeCi.lift}
2115
+ JavaScript: {test: test, lift: javascript},
2116
+ Renovate: {test: predicate, lift: lift$2},
2117
+ 'GitHub Actions CI': {test: test$1, lift: lift$3}
269
2118
  }
270
2119
  });
271
2120
  }
@@ -274,10 +2123,10 @@ const command = 'lift';
274
2123
  const describe = 'Lift an existing project with additional functionality';
275
2124
 
276
2125
  var liftCommand = /*#__PURE__*/Object.freeze({
277
- __proto__: null,
278
- command: command,
279
- describe: describe,
280
- handler: handler
2126
+ __proto__: null,
2127
+ command: command,
2128
+ describe: describe,
2129
+ handler: handler
281
2130
  });
282
2131
 
283
2132
  function cli (yargs) {
@@ -292,7 +2141,7 @@ function cli (yargs) {
292
2141
  .argv;
293
2142
  }
294
2143
 
295
- cli(yargs);
2144
+ cli(yargs(hideBin(process.argv)));
296
2145
 
297
2146
  updateNotifier({pkg}).notify();
298
2147
  //# sourceMappingURL=form8ion-utils.js.map