@baic/yolk-cli 2.1.0-alpha.250 → 2.1.0-alpha.252
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.
- package/README.md +4 -4
- package/compiled/commander/index.d.ts +192 -44
- package/compiled/commander/index.js +1 -1
- package/compiled/commander/package.json +1 -1
- package/es/yolk.js +1 -1
- package/lib/yolk.js +1 -1
- package/package.json +12 -12
- package/templates/taro-miniprogram/.gitignore.tpl +6 -1
- package/templates/umi-mobile/.gitignore.tpl +5 -0
- package/templates/umi-mobile-h5+app/.gitignore.tpl +5 -0
- package/templates/umi-mobile-native/.gitignore.tpl +5 -0
- package/templates/umi-mobile-uni-app/.gitignore.tpl +5 -0
- package/templates/umi-web/.gitignore.tpl +5 -0
- package/templates/umi-web-screen/.gitignore.tpl +5 -0
package/README.md
CHANGED
|
@@ -3,25 +3,25 @@
|
|
|
3
3
|
## 脚手架
|
|
4
4
|
|
|
5
5
|
```shell
|
|
6
|
-
|
|
6
|
+
npm install -g @baic/yolk-cli
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
## 初始化项目
|
|
10
10
|
|
|
11
11
|
```shell
|
|
12
|
-
|
|
12
|
+
yolk init
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## 启动项目
|
|
16
16
|
|
|
17
17
|
```shell
|
|
18
|
-
|
|
18
|
+
yolk start
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## 编译项目
|
|
22
22
|
|
|
23
23
|
```shell
|
|
24
|
-
|
|
24
|
+
yolk build
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
## .yolkrc
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare interface AddHelpTextContext {
|
|
1
|
+
export declare interface AddHelpTextContext {
|
|
2
|
+
// passed to text function used with .addHelpText()
|
|
2
3
|
error: boolean;
|
|
3
4
|
command: Command;
|
|
4
5
|
}
|
|
@@ -95,7 +96,10 @@ export declare class Command {
|
|
|
95
96
|
* @param opts - configuration options
|
|
96
97
|
* @returns new command
|
|
97
98
|
*/
|
|
98
|
-
command(
|
|
99
|
+
command(
|
|
100
|
+
nameAndArgs: string,
|
|
101
|
+
opts?: CommandOptions,
|
|
102
|
+
): ReturnType<this['createCommand']>;
|
|
99
103
|
/**
|
|
100
104
|
* Define a command, implemented in a separate executable file.
|
|
101
105
|
*
|
|
@@ -114,7 +118,11 @@ export declare class Command {
|
|
|
114
118
|
* @param opts - configuration options
|
|
115
119
|
* @returns `this` command for chaining
|
|
116
120
|
*/
|
|
117
|
-
command(
|
|
121
|
+
command(
|
|
122
|
+
nameAndArgs: string,
|
|
123
|
+
description: string,
|
|
124
|
+
opts?: ExecutableCommandOptions,
|
|
125
|
+
): this;
|
|
118
126
|
|
|
119
127
|
/**
|
|
120
128
|
* Factory routine to create a new unattached command.
|
|
@@ -155,7 +163,12 @@ export declare class Command {
|
|
|
155
163
|
*
|
|
156
164
|
* @returns `this` command for chaining
|
|
157
165
|
*/
|
|
158
|
-
argument<T>(
|
|
166
|
+
argument<T>(
|
|
167
|
+
flags: string,
|
|
168
|
+
description: string,
|
|
169
|
+
fn: (value: string, previous: T) => T,
|
|
170
|
+
defaultValue?: T,
|
|
171
|
+
): this;
|
|
159
172
|
argument(name: string, description?: string, defaultValue?: unknown): this;
|
|
160
173
|
|
|
161
174
|
/**
|
|
@@ -205,7 +218,13 @@ export declare class Command {
|
|
|
205
218
|
/**
|
|
206
219
|
* Add hook for life cycle event.
|
|
207
220
|
*/
|
|
208
|
-
hook(
|
|
221
|
+
hook(
|
|
222
|
+
event: HookEvent,
|
|
223
|
+
listener: (
|
|
224
|
+
thisCommand: Command,
|
|
225
|
+
actionCommand: Command,
|
|
226
|
+
) => void | Promise<void>,
|
|
227
|
+
): this;
|
|
209
228
|
|
|
210
229
|
/**
|
|
211
230
|
* Register callback to use as replacement for calling process.exit.
|
|
@@ -283,7 +302,7 @@ export declare class Command {
|
|
|
283
302
|
*
|
|
284
303
|
* @returns `this` command for chaining
|
|
285
304
|
*/
|
|
286
|
-
action(fn: (...args: any[]) => void | Promise<void>): this;
|
|
305
|
+
action(fn: (this: this, ...args: any[]) => void | Promise<void>): this;
|
|
287
306
|
|
|
288
307
|
/**
|
|
289
308
|
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
|
|
@@ -298,17 +317,31 @@ export declare class Command {
|
|
|
298
317
|
* ```js
|
|
299
318
|
* program
|
|
300
319
|
* .option('-p, --pepper', 'add pepper')
|
|
301
|
-
* .option('
|
|
320
|
+
* .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
|
|
302
321
|
* .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
|
|
303
322
|
* .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
|
|
304
323
|
* ```
|
|
305
324
|
*
|
|
306
325
|
* @returns `this` command for chaining
|
|
307
326
|
*/
|
|
308
|
-
option(
|
|
309
|
-
|
|
327
|
+
option(
|
|
328
|
+
flags: string,
|
|
329
|
+
description?: string,
|
|
330
|
+
defaultValue?: string | boolean | string[],
|
|
331
|
+
): this;
|
|
332
|
+
option<T>(
|
|
333
|
+
flags: string,
|
|
334
|
+
description: string,
|
|
335
|
+
parseArg: (value: string, previous: T) => T,
|
|
336
|
+
defaultValue?: T,
|
|
337
|
+
): this;
|
|
310
338
|
/** @deprecated since v7, instead use choices or a custom function */
|
|
311
|
-
option(
|
|
339
|
+
option(
|
|
340
|
+
flags: string,
|
|
341
|
+
description: string,
|
|
342
|
+
regexp: RegExp,
|
|
343
|
+
defaultValue?: string | boolean | string[],
|
|
344
|
+
): this;
|
|
312
345
|
|
|
313
346
|
/**
|
|
314
347
|
* Define a required option, which must have a value after parsing. This usually means
|
|
@@ -316,10 +349,24 @@ export declare class Command {
|
|
|
316
349
|
*
|
|
317
350
|
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
|
|
318
351
|
*/
|
|
319
|
-
requiredOption(
|
|
320
|
-
|
|
352
|
+
requiredOption(
|
|
353
|
+
flags: string,
|
|
354
|
+
description?: string,
|
|
355
|
+
defaultValue?: string | boolean | string[],
|
|
356
|
+
): this;
|
|
357
|
+
requiredOption<T>(
|
|
358
|
+
flags: string,
|
|
359
|
+
description: string,
|
|
360
|
+
parseArg: (value: string, previous: T) => T,
|
|
361
|
+
defaultValue?: T,
|
|
362
|
+
): this;
|
|
321
363
|
/** @deprecated since v7, instead use choices or a custom function */
|
|
322
|
-
requiredOption(
|
|
364
|
+
requiredOption(
|
|
365
|
+
flags: string,
|
|
366
|
+
description: string,
|
|
367
|
+
regexp: RegExp,
|
|
368
|
+
defaultValue?: string | boolean | string[],
|
|
369
|
+
): this;
|
|
323
370
|
|
|
324
371
|
/**
|
|
325
372
|
* Factory routine to create a new unattached option.
|
|
@@ -344,7 +391,9 @@ export declare class Command {
|
|
|
344
391
|
* @returns `this` command for chaining
|
|
345
392
|
*/
|
|
346
393
|
storeOptionsAsProperties<T extends OptionValues>(): this & T;
|
|
347
|
-
storeOptionsAsProperties<T extends OptionValues>(
|
|
394
|
+
storeOptionsAsProperties<T extends OptionValues>(
|
|
395
|
+
storeAsProperties: true,
|
|
396
|
+
): this & T;
|
|
348
397
|
storeOptionsAsProperties(storeAsProperties?: boolean): this;
|
|
349
398
|
|
|
350
399
|
/**
|
|
@@ -360,7 +409,11 @@ export declare class Command {
|
|
|
360
409
|
/**
|
|
361
410
|
* Store option value and where the value came from.
|
|
362
411
|
*/
|
|
363
|
-
setOptionValueWithSource(
|
|
412
|
+
setOptionValueWithSource(
|
|
413
|
+
key: string,
|
|
414
|
+
value: unknown,
|
|
415
|
+
source: OptionValueSource,
|
|
416
|
+
): this;
|
|
364
417
|
|
|
365
418
|
/**
|
|
366
419
|
* Get source of option value.
|
|
@@ -424,43 +477,72 @@ export declare class Command {
|
|
|
424
477
|
/**
|
|
425
478
|
* Parse `argv`, setting options and invoking commands when defined.
|
|
426
479
|
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
480
|
+
* Use parseAsync instead of parse if any of your action handlers are async.
|
|
481
|
+
*
|
|
482
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
483
|
+
*
|
|
484
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
485
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
486
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
487
|
+
* - `'user'`: just user arguments
|
|
429
488
|
*
|
|
430
489
|
* @example
|
|
431
490
|
* ```
|
|
432
|
-
* program.parse(process.argv
|
|
433
|
-
* program.parse(); //
|
|
491
|
+
* program.parse(); // parse process.argv and auto-detect electron and special node flags
|
|
492
|
+
* program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
|
434
493
|
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
435
494
|
* ```
|
|
436
495
|
*
|
|
437
496
|
* @returns `this` command for chaining
|
|
438
497
|
*/
|
|
439
|
-
parse(argv?: readonly string[],
|
|
498
|
+
parse(argv?: readonly string[], parseOptions?: ParseOptions): this;
|
|
440
499
|
|
|
441
500
|
/**
|
|
442
501
|
* Parse `argv`, setting options and invoking commands when defined.
|
|
443
502
|
*
|
|
444
|
-
*
|
|
503
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
445
504
|
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
505
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
506
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
507
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
508
|
+
* - `'user'`: just user arguments
|
|
448
509
|
*
|
|
449
510
|
* @example
|
|
450
511
|
* ```
|
|
451
|
-
* program.parseAsync(process.argv
|
|
452
|
-
* program.parseAsync(); //
|
|
453
|
-
* program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
512
|
+
* await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
|
|
513
|
+
* await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
|
|
514
|
+
* await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
454
515
|
* ```
|
|
455
516
|
*
|
|
456
517
|
* @returns Promise
|
|
457
518
|
*/
|
|
458
|
-
parseAsync(
|
|
519
|
+
parseAsync(
|
|
520
|
+
argv?: readonly string[],
|
|
521
|
+
parseOptions?: ParseOptions,
|
|
522
|
+
): Promise<this>;
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
|
|
526
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
527
|
+
*
|
|
528
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state saved.
|
|
529
|
+
*/
|
|
530
|
+
saveStateBeforeParse(): void;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Restore state before parse for calls after the first.
|
|
534
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
535
|
+
*
|
|
536
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state restored.
|
|
537
|
+
*/
|
|
538
|
+
restoreStateBeforeParse(): void;
|
|
459
539
|
|
|
460
540
|
/**
|
|
461
541
|
* Parse options from `argv` removing known options,
|
|
462
542
|
* and return argv split into operands and unknown arguments.
|
|
463
543
|
*
|
|
544
|
+
* Side effects: modifies command by storing options. Does not reset state if called again.
|
|
545
|
+
*
|
|
464
546
|
* argv => operands, unknown
|
|
465
547
|
* --known kkk op => [op], []
|
|
466
548
|
* op --known kkk => [op], []
|
|
@@ -630,7 +712,10 @@ export declare class Command {
|
|
|
630
712
|
* and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
|
|
631
713
|
*/
|
|
632
714
|
addHelpText(position: AddHelpTextPosition, text: string): this;
|
|
633
|
-
addHelpText(
|
|
715
|
+
addHelpText(
|
|
716
|
+
position: AddHelpTextPosition,
|
|
717
|
+
text: (context: AddHelpTextContext) => string,
|
|
718
|
+
): this;
|
|
634
719
|
|
|
635
720
|
/**
|
|
636
721
|
* Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
|
|
@@ -649,7 +734,6 @@ export declare class CommanderError extends Error {
|
|
|
649
734
|
* @param exitCode - suggested exit code which could be used with process.exit
|
|
650
735
|
* @param code - an id string representing the error
|
|
651
736
|
* @param message - human-readable description of the error
|
|
652
|
-
* @constructor
|
|
653
737
|
*/
|
|
654
738
|
constructor(exitCode: number, code: string, message: string);
|
|
655
739
|
}
|
|
@@ -667,7 +751,8 @@ export declare function createCommand(name?: string): Command;
|
|
|
667
751
|
|
|
668
752
|
export declare function createOption(flags: string, description?: string): Option_2;
|
|
669
753
|
|
|
670
|
-
export declare interface ErrorOptions {
|
|
754
|
+
export declare interface ErrorOptions {
|
|
755
|
+
// optional parameter for error()
|
|
671
756
|
/** an id string representing the error */
|
|
672
757
|
code?: string;
|
|
673
758
|
/** suggested exit code which could be used with process.exit */
|
|
@@ -681,12 +766,25 @@ export declare interface ExecutableCommandOptions extends CommandOptions {
|
|
|
681
766
|
export declare class Help {
|
|
682
767
|
/** output helpWidth, long lines are wrapped to fit */
|
|
683
768
|
helpWidth?: number;
|
|
769
|
+
minWidthToWrap: number;
|
|
684
770
|
sortSubcommands: boolean;
|
|
685
771
|
sortOptions: boolean;
|
|
686
772
|
showGlobalOptions: boolean;
|
|
687
773
|
|
|
688
774
|
constructor();
|
|
689
775
|
|
|
776
|
+
/*
|
|
777
|
+
* prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
|
|
778
|
+
* and just before calling `formatHelp()`.
|
|
779
|
+
*
|
|
780
|
+
* Commander just uses the helpWidth and the others are provided for subclasses.
|
|
781
|
+
*/
|
|
782
|
+
prepareContext(contextOptions: {
|
|
783
|
+
error?: boolean;
|
|
784
|
+
helpWidth?: number;
|
|
785
|
+
outputHasColors?: boolean;
|
|
786
|
+
}): void;
|
|
787
|
+
|
|
690
788
|
/** Get the command term to show in the list of subcommands. */
|
|
691
789
|
subcommandTerm(cmd: Command): string;
|
|
692
790
|
/** Get the command summary to show in the list of subcommands. */
|
|
@@ -722,14 +820,61 @@ export declare class Help {
|
|
|
722
820
|
longestGlobalOptionTermLength(cmd: Command, helper: Help): number;
|
|
723
821
|
/** Get the longest argument term length. */
|
|
724
822
|
longestArgumentTermLength(cmd: Command, helper: Help): number;
|
|
823
|
+
|
|
824
|
+
/** Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations. */
|
|
825
|
+
displayWidth(str: string): number;
|
|
826
|
+
|
|
827
|
+
/** Style the titles. Called with 'Usage:', 'Options:', etc. */
|
|
828
|
+
styleTitle(title: string): string;
|
|
829
|
+
|
|
830
|
+
/** Usage: <str> */
|
|
831
|
+
styleUsage(str: string): string;
|
|
832
|
+
/** Style for command name in usage string. */
|
|
833
|
+
styleCommandText(str: string): string;
|
|
834
|
+
|
|
835
|
+
styleCommandDescription(str: string): string;
|
|
836
|
+
styleOptionDescription(str: string): string;
|
|
837
|
+
styleSubcommandDescription(str: string): string;
|
|
838
|
+
styleArgumentDescription(str: string): string;
|
|
839
|
+
/** Base style used by descriptions. */
|
|
840
|
+
styleDescriptionText(str: string): string;
|
|
841
|
+
|
|
842
|
+
styleOptionTerm(str: string): string;
|
|
843
|
+
styleSubcommandTerm(str: string): string;
|
|
844
|
+
styleArgumentTerm(str: string): string;
|
|
845
|
+
|
|
846
|
+
/** Base style used in terms and usage for options. */
|
|
847
|
+
styleOptionText(str: string): string;
|
|
848
|
+
/** Base style used in terms and usage for subcommands. */
|
|
849
|
+
styleSubcommandText(str: string): string;
|
|
850
|
+
/** Base style used in terms and usage for arguments. */
|
|
851
|
+
styleArgumentText(str: string): string;
|
|
852
|
+
|
|
725
853
|
/** Calculate the pad width from the maximum term length. */
|
|
726
854
|
padWidth(cmd: Command, helper: Help): number;
|
|
727
855
|
|
|
728
856
|
/**
|
|
729
|
-
* Wrap
|
|
730
|
-
*
|
|
857
|
+
* Wrap a string at whitespace, preserving existing line breaks.
|
|
858
|
+
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
731
859
|
*/
|
|
732
|
-
|
|
860
|
+
boxWrap(str: string, width: number): string;
|
|
861
|
+
|
|
862
|
+
/** Detect manually wrapped and indented strings by checking for line break followed by whitespace. */
|
|
863
|
+
preformatted(str: string): boolean;
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
867
|
+
*
|
|
868
|
+
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
869
|
+
* TTT DDD DDDD
|
|
870
|
+
* DD DDD
|
|
871
|
+
*/
|
|
872
|
+
formatItem(
|
|
873
|
+
term: string,
|
|
874
|
+
termWidth: number,
|
|
875
|
+
description: string,
|
|
876
|
+
helper: Help,
|
|
877
|
+
): string;
|
|
733
878
|
|
|
734
879
|
/** Generate the built-in help text. */
|
|
735
880
|
formatHelp(cmd: Command, helper: Help): string;
|
|
@@ -737,7 +882,8 @@ export declare class Help {
|
|
|
737
882
|
|
|
738
883
|
export declare type HelpConfiguration = Partial<Help>;
|
|
739
884
|
|
|
740
|
-
export declare interface HelpContext {
|
|
885
|
+
export declare interface HelpContext {
|
|
886
|
+
// optional parameter for .help() and .outputHelp()
|
|
741
887
|
error: boolean;
|
|
742
888
|
}
|
|
743
889
|
|
|
@@ -747,14 +893,15 @@ declare class InvalidArgumentError extends CommanderError {
|
|
|
747
893
|
/**
|
|
748
894
|
* Constructs the InvalidArgumentError class
|
|
749
895
|
* @param message - explanation of why argument is invalid
|
|
750
|
-
* @constructor
|
|
751
896
|
*/
|
|
752
897
|
constructor(message: string);
|
|
753
898
|
}
|
|
754
899
|
export { InvalidArgumentError }
|
|
755
900
|
export { InvalidArgumentError as InvalidOptionArgumentError }
|
|
756
901
|
|
|
757
|
-
declare type LiteralUnion<LiteralType, BaseType extends string | number> =
|
|
902
|
+
declare type LiteralUnion<LiteralType, BaseType extends string | number> =
|
|
903
|
+
| LiteralType
|
|
904
|
+
| (BaseType & Record<never, never>);
|
|
758
905
|
|
|
759
906
|
declare class Option_2 {
|
|
760
907
|
flags: string;
|
|
@@ -826,11 +973,6 @@ declare class Option_2 {
|
|
|
826
973
|
*/
|
|
827
974
|
env(name: string): this;
|
|
828
975
|
|
|
829
|
-
/**
|
|
830
|
-
* Calculate the full description, including defaultValue etc.
|
|
831
|
-
*/
|
|
832
|
-
fullDescription(): string;
|
|
833
|
-
|
|
834
976
|
/**
|
|
835
977
|
* Set the custom handler for processing CLI option arguments into option values.
|
|
836
978
|
*/
|
|
@@ -858,7 +1000,7 @@ declare class Option_2 {
|
|
|
858
1000
|
|
|
859
1001
|
/**
|
|
860
1002
|
* Return option name, in a camelcase format that can be used
|
|
861
|
-
* as
|
|
1003
|
+
* as an object attribute key.
|
|
862
1004
|
*/
|
|
863
1005
|
attributeName(): string;
|
|
864
1006
|
|
|
@@ -873,15 +1015,21 @@ export { Option_2 as Option }
|
|
|
873
1015
|
|
|
874
1016
|
export declare type OptionValues = Record<string, any>;
|
|
875
1017
|
|
|
876
|
-
export declare type OptionValueSource =
|
|
1018
|
+
export declare type OptionValueSource =
|
|
1019
|
+
| LiteralUnion<'default' | 'config' | 'env' | 'cli' | 'implied', string>
|
|
1020
|
+
| undefined;
|
|
877
1021
|
|
|
878
1022
|
export declare interface OutputConfiguration {
|
|
879
1023
|
writeOut?(str: string): void;
|
|
880
1024
|
writeErr?(str: string): void;
|
|
1025
|
+
outputError?(str: string, write: (str: string) => void): void;
|
|
1026
|
+
|
|
881
1027
|
getOutHelpWidth?(): number;
|
|
882
1028
|
getErrHelpWidth?(): number;
|
|
883
|
-
outputError?(str: string, write: (str: string) => void): void;
|
|
884
1029
|
|
|
1030
|
+
getOutHasColors?(): boolean;
|
|
1031
|
+
getErrHasColors?(): boolean;
|
|
1032
|
+
stripColor?(str: string): string;
|
|
885
1033
|
}
|
|
886
1034
|
|
|
887
1035
|
export declare interface ParseOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var t={718:function(t){"use strict";t.exports=require("node:child_process")},673:function(t){"use strict";t.exports=require("node:events")},561:function(t){"use strict";t.exports=require("node:fs")},411:function(t){"use strict";t.exports=require("node:path")},742:function(t){"use strict";t.exports=require("node:process")},142:function(t,e,i){const{InvalidArgumentError:n}=i(841);class Argument{constructor(t,e){this.description=e||"";this.variadic=false;this.parseArg=undefined;this.defaultValue=undefined;this.defaultValueDescription=undefined;this.argChoices=undefined;switch(t[0]){case"<":this.required=true;this._name=t.slice(1,-1);break;case"[":this.required=false;this._name=t.slice(1,-1);break;default:this.required=true;this._name=t;break}if(this._name.length>3&&this._name.slice(-3)==="..."){this.variadic=true;this._name=this._name.slice(0,-3)}}name(){return this._name}_concatValue(t,e){if(e===this.defaultValue||!Array.isArray(e)){return[t]}return e.concat(t)}default(t,e){this.defaultValue=t;this.defaultValueDescription=e;return this}argParser(t){this.parseArg=t;return this}choices(t){this.argChoices=t.slice();this.parseArg=(t,e)=>{if(!this.argChoices.includes(t)){throw new n(`Allowed choices are ${this.argChoices.join(", ")}.`)}if(this.variadic){return this._concatValue(t,e)}return t};return this}argRequired(){this.required=true;return this}argOptional(){this.required=false;return this}}function humanReadableArgName(t){const e=t.name()+(t.variadic===true?"...":"");return t.required?"<"+e+">":"["+e+"]"}e.Argument=Argument;e.humanReadableArgName=humanReadableArgName},728:function(t,e,i){const n=i(673).EventEmitter;const s=i(718);const r=i(411);const o=i(561);const a=i(742);const{Argument:h,humanReadableArgName:l}=i(142);const{CommanderError:u}=i(841);const{Help:c}=i(202);const{Option:p,DualOptions:d}=i(257);const{suggestSimilar:m}=i(824);class Command extends n{constructor(t){super();this.commands=[];this.options=[];this.parent=null;this._allowUnknownOption=false;this._allowExcessArguments=true;this.registeredArguments=[];this._args=this.registeredArguments;this.args=[];this.rawArgs=[];this.processedArgs=[];this._scriptPath=null;this._name=t||"";this._optionValues={};this._optionValueSources={};this._storeOptionsAsProperties=false;this._actionHandler=null;this._executableHandler=false;this._executableFile=null;this._executableDir=null;this._defaultCommandName=null;this._exitCallback=null;this._aliases=[];this._combineFlagAndOptionalValue=true;this._description="";this._summary="";this._argsDescription=undefined;this._enablePositionalOptions=false;this._passThroughOptions=false;this._lifeCycleHooks={};this._showHelpAfterError=false;this._showSuggestionAfterError=true;this._outputConfiguration={writeOut:t=>a.stdout.write(t),writeErr:t=>a.stderr.write(t),getOutHelpWidth:()=>a.stdout.isTTY?a.stdout.columns:undefined,getErrHelpWidth:()=>a.stderr.isTTY?a.stderr.columns:undefined,outputError:(t,e)=>e(t)};this._hidden=false;this._helpOption=undefined;this._addImplicitHelpCommand=undefined;this._helpCommand=undefined;this._helpConfiguration={}}copyInheritedSettings(t){this._outputConfiguration=t._outputConfiguration;this._helpOption=t._helpOption;this._helpCommand=t._helpCommand;this._helpConfiguration=t._helpConfiguration;this._exitCallback=t._exitCallback;this._storeOptionsAsProperties=t._storeOptionsAsProperties;this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue;this._allowExcessArguments=t._allowExcessArguments;this._enablePositionalOptions=t._enablePositionalOptions;this._showHelpAfterError=t._showHelpAfterError;this._showSuggestionAfterError=t._showSuggestionAfterError;return this}_getCommandAndAncestors(){const t=[];for(let e=this;e;e=e.parent){t.push(e)}return t}command(t,e,i){let n=e;let s=i;if(typeof n==="object"&&n!==null){s=n;n=null}s=s||{};const[,r,o]=t.match(/([^ ]+) *(.*)/);const a=this.createCommand(r);if(n){a.description(n);a._executableHandler=true}if(s.isDefault)this._defaultCommandName=a._name;a._hidden=!!(s.noHelp||s.hidden);a._executableFile=s.executableFile||null;if(o)a.arguments(o);this._registerCommand(a);a.parent=this;a.copyInheritedSettings(this);if(n)return this;return a}createCommand(t){return new Command(t)}createHelp(){return Object.assign(new c,this.configureHelp())}configureHelp(t){if(t===undefined)return this._helpConfiguration;this._helpConfiguration=t;return this}configureOutput(t){if(t===undefined)return this._outputConfiguration;Object.assign(this._outputConfiguration,t);return this}showHelpAfterError(t=true){if(typeof t!=="string")t=!!t;this._showHelpAfterError=t;return this}showSuggestionAfterError(t=true){this._showSuggestionAfterError=!!t;return this}addCommand(t,e){if(!t._name){throw new Error(`Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()`)}e=e||{};if(e.isDefault)this._defaultCommandName=t._name;if(e.noHelp||e.hidden)t._hidden=true;this._registerCommand(t);t.parent=this;t._checkForBrokenPassThrough();return this}createArgument(t,e){return new h(t,e)}argument(t,e,i,n){const s=this.createArgument(t,e);if(typeof i==="function"){s.default(n).argParser(i)}else{s.default(i)}this.addArgument(s);return this}arguments(t){t.trim().split(/ +/).forEach((t=>{this.argument(t)}));return this}addArgument(t){const e=this.registeredArguments.slice(-1)[0];if(e&&e.variadic){throw new Error(`only the last argument can be variadic '${e.name()}'`)}if(t.required&&t.defaultValue!==undefined&&t.parseArg===undefined){throw new Error(`a default value for a required argument is never used: '${t.name()}'`)}this.registeredArguments.push(t);return this}helpCommand(t,e){if(typeof t==="boolean"){this._addImplicitHelpCommand=t;return this}t=t??"help [command]";const[,i,n]=t.match(/([^ ]+) *(.*)/);const s=e??"display help for command";const r=this.createCommand(i);r.helpOption(false);if(n)r.arguments(n);if(s)r.description(s);this._addImplicitHelpCommand=true;this._helpCommand=r;return this}addHelpCommand(t,e){if(typeof t!=="object"){this.helpCommand(t,e);return this}this._addImplicitHelpCommand=true;this._helpCommand=t;return this}_getHelpCommand(){const t=this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"));if(t){if(this._helpCommand===undefined){this.helpCommand(undefined,undefined)}return this._helpCommand}return null}hook(t,e){const i=["preSubcommand","preAction","postAction"];if(!i.includes(t)){throw new Error(`Unexpected value for event passed to hook : '${t}'.\nExpecting one of '${i.join("', '")}'`)}if(this._lifeCycleHooks[t]){this._lifeCycleHooks[t].push(e)}else{this._lifeCycleHooks[t]=[e]}return this}exitOverride(t){if(t){this._exitCallback=t}else{this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync"){throw t}else{}}}return this}_exit(t,e,i){if(this._exitCallback){this._exitCallback(new u(t,e,i))}a.exit(t)}action(t){const listener=e=>{const i=this.registeredArguments.length;const n=e.slice(0,i);if(this._storeOptionsAsProperties){n[i]=this}else{n[i]=this.opts()}n.push(this);return t.apply(this,n)};this._actionHandler=listener;return this}createOption(t,e){return new p(t,e)}_callParseArg(t,e,i,n){try{return t.parseArg(e,i)}catch(t){if(t.code==="commander.invalidArgument"){const e=`${n} ${t.message}`;this.error(e,{exitCode:t.exitCode,code:t.code})}throw t}}_registerOption(t){const e=t.short&&this._findOption(t.short)||t.long&&this._findOption(t.long);if(e){const i=t.long&&this._findOption(t.long)?t.long:t.short;throw new Error(`Cannot add option '${t.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${i}'\n- already used by option '${e.flags}'`)}this.options.push(t)}_registerCommand(t){const knownBy=t=>[t.name()].concat(t.aliases());const e=knownBy(t).find((t=>this._findCommand(t)));if(e){const i=knownBy(this._findCommand(e)).join("|");const n=knownBy(t).join("|");throw new Error(`cannot add command '${n}' as already have command '${i}'`)}this.commands.push(t)}addOption(t){this._registerOption(t);const e=t.name();const i=t.attributeName();if(t.negate){const e=t.long.replace(/^--no-/,"--");if(!this._findOption(e)){this.setOptionValueWithSource(i,t.defaultValue===undefined?true:t.defaultValue,"default")}}else if(t.defaultValue!==undefined){this.setOptionValueWithSource(i,t.defaultValue,"default")}const handleOptionValue=(e,n,s)=>{if(e==null&&t.presetArg!==undefined){e=t.presetArg}const r=this.getOptionValue(i);if(e!==null&&t.parseArg){e=this._callParseArg(t,e,r,n)}else if(e!==null&&t.variadic){e=t._concatValue(e,r)}if(e==null){if(t.negate){e=false}else if(t.isBoolean()||t.optional){e=true}else{e=""}}this.setOptionValueWithSource(i,e,s)};this.on("option:"+e,(e=>{const i=`error: option '${t.flags}' argument '${e}' is invalid.`;handleOptionValue(e,i,"cli")}));if(t.envVar){this.on("optionEnv:"+e,(e=>{const i=`error: option '${t.flags}' value '${e}' from env '${t.envVar}' is invalid.`;handleOptionValue(e,i,"env")}))}return this}_optionEx(t,e,i,n,s){if(typeof e==="object"&&e instanceof p){throw new Error("To add an Option object use addOption() instead of option() or requiredOption()")}const r=this.createOption(e,i);r.makeOptionMandatory(!!t.mandatory);if(typeof n==="function"){r.default(s).argParser(n)}else if(n instanceof RegExp){const t=n;n=(e,i)=>{const n=t.exec(e);return n?n[0]:i};r.default(s).argParser(n)}else{r.default(n)}return this.addOption(r)}option(t,e,i,n){return this._optionEx({},t,e,i,n)}requiredOption(t,e,i,n){return this._optionEx({mandatory:true},t,e,i,n)}combineFlagAndOptionalValue(t=true){this._combineFlagAndOptionalValue=!!t;return this}allowUnknownOption(t=true){this._allowUnknownOption=!!t;return this}allowExcessArguments(t=true){this._allowExcessArguments=!!t;return this}enablePositionalOptions(t=true){this._enablePositionalOptions=!!t;return this}passThroughOptions(t=true){this._passThroughOptions=!!t;this._checkForBrokenPassThrough();return this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions){throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}}storeOptionsAsProperties(t=true){if(this.options.length){throw new Error("call .storeOptionsAsProperties() before adding options")}if(Object.keys(this._optionValues).length){throw new Error("call .storeOptionsAsProperties() before setting option values")}this._storeOptionsAsProperties=!!t;return this}getOptionValue(t){if(this._storeOptionsAsProperties){return this[t]}return this._optionValues[t]}setOptionValue(t,e){return this.setOptionValueWithSource(t,e,undefined)}setOptionValueWithSource(t,e,i){if(this._storeOptionsAsProperties){this[t]=e}else{this._optionValues[t]=e}this._optionValueSources[t]=i;return this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let e;this._getCommandAndAncestors().forEach((i=>{if(i.getOptionValueSource(t)!==undefined){e=i.getOptionValueSource(t)}}));return e}_prepareUserArgs(t,e){if(t!==undefined&&!Array.isArray(t)){throw new Error("first parameter to parse must be array or undefined")}e=e||{};if(t===undefined&&e.from===undefined){if(a.versions?.electron){e.from="electron"}const t=a.execArgv??[];if(t.includes("-e")||t.includes("--eval")||t.includes("-p")||t.includes("--print")){e.from="eval"}}if(t===undefined){t=a.argv}this.rawArgs=t.slice();let i;switch(e.from){case undefined:case"node":this._scriptPath=t[1];i=t.slice(2);break;case"electron":if(a.defaultApp){this._scriptPath=t[1];i=t.slice(2)}else{i=t.slice(1)}break;case"user":i=t.slice(0);break;case"eval":i=t.slice(1);break;default:throw new Error(`unexpected parse option { from: '${e.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);this._name=this._name||"program";return i}parse(t,e){const i=this._prepareUserArgs(t,e);this._parseCommand([],i);return this}async parseAsync(t,e){const i=this._prepareUserArgs(t,e);await this._parseCommand([],i);return this}_executeSubCommand(t,e){e=e.slice();let i=false;const n=[".js",".ts",".tsx",".mjs",".cjs"];function findFile(t,e){const i=r.resolve(t,e);if(o.existsSync(i))return i;if(n.includes(r.extname(e)))return undefined;const s=n.find((t=>o.existsSync(`${i}${t}`)));if(s)return`${i}${s}`;return undefined}this._checkForMissingMandatoryOptions();this._checkForConflictingOptions();let h=t._executableFile||`${this._name}-${t._name}`;let l=this._executableDir||"";if(this._scriptPath){let t;try{t=o.realpathSync(this._scriptPath)}catch(e){t=this._scriptPath}l=r.resolve(r.dirname(t),l)}if(l){let e=findFile(l,h);if(!e&&!t._executableFile&&this._scriptPath){const i=r.basename(this._scriptPath,r.extname(this._scriptPath));if(i!==this._name){e=findFile(l,`${i}-${t._name}`)}}h=e||h}i=n.includes(r.extname(h));let c;if(a.platform!=="win32"){if(i){e.unshift(h);e=incrementNodeInspectorPort(a.execArgv).concat(e);c=s.spawn(a.argv[0],e,{stdio:"inherit"})}else{c=s.spawn(h,e,{stdio:"inherit"})}}else{e.unshift(h);e=incrementNodeInspectorPort(a.execArgv).concat(e);c=s.spawn(a.execPath,e,{stdio:"inherit"})}if(!c.killed){const t=["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"];t.forEach((t=>{a.on(t,(()=>{if(c.killed===false&&c.exitCode===null){c.kill(t)}}))}))}const p=this._exitCallback;c.on("close",(t=>{t=t??1;if(!p){a.exit(t)}else{p(new u(t,"commander.executeSubCommandAsync","(close)"))}}));c.on("error",(e=>{if(e.code==="ENOENT"){const e=l?`searched for local subcommand relative to directory '${l}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory";const i=`'${h}' does not exist\n - if '${t._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${e}`;throw new Error(i)}else if(e.code==="EACCES"){throw new Error(`'${h}' not executable`)}if(!p){a.exit(1)}else{const t=new u(1,"commander.executeSubCommandAsync","(error)");t.nestedError=e;p(t)}}));this.runningCommand=c}_dispatchSubcommand(t,e,i){const n=this._findCommand(t);if(!n)this.help({error:true});let s;s=this._chainOrCallSubCommandHook(s,n,"preSubcommand");s=this._chainOrCall(s,(()=>{if(n._executableHandler){this._executeSubCommand(n,e.concat(i))}else{return n._parseCommand(e,i)}}));return s}_dispatchHelpCommand(t){if(!t){this.help()}const e=this._findCommand(t);if(e&&!e._executableHandler){e.help()}return this._dispatchSubcommand(t,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach(((t,e)=>{if(t.required&&this.args[e]==null){this.missingArgument(t.name())}}));if(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic){return}if(this.args.length>this.registeredArguments.length){this._excessArguments(this.args)}}_processArguments(){const myParseArg=(t,e,i)=>{let n=e;if(e!==null&&t.parseArg){const s=`error: command-argument value '${e}' is invalid for argument '${t.name()}'.`;n=this._callParseArg(t,e,i,s)}return n};this._checkNumberOfArguments();const t=[];this.registeredArguments.forEach(((e,i)=>{let n=e.defaultValue;if(e.variadic){if(i<this.args.length){n=this.args.slice(i);if(e.parseArg){n=n.reduce(((t,i)=>myParseArg(e,i,t)),e.defaultValue)}}else if(n===undefined){n=[]}}else if(i<this.args.length){n=this.args[i];if(e.parseArg){n=myParseArg(e,n,e.defaultValue)}}t[i]=n}));this.processedArgs=t}_chainOrCall(t,e){if(t&&t.then&&typeof t.then==="function"){return t.then((()=>e()))}return e()}_chainOrCallHooks(t,e){let i=t;const n=[];this._getCommandAndAncestors().reverse().filter((t=>t._lifeCycleHooks[e]!==undefined)).forEach((t=>{t._lifeCycleHooks[e].forEach((e=>{n.push({hookedCommand:t,callback:e})}))}));if(e==="postAction"){n.reverse()}n.forEach((t=>{i=this._chainOrCall(i,(()=>t.callback(t.hookedCommand,this)))}));return i}_chainOrCallSubCommandHook(t,e,i){let n=t;if(this._lifeCycleHooks[i]!==undefined){this._lifeCycleHooks[i].forEach((t=>{n=this._chainOrCall(n,(()=>t(this,e)))}))}return n}_parseCommand(t,e){const i=this.parseOptions(e);this._parseOptionsEnv();this._parseOptionsImplied();t=t.concat(i.operands);e=i.unknown;this.args=t.concat(e);if(t&&this._findCommand(t[0])){return this._dispatchSubcommand(t[0],t.slice(1),e)}if(this._getHelpCommand()&&t[0]===this._getHelpCommand().name()){return this._dispatchHelpCommand(t[1])}if(this._defaultCommandName){this._outputHelpIfRequested(e);return this._dispatchSubcommand(this._defaultCommandName,t,e)}if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName){this.help({error:true})}this._outputHelpIfRequested(i.unknown);this._checkForMissingMandatoryOptions();this._checkForConflictingOptions();const checkForUnknownOptions=()=>{if(i.unknown.length>0){this.unknownOption(i.unknown[0])}};const n=`command:${this.name()}`;if(this._actionHandler){checkForUnknownOptions();this._processArguments();let i;i=this._chainOrCallHooks(i,"preAction");i=this._chainOrCall(i,(()=>this._actionHandler(this.processedArgs)));if(this.parent){i=this._chainOrCall(i,(()=>{this.parent.emit(n,t,e)}))}i=this._chainOrCallHooks(i,"postAction");return i}if(this.parent&&this.parent.listenerCount(n)){checkForUnknownOptions();this._processArguments();this.parent.emit(n,t,e)}else if(t.length){if(this._findCommand("*")){return this._dispatchSubcommand("*",t,e)}if(this.listenerCount("command:*")){this.emit("command:*",t,e)}else if(this.commands.length){this.unknownCommand()}else{checkForUnknownOptions();this._processArguments()}}else if(this.commands.length){checkForUnknownOptions();this.help({error:true})}else{checkForUnknownOptions();this._processArguments()}}_findCommand(t){if(!t)return undefined;return this.commands.find((e=>e._name===t||e._aliases.includes(t)))}_findOption(t){return this.options.find((e=>e.is(t)))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((t=>{t.options.forEach((e=>{if(e.mandatory&&t.getOptionValue(e.attributeName())===undefined){t.missingMandatoryOptionValue(e)}}))}))}_checkForConflictingLocalOptions(){const t=this.options.filter((t=>{const e=t.attributeName();if(this.getOptionValue(e)===undefined){return false}return this.getOptionValueSource(e)!=="default"}));const e=t.filter((t=>t.conflictsWith.length>0));e.forEach((e=>{const i=t.find((t=>e.conflictsWith.includes(t.attributeName())));if(i){this._conflictingOption(e,i)}}))}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((t=>{t._checkForConflictingLocalOptions()}))}parseOptions(t){const e=[];const i=[];let n=e;const s=t.slice();function maybeOption(t){return t.length>1&&t[0]==="-"}let r=null;while(s.length){const t=s.shift();if(t==="--"){if(n===i)n.push(t);n.push(...s);break}if(r&&!maybeOption(t)){this.emit(`option:${r.name()}`,t);continue}r=null;if(maybeOption(t)){const e=this._findOption(t);if(e){if(e.required){const t=s.shift();if(t===undefined)this.optionMissingArgument(e);this.emit(`option:${e.name()}`,t)}else if(e.optional){let t=null;if(s.length>0&&!maybeOption(s[0])){t=s.shift()}this.emit(`option:${e.name()}`,t)}else{this.emit(`option:${e.name()}`)}r=e.variadic?e:null;continue}}if(t.length>2&&t[0]==="-"&&t[1]!=="-"){const e=this._findOption(`-${t[1]}`);if(e){if(e.required||e.optional&&this._combineFlagAndOptionalValue){this.emit(`option:${e.name()}`,t.slice(2))}else{this.emit(`option:${e.name()}`);s.unshift(`-${t.slice(2)}`)}continue}}if(/^--[^=]+=/.test(t)){const e=t.indexOf("=");const i=this._findOption(t.slice(0,e));if(i&&(i.required||i.optional)){this.emit(`option:${i.name()}`,t.slice(e+1));continue}}if(maybeOption(t)){n=i}if((this._enablePositionalOptions||this._passThroughOptions)&&e.length===0&&i.length===0){if(this._findCommand(t)){e.push(t);if(s.length>0)i.push(...s);break}else if(this._getHelpCommand()&&t===this._getHelpCommand().name()){e.push(t);if(s.length>0)e.push(...s);break}else if(this._defaultCommandName){i.push(t);if(s.length>0)i.push(...s);break}}if(this._passThroughOptions){n.push(t);if(s.length>0)n.push(...s);break}n.push(t)}return{operands:e,unknown:i}}opts(){if(this._storeOptionsAsProperties){const t={};const e=this.options.length;for(let i=0;i<e;i++){const e=this.options[i].attributeName();t[e]=e===this._versionOptionName?this._version:this[e]}return t}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce(((t,e)=>Object.assign(t,e.opts())),{})}error(t,e){this._outputConfiguration.outputError(`${t}\n`,this._outputConfiguration.writeErr);if(typeof this._showHelpAfterError==="string"){this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`)}else if(this._showHelpAfterError){this._outputConfiguration.writeErr("\n");this.outputHelp({error:true})}const i=e||{};const n=i.exitCode||1;const s=i.code||"commander.error";this._exit(n,s,t)}_parseOptionsEnv(){this.options.forEach((t=>{if(t.envVar&&t.envVar in a.env){const e=t.attributeName();if(this.getOptionValue(e)===undefined||["default","config","env"].includes(this.getOptionValueSource(e))){if(t.required||t.optional){this.emit(`optionEnv:${t.name()}`,a.env[t.envVar])}else{this.emit(`optionEnv:${t.name()}`)}}}}))}_parseOptionsImplied(){const t=new d(this.options);const hasCustomOptionValue=t=>this.getOptionValue(t)!==undefined&&!["default","implied"].includes(this.getOptionValueSource(t));this.options.filter((e=>e.implied!==undefined&&hasCustomOptionValue(e.attributeName())&&t.valueFromOption(this.getOptionValue(e.attributeName()),e))).forEach((t=>{Object.keys(t.implied).filter((t=>!hasCustomOptionValue(t))).forEach((e=>{this.setOptionValueWithSource(e,t.implied[e],"implied")}))}))}missingArgument(t){const e=`error: missing required argument '${t}'`;this.error(e,{code:"commander.missingArgument"})}optionMissingArgument(t){const e=`error: option '${t.flags}' argument missing`;this.error(e,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(t){const e=`error: required option '${t.flags}' not specified`;this.error(e,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(t,e){const findBestOptionFromValue=t=>{const e=t.attributeName();const i=this.getOptionValue(e);const n=this.options.find((t=>t.negate&&e===t.attributeName()));const s=this.options.find((t=>!t.negate&&e===t.attributeName()));if(n&&(n.presetArg===undefined&&i===false||n.presetArg!==undefined&&i===n.presetArg)){return n}return s||t};const getErrorMessage=t=>{const e=findBestOptionFromValue(t);const i=e.attributeName();const n=this.getOptionValueSource(i);if(n==="env"){return`environment variable '${e.envVar}'`}return`option '${e.flags}'`};const i=`error: ${getErrorMessage(t)} cannot be used with ${getErrorMessage(e)}`;this.error(i,{code:"commander.conflictingOption"})}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let i=[];let n=this;do{const t=n.createHelp().visibleOptions(n).filter((t=>t.long)).map((t=>t.long));i=i.concat(t);n=n.parent}while(n&&!n._enablePositionalOptions);e=m(t,i)}const i=`error: unknown option '${t}'${e}`;this.error(i,{code:"commander.unknownOption"})}_excessArguments(t){if(this._allowExcessArguments)return;const e=this.registeredArguments.length;const i=e===1?"":"s";const n=this.parent?` for '${this.name()}'`:"";const s=`error: too many arguments${n}. Expected ${e} argument${i} but got ${t.length}.`;this.error(s,{code:"commander.excessArguments"})}unknownCommand(){const t=this.args[0];let e="";if(this._showSuggestionAfterError){const i=[];this.createHelp().visibleCommands(this).forEach((t=>{i.push(t.name());if(t.alias())i.push(t.alias())}));e=m(t,i)}const i=`error: unknown command '${t}'${e}`;this.error(i,{code:"commander.unknownCommand"})}version(t,e,i){if(t===undefined)return this._version;this._version=t;e=e||"-V, --version";i=i||"output the version number";const n=this.createOption(e,i);this._versionOptionName=n.attributeName();this._registerOption(n);this.on("option:"+n.name(),(()=>{this._outputConfiguration.writeOut(`${t}\n`);this._exit(0,"commander.version",t)}));return this}description(t,e){if(t===undefined&&e===undefined)return this._description;this._description=t;if(e){this._argsDescription=e}return this}summary(t){if(t===undefined)return this._summary;this._summary=t;return this}alias(t){if(t===undefined)return this._aliases[0];let e=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler){e=this.commands[this.commands.length-1]}if(t===e._name)throw new Error("Command alias can't be the same as its name");const i=this.parent?._findCommand(t);if(i){const e=[i.name()].concat(i.aliases()).join("|");throw new Error(`cannot add alias '${t}' to command '${this.name()}' as already have command '${e}'`)}e._aliases.push(t);return this}aliases(t){if(t===undefined)return this._aliases;t.forEach((t=>this.alias(t)));return this}usage(t){if(t===undefined){if(this._usage)return this._usage;const t=this.registeredArguments.map((t=>l(t)));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}this._usage=t;return this}name(t){if(t===undefined)return this._name;this._name=t;return this}nameFromFilename(t){this._name=r.basename(t,r.extname(t));return this}executableDir(t){if(t===undefined)return this._executableDir;this._executableDir=t;return this}helpInformation(t){const e=this.createHelp();if(e.helpWidth===undefined){e.helpWidth=t&&t.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth()}return e.formatHelp(this,e)}_getHelpContext(t){t=t||{};const e={error:!!t.error};let i;if(e.error){i=t=>this._outputConfiguration.writeErr(t)}else{i=t=>this._outputConfiguration.writeOut(t)}e.write=t.write||i;e.command=this;return e}outputHelp(t){let e;if(typeof t==="function"){e=t;t=undefined}const i=this._getHelpContext(t);this._getCommandAndAncestors().reverse().forEach((t=>t.emit("beforeAllHelp",i)));this.emit("beforeHelp",i);let n=this.helpInformation(i);if(e){n=e(n);if(typeof n!=="string"&&!Buffer.isBuffer(n)){throw new Error("outputHelp callback must return a string or a Buffer")}}i.write(n);if(this._getHelpOption()?.long){this.emit(this._getHelpOption().long)}this.emit("afterHelp",i);this._getCommandAndAncestors().forEach((t=>t.emit("afterAllHelp",i)))}helpOption(t,e){if(typeof t==="boolean"){if(t){this._helpOption=this._helpOption??undefined}else{this._helpOption=null}return this}t=t??"-h, --help";e=e??"display help for command";this._helpOption=this.createOption(t,e);return this}_getHelpOption(){if(this._helpOption===undefined){this.helpOption(undefined,undefined)}return this._helpOption}addHelpOption(t){this._helpOption=t;return this}help(t){this.outputHelp(t);let e=a.exitCode||0;if(e===0&&t&&typeof t!=="function"&&t.error){e=1}this._exit(e,"commander.help","(outputHelp)")}addHelpText(t,e){const i=["beforeAll","before","after","afterAll"];if(!i.includes(t)){throw new Error(`Unexpected value for position to addHelpText.\nExpecting one of '${i.join("', '")}'`)}const n=`${t}Help`;this.on(n,(t=>{let i;if(typeof e==="function"){i=e({error:t.error,command:t.command})}else{i=e}if(i){t.write(`${i}\n`)}}));return this}_outputHelpIfRequested(t){const e=this._getHelpOption();const i=e&&t.find((t=>e.is(t)));if(i){this.outputHelp();this._exit(0,"commander.helpDisplayed","(outputHelp)")}}}function incrementNodeInspectorPort(t){return t.map((t=>{if(!t.startsWith("--inspect")){return t}let e;let i="127.0.0.1";let n="9229";let s;if((s=t.match(/^(--inspect(-brk)?)$/))!==null){e=s[1]}else if((s=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null){e=s[1];if(/^\d+$/.test(s[3])){n=s[3]}else{i=s[3]}}else if((s=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null){e=s[1];i=s[3];n=s[4]}if(e&&n!=="0"){return`${e}=${i}:${parseInt(n)+1}`}return t}))}e.Command=Command},841:function(t,e){class CommanderError extends Error{constructor(t,e,i){super(i);Error.captureStackTrace(this,this.constructor);this.name=this.constructor.name;this.code=e;this.exitCode=t;this.nestedError=undefined}}class InvalidArgumentError extends CommanderError{constructor(t){super(1,"commander.invalidArgument",t);Error.captureStackTrace(this,this.constructor);this.name=this.constructor.name}}e.CommanderError=CommanderError;e.InvalidArgumentError=InvalidArgumentError},202:function(t,e,i){const{humanReadableArgName:n}=i(142);class Help{constructor(){this.helpWidth=undefined;this.sortSubcommands=false;this.sortOptions=false;this.showGlobalOptions=false}visibleCommands(t){const e=t.commands.filter((t=>!t._hidden));const i=t._getHelpCommand();if(i&&!i._hidden){e.push(i)}if(this.sortSubcommands){e.sort(((t,e)=>t.name().localeCompare(e.name())))}return e}compareOptions(t,e){const getSortKey=t=>t.short?t.short.replace(/^-/,""):t.long.replace(/^--/,"");return getSortKey(t).localeCompare(getSortKey(e))}visibleOptions(t){const e=t.options.filter((t=>!t.hidden));const i=t._getHelpOption();if(i&&!i.hidden){const n=i.short&&t._findOption(i.short);const s=i.long&&t._findOption(i.long);if(!n&&!s){e.push(i)}else if(i.long&&!s){e.push(t.createOption(i.long,i.description))}else if(i.short&&!n){e.push(t.createOption(i.short,i.description))}}if(this.sortOptions){e.sort(this.compareOptions)}return e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];const e=[];for(let i=t.parent;i;i=i.parent){const t=i.options.filter((t=>!t.hidden));e.push(...t)}if(this.sortOptions){e.sort(this.compareOptions)}return e}visibleArguments(t){if(t._argsDescription){t.registeredArguments.forEach((e=>{e.description=e.description||t._argsDescription[e.name()]||""}))}if(t.registeredArguments.find((t=>t.description))){return t.registeredArguments}return[]}subcommandTerm(t){const e=t.registeredArguments.map((t=>n(t))).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(e?" "+e:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce(((t,i)=>Math.max(t,e.subcommandTerm(i).length)),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce(((t,i)=>Math.max(t,e.optionTerm(i).length)),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce(((t,i)=>Math.max(t,e.optionTerm(i).length)),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce(((t,i)=>Math.max(t,e.argumentTerm(i).length)),0)}commandUsage(t){let e=t._name;if(t._aliases[0]){e=e+"|"+t._aliases[0]}let i="";for(let e=t.parent;e;e=e.parent){i=e.name()+" "+i}return i+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){const e=[];if(t.argChoices){e.push(`choices: ${t.argChoices.map((t=>JSON.stringify(t))).join(", ")}`)}if(t.defaultValue!==undefined){const i=t.required||t.optional||t.isBoolean()&&typeof t.defaultValue==="boolean";if(i){e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`)}}if(t.presetArg!==undefined&&t.optional){e.push(`preset: ${JSON.stringify(t.presetArg)}`)}if(t.envVar!==undefined){e.push(`env: ${t.envVar}`)}if(e.length>0){return`${t.description} (${e.join(", ")})`}return t.description}argumentDescription(t){const e=[];if(t.argChoices){e.push(`choices: ${t.argChoices.map((t=>JSON.stringify(t))).join(", ")}`)}if(t.defaultValue!==undefined){e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`)}if(e.length>0){const i=`(${e.join(", ")})`;if(t.description){return`${t.description} ${i}`}return i}return t.description}formatHelp(t,e){const i=e.padWidth(t,e);const n=e.helpWidth||80;const s=2;const r=2;function formatItem(t,o){if(o){const a=`${t.padEnd(i+r)}${o}`;return e.wrap(a,n-s,i+r)}return t}function formatList(t){return t.join("\n").replace(/^/gm," ".repeat(s))}let o=[`Usage: ${e.commandUsage(t)}`,""];const a=e.commandDescription(t);if(a.length>0){o=o.concat([e.wrap(a,n,0),""])}const h=e.visibleArguments(t).map((t=>formatItem(e.argumentTerm(t),e.argumentDescription(t))));if(h.length>0){o=o.concat(["Arguments:",formatList(h),""])}const l=e.visibleOptions(t).map((t=>formatItem(e.optionTerm(t),e.optionDescription(t))));if(l.length>0){o=o.concat(["Options:",formatList(l),""])}if(this.showGlobalOptions){const i=e.visibleGlobalOptions(t).map((t=>formatItem(e.optionTerm(t),e.optionDescription(t))));if(i.length>0){o=o.concat(["Global Options:",formatList(i),""])}}const u=e.visibleCommands(t).map((t=>formatItem(e.subcommandTerm(t),e.subcommandDescription(t))));if(u.length>0){o=o.concat(["Commands:",formatList(u),""])}return o.join("\n")}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestGlobalOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}wrap(t,e,i,n=40){const s=" \\f\\t\\v - \ufeff";const r=new RegExp(`[\\n][${s}]+`);if(t.match(r))return t;const o=e-i;if(o<n)return t;const a=t.slice(0,i);const h=t.slice(i).replace("\r\n","\n");const l=" ".repeat(i);const u="";const c=`\\s${u}`;const p=new RegExp(`\n|.{1,${o-1}}([${c}]|$)|[^${c}]+?([${c}]|$)`,"g");const d=h.match(p)||[];return a+d.map(((t,e)=>{if(t==="\n")return"";return(e>0?l:"")+t.trimEnd()})).join("\n")}}e.Help=Help},257:function(t,e,i){const{InvalidArgumentError:n}=i(841);class Option{constructor(t,e){this.flags=t;this.description=e||"";this.required=t.includes("<");this.optional=t.includes("[");this.variadic=/\w\.\.\.[>\]]$/.test(t);this.mandatory=false;const i=splitOptionFlags(t);this.short=i.shortFlag;this.long=i.longFlag;this.negate=false;if(this.long){this.negate=this.long.startsWith("--no-")}this.defaultValue=undefined;this.defaultValueDescription=undefined;this.presetArg=undefined;this.envVar=undefined;this.parseArg=undefined;this.hidden=false;this.argChoices=undefined;this.conflictsWith=[];this.implied=undefined}default(t,e){this.defaultValue=t;this.defaultValueDescription=e;return this}preset(t){this.presetArg=t;return this}conflicts(t){this.conflictsWith=this.conflictsWith.concat(t);return this}implies(t){let e=t;if(typeof t==="string"){e={[t]:true}}this.implied=Object.assign(this.implied||{},e);return this}env(t){this.envVar=t;return this}argParser(t){this.parseArg=t;return this}makeOptionMandatory(t=true){this.mandatory=!!t;return this}hideHelp(t=true){this.hidden=!!t;return this}_concatValue(t,e){if(e===this.defaultValue||!Array.isArray(e)){return[t]}return e.concat(t)}choices(t){this.argChoices=t.slice();this.parseArg=(t,e)=>{if(!this.argChoices.includes(t)){throw new n(`Allowed choices are ${this.argChoices.join(", ")}.`)}if(this.variadic){return this._concatValue(t,e)}return t};return this}name(){if(this.long){return this.long.replace(/^--/,"")}return this.short.replace(/^-/,"")}attributeName(){return camelcase(this.name().replace(/^no-/,""))}is(t){return this.short===t||this.long===t}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class DualOptions{constructor(t){this.positiveOptions=new Map;this.negativeOptions=new Map;this.dualOptions=new Set;t.forEach((t=>{if(t.negate){this.negativeOptions.set(t.attributeName(),t)}else{this.positiveOptions.set(t.attributeName(),t)}}));this.negativeOptions.forEach(((t,e)=>{if(this.positiveOptions.has(e)){this.dualOptions.add(e)}}))}valueFromOption(t,e){const i=e.attributeName();if(!this.dualOptions.has(i))return true;const n=this.negativeOptions.get(i).presetArg;const s=n!==undefined?n:false;return e.negate===(s===t)}}function camelcase(t){return t.split("-").reduce(((t,e)=>t+e[0].toUpperCase()+e.slice(1)))}function splitOptionFlags(t){let e;let i;const n=t.split(/[ |,]+/);if(n.length>1&&!/^[[<]/.test(n[1]))e=n.shift();i=n.shift();if(!e&&/^-[^-]$/.test(i)){e=i;i=undefined}return{shortFlag:e,longFlag:i}}e.Option=Option;e.DualOptions=DualOptions},824:function(t,e){const i=3;function editDistance(t,e){if(Math.abs(t.length-e.length)>i)return Math.max(t.length,e.length);const n=[];for(let e=0;e<=t.length;e++){n[e]=[e]}for(let t=0;t<=e.length;t++){n[0][t]=t}for(let i=1;i<=e.length;i++){for(let s=1;s<=t.length;s++){let r=1;if(t[s-1]===e[i-1]){r=0}else{r=1}n[s][i]=Math.min(n[s-1][i]+1,n[s][i-1]+1,n[s-1][i-1]+r);if(s>1&&i>1&&t[s-1]===e[i-2]&&t[s-2]===e[i-1]){n[s][i]=Math.min(n[s][i],n[s-2][i-2]+1)}}}return n[t.length][e.length]}function suggestSimilar(t,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));const n=t.startsWith("--");if(n){t=t.slice(2);e=e.map((t=>t.slice(2)))}let s=[];let r=i;const o=.4;e.forEach((e=>{if(e.length<=1)return;const i=editDistance(t,e);const n=Math.max(t.length,e.length);const a=(n-i)/n;if(a>o){if(i<r){r=i;s=[e]}else if(i===r){s.push(e)}}}));s.sort(((t,e)=>t.localeCompare(e)));if(n){s=s.map((t=>`--${t}`))}if(s.length>1){return`\n(Did you mean one of ${s.join(", ")}?)`}if(s.length===1){return`\n(Did you mean ${s[0]}?)`}return""}e.suggestSimilar=suggestSimilar}};var e={};function __nccwpck_require__(i){var n=e[i];if(n!==undefined){return n.exports}var s=e[i]={exports:{}};var r=true;try{t[i](s,s.exports,__nccwpck_require__);r=false}finally{if(r)delete e[i]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var i={};!function(){var t=i;const{Argument:e}=__nccwpck_require__(142);const{Command:n}=__nccwpck_require__(728);const{CommanderError:s,InvalidArgumentError:r}=__nccwpck_require__(841);const{Help:o}=__nccwpck_require__(202);const{Option:a}=__nccwpck_require__(257);t.program=new n;t.createCommand=t=>new n(t);t.createOption=(t,e)=>new a(t,e);t.createArgument=(t,i)=>new e(t,i);t.Command=n;t.Option=a;t.Argument=e;t.Help=o;t.CommanderError=s;t.InvalidArgumentError=r;t.InvalidOptionArgumentError=r}();module.exports=i})();
|
|
1
|
+
(function(){var t={718:function(t){"use strict";t.exports=require("node:child_process")},673:function(t){"use strict";t.exports=require("node:events")},561:function(t){"use strict";t.exports=require("node:fs")},411:function(t){"use strict";t.exports=require("node:path")},742:function(t){"use strict";t.exports=require("node:process")},354:function(t,e,i){const{InvalidArgumentError:n}=i(671);class Argument{constructor(t,e){this.description=e||"";this.variadic=false;this.parseArg=undefined;this.defaultValue=undefined;this.defaultValueDescription=undefined;this.argChoices=undefined;switch(t[0]){case"<":this.required=true;this._name=t.slice(1,-1);break;case"[":this.required=false;this._name=t.slice(1,-1);break;default:this.required=true;this._name=t;break}if(this._name.length>3&&this._name.slice(-3)==="..."){this.variadic=true;this._name=this._name.slice(0,-3)}}name(){return this._name}_concatValue(t,e){if(e===this.defaultValue||!Array.isArray(e)){return[t]}return e.concat(t)}default(t,e){this.defaultValue=t;this.defaultValueDescription=e;return this}argParser(t){this.parseArg=t;return this}choices(t){this.argChoices=t.slice();this.parseArg=(t,e)=>{if(!this.argChoices.includes(t)){throw new n(`Allowed choices are ${this.argChoices.join(", ")}.`)}if(this.variadic){return this._concatValue(t,e)}return t};return this}argRequired(){this.required=true;return this}argOptional(){this.required=false;return this}}function humanReadableArgName(t){const e=t.name()+(t.variadic===true?"...":"");return t.required?"<"+e+">":"["+e+"]"}e.Argument=Argument;e.humanReadableArgName=humanReadableArgName},691:function(t,e,i){const n=i(673).EventEmitter;const s=i(718);const r=i(411);const o=i(561);const a=i(742);const{Argument:l,humanReadableArgName:h}=i(354);const{CommanderError:u}=i(671);const{Help:c,stripColor:p}=i(896);const{Option:d,DualOptions:m}=i(284);const{suggestSimilar:f}=i(378);class Command extends n{constructor(t){super();this.commands=[];this.options=[];this.parent=null;this._allowUnknownOption=false;this._allowExcessArguments=false;this.registeredArguments=[];this._args=this.registeredArguments;this.args=[];this.rawArgs=[];this.processedArgs=[];this._scriptPath=null;this._name=t||"";this._optionValues={};this._optionValueSources={};this._storeOptionsAsProperties=false;this._actionHandler=null;this._executableHandler=false;this._executableFile=null;this._executableDir=null;this._defaultCommandName=null;this._exitCallback=null;this._aliases=[];this._combineFlagAndOptionalValue=true;this._description="";this._summary="";this._argsDescription=undefined;this._enablePositionalOptions=false;this._passThroughOptions=false;this._lifeCycleHooks={};this._showHelpAfterError=false;this._showSuggestionAfterError=true;this._savedState=null;this._outputConfiguration={writeOut:t=>a.stdout.write(t),writeErr:t=>a.stderr.write(t),outputError:(t,e)=>e(t),getOutHelpWidth:()=>a.stdout.isTTY?a.stdout.columns:undefined,getErrHelpWidth:()=>a.stderr.isTTY?a.stderr.columns:undefined,getOutHasColors:()=>useColor()??(a.stdout.isTTY&&a.stdout.hasColors?.()),getErrHasColors:()=>useColor()??(a.stderr.isTTY&&a.stderr.hasColors?.()),stripColor:t=>p(t)};this._hidden=false;this._helpOption=undefined;this._addImplicitHelpCommand=undefined;this._helpCommand=undefined;this._helpConfiguration={}}copyInheritedSettings(t){this._outputConfiguration=t._outputConfiguration;this._helpOption=t._helpOption;this._helpCommand=t._helpCommand;this._helpConfiguration=t._helpConfiguration;this._exitCallback=t._exitCallback;this._storeOptionsAsProperties=t._storeOptionsAsProperties;this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue;this._allowExcessArguments=t._allowExcessArguments;this._enablePositionalOptions=t._enablePositionalOptions;this._showHelpAfterError=t._showHelpAfterError;this._showSuggestionAfterError=t._showSuggestionAfterError;return this}_getCommandAndAncestors(){const t=[];for(let e=this;e;e=e.parent){t.push(e)}return t}command(t,e,i){let n=e;let s=i;if(typeof n==="object"&&n!==null){s=n;n=null}s=s||{};const[,r,o]=t.match(/([^ ]+) *(.*)/);const a=this.createCommand(r);if(n){a.description(n);a._executableHandler=true}if(s.isDefault)this._defaultCommandName=a._name;a._hidden=!!(s.noHelp||s.hidden);a._executableFile=s.executableFile||null;if(o)a.arguments(o);this._registerCommand(a);a.parent=this;a.copyInheritedSettings(this);if(n)return this;return a}createCommand(t){return new Command(t)}createHelp(){return Object.assign(new c,this.configureHelp())}configureHelp(t){if(t===undefined)return this._helpConfiguration;this._helpConfiguration=t;return this}configureOutput(t){if(t===undefined)return this._outputConfiguration;Object.assign(this._outputConfiguration,t);return this}showHelpAfterError(t=true){if(typeof t!=="string")t=!!t;this._showHelpAfterError=t;return this}showSuggestionAfterError(t=true){this._showSuggestionAfterError=!!t;return this}addCommand(t,e){if(!t._name){throw new Error(`Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()`)}e=e||{};if(e.isDefault)this._defaultCommandName=t._name;if(e.noHelp||e.hidden)t._hidden=true;this._registerCommand(t);t.parent=this;t._checkForBrokenPassThrough();return this}createArgument(t,e){return new l(t,e)}argument(t,e,i,n){const s=this.createArgument(t,e);if(typeof i==="function"){s.default(n).argParser(i)}else{s.default(i)}this.addArgument(s);return this}arguments(t){t.trim().split(/ +/).forEach((t=>{this.argument(t)}));return this}addArgument(t){const e=this.registeredArguments.slice(-1)[0];if(e&&e.variadic){throw new Error(`only the last argument can be variadic '${e.name()}'`)}if(t.required&&t.defaultValue!==undefined&&t.parseArg===undefined){throw new Error(`a default value for a required argument is never used: '${t.name()}'`)}this.registeredArguments.push(t);return this}helpCommand(t,e){if(typeof t==="boolean"){this._addImplicitHelpCommand=t;return this}t=t??"help [command]";const[,i,n]=t.match(/([^ ]+) *(.*)/);const s=e??"display help for command";const r=this.createCommand(i);r.helpOption(false);if(n)r.arguments(n);if(s)r.description(s);this._addImplicitHelpCommand=true;this._helpCommand=r;return this}addHelpCommand(t,e){if(typeof t!=="object"){this.helpCommand(t,e);return this}this._addImplicitHelpCommand=true;this._helpCommand=t;return this}_getHelpCommand(){const t=this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"));if(t){if(this._helpCommand===undefined){this.helpCommand(undefined,undefined)}return this._helpCommand}return null}hook(t,e){const i=["preSubcommand","preAction","postAction"];if(!i.includes(t)){throw new Error(`Unexpected value for event passed to hook : '${t}'.\nExpecting one of '${i.join("', '")}'`)}if(this._lifeCycleHooks[t]){this._lifeCycleHooks[t].push(e)}else{this._lifeCycleHooks[t]=[e]}return this}exitOverride(t){if(t){this._exitCallback=t}else{this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync"){throw t}else{}}}return this}_exit(t,e,i){if(this._exitCallback){this._exitCallback(new u(t,e,i))}a.exit(t)}action(t){const listener=e=>{const i=this.registeredArguments.length;const n=e.slice(0,i);if(this._storeOptionsAsProperties){n[i]=this}else{n[i]=this.opts()}n.push(this);return t.apply(this,n)};this._actionHandler=listener;return this}createOption(t,e){return new d(t,e)}_callParseArg(t,e,i,n){try{return t.parseArg(e,i)}catch(t){if(t.code==="commander.invalidArgument"){const e=`${n} ${t.message}`;this.error(e,{exitCode:t.exitCode,code:t.code})}throw t}}_registerOption(t){const e=t.short&&this._findOption(t.short)||t.long&&this._findOption(t.long);if(e){const i=t.long&&this._findOption(t.long)?t.long:t.short;throw new Error(`Cannot add option '${t.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${i}'\n- already used by option '${e.flags}'`)}this.options.push(t)}_registerCommand(t){const knownBy=t=>[t.name()].concat(t.aliases());const e=knownBy(t).find((t=>this._findCommand(t)));if(e){const i=knownBy(this._findCommand(e)).join("|");const n=knownBy(t).join("|");throw new Error(`cannot add command '${n}' as already have command '${i}'`)}this.commands.push(t)}addOption(t){this._registerOption(t);const e=t.name();const i=t.attributeName();if(t.negate){const e=t.long.replace(/^--no-/,"--");if(!this._findOption(e)){this.setOptionValueWithSource(i,t.defaultValue===undefined?true:t.defaultValue,"default")}}else if(t.defaultValue!==undefined){this.setOptionValueWithSource(i,t.defaultValue,"default")}const handleOptionValue=(e,n,s)=>{if(e==null&&t.presetArg!==undefined){e=t.presetArg}const r=this.getOptionValue(i);if(e!==null&&t.parseArg){e=this._callParseArg(t,e,r,n)}else if(e!==null&&t.variadic){e=t._concatValue(e,r)}if(e==null){if(t.negate){e=false}else if(t.isBoolean()||t.optional){e=true}else{e=""}}this.setOptionValueWithSource(i,e,s)};this.on("option:"+e,(e=>{const i=`error: option '${t.flags}' argument '${e}' is invalid.`;handleOptionValue(e,i,"cli")}));if(t.envVar){this.on("optionEnv:"+e,(e=>{const i=`error: option '${t.flags}' value '${e}' from env '${t.envVar}' is invalid.`;handleOptionValue(e,i,"env")}))}return this}_optionEx(t,e,i,n,s){if(typeof e==="object"&&e instanceof d){throw new Error("To add an Option object use addOption() instead of option() or requiredOption()")}const r=this.createOption(e,i);r.makeOptionMandatory(!!t.mandatory);if(typeof n==="function"){r.default(s).argParser(n)}else if(n instanceof RegExp){const t=n;n=(e,i)=>{const n=t.exec(e);return n?n[0]:i};r.default(s).argParser(n)}else{r.default(n)}return this.addOption(r)}option(t,e,i,n){return this._optionEx({},t,e,i,n)}requiredOption(t,e,i,n){return this._optionEx({mandatory:true},t,e,i,n)}combineFlagAndOptionalValue(t=true){this._combineFlagAndOptionalValue=!!t;return this}allowUnknownOption(t=true){this._allowUnknownOption=!!t;return this}allowExcessArguments(t=true){this._allowExcessArguments=!!t;return this}enablePositionalOptions(t=true){this._enablePositionalOptions=!!t;return this}passThroughOptions(t=true){this._passThroughOptions=!!t;this._checkForBrokenPassThrough();return this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions){throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}}storeOptionsAsProperties(t=true){if(this.options.length){throw new Error("call .storeOptionsAsProperties() before adding options")}if(Object.keys(this._optionValues).length){throw new Error("call .storeOptionsAsProperties() before setting option values")}this._storeOptionsAsProperties=!!t;return this}getOptionValue(t){if(this._storeOptionsAsProperties){return this[t]}return this._optionValues[t]}setOptionValue(t,e){return this.setOptionValueWithSource(t,e,undefined)}setOptionValueWithSource(t,e,i){if(this._storeOptionsAsProperties){this[t]=e}else{this._optionValues[t]=e}this._optionValueSources[t]=i;return this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let e;this._getCommandAndAncestors().forEach((i=>{if(i.getOptionValueSource(t)!==undefined){e=i.getOptionValueSource(t)}}));return e}_prepareUserArgs(t,e){if(t!==undefined&&!Array.isArray(t)){throw new Error("first parameter to parse must be array or undefined")}e=e||{};if(t===undefined&&e.from===undefined){if(a.versions?.electron){e.from="electron"}const t=a.execArgv??[];if(t.includes("-e")||t.includes("--eval")||t.includes("-p")||t.includes("--print")){e.from="eval"}}if(t===undefined){t=a.argv}this.rawArgs=t.slice();let i;switch(e.from){case undefined:case"node":this._scriptPath=t[1];i=t.slice(2);break;case"electron":if(a.defaultApp){this._scriptPath=t[1];i=t.slice(2)}else{i=t.slice(1)}break;case"user":i=t.slice(0);break;case"eval":i=t.slice(1);break;default:throw new Error(`unexpected parse option { from: '${e.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);this._name=this._name||"program";return i}parse(t,e){this._prepareForParse();const i=this._prepareUserArgs(t,e);this._parseCommand([],i);return this}async parseAsync(t,e){this._prepareForParse();const i=this._prepareUserArgs(t,e);await this._parseCommand([],i);return this}_prepareForParse(){if(this._savedState===null){this.saveStateBeforeParse()}else{this.restoreStateBeforeParse()}}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.\n- either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name;this._scriptPath=null;this.rawArgs=[];this._optionValues={...this._savedState._optionValues};this._optionValueSources={...this._savedState._optionValueSources};this.args=[];this.processedArgs=[]}_checkForMissingExecutable(t,e,i){if(o.existsSync(t))return;const n=e?`searched for local subcommand relative to directory '${e}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory";const s=`'${t}' does not exist\n - if '${i}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${n}`;throw new Error(s)}_executeSubCommand(t,e){e=e.slice();let i=false;const n=[".js",".ts",".tsx",".mjs",".cjs"];function findFile(t,e){const i=r.resolve(t,e);if(o.existsSync(i))return i;if(n.includes(r.extname(e)))return undefined;const s=n.find((t=>o.existsSync(`${i}${t}`)));if(s)return`${i}${s}`;return undefined}this._checkForMissingMandatoryOptions();this._checkForConflictingOptions();let l=t._executableFile||`${this._name}-${t._name}`;let h=this._executableDir||"";if(this._scriptPath){let t;try{t=o.realpathSync(this._scriptPath)}catch{t=this._scriptPath}h=r.resolve(r.dirname(t),h)}if(h){let e=findFile(h,l);if(!e&&!t._executableFile&&this._scriptPath){const i=r.basename(this._scriptPath,r.extname(this._scriptPath));if(i!==this._name){e=findFile(h,`${i}-${t._name}`)}}l=e||l}i=n.includes(r.extname(l));let c;if(a.platform!=="win32"){if(i){e.unshift(l);e=incrementNodeInspectorPort(a.execArgv).concat(e);c=s.spawn(a.argv[0],e,{stdio:"inherit"})}else{c=s.spawn(l,e,{stdio:"inherit"})}}else{this._checkForMissingExecutable(l,h,t._name);e.unshift(l);e=incrementNodeInspectorPort(a.execArgv).concat(e);c=s.spawn(a.execPath,e,{stdio:"inherit"})}if(!c.killed){const t=["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"];t.forEach((t=>{a.on(t,(()=>{if(c.killed===false&&c.exitCode===null){c.kill(t)}}))}))}const p=this._exitCallback;c.on("close",(t=>{t=t??1;if(!p){a.exit(t)}else{p(new u(t,"commander.executeSubCommandAsync","(close)"))}}));c.on("error",(e=>{if(e.code==="ENOENT"){this._checkForMissingExecutable(l,h,t._name)}else if(e.code==="EACCES"){throw new Error(`'${l}' not executable`)}if(!p){a.exit(1)}else{const t=new u(1,"commander.executeSubCommandAsync","(error)");t.nestedError=e;p(t)}}));this.runningCommand=c}_dispatchSubcommand(t,e,i){const n=this._findCommand(t);if(!n)this.help({error:true});n._prepareForParse();let s;s=this._chainOrCallSubCommandHook(s,n,"preSubcommand");s=this._chainOrCall(s,(()=>{if(n._executableHandler){this._executeSubCommand(n,e.concat(i))}else{return n._parseCommand(e,i)}}));return s}_dispatchHelpCommand(t){if(!t){this.help()}const e=this._findCommand(t);if(e&&!e._executableHandler){e.help()}return this._dispatchSubcommand(t,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach(((t,e)=>{if(t.required&&this.args[e]==null){this.missingArgument(t.name())}}));if(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic){return}if(this.args.length>this.registeredArguments.length){this._excessArguments(this.args)}}_processArguments(){const myParseArg=(t,e,i)=>{let n=e;if(e!==null&&t.parseArg){const s=`error: command-argument value '${e}' is invalid for argument '${t.name()}'.`;n=this._callParseArg(t,e,i,s)}return n};this._checkNumberOfArguments();const t=[];this.registeredArguments.forEach(((e,i)=>{let n=e.defaultValue;if(e.variadic){if(i<this.args.length){n=this.args.slice(i);if(e.parseArg){n=n.reduce(((t,i)=>myParseArg(e,i,t)),e.defaultValue)}}else if(n===undefined){n=[]}}else if(i<this.args.length){n=this.args[i];if(e.parseArg){n=myParseArg(e,n,e.defaultValue)}}t[i]=n}));this.processedArgs=t}_chainOrCall(t,e){if(t&&t.then&&typeof t.then==="function"){return t.then((()=>e()))}return e()}_chainOrCallHooks(t,e){let i=t;const n=[];this._getCommandAndAncestors().reverse().filter((t=>t._lifeCycleHooks[e]!==undefined)).forEach((t=>{t._lifeCycleHooks[e].forEach((e=>{n.push({hookedCommand:t,callback:e})}))}));if(e==="postAction"){n.reverse()}n.forEach((t=>{i=this._chainOrCall(i,(()=>t.callback(t.hookedCommand,this)))}));return i}_chainOrCallSubCommandHook(t,e,i){let n=t;if(this._lifeCycleHooks[i]!==undefined){this._lifeCycleHooks[i].forEach((t=>{n=this._chainOrCall(n,(()=>t(this,e)))}))}return n}_parseCommand(t,e){const i=this.parseOptions(e);this._parseOptionsEnv();this._parseOptionsImplied();t=t.concat(i.operands);e=i.unknown;this.args=t.concat(e);if(t&&this._findCommand(t[0])){return this._dispatchSubcommand(t[0],t.slice(1),e)}if(this._getHelpCommand()&&t[0]===this._getHelpCommand().name()){return this._dispatchHelpCommand(t[1])}if(this._defaultCommandName){this._outputHelpIfRequested(e);return this._dispatchSubcommand(this._defaultCommandName,t,e)}if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName){this.help({error:true})}this._outputHelpIfRequested(i.unknown);this._checkForMissingMandatoryOptions();this._checkForConflictingOptions();const checkForUnknownOptions=()=>{if(i.unknown.length>0){this.unknownOption(i.unknown[0])}};const n=`command:${this.name()}`;if(this._actionHandler){checkForUnknownOptions();this._processArguments();let i;i=this._chainOrCallHooks(i,"preAction");i=this._chainOrCall(i,(()=>this._actionHandler(this.processedArgs)));if(this.parent){i=this._chainOrCall(i,(()=>{this.parent.emit(n,t,e)}))}i=this._chainOrCallHooks(i,"postAction");return i}if(this.parent&&this.parent.listenerCount(n)){checkForUnknownOptions();this._processArguments();this.parent.emit(n,t,e)}else if(t.length){if(this._findCommand("*")){return this._dispatchSubcommand("*",t,e)}if(this.listenerCount("command:*")){this.emit("command:*",t,e)}else if(this.commands.length){this.unknownCommand()}else{checkForUnknownOptions();this._processArguments()}}else if(this.commands.length){checkForUnknownOptions();this.help({error:true})}else{checkForUnknownOptions();this._processArguments()}}_findCommand(t){if(!t)return undefined;return this.commands.find((e=>e._name===t||e._aliases.includes(t)))}_findOption(t){return this.options.find((e=>e.is(t)))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((t=>{t.options.forEach((e=>{if(e.mandatory&&t.getOptionValue(e.attributeName())===undefined){t.missingMandatoryOptionValue(e)}}))}))}_checkForConflictingLocalOptions(){const t=this.options.filter((t=>{const e=t.attributeName();if(this.getOptionValue(e)===undefined){return false}return this.getOptionValueSource(e)!=="default"}));const e=t.filter((t=>t.conflictsWith.length>0));e.forEach((e=>{const i=t.find((t=>e.conflictsWith.includes(t.attributeName())));if(i){this._conflictingOption(e,i)}}))}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((t=>{t._checkForConflictingLocalOptions()}))}parseOptions(t){const e=[];const i=[];let n=e;const s=t.slice();function maybeOption(t){return t.length>1&&t[0]==="-"}let r=null;while(s.length){const t=s.shift();if(t==="--"){if(n===i)n.push(t);n.push(...s);break}if(r&&!maybeOption(t)){this.emit(`option:${r.name()}`,t);continue}r=null;if(maybeOption(t)){const e=this._findOption(t);if(e){if(e.required){const t=s.shift();if(t===undefined)this.optionMissingArgument(e);this.emit(`option:${e.name()}`,t)}else if(e.optional){let t=null;if(s.length>0&&!maybeOption(s[0])){t=s.shift()}this.emit(`option:${e.name()}`,t)}else{this.emit(`option:${e.name()}`)}r=e.variadic?e:null;continue}}if(t.length>2&&t[0]==="-"&&t[1]!=="-"){const e=this._findOption(`-${t[1]}`);if(e){if(e.required||e.optional&&this._combineFlagAndOptionalValue){this.emit(`option:${e.name()}`,t.slice(2))}else{this.emit(`option:${e.name()}`);s.unshift(`-${t.slice(2)}`)}continue}}if(/^--[^=]+=/.test(t)){const e=t.indexOf("=");const i=this._findOption(t.slice(0,e));if(i&&(i.required||i.optional)){this.emit(`option:${i.name()}`,t.slice(e+1));continue}}if(maybeOption(t)){n=i}if((this._enablePositionalOptions||this._passThroughOptions)&&e.length===0&&i.length===0){if(this._findCommand(t)){e.push(t);if(s.length>0)i.push(...s);break}else if(this._getHelpCommand()&&t===this._getHelpCommand().name()){e.push(t);if(s.length>0)e.push(...s);break}else if(this._defaultCommandName){i.push(t);if(s.length>0)i.push(...s);break}}if(this._passThroughOptions){n.push(t);if(s.length>0)n.push(...s);break}n.push(t)}return{operands:e,unknown:i}}opts(){if(this._storeOptionsAsProperties){const t={};const e=this.options.length;for(let i=0;i<e;i++){const e=this.options[i].attributeName();t[e]=e===this._versionOptionName?this._version:this[e]}return t}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce(((t,e)=>Object.assign(t,e.opts())),{})}error(t,e){this._outputConfiguration.outputError(`${t}\n`,this._outputConfiguration.writeErr);if(typeof this._showHelpAfterError==="string"){this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`)}else if(this._showHelpAfterError){this._outputConfiguration.writeErr("\n");this.outputHelp({error:true})}const i=e||{};const n=i.exitCode||1;const s=i.code||"commander.error";this._exit(n,s,t)}_parseOptionsEnv(){this.options.forEach((t=>{if(t.envVar&&t.envVar in a.env){const e=t.attributeName();if(this.getOptionValue(e)===undefined||["default","config","env"].includes(this.getOptionValueSource(e))){if(t.required||t.optional){this.emit(`optionEnv:${t.name()}`,a.env[t.envVar])}else{this.emit(`optionEnv:${t.name()}`)}}}}))}_parseOptionsImplied(){const t=new m(this.options);const hasCustomOptionValue=t=>this.getOptionValue(t)!==undefined&&!["default","implied"].includes(this.getOptionValueSource(t));this.options.filter((e=>e.implied!==undefined&&hasCustomOptionValue(e.attributeName())&&t.valueFromOption(this.getOptionValue(e.attributeName()),e))).forEach((t=>{Object.keys(t.implied).filter((t=>!hasCustomOptionValue(t))).forEach((e=>{this.setOptionValueWithSource(e,t.implied[e],"implied")}))}))}missingArgument(t){const e=`error: missing required argument '${t}'`;this.error(e,{code:"commander.missingArgument"})}optionMissingArgument(t){const e=`error: option '${t.flags}' argument missing`;this.error(e,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(t){const e=`error: required option '${t.flags}' not specified`;this.error(e,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(t,e){const findBestOptionFromValue=t=>{const e=t.attributeName();const i=this.getOptionValue(e);const n=this.options.find((t=>t.negate&&e===t.attributeName()));const s=this.options.find((t=>!t.negate&&e===t.attributeName()));if(n&&(n.presetArg===undefined&&i===false||n.presetArg!==undefined&&i===n.presetArg)){return n}return s||t};const getErrorMessage=t=>{const e=findBestOptionFromValue(t);const i=e.attributeName();const n=this.getOptionValueSource(i);if(n==="env"){return`environment variable '${e.envVar}'`}return`option '${e.flags}'`};const i=`error: ${getErrorMessage(t)} cannot be used with ${getErrorMessage(e)}`;this.error(i,{code:"commander.conflictingOption"})}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let i=[];let n=this;do{const t=n.createHelp().visibleOptions(n).filter((t=>t.long)).map((t=>t.long));i=i.concat(t);n=n.parent}while(n&&!n._enablePositionalOptions);e=f(t,i)}const i=`error: unknown option '${t}'${e}`;this.error(i,{code:"commander.unknownOption"})}_excessArguments(t){if(this._allowExcessArguments)return;const e=this.registeredArguments.length;const i=e===1?"":"s";const n=this.parent?` for '${this.name()}'`:"";const s=`error: too many arguments${n}. Expected ${e} argument${i} but got ${t.length}.`;this.error(s,{code:"commander.excessArguments"})}unknownCommand(){const t=this.args[0];let e="";if(this._showSuggestionAfterError){const i=[];this.createHelp().visibleCommands(this).forEach((t=>{i.push(t.name());if(t.alias())i.push(t.alias())}));e=f(t,i)}const i=`error: unknown command '${t}'${e}`;this.error(i,{code:"commander.unknownCommand"})}version(t,e,i){if(t===undefined)return this._version;this._version=t;e=e||"-V, --version";i=i||"output the version number";const n=this.createOption(e,i);this._versionOptionName=n.attributeName();this._registerOption(n);this.on("option:"+n.name(),(()=>{this._outputConfiguration.writeOut(`${t}\n`);this._exit(0,"commander.version",t)}));return this}description(t,e){if(t===undefined&&e===undefined)return this._description;this._description=t;if(e){this._argsDescription=e}return this}summary(t){if(t===undefined)return this._summary;this._summary=t;return this}alias(t){if(t===undefined)return this._aliases[0];let e=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler){e=this.commands[this.commands.length-1]}if(t===e._name)throw new Error("Command alias can't be the same as its name");const i=this.parent?._findCommand(t);if(i){const e=[i.name()].concat(i.aliases()).join("|");throw new Error(`cannot add alias '${t}' to command '${this.name()}' as already have command '${e}'`)}e._aliases.push(t);return this}aliases(t){if(t===undefined)return this._aliases;t.forEach((t=>this.alias(t)));return this}usage(t){if(t===undefined){if(this._usage)return this._usage;const t=this.registeredArguments.map((t=>h(t)));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}this._usage=t;return this}name(t){if(t===undefined)return this._name;this._name=t;return this}nameFromFilename(t){this._name=r.basename(t,r.extname(t));return this}executableDir(t){if(t===undefined)return this._executableDir;this._executableDir=t;return this}helpInformation(t){const e=this.createHelp();const i=this._getOutputContext(t);e.prepareContext({error:i.error,helpWidth:i.helpWidth,outputHasColors:i.hasColors});const n=e.formatHelp(this,e);if(i.hasColors)return n;return this._outputConfiguration.stripColor(n)}_getOutputContext(t){t=t||{};const e=!!t.error;let i;let n;let s;if(e){i=t=>this._outputConfiguration.writeErr(t);n=this._outputConfiguration.getErrHasColors();s=this._outputConfiguration.getErrHelpWidth()}else{i=t=>this._outputConfiguration.writeOut(t);n=this._outputConfiguration.getOutHasColors();s=this._outputConfiguration.getOutHelpWidth()}const write=t=>{if(!n)t=this._outputConfiguration.stripColor(t);return i(t)};return{error:e,write:write,hasColors:n,helpWidth:s}}outputHelp(t){let e;if(typeof t==="function"){e=t;t=undefined}const i=this._getOutputContext(t);const n={error:i.error,write:i.write,command:this};this._getCommandAndAncestors().reverse().forEach((t=>t.emit("beforeAllHelp",n)));this.emit("beforeHelp",n);let s=this.helpInformation({error:i.error});if(e){s=e(s);if(typeof s!=="string"&&!Buffer.isBuffer(s)){throw new Error("outputHelp callback must return a string or a Buffer")}}i.write(s);if(this._getHelpOption()?.long){this.emit(this._getHelpOption().long)}this.emit("afterHelp",n);this._getCommandAndAncestors().forEach((t=>t.emit("afterAllHelp",n)))}helpOption(t,e){if(typeof t==="boolean"){if(t){this._helpOption=this._helpOption??undefined}else{this._helpOption=null}return this}t=t??"-h, --help";e=e??"display help for command";this._helpOption=this.createOption(t,e);return this}_getHelpOption(){if(this._helpOption===undefined){this.helpOption(undefined,undefined)}return this._helpOption}addHelpOption(t){this._helpOption=t;return this}help(t){this.outputHelp(t);let e=Number(a.exitCode??0);if(e===0&&t&&typeof t!=="function"&&t.error){e=1}this._exit(e,"commander.help","(outputHelp)")}addHelpText(t,e){const i=["beforeAll","before","after","afterAll"];if(!i.includes(t)){throw new Error(`Unexpected value for position to addHelpText.\nExpecting one of '${i.join("', '")}'`)}const n=`${t}Help`;this.on(n,(t=>{let i;if(typeof e==="function"){i=e({error:t.error,command:t.command})}else{i=e}if(i){t.write(`${i}\n`)}}));return this}_outputHelpIfRequested(t){const e=this._getHelpOption();const i=e&&t.find((t=>e.is(t)));if(i){this.outputHelp();this._exit(0,"commander.helpDisplayed","(outputHelp)")}}}function incrementNodeInspectorPort(t){return t.map((t=>{if(!t.startsWith("--inspect")){return t}let e;let i="127.0.0.1";let n="9229";let s;if((s=t.match(/^(--inspect(-brk)?)$/))!==null){e=s[1]}else if((s=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null){e=s[1];if(/^\d+$/.test(s[3])){n=s[3]}else{i=s[3]}}else if((s=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null){e=s[1];i=s[3];n=s[4]}if(e&&n!=="0"){return`${e}=${i}:${parseInt(n)+1}`}return t}))}function useColor(){if(a.env.NO_COLOR||a.env.FORCE_COLOR==="0"||a.env.FORCE_COLOR==="false")return false;if(a.env.FORCE_COLOR||a.env.CLICOLOR_FORCE!==undefined)return true;return undefined}e.Command=Command;e.useColor=useColor},671:function(t,e){class CommanderError extends Error{constructor(t,e,i){super(i);Error.captureStackTrace(this,this.constructor);this.name=this.constructor.name;this.code=e;this.exitCode=t;this.nestedError=undefined}}class InvalidArgumentError extends CommanderError{constructor(t){super(1,"commander.invalidArgument",t);Error.captureStackTrace(this,this.constructor);this.name=this.constructor.name}}e.CommanderError=CommanderError;e.InvalidArgumentError=InvalidArgumentError},896:function(t,e,i){const{humanReadableArgName:n}=i(354);class Help{constructor(){this.helpWidth=undefined;this.minWidthToWrap=40;this.sortSubcommands=false;this.sortOptions=false;this.showGlobalOptions=false}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80}visibleCommands(t){const e=t.commands.filter((t=>!t._hidden));const i=t._getHelpCommand();if(i&&!i._hidden){e.push(i)}if(this.sortSubcommands){e.sort(((t,e)=>t.name().localeCompare(e.name())))}return e}compareOptions(t,e){const getSortKey=t=>t.short?t.short.replace(/^-/,""):t.long.replace(/^--/,"");return getSortKey(t).localeCompare(getSortKey(e))}visibleOptions(t){const e=t.options.filter((t=>!t.hidden));const i=t._getHelpOption();if(i&&!i.hidden){const n=i.short&&t._findOption(i.short);const s=i.long&&t._findOption(i.long);if(!n&&!s){e.push(i)}else if(i.long&&!s){e.push(t.createOption(i.long,i.description))}else if(i.short&&!n){e.push(t.createOption(i.short,i.description))}}if(this.sortOptions){e.sort(this.compareOptions)}return e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];const e=[];for(let i=t.parent;i;i=i.parent){const t=i.options.filter((t=>!t.hidden));e.push(...t)}if(this.sortOptions){e.sort(this.compareOptions)}return e}visibleArguments(t){if(t._argsDescription){t.registeredArguments.forEach((e=>{e.description=e.description||t._argsDescription[e.name()]||""}))}if(t.registeredArguments.find((t=>t.description))){return t.registeredArguments}return[]}subcommandTerm(t){const e=t.registeredArguments.map((t=>n(t))).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(e?" "+e:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce(((t,i)=>Math.max(t,this.displayWidth(e.styleSubcommandTerm(e.subcommandTerm(i))))),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce(((t,i)=>Math.max(t,this.displayWidth(e.styleOptionTerm(e.optionTerm(i))))),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce(((t,i)=>Math.max(t,this.displayWidth(e.styleOptionTerm(e.optionTerm(i))))),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce(((t,i)=>Math.max(t,this.displayWidth(e.styleArgumentTerm(e.argumentTerm(i))))),0)}commandUsage(t){let e=t._name;if(t._aliases[0]){e=e+"|"+t._aliases[0]}let i="";for(let e=t.parent;e;e=e.parent){i=e.name()+" "+i}return i+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){const e=[];if(t.argChoices){e.push(`choices: ${t.argChoices.map((t=>JSON.stringify(t))).join(", ")}`)}if(t.defaultValue!==undefined){const i=t.required||t.optional||t.isBoolean()&&typeof t.defaultValue==="boolean";if(i){e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`)}}if(t.presetArg!==undefined&&t.optional){e.push(`preset: ${JSON.stringify(t.presetArg)}`)}if(t.envVar!==undefined){e.push(`env: ${t.envVar}`)}if(e.length>0){return`${t.description} (${e.join(", ")})`}return t.description}argumentDescription(t){const e=[];if(t.argChoices){e.push(`choices: ${t.argChoices.map((t=>JSON.stringify(t))).join(", ")}`)}if(t.defaultValue!==undefined){e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`)}if(e.length>0){const i=`(${e.join(", ")})`;if(t.description){return`${t.description} ${i}`}return i}return t.description}formatHelp(t,e){const i=e.padWidth(t,e);const n=e.helpWidth??80;function callFormatItem(t,n){return e.formatItem(t,i,n,e)}let s=[`${e.styleTitle("Usage:")} ${e.styleUsage(e.commandUsage(t))}`,""];const r=e.commandDescription(t);if(r.length>0){s=s.concat([e.boxWrap(e.styleCommandDescription(r),n),""])}const o=e.visibleArguments(t).map((t=>callFormatItem(e.styleArgumentTerm(e.argumentTerm(t)),e.styleArgumentDescription(e.argumentDescription(t)))));if(o.length>0){s=s.concat([e.styleTitle("Arguments:"),...o,""])}const a=e.visibleOptions(t).map((t=>callFormatItem(e.styleOptionTerm(e.optionTerm(t)),e.styleOptionDescription(e.optionDescription(t)))));if(a.length>0){s=s.concat([e.styleTitle("Options:"),...a,""])}if(e.showGlobalOptions){const i=e.visibleGlobalOptions(t).map((t=>callFormatItem(e.styleOptionTerm(e.optionTerm(t)),e.styleOptionDescription(e.optionDescription(t)))));if(i.length>0){s=s.concat([e.styleTitle("Global Options:"),...i,""])}}const l=e.visibleCommands(t).map((t=>callFormatItem(e.styleSubcommandTerm(e.subcommandTerm(t)),e.styleSubcommandDescription(e.subcommandDescription(t)))));if(l.length>0){s=s.concat([e.styleTitle("Commands:"),...l,""])}return s.join("\n")}displayWidth(t){return stripColor(t).length}styleTitle(t){return t}styleUsage(t){return t.split(" ").map((t=>{if(t==="[options]")return this.styleOptionText(t);if(t==="[command]")return this.styleSubcommandText(t);if(t[0]==="["||t[0]==="<")return this.styleArgumentText(t);return this.styleCommandText(t)})).join(" ")}styleCommandDescription(t){return this.styleDescriptionText(t)}styleOptionDescription(t){return this.styleDescriptionText(t)}styleSubcommandDescription(t){return this.styleDescriptionText(t)}styleArgumentDescription(t){return this.styleDescriptionText(t)}styleDescriptionText(t){return t}styleOptionTerm(t){return this.styleOptionText(t)}styleSubcommandTerm(t){return t.split(" ").map((t=>{if(t==="[options]")return this.styleOptionText(t);if(t[0]==="["||t[0]==="<")return this.styleArgumentText(t);return this.styleSubcommandText(t)})).join(" ")}styleArgumentTerm(t){return this.styleArgumentText(t)}styleOptionText(t){return t}styleArgumentText(t){return t}styleSubcommandText(t){return t}styleCommandText(t){return t}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestGlobalOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}preformatted(t){return/\n[^\S\r\n]/.test(t)}formatItem(t,e,i,n){const s=2;const r=" ".repeat(s);if(!i)return r+t;const o=t.padEnd(e+t.length-n.displayWidth(t));const a=2;const l=this.helpWidth??80;const h=l-e-a-s;let u;if(h<this.minWidthToWrap||n.preformatted(i)){u=i}else{const t=n.boxWrap(i,h);u=t.replace(/\n/g,"\n"+" ".repeat(e+a))}return r+o+" ".repeat(a)+u.replace(/\n/g,`\n${r}`)}boxWrap(t,e){if(e<this.minWidthToWrap)return t;const i=t.split(/\r\n|\n/);const n=/[\s]*[^\s]+/g;const s=[];i.forEach((t=>{const i=t.match(n);if(i===null){s.push("");return}let r=[i.shift()];let o=this.displayWidth(r[0]);i.forEach((t=>{const i=this.displayWidth(t);if(o+i<=e){r.push(t);o+=i;return}s.push(r.join(""));const n=t.trimStart();r=[n];o=this.displayWidth(n)}));s.push(r.join(""))}));return s.join("\n")}}function stripColor(t){const e=/\x1b\[\d*(;\d*)*m/g;return t.replace(e,"")}e.Help=Help;e.stripColor=stripColor},284:function(t,e,i){const{InvalidArgumentError:n}=i(671);class Option{constructor(t,e){this.flags=t;this.description=e||"";this.required=t.includes("<");this.optional=t.includes("[");this.variadic=/\w\.\.\.[>\]]$/.test(t);this.mandatory=false;const i=splitOptionFlags(t);this.short=i.shortFlag;this.long=i.longFlag;this.negate=false;if(this.long){this.negate=this.long.startsWith("--no-")}this.defaultValue=undefined;this.defaultValueDescription=undefined;this.presetArg=undefined;this.envVar=undefined;this.parseArg=undefined;this.hidden=false;this.argChoices=undefined;this.conflictsWith=[];this.implied=undefined}default(t,e){this.defaultValue=t;this.defaultValueDescription=e;return this}preset(t){this.presetArg=t;return this}conflicts(t){this.conflictsWith=this.conflictsWith.concat(t);return this}implies(t){let e=t;if(typeof t==="string"){e={[t]:true}}this.implied=Object.assign(this.implied||{},e);return this}env(t){this.envVar=t;return this}argParser(t){this.parseArg=t;return this}makeOptionMandatory(t=true){this.mandatory=!!t;return this}hideHelp(t=true){this.hidden=!!t;return this}_concatValue(t,e){if(e===this.defaultValue||!Array.isArray(e)){return[t]}return e.concat(t)}choices(t){this.argChoices=t.slice();this.parseArg=(t,e)=>{if(!this.argChoices.includes(t)){throw new n(`Allowed choices are ${this.argChoices.join(", ")}.`)}if(this.variadic){return this._concatValue(t,e)}return t};return this}name(){if(this.long){return this.long.replace(/^--/,"")}return this.short.replace(/^-/,"")}attributeName(){if(this.negate){return camelcase(this.name().replace(/^no-/,""))}return camelcase(this.name())}is(t){return this.short===t||this.long===t}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class DualOptions{constructor(t){this.positiveOptions=new Map;this.negativeOptions=new Map;this.dualOptions=new Set;t.forEach((t=>{if(t.negate){this.negativeOptions.set(t.attributeName(),t)}else{this.positiveOptions.set(t.attributeName(),t)}}));this.negativeOptions.forEach(((t,e)=>{if(this.positiveOptions.has(e)){this.dualOptions.add(e)}}))}valueFromOption(t,e){const i=e.attributeName();if(!this.dualOptions.has(i))return true;const n=this.negativeOptions.get(i).presetArg;const s=n!==undefined?n:false;return e.negate===(s===t)}}function camelcase(t){return t.split("-").reduce(((t,e)=>t+e[0].toUpperCase()+e.slice(1)))}function splitOptionFlags(t){let e;let i;const n=/^-[^-]$/;const s=/^--[^-]/;const r=t.split(/[ |,]+/).concat("guard");if(n.test(r[0]))e=r.shift();if(s.test(r[0]))i=r.shift();if(!e&&n.test(r[0]))e=r.shift();if(!e&&s.test(r[0])){e=i;i=r.shift()}if(r[0].startsWith("-")){const e=r[0];const i=`option creation failed due to '${e}' in option flags '${t}'`;if(/^-[^-][^-]/.test(e))throw new Error(`${i}\n- a short flag is a single dash and a single character\n - either use a single dash and a single character (for a short flag)\n - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(n.test(e))throw new Error(`${i}\n- too many short flags`);if(s.test(e))throw new Error(`${i}\n- too many long flags`);throw new Error(`${i}\n- unrecognised flag format`)}if(e===undefined&&i===undefined)throw new Error(`option creation failed due to no flags found in '${t}'.`);return{shortFlag:e,longFlag:i}}e.Option=Option;e.DualOptions=DualOptions},378:function(t,e){const i=3;function editDistance(t,e){if(Math.abs(t.length-e.length)>i)return Math.max(t.length,e.length);const n=[];for(let e=0;e<=t.length;e++){n[e]=[e]}for(let t=0;t<=e.length;t++){n[0][t]=t}for(let i=1;i<=e.length;i++){for(let s=1;s<=t.length;s++){let r=1;if(t[s-1]===e[i-1]){r=0}else{r=1}n[s][i]=Math.min(n[s-1][i]+1,n[s][i-1]+1,n[s-1][i-1]+r);if(s>1&&i>1&&t[s-1]===e[i-2]&&t[s-2]===e[i-1]){n[s][i]=Math.min(n[s][i],n[s-2][i-2]+1)}}}return n[t.length][e.length]}function suggestSimilar(t,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));const n=t.startsWith("--");if(n){t=t.slice(2);e=e.map((t=>t.slice(2)))}let s=[];let r=i;const o=.4;e.forEach((e=>{if(e.length<=1)return;const i=editDistance(t,e);const n=Math.max(t.length,e.length);const a=(n-i)/n;if(a>o){if(i<r){r=i;s=[e]}else if(i===r){s.push(e)}}}));s.sort(((t,e)=>t.localeCompare(e)));if(n){s=s.map((t=>`--${t}`))}if(s.length>1){return`\n(Did you mean one of ${s.join(", ")}?)`}if(s.length===1){return`\n(Did you mean ${s[0]}?)`}return""}e.suggestSimilar=suggestSimilar}};var e={};function __nccwpck_require__(i){var n=e[i];if(n!==undefined){return n.exports}var s=e[i]={exports:{}};var r=true;try{t[i](s,s.exports,__nccwpck_require__);r=false}finally{if(r)delete e[i]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var i={};!function(){var t=i;const{Argument:e}=__nccwpck_require__(354);const{Command:n}=__nccwpck_require__(691);const{CommanderError:s,InvalidArgumentError:r}=__nccwpck_require__(671);const{Help:o}=__nccwpck_require__(896);const{Option:a}=__nccwpck_require__(284);t.program=new n;t.createCommand=t=>new n(t);t.createOption=(t,e)=>new a(t,e);t.createArgument=(t,i)=>new e(t,i);t.Command=n;t.Option=a;t.Argument=e;t.Help=o;t.CommanderError=s;t.InvalidArgumentError=r;t.InvalidOptionArgumentError=r}();module.exports=i})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"commander","version":"
|
|
1
|
+
{"name":"commander","version":"13.1.0","author":"TJ Holowaychuk <tj@vision-media.ca>","license":"MIT","_lastModified":"2025-05-29T07:54:26.342Z"}
|
package/es/yolk.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import e from"@babel/runtime/helpers/defineProperty";function t(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function o(o){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?t(Object(i),!0).forEach((function(t){e(o,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(e){Object.defineProperty(o,e,Object.getOwnPropertyDescriptor(i,e))}))}return o}import{execSync as r}from"node:child_process";import{chmodSync as i,copyFileSync as a,existsSync as n,readFileSync as s,statSync as c,writeFileSync as m}from"node:fs";import p from"node:os";import{basename as d,dirname as l,join as u,relative as g}from"node:path";import{floor as f,isString as y}from"lodash";import{globSync as h}from"glob";import v from"inquirer";import*as b from"miniprogram-ci";import{mkdirpSync as $}from"mkdirp";import{program as j}from"../compiled/commander";import k from"../compiled/mustache";import O from"../package.json";import{breakExit as w,cwd as P,ENCODING as x,error as D,execCommand as S,getPackageJSON as E,getProjectConfigJSON as q,getYolkConfig as _,info as Q,ready as N,rimrafSync as F,warn as K}from"./_util";const L="##### CREATED BY YOLK #####",R=(e,t,o)=>{v.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u6a21\u7248",default:"web",choices:[{name:"web template(umi framework)",value:"umi-web"},{name:"web big screen template(umi framework)",value:"umi-web-screen"},{name:"mobile template(umi framework)",value:"umi-mobile"},{name:"mobile HBuilderX h5+app template(umi framework)",value:"umi-mobile-h5+app"},{name:"mobile HBuilderX uni-app template(umi framework)",value:"umi-mobile-uni-app"},{name:"mobile native template(umi framework)",value:"umi-mobile-native"},{name:"taro-miniprogram template",value:"taro-miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:d(d(process.cwd()))},{type:"list",name:"packageManager",message:"\u9009\u62e9\u5305\u7ba1\u7406\u5668(\u9ed8\u8ba4\uff1apnpm\uff0c\u63a8\u8350\uff1apnpm)",default:"default",choices:[{name:"\u9ed8\u8ba4\u5b89\u88c5",value:"default"},{name:"\u8df3\u8fc7\u5b89\u88c5",value:!1},{name:"pnpm install",value:"pnpm"},{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"}]}]).then((({type:r,projectName:i,packageManager:p})=>{const f={projectName:i,packageManager:"default"===p?"pnpm":p,yolkVersion:O.version};if("umi-mobile-uni-app"===r)return void K("\u6682\u4e0d\u652f\u6301");const y=t||u(__dirname,`../templates/${r}`);N(`\u590d\u5236\u6a21\u7248 ${d(y)}`);const v=h("**/*",{cwd:y,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(v.forEach((t=>{if(!y)return;const o=u(y,t);if(!c(o).isDirectory())if(t.endsWith(".tpl")){const r=s(o,x),i=u(e,t.replace(/\.tpl$/,"")),a=k.render(r,f);$(l(i)),N(`\u521b\u5efa ${g(e,i)}`),m(i,a,x)}else{N(`\u521b\u5efa ${t}`);const r=u(e,t);$(l(r)),a(o,r)}})),N("\u590d\u5236\u6a21\u7248 success!"),o&&n(y)&&F(y)&&N(`\u7f13\u5b58\u5220\u9664 success! ${d(y||"")}`),p)switch(N("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),p){case"default":case"pnpm":S({command:"pnpm",args:["install"]});break;case"yarn":S({command:"yarn",args:["install"]});break;case"npm":S({command:"npm",args:["install"]});break;default:}N("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},M=(e,t)=>R(e,t,!0),B=()=>n(u(P,"project.config.json")),I=()=>{let e=n(u(P,"node_modules/.bin/max"));if(!e)try{e=n(require.resolve("@umijs/max"))}catch(t){}if(!e)try{e=/umi@4\.(\d+)\.(\d+)/.test(r("umi -v").toString())}catch(t){}if(!e){const o=u(P,"node_modules","umi","package.json");if(n(o))try{const t=JSON.parse(s(o,x))||{};e=t.version&&+t.version.split(".")[0]>3}catch(t){}}return e},U=()=>{const e=u(P,"project.config.json");if(n(e)){const t=require(e);return t.appid}return""},W=()=>n(u(P,"project.tt.json"))&&0===U().indexOf("tt"),A=()=>0===U().indexOf("20"),T=()=>{const e=_(),t=u(P,".husky/pre-commit"),o=u(P,".git/"),r=u(P,".git/hooks"),a=u(r,"pre-commit"),c=n(t),d=n(o),l=n(r),g=n(a),f=!1!==e.initPreCommit&&!c,y=[L,"npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",L].join(p.EOL),h=e=>{let t=e||"";return t&&t.indexOf(L)>=0&&(t=`${t.substring(0,t.indexOf(L))}${t.substring(t.lastIndexOf(L)+L.length)}`.replace(/(\r|\n)+$/gu,"")),t};if(d)if(f)if(l||($(r),N("create .git/hooks")),g){try{i(a,"777")}catch(v){D(`chmod ${a} failed: ${v.message}`)}const e=h(s(a,x).toString());m(a,(e.indexOf("#!/")<0?["#!/bin/sh"]:[]).concat([e,y]).filter((e=>!!e)).join(p.EOL),x)}else m(a,["#!/bin/sh",y].join(p.EOL),x),N("create pre-commit");else if(g){const e=h(s(a,x).toString());m(a,e,x)}},V=()=>{K("\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),S({command:"lint-staged",args:["-c",require.resolve("./lintstagedrc")]})},X=({mAppid:e,mProject:t,mPrivateKeyPath:i,mVersion:a,mDesc:s,mRobot:c,mQrcodeFormat:m,mQrcodeOutputDest:p,mPagePath:d,mSearchQuery:l})=>{let g="";try{g=n(u(P,".git"))?r("git log -1 --pretty=format:%H").toString():""}catch(D){}const f=q(),y=e||f.appid,h=t||u(P,"dist"),v=i||u(P,`private.${y}.key`);if(n(h)){if(n(v)){const e=E(),t=a||e.version||f.version||"1.0.0",r=s||e.description||f.description,i=`${g?` commit: ${g};`:""}${r?` description: ${r};`:""}`;g&&Q(`commit: ${g}`),Q(`dist: ${h}`),Q(`key: ${v}`),Q(`appid: ${y}`),Q(`version: ${t}`),Q(`desc: ${i}`);const n=new b.Project({appid:y,type:"miniProgram",projectPath:h,privateKeyPath:v,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:y,options:{project:n,version:t,desc:i,setting:o(o({},f.setting),{},{es6:!1,es7:!1,minifyJS:!1,minifyWXML:!1,minifyWXSS:!1,minify:!1}),robot:c,qrcodeFormat:m,qrcodeOutputDest:p,pagePath:d,searchQuery:l}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${v})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${h})`)},C=()=>{let e="";try{e=r(`npm view ${O.name} version`,{timeout:3e3}).toString().replace(/\n/g,"")}catch(t){}Q(`yolk version: ${O.version}${e&&e!==O.version?`(latest\uff1a${e})`:""}`),Q(`node version: ${process.version}`),Q(`platform: ${p.platform()}`),Q(`memory: ${f(p.freemem()/1024/1024)} MB(${f(p.totalmem()/1024/1024)} MB)`)},H=e=>e.option("--appid, --mAppid <appid>","\u5c0f\u7a0b\u5e8fappid").option("--project, --mProject <project>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u5de5\u7a0b\u76ee\u5f55").option("--privateKeyPath, --mPrivateKeyPath <privateKeyPath>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20key\u6587\u4ef6\uff0c\u9ed8\u8ba4\uff1a{\u5f53\u524d\u76ee\u5f55}/private.{appid}.key").option("--version, --mVersion <version>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u7248\u672c\u53f7").option("--desc, --mDesc <desc>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u63cf\u8ff0").option("--robot, --mRobot <robot>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20ci\u673a\u5668\u4eba1~30").option("--qrcodeFormat, --mQrcodeFormat <qrcodeFormat>",'\u5c0f\u7a0b\u5e8f\u9884\u89c8\u8fd4\u56de\u4e8c\u7ef4\u7801\u6587\u4ef6\u7684\u683c\u5f0f "image" \u6216 "base64"\uff0c \u9ed8\u8ba4\u503c "terminal" \u4f9b\u8c03\u8bd5\u7528').option("--qrcodeOutputDest, --mQrcodeOutputDest <qrcodeOutputDest>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u4e8c\u7ef4\u7801\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84").option("--pagePath, --mPagePath <pagePath>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84").option("--searchQuery, --mSearchQuery <searchQuery>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84\u542f\u52a8\u53c2\u6570"),J=/(\w+)=('(.*)'|"(.*)"|(.*))/giu,Y=e=>{process.env.DID_YOU_KNOW="none",process.env.VITE_CJS_IGNORE_WARNING="true";const t=[];return null===e||void 0===e||e.forEach((e=>{if(J.test(e)){const[t,o]=e.split("=");process.env[t]=o,Q(`\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a${t}=${o}`)}else t.push(e)})),t},G=()=>{T(),process.argv.length>2?(j.version(O.version,"-v,--version","\u8f93\u51fa\u7248\u672c\u53f7").usage("[command] [options]"),j.command("init").description("\u521d\u59cb\u5316\u9879\u76ee").option("--clone <template>","\u5982\u679c\u9700\u8981\uff0c\u53ef\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248\uff0c\u9ed8\u8ba4\u53d6cli\u9ed8\u8ba4\u6a21\u7248").action((({clone:e},{args:t})=>{if(C(),N("yolk init \u5f00\u59cb"),e){const o=".yolk",r=u(P,o);n(r)&&F(r)&&N(`\u7f13\u5b58\u5220\u9664 success! ${r}`),S({command:"git",args:["clone","-b","master","--depth","1",e,o].concat(t)}),M(P,r)}else R(P)})),j.command("start").description("\u542f\u52a8\u9879\u76ee").option("--docs","\u6587\u6863\u6a21\u5f0f").action((({docs:e},{args:t})=>{C();const o=Y(t);B()?W()?S({command:"taro",args:["build","--type","tt","--watch"].concat(o)}):A()?S({command:"taro",args:["build","--type","alipay","--watch"].concat(o)}):S({command:"taro",args:["build","--type","weapp","--watch"].concat(o)}):e?S({command:"dumi",args:["dev"].concat(o)}):I()?S({command:"max",args:["dev"].concat(o)}):S({command:"umi",args:["dev"].concat(o)})})),j.command("build").description("\u7f16\u8bd1\u9879\u76ee").option("--docs","\u6587\u6863\u6a21\u5f0f").action((({docs:e},{args:t})=>{C();const o=Y(t);B()?W()?S({command:"taro",args:["build","--type","tt"].concat(o)}):A()?S({command:"taro",args:["build","--type","alipay"].concat(o)}):S({command:"taro",args:["build","--type","weapp"].concat(o)}):e?S({command:"dumi",args:["build"].concat(o)}):I()?S({command:"max",args:["setup"].concat(o),complete:()=>S({command:"max",args:["build"].concat(o)}),exit:!1}):S({command:"umi",args:["build"].concat(o)})})),j.command("init-pre-commit").description("\u521d\u59cb\u5316 commit hook").action(T),j.command("pre-commit").description("\u6267\u884ccommit hook").action(V),H(j.command("miniprogram-upload").description("\u4f7f\u7528 miniprogram-ci \u4e0a\u4f20\u5c0f\u7a0b\u5e8f")).action((e=>{if(B())if(W());else if(A());else{const{appid:t,options:{project:o,version:r,desc:i,setting:a,robot:n}}=X(e);Q(`${t} \u4e0a\u4f20\u5f00\u59cb`),b.upload({project:o,version:r,desc:i,setting:a,robot:n,onProgressUpdate:e=>{if(y(e))Q(`task: ${e}`);else{const{status:t,message:o}=e;Q(`task(${t}): ${o}`)}}}).then((()=>{N(`${t} \u4e0a\u4f20\u5b8c\u6210`)}))}else D("\u975e\u5c0f\u7a0b\u5e8f\u9879\u76ee\u76ee\u5f55")})),H(j.command("miniprogram-preview").description("\u4f7f\u7528 miniprogram-ci \u9884\u89c8\u5c0f\u7a0b\u5e8f")).action((e=>{if(B())if(W());else if(A());else{const{appid:t,options:{project:o,version:r,desc:i,setting:a,robot:n,qrcodeFormat:s,qrcodeOutputDest:c,pagePath:m,searchQuery:p}}=X(e);Q(`${t} \u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),b.preview({project:o,version:r,desc:i,setting:a,robot:n,qrcodeFormat:s,qrcodeOutputDest:c,pagePath:m,searchQuery:p,onProgressUpdate:e=>{if(y(e))Q(`task: ${e}`);else{const{status:t,message:o}=e;Q(`task(${t}): ${o}`)}}}).then((()=>{N(`${t} \u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}else D("\u975e\u5c0f\u7a0b\u5e8f\u9879\u76ee\u76ee\u5f55")})),j.command("exec").description("\u6267\u884cts\u6587\u4ef6").argument("<path>","\u6267\u884c\u7684ts\u6587\u4ef6").action(((e,t,{args:o})=>{const r=Y(o);S({command:"tsx",args:[e].concat(r)})})),j.command("test").description("\u6267\u884c\u6d4b\u8bd5").option("--config","\u914d\u7f6e\u6587\u4ef6\u5730\u5740").option("--framework <framework>","\u6d4b\u8bd5\u6846\u67b6").action((({config:e},{args:t})=>{const o=Y(t);S({command:"yest",args:["run"].concat(e?["--config",e]:[]).concat(o)})})),j.parse(process.argv)):w()};G();
|
|
2
|
+
import e from"@babel/runtime/helpers/defineProperty";function t(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function o(o){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?t(Object(i),!0).forEach((function(t){e(o,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(e){Object.defineProperty(o,e,Object.getOwnPropertyDescriptor(i,e))}))}return o}import{execSync as r}from"node:child_process";import{chmodSync as i,copyFileSync as a,existsSync as n,readFileSync as s,statSync as c,writeFileSync as m}from"node:fs";import p from"node:os";import{basename as d,dirname as l,join as u,relative as g}from"node:path";import{floor as f,isString as y}from"lodash";import{globSync as h}from"glob";import v from"inquirer";import*as b from"miniprogram-ci";import{mkdirpSync as $}from"mkdirp";import{program as j}from"../compiled/commander";import k from"../compiled/mustache";import O from"../package.json";import{breakExit as w,cwd as P,ENCODING as x,error as D,execCommand as S,getPackageJSON as E,getProjectConfigJSON as q,getYolkConfig as _,info as Q,ready as N,rimrafSync as F,warn as K}from"./_util";const L="##### CREATED BY YOLK #####",R=(e,t,o)=>{v.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u6a21\u7248",default:"web",choices:[{name:"web template(umi framework)",value:"umi-web"},{name:"web big screen template(umi framework)",value:"umi-web-screen"},{name:"mobile template(umi framework)",value:"umi-mobile"},{name:"mobile HBuilderX h5+app template(umi framework)",value:"umi-mobile-h5+app"},{name:"mobile HBuilderX uni-app template(umi framework)",value:"umi-mobile-uni-app"},{name:"mobile native template(umi framework)",value:"umi-mobile-native"},{name:"taro-miniprogram template",value:"taro-miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:d(d(process.cwd()))},{type:"list",name:"packageManager",message:"\u9009\u62e9\u5305\u7ba1\u7406\u5668(\u9ed8\u8ba4\uff1apnpm\uff0c\u63a8\u8350\uff1apnpm)",default:"default",choices:[{name:"\u9ed8\u8ba4\u5b89\u88c5",value:"default"},{name:"\u8df3\u8fc7\u5b89\u88c5",value:!1},{name:"pnpm install",value:"pnpm"},{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"}]}]).then((({type:r,projectName:i,packageManager:p})=>{const f={projectName:i,packageManager:"default"===p?"pnpm":p,yolkVersion:O.version};if("umi-mobile-uni-app"===r)return void K("\u6682\u4e0d\u652f\u6301");const y=t||u(__dirname,`../templates/${r}`);N(`\u590d\u5236\u6a21\u7248 ${d(y)}`);const v=h("**/*",{cwd:y,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(v.forEach((t=>{if(!y)return;const o=u(y,t);if(!c(o).isDirectory())if(t.endsWith(".tpl")){const r=s(o,x),i=u(e,t.replace(/\.tpl$/,"")),a=k.render(r,f);$(l(i)),N(`\u521b\u5efa ${g(e,i)}`),m(i,a,x)}else{N(`\u521b\u5efa ${t}`);const r=u(e,t);$(l(r)),a(o,r)}})),N("\u590d\u5236\u6a21\u7248 success!"),o&&n(y)&&F(y)&&N(`\u7f13\u5b58\u5220\u9664 success! ${d(y||"")}`),p)switch(N("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),p){case"default":case"pnpm":S({command:"pnpm",args:["install"]});break;case"yarn":S({command:"yarn",args:["install"]});break;case"npm":S({command:"npm",args:["install"]});break;default:}N("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},M=(e,t)=>R(e,t,!0),B=()=>n(u(P,"project.config.json")),I=()=>{let e=n(u(P,"node_modules/.bin/max"));if(!e)try{e=n(require.resolve("@umijs/max"))}catch(t){}if(!e)try{e=/umi@4\.(\d+)\.(\d+)/.test(r("umi -v").toString())}catch(t){}if(!e){const o=u(P,"node_modules","umi","package.json");if(n(o))try{const t=JSON.parse(s(o,x))||{};e=t.version&&+t.version.split(".")[0]>3}catch(t){}}return e},U=()=>{const e=u(P,"project.config.json");if(n(e)){const t=require(e);return t.appid}return""},W=()=>n(u(P,"project.tt.json"))&&0===U().indexOf("tt"),A=()=>0===U().indexOf("20"),T=()=>{const e=_(),t=u(P,".husky/pre-commit"),o=u(P,".git/"),r=u(P,".git/hooks"),a=u(r,"pre-commit"),c=n(t),d=n(o),l=n(r),g=n(a),f=!1!==e.initPreCommit&&!c,y=[L,"npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",L].join(p.EOL),h=e=>{let t=e||"";return t&&t.indexOf(L)>=0&&(t=`${t.substring(0,t.indexOf(L))}${t.substring(t.lastIndexOf(L)+L.length)}`.replace(/(\r|\n)+$/gu,"")),t};if(d)if(f)if(l||($(r),N("create .git/hooks")),g){try{i(a,"777")}catch(v){D(`chmod ${a} failed: ${v.message}`)}const e=h(s(a,x).toString());m(a,(e.indexOf("#!/")<0?["#!/bin/sh"]:[]).concat([e,y]).filter((e=>!!e)).join(p.EOL),x)}else m(a,["#!/bin/sh",y].join(p.EOL),x),N("create pre-commit");else if(g){const e=h(s(a,x).toString());m(a,e,x)}},V=()=>{K("\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),S({command:"lint-staged",args:["-c",require.resolve("./lintstagedrc")]})},X=({mAppid:e,mProject:t,mPrivateKeyPath:i,mVersion:a,mDesc:s,mRobot:c,mQrcodeFormat:m,mQrcodeOutputDest:p,mPagePath:d,mSearchQuery:l})=>{let g="";try{g=n(u(P,".git"))?r("git log -1 --pretty=format:%H").toString():""}catch(D){}const f=q(),y=e||f.appid,h=t||u(P,"dist"),v=i||u(P,`private.${y}.key`);if(n(h)){if(n(v)){const e=E(),t=a||e.version||f.version||"1.0.0",r=s||e.description||f.description,i=`${g?` commit: ${g};`:""}${r?` description: ${r};`:""}`;g&&Q(`commit: ${g}`),Q(`dist: ${h}`),Q(`key: ${v}`),Q(`appid: ${y}`),Q(`version: ${t}`),Q(`desc: ${i}`);const n=new b.Project({appid:y,type:"miniProgram",projectPath:h,privateKeyPath:v,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:y,options:{project:n,version:t,desc:i,setting:o(o({},f.setting),{},{es6:!1,es7:!1,minifyJS:!1,minifyWXML:!1,minifyWXSS:!1,minify:!1}),robot:c,qrcodeFormat:m,qrcodeOutputDest:p,pagePath:d,searchQuery:l}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${v})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${h})`)},C=()=>{let e="";try{e=r(`npm view ${O.name} version`,{timeout:3e3}).toString().replace(/\n/g,"")}catch(t){}Q(`yolk version: ${O.version}${e&&e!==O.version?`(latest\uff1a${e})`:""}`),Q(`node version: ${process.version}`),Q(`platform: ${p.platform()}`),Q(`memory: ${f(p.freemem()/1024/1024)} MB(${f(p.totalmem()/1024/1024)} MB)`)},H=e=>e.option("--appid, --mAppid <appid>","\u5c0f\u7a0b\u5e8fappid").option("--project, --mProject <project>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u5de5\u7a0b\u76ee\u5f55").option("--privateKeyPath, --mPrivateKeyPath <privateKeyPath>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20key\u6587\u4ef6\uff0c\u9ed8\u8ba4\uff1a{\u5f53\u524d\u76ee\u5f55}/private.{appid}.key").option("--version, --mVersion <version>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u7248\u672c\u53f7").option("--desc, --mDesc <desc>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u63cf\u8ff0").option("--robot, --mRobot <robot>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20ci\u673a\u5668\u4eba1~30").option("--qrcodeFormat, --mQrcodeFormat <qrcodeFormat>",'\u5c0f\u7a0b\u5e8f\u9884\u89c8\u8fd4\u56de\u4e8c\u7ef4\u7801\u6587\u4ef6\u7684\u683c\u5f0f "image" \u6216 "base64"\uff0c \u9ed8\u8ba4\u503c "terminal" \u4f9b\u8c03\u8bd5\u7528').option("--qrcodeOutputDest, --mQrcodeOutputDest <qrcodeOutputDest>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u4e8c\u7ef4\u7801\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84").option("--pagePath, --mPagePath <pagePath>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84").option("--searchQuery, --mSearchQuery <searchQuery>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84\u542f\u52a8\u53c2\u6570"),J=/(\w+)=('(.*)'|"(.*)"|(.*))/giu,Y=e=>{process.env.DID_YOU_KNOW="none",process.env.VITE_CJS_IGNORE_WARNING="true";const t=[];return null===e||void 0===e||e.forEach((e=>{if(J.test(e)){const[t,o]=e.split("=");process.env[t]=o,Q(`\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a${t}=${o}`)}else t.push(e)})),t},G=()=>{T(),process.argv.length>2?(j.version(O.version,"-v,--version","\u8f93\u51fa\u7248\u672c\u53f7").usage("[command] [options]"),j.command("init").description("\u521d\u59cb\u5316\u9879\u76ee").option("--clone <template>","\u5982\u679c\u9700\u8981\uff0c\u53ef\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248\uff0c\u9ed8\u8ba4\u53d6cli\u9ed8\u8ba4\u6a21\u7248").action((({clone:e},{args:t})=>{if(C(),N("yolk init \u5f00\u59cb"),e){const o=".yolk",r=u(P,o);n(r)&&F(r)&&N(`\u7f13\u5b58\u5220\u9664 success! ${r}`),S({command:"git",args:["clone","-b","master","--depth","1",e,o].concat(t)}),M(P,r)}else R(P)})),j.command("start").description("\u542f\u52a8\u9879\u76ee").option("--docs","\u6587\u6863\u6a21\u5f0f").action((({docs:e},{args:t})=>{C();const o=Y(t);B()?W()?S({command:"taro",args:["build","--type","tt","--watch"].concat(o)}):A()?S({command:"taro",args:["build","--type","alipay","--watch"].concat(o)}):S({command:"taro",args:["build","--type","weapp","--watch"].concat(o)}):e?S({command:"dumi",args:["dev"].concat(o)}):I()?S({command:"max",args:["dev"].concat(o)}):S({command:"umi",args:["dev"].concat(o)})})),j.command("build").description("\u7f16\u8bd1\u9879\u76ee").option("--docs","\u6587\u6863\u6a21\u5f0f").action((({docs:e},{args:t})=>{C();const o=Y(t);B()?W()?S({command:"taro",args:["build","--type","tt"].concat(o)}):A()?S({command:"taro",args:["build","--type","alipay"].concat(o)}):S({command:"taro",args:["build","--type","weapp"].concat(o)}):e?S({command:"dumi",args:["build"].concat(o)}):I()?S({command:"max",args:["setup"].concat(o),complete:()=>S({command:"max",args:["build"].concat(o)}),exit:!1}):S({command:"umi",args:["build"].concat(o)})})),j.command("init-pre-commit").description("\u521d\u59cb\u5316 commit hook").action(T),j.command("pre-commit").description("\u6267\u884ccommit hook").action(V),H(j.command("miniprogram-upload").description("\u4f7f\u7528 miniprogram-ci \u4e0a\u4f20\u5c0f\u7a0b\u5e8f")).action((e=>{if(B())if(W());else if(A());else{const{appid:t,options:{project:o,version:r,desc:i,setting:a,robot:n}}=X(e);Q(`${t} \u4e0a\u4f20\u5f00\u59cb`),b.upload({project:o,version:r,desc:i,setting:a,robot:n,onProgressUpdate:e=>{if(y(e))Q(`task: ${e}`);else{const{status:t,message:o}=e;Q(`task(${t}): ${o}`)}}}).then((()=>{N(`${t} \u4e0a\u4f20\u5b8c\u6210`)}))}else D("\u975e\u5c0f\u7a0b\u5e8f\u9879\u76ee\u76ee\u5f55")})),H(j.command("miniprogram-preview").description("\u4f7f\u7528 miniprogram-ci \u9884\u89c8\u5c0f\u7a0b\u5e8f")).action((e=>{if(B())if(W());else if(A());else{const{appid:t,options:{project:o,version:r,desc:i,setting:a,robot:n,qrcodeFormat:s,qrcodeOutputDest:c,pagePath:m,searchQuery:p}}=X(e);Q(`${t} \u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),b.preview({project:o,version:r,desc:i,setting:a,robot:n,qrcodeFormat:s,qrcodeOutputDest:c,pagePath:m,searchQuery:p,onProgressUpdate:e=>{if(y(e))Q(`task: ${e}`);else{const{status:t,message:o}=e;Q(`task(${t}): ${o}`)}}}).then((()=>{N(`${t} \u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}else D("\u975e\u5c0f\u7a0b\u5e8f\u9879\u76ee\u76ee\u5f55")})),j.command("exec").description("\u6267\u884cts\u6587\u4ef6").argument("<path>","\u6267\u884c\u7684ts\u6587\u4ef6").action(((e,t,{args:o})=>{const r=Y(o);S({command:"tsx",args:[e].concat(r)})})),j.command("test").description("\u6267\u884c\u6d4b\u8bd5").option("--config","\u914d\u7f6e\u6587\u4ef6\u5730\u5740").option("--framework <framework>","\u6d4b\u8bd5\u6846\u67b6").action((({config:e},{args:t})=>{const o=Y(t);S({command:"yest",args:["run"].concat(e?["--config",e]:[]).concat(o),exit:!1})})),j.parse(process.argv)):w()};G();
|
package/lib/yolk.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
"use strict";var e=require("@babel/runtime/helpers/interopRequireDefault"),t=e(require("@babel/runtime/helpers/defineProperty")),o=require("node:child_process"),r=require("node:fs"),n=e(require("node:os")),i=require("node:path"),a=require("lodash"),c=require("glob"),s=e(require("inquirer")),m=y(require("miniprogram-ci")),p=require("mkdirp"),d=require("../compiled/commander"),l=e(require("../compiled/mustache")),u=e(require("../package.json")),f=require("./_util");function g(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,o=new WeakMap;return(g=function(e){return e?o:t})(e)}function y(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var o=g(t);if(o&&o.has(e))return o.get(e);var r={__proto__:null},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if("default"!==i&&Object.prototype.hasOwnProperty.call(e,i)){var a=n?Object.getOwnPropertyDescriptor(e,i):null;a&&(a.get||a.set)?Object.defineProperty(r,i,a):r[i]=e[i]}return r.default=e,o&&o.set(e,r),r}function b(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function v(e){for(var o=1;o<arguments.length;o++){var r=null!=arguments[o]?arguments[o]:{};o%2?b(Object(r),!0).forEach((function(o){(0,t.default)(e,o,r[o])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):b(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}const h="##### CREATED BY YOLK #####",j=(e,t,o)=>{s.default.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u6a21\u7248",default:"web",choices:[{name:"web template(umi framework)",value:"umi-web"},{name:"web big screen template(umi framework)",value:"umi-web-screen"},{name:"mobile template(umi framework)",value:"umi-mobile"},{name:"mobile HBuilderX h5+app template(umi framework)",value:"umi-mobile-h5+app"},{name:"mobile HBuilderX uni-app template(umi framework)",value:"umi-mobile-uni-app"},{name:"mobile native template(umi framework)",value:"umi-mobile-native"},{name:"taro-miniprogram template",value:"taro-miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:(0,i.basename)((0,i.basename)(process.cwd()))},{type:"list",name:"packageManager",message:"\u9009\u62e9\u5305\u7ba1\u7406\u5668(\u9ed8\u8ba4\uff1apnpm\uff0c\u63a8\u8350\uff1apnpm)",default:"default",choices:[{name:"\u9ed8\u8ba4\u5b89\u88c5",value:"default"},{name:"\u8df3\u8fc7\u5b89\u88c5",value:!1},{name:"pnpm install",value:"pnpm"},{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"}]}]).then((({type:n,projectName:a,packageManager:s})=>{const m={projectName:a,packageManager:"default"===s?"pnpm":s,yolkVersion:u.default.version};if("umi-mobile-uni-app"===n)return void(0,f.warn)("\u6682\u4e0d\u652f\u6301");const d=t||(0,i.join)(__dirname,`../templates/${n}`);(0,f.ready)(`\u590d\u5236\u6a21\u7248 ${(0,i.basename)(d)}`);const g=(0,c.globSync)("**/*",{cwd:d,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(g.forEach((t=>{if(!d)return;const o=(0,i.join)(d,t);if(!(0,r.statSync)(o).isDirectory())if(t.endsWith(".tpl")){const n=(0,r.readFileSync)(o,f.ENCODING),a=(0,i.join)(e,t.replace(/\.tpl$/,"")),c=l.default.render(n,m);(0,p.mkdirpSync)((0,i.dirname)(a)),(0,f.ready)(`\u521b\u5efa ${(0,i.relative)(e,a)}`),(0,r.writeFileSync)(a,c,f.ENCODING)}else{(0,f.ready)(`\u521b\u5efa ${t}`);const n=(0,i.join)(e,t);(0,p.mkdirpSync)((0,i.dirname)(n)),(0,r.copyFileSync)(o,n)}})),(0,f.ready)("\u590d\u5236\u6a21\u7248 success!"),o&&(0,r.existsSync)(d)&&(0,f.rimrafSync)(d)&&(0,f.ready)(`\u7f13\u5b58\u5220\u9664 success! ${(0,i.basename)(d||"")}`),s)switch((0,f.ready)("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),s){case"default":case"pnpm":(0,f.execCommand)({command:"pnpm",args:["install"]});break;case"yarn":(0,f.execCommand)({command:"yarn",args:["install"]});break;case"npm":(0,f.execCommand)({command:"npm",args:["install"]});break;default:}(0,f.ready)("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},w=(e,t)=>j(e,t,!0),x=()=>(0,r.existsSync)((0,i.join)(f.cwd,"project.config.json")),S=()=>{let e=(0,r.existsSync)((0,i.join)(f.cwd,"node_modules/.bin/max"));if(!e)try{e=(0,r.existsSync)(require.resolve("@umijs/max"))}catch(t){}if(!e)try{e=/umi@4\.(\d+)\.(\d+)/.test((0,o.execSync)("umi -v").toString())}catch(t){}if(!e){const o=(0,i.join)(f.cwd,"node_modules","umi","package.json");if((0,r.existsSync)(o))try{const t=JSON.parse((0,r.readFileSync)(o,f.ENCODING))||{};e=t.version&&+t.version.split(".")[0]>3}catch(t){}}return e},O=()=>{const e=(0,i.join)(f.cwd,"project.config.json");if((0,r.existsSync)(e)){const t=require(e);return t.appid}return""},k=()=>(0,r.existsSync)((0,i.join)(f.cwd,"project.tt.json"))&&0===O().indexOf("tt"),$=()=>0===O().indexOf("20"),P=()=>{const e=(0,f.getYolkConfig)(),t=(0,i.join)(f.cwd,".husky/pre-commit"),o=(0,i.join)(f.cwd,".git/"),a=(0,i.join)(f.cwd,".git/hooks"),c=(0,i.join)(a,"pre-commit"),s=(0,r.existsSync)(t),m=(0,r.existsSync)(o),d=(0,r.existsSync)(a),l=(0,r.existsSync)(c),u=!1!==e.initPreCommit&&!s,g=[h,"npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",h].join(n.default.EOL),y=e=>{let t=e||"";return t&&t.indexOf(h)>=0&&(t=`${t.substring(0,t.indexOf(h))}${t.substring(t.lastIndexOf(h)+h.length)}`.replace(/(\r|\n)+$/gu,"")),t};if(m)if(u)if(d||((0,p.mkdirpSync)(a),(0,f.ready)("create .git/hooks")),l){try{(0,r.chmodSync)(c,"777")}catch(b){(0,f.error)(`chmod ${c} failed: ${b.message}`)}const e=y((0,r.readFileSync)(c,f.ENCODING).toString());(0,r.writeFileSync)(c,(e.indexOf("#!/")<0?["#!/bin/sh"]:[]).concat([e,g]).filter((e=>!!e)).join(n.default.EOL),f.ENCODING)}else(0,r.writeFileSync)(c,["#!/bin/sh",g].join(n.default.EOL),f.ENCODING),(0,f.ready)("create pre-commit");else if(l){const e=y((0,r.readFileSync)(c,f.ENCODING).toString());(0,r.writeFileSync)(c,e,f.ENCODING)}},C=()=>{(0,f.warn)("\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),(0,f.execCommand)({command:"lint-staged",args:["-c",require.resolve("./lintstagedrc")]})},q=({mAppid:e,mProject:t,mPrivateKeyPath:n,mVersion:a,mDesc:c,mRobot:s,mQrcodeFormat:p,mQrcodeOutputDest:d,mPagePath:l,mSearchQuery:u})=>{let g="";try{g=(0,r.existsSync)((0,i.join)(f.cwd,".git"))?(0,o.execSync)("git log -1 --pretty=format:%H").toString():""}catch(w){}const y=(0,f.getProjectConfigJSON)(),b=e||y.appid,h=t||(0,i.join)(f.cwd,"dist"),j=n||(0,i.join)(f.cwd,`private.${b}.key`);if((0,r.existsSync)(h)){if((0,r.existsSync)(j)){const e=(0,f.getPackageJSON)(),t=a||e.version||y.version||"1.0.0",o=c||e.description||y.description,r=`${g?` commit: ${g};`:""}${o?` description: ${o};`:""}`;g&&(0,f.info)(`commit: ${g}`),(0,f.info)(`dist: ${h}`),(0,f.info)(`key: ${j}`),(0,f.info)(`appid: ${b}`),(0,f.info)(`version: ${t}`),(0,f.info)(`desc: ${r}`);const n=new m.Project({appid:b,type:"miniProgram",projectPath:h,privateKeyPath:j,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:b,options:{project:n,version:t,desc:r,setting:v(v({},y.setting),{},{es6:!1,es7:!1,minifyJS:!1,minifyWXML:!1,minifyWXSS:!1,minify:!1}),robot:s,qrcodeFormat:p,qrcodeOutputDest:d,pagePath:l,searchQuery:u}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${j})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${h})`)},D=()=>{let e="";try{e=(0,o.execSync)(`npm view ${u.default.name} version`,{timeout:3e3}).toString().replace(/\n/g,"")}catch(t){}(0,f.info)(`yolk version: ${u.default.version}${e&&e!==u.default.version?`(latest\uff1a${e})`:""}`),(0,f.info)(`node version: ${process.version}`),(0,f.info)(`platform: ${n.default.platform()}`),(0,f.info)(`memory: ${(0,a.floor)(n.default.freemem()/1024/1024)} MB(${(0,a.floor)(n.default.totalmem()/1024/1024)} MB)`)},N=e=>e.option("--appid, --mAppid <appid>","\u5c0f\u7a0b\u5e8fappid").option("--project, --mProject <project>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u5de5\u7a0b\u76ee\u5f55").option("--privateKeyPath, --mPrivateKeyPath <privateKeyPath>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20key\u6587\u4ef6\uff0c\u9ed8\u8ba4\uff1a{\u5f53\u524d\u76ee\u5f55}/private.{appid}.key").option("--version, --mVersion <version>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u7248\u672c\u53f7").option("--desc, --mDesc <desc>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u63cf\u8ff0").option("--robot, --mRobot <robot>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20ci\u673a\u5668\u4eba1~30").option("--qrcodeFormat, --mQrcodeFormat <qrcodeFormat>",'\u5c0f\u7a0b\u5e8f\u9884\u89c8\u8fd4\u56de\u4e8c\u7ef4\u7801\u6587\u4ef6\u7684\u683c\u5f0f "image" \u6216 "base64"\uff0c \u9ed8\u8ba4\u503c "terminal" \u4f9b\u8c03\u8bd5\u7528').option("--qrcodeOutputDest, --mQrcodeOutputDest <qrcodeOutputDest>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u4e8c\u7ef4\u7801\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84").option("--pagePath, --mPagePath <pagePath>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84").option("--searchQuery, --mSearchQuery <searchQuery>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84\u542f\u52a8\u53c2\u6570"),E=/(\w+)=('(.*)'|"(.*)"|(.*))/giu,_=e=>{process.env.DID_YOU_KNOW="none",process.env.VITE_CJS_IGNORE_WARNING="true";const t=[];return null===e||void 0===e||e.forEach((e=>{if(E.test(e)){const[t,o]=e.split("=");process.env[t]=o,(0,f.info)(`\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a${t}=${o}`)}else t.push(e)})),t},F=()=>{P(),process.argv.length>2?(d.program.version(u.default.version,"-v,--version","\u8f93\u51fa\u7248\u672c\u53f7").usage("[command] [options]"),d.program.command("init").description("\u521d\u59cb\u5316\u9879\u76ee").option("--clone <template>","\u5982\u679c\u9700\u8981\uff0c\u53ef\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248\uff0c\u9ed8\u8ba4\u53d6cli\u9ed8\u8ba4\u6a21\u7248").action((({clone:e},{args:t})=>{if(D(),(0,f.ready)("yolk init \u5f00\u59cb"),e){const o=".yolk",n=(0,i.join)(f.cwd,o);(0,r.existsSync)(n)&&(0,f.rimrafSync)(n)&&(0,f.ready)(`\u7f13\u5b58\u5220\u9664 success! ${n}`),(0,f.execCommand)({command:"git",args:["clone","-b","master","--depth","1",e,o].concat(t)}),w(f.cwd,n)}else j(f.cwd)})),d.program.command("start").description("\u542f\u52a8\u9879\u76ee").option("--docs","\u6587\u6863\u6a21\u5f0f").action((({docs:e},{args:t})=>{D();const o=_(t);x()?k()?(0,f.execCommand)({command:"taro",args:["build","--type","tt","--watch"].concat(o)}):$()?(0,f.execCommand)({command:"taro",args:["build","--type","alipay","--watch"].concat(o)}):(0,f.execCommand)({command:"taro",args:["build","--type","weapp","--watch"].concat(o)}):e?(0,f.execCommand)({command:"dumi",args:["dev"].concat(o)}):S()?(0,f.execCommand)({command:"max",args:["dev"].concat(o)}):(0,f.execCommand)({command:"umi",args:["dev"].concat(o)})})),d.program.command("build").description("\u7f16\u8bd1\u9879\u76ee").option("--docs","\u6587\u6863\u6a21\u5f0f").action((({docs:e},{args:t})=>{D();const o=_(t);x()?k()?(0,f.execCommand)({command:"taro",args:["build","--type","tt"].concat(o)}):$()?(0,f.execCommand)({command:"taro",args:["build","--type","alipay"].concat(o)}):(0,f.execCommand)({command:"taro",args:["build","--type","weapp"].concat(o)}):e?(0,f.execCommand)({command:"dumi",args:["build"].concat(o)}):S()?(0,f.execCommand)({command:"max",args:["setup"].concat(o),complete:()=>(0,f.execCommand)({command:"max",args:["build"].concat(o)}),exit:!1}):(0,f.execCommand)({command:"umi",args:["build"].concat(o)})})),d.program.command("init-pre-commit").description("\u521d\u59cb\u5316 commit hook").action(P),d.program.command("pre-commit").description("\u6267\u884ccommit hook").action(C),N(d.program.command("miniprogram-upload").description("\u4f7f\u7528 miniprogram-ci \u4e0a\u4f20\u5c0f\u7a0b\u5e8f")).action((e=>{if(x())if(k());else if($());else{const{appid:t,options:{project:o,version:r,desc:n,setting:i,robot:c}}=q(e);(0,f.info)(`${t} \u4e0a\u4f20\u5f00\u59cb`),m.upload({project:o,version:r,desc:n,setting:i,robot:c,onProgressUpdate:e=>{if((0,a.isString)(e))(0,f.info)(`task: ${e}`);else{const{status:t,message:o}=e;(0,f.info)(`task(${t}): ${o}`)}}}).then((()=>{(0,f.ready)(`${t} \u4e0a\u4f20\u5b8c\u6210`)}))}else(0,f.error)("\u975e\u5c0f\u7a0b\u5e8f\u9879\u76ee\u76ee\u5f55")})),N(d.program.command("miniprogram-preview").description("\u4f7f\u7528 miniprogram-ci \u9884\u89c8\u5c0f\u7a0b\u5e8f")).action((e=>{if(x())if(k());else if($());else{const{appid:t,options:{project:o,version:r,desc:n,setting:i,robot:c,qrcodeFormat:s,qrcodeOutputDest:p,pagePath:d,searchQuery:l}}=q(e);(0,f.info)(`${t} \u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),m.preview({project:o,version:r,desc:n,setting:i,robot:c,qrcodeFormat:s,qrcodeOutputDest:p,pagePath:d,searchQuery:l,onProgressUpdate:e=>{if((0,a.isString)(e))(0,f.info)(`task: ${e}`);else{const{status:t,message:o}=e;(0,f.info)(`task(${t}): ${o}`)}}}).then((()=>{(0,f.ready)(`${t} \u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}else(0,f.error)("\u975e\u5c0f\u7a0b\u5e8f\u9879\u76ee\u76ee\u5f55")})),d.program.command("exec").description("\u6267\u884cts\u6587\u4ef6").argument("<path>","\u6267\u884c\u7684ts\u6587\u4ef6").action(((e,t,{args:o})=>{const r=_(o);(0,f.execCommand)({command:"tsx",args:[e].concat(r)})})),d.program.command("test").description("\u6267\u884c\u6d4b\u8bd5").option("--config","\u914d\u7f6e\u6587\u4ef6\u5730\u5740").option("--framework <framework>","\u6d4b\u8bd5\u6846\u67b6").action((({config:e},{args:t})=>{const o=_(t);(0,f.execCommand)({command:"yest",args:["run"].concat(e?["--config",e]:[]).concat(o)})})),d.program.parse(process.argv)):(0,f.breakExit)()};F();
|
|
2
|
+
"use strict";var e=require("@babel/runtime/helpers/interopRequireDefault"),t=e(require("@babel/runtime/helpers/defineProperty")),o=require("node:child_process"),r=require("node:fs"),n=e(require("node:os")),i=require("node:path"),a=require("lodash"),c=require("glob"),s=e(require("inquirer")),m=y(require("miniprogram-ci")),p=require("mkdirp"),d=require("../compiled/commander"),l=e(require("../compiled/mustache")),u=e(require("../package.json")),f=require("./_util");function g(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,o=new WeakMap;return(g=function(e){return e?o:t})(e)}function y(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var o=g(t);if(o&&o.has(e))return o.get(e);var r={__proto__:null},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if("default"!==i&&Object.prototype.hasOwnProperty.call(e,i)){var a=n?Object.getOwnPropertyDescriptor(e,i):null;a&&(a.get||a.set)?Object.defineProperty(r,i,a):r[i]=e[i]}return r.default=e,o&&o.set(e,r),r}function b(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function v(e){for(var o=1;o<arguments.length;o++){var r=null!=arguments[o]?arguments[o]:{};o%2?b(Object(r),!0).forEach((function(o){(0,t.default)(e,o,r[o])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):b(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}const h="##### CREATED BY YOLK #####",j=(e,t,o)=>{s.default.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u6a21\u7248",default:"web",choices:[{name:"web template(umi framework)",value:"umi-web"},{name:"web big screen template(umi framework)",value:"umi-web-screen"},{name:"mobile template(umi framework)",value:"umi-mobile"},{name:"mobile HBuilderX h5+app template(umi framework)",value:"umi-mobile-h5+app"},{name:"mobile HBuilderX uni-app template(umi framework)",value:"umi-mobile-uni-app"},{name:"mobile native template(umi framework)",value:"umi-mobile-native"},{name:"taro-miniprogram template",value:"taro-miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:(0,i.basename)((0,i.basename)(process.cwd()))},{type:"list",name:"packageManager",message:"\u9009\u62e9\u5305\u7ba1\u7406\u5668(\u9ed8\u8ba4\uff1apnpm\uff0c\u63a8\u8350\uff1apnpm)",default:"default",choices:[{name:"\u9ed8\u8ba4\u5b89\u88c5",value:"default"},{name:"\u8df3\u8fc7\u5b89\u88c5",value:!1},{name:"pnpm install",value:"pnpm"},{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"}]}]).then((({type:n,projectName:a,packageManager:s})=>{const m={projectName:a,packageManager:"default"===s?"pnpm":s,yolkVersion:u.default.version};if("umi-mobile-uni-app"===n)return void(0,f.warn)("\u6682\u4e0d\u652f\u6301");const d=t||(0,i.join)(__dirname,`../templates/${n}`);(0,f.ready)(`\u590d\u5236\u6a21\u7248 ${(0,i.basename)(d)}`);const g=(0,c.globSync)("**/*",{cwd:d,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(g.forEach((t=>{if(!d)return;const o=(0,i.join)(d,t);if(!(0,r.statSync)(o).isDirectory())if(t.endsWith(".tpl")){const n=(0,r.readFileSync)(o,f.ENCODING),a=(0,i.join)(e,t.replace(/\.tpl$/,"")),c=l.default.render(n,m);(0,p.mkdirpSync)((0,i.dirname)(a)),(0,f.ready)(`\u521b\u5efa ${(0,i.relative)(e,a)}`),(0,r.writeFileSync)(a,c,f.ENCODING)}else{(0,f.ready)(`\u521b\u5efa ${t}`);const n=(0,i.join)(e,t);(0,p.mkdirpSync)((0,i.dirname)(n)),(0,r.copyFileSync)(o,n)}})),(0,f.ready)("\u590d\u5236\u6a21\u7248 success!"),o&&(0,r.existsSync)(d)&&(0,f.rimrafSync)(d)&&(0,f.ready)(`\u7f13\u5b58\u5220\u9664 success! ${(0,i.basename)(d||"")}`),s)switch((0,f.ready)("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),s){case"default":case"pnpm":(0,f.execCommand)({command:"pnpm",args:["install"]});break;case"yarn":(0,f.execCommand)({command:"yarn",args:["install"]});break;case"npm":(0,f.execCommand)({command:"npm",args:["install"]});break;default:}(0,f.ready)("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},x=(e,t)=>j(e,t,!0),w=()=>(0,r.existsSync)((0,i.join)(f.cwd,"project.config.json")),S=()=>{let e=(0,r.existsSync)((0,i.join)(f.cwd,"node_modules/.bin/max"));if(!e)try{e=(0,r.existsSync)(require.resolve("@umijs/max"))}catch(t){}if(!e)try{e=/umi@4\.(\d+)\.(\d+)/.test((0,o.execSync)("umi -v").toString())}catch(t){}if(!e){const o=(0,i.join)(f.cwd,"node_modules","umi","package.json");if((0,r.existsSync)(o))try{const t=JSON.parse((0,r.readFileSync)(o,f.ENCODING))||{};e=t.version&&+t.version.split(".")[0]>3}catch(t){}}return e},O=()=>{const e=(0,i.join)(f.cwd,"project.config.json");if((0,r.existsSync)(e)){const t=require(e);return t.appid}return""},k=()=>(0,r.existsSync)((0,i.join)(f.cwd,"project.tt.json"))&&0===O().indexOf("tt"),$=()=>0===O().indexOf("20"),P=()=>{const e=(0,f.getYolkConfig)(),t=(0,i.join)(f.cwd,".husky/pre-commit"),o=(0,i.join)(f.cwd,".git/"),a=(0,i.join)(f.cwd,".git/hooks"),c=(0,i.join)(a,"pre-commit"),s=(0,r.existsSync)(t),m=(0,r.existsSync)(o),d=(0,r.existsSync)(a),l=(0,r.existsSync)(c),u=!1!==e.initPreCommit&&!s,g=[h,"npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",h].join(n.default.EOL),y=e=>{let t=e||"";return t&&t.indexOf(h)>=0&&(t=`${t.substring(0,t.indexOf(h))}${t.substring(t.lastIndexOf(h)+h.length)}`.replace(/(\r|\n)+$/gu,"")),t};if(m)if(u)if(d||((0,p.mkdirpSync)(a),(0,f.ready)("create .git/hooks")),l){try{(0,r.chmodSync)(c,"777")}catch(b){(0,f.error)(`chmod ${c} failed: ${b.message}`)}const e=y((0,r.readFileSync)(c,f.ENCODING).toString());(0,r.writeFileSync)(c,(e.indexOf("#!/")<0?["#!/bin/sh"]:[]).concat([e,g]).filter((e=>!!e)).join(n.default.EOL),f.ENCODING)}else(0,r.writeFileSync)(c,["#!/bin/sh",g].join(n.default.EOL),f.ENCODING),(0,f.ready)("create pre-commit");else if(l){const e=y((0,r.readFileSync)(c,f.ENCODING).toString());(0,r.writeFileSync)(c,e,f.ENCODING)}},C=()=>{(0,f.warn)("\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),(0,f.execCommand)({command:"lint-staged",args:["-c",require.resolve("./lintstagedrc")]})},q=({mAppid:e,mProject:t,mPrivateKeyPath:n,mVersion:a,mDesc:c,mRobot:s,mQrcodeFormat:p,mQrcodeOutputDest:d,mPagePath:l,mSearchQuery:u})=>{let g="";try{g=(0,r.existsSync)((0,i.join)(f.cwd,".git"))?(0,o.execSync)("git log -1 --pretty=format:%H").toString():""}catch(x){}const y=(0,f.getProjectConfigJSON)(),b=e||y.appid,h=t||(0,i.join)(f.cwd,"dist"),j=n||(0,i.join)(f.cwd,`private.${b}.key`);if((0,r.existsSync)(h)){if((0,r.existsSync)(j)){const e=(0,f.getPackageJSON)(),t=a||e.version||y.version||"1.0.0",o=c||e.description||y.description,r=`${g?` commit: ${g};`:""}${o?` description: ${o};`:""}`;g&&(0,f.info)(`commit: ${g}`),(0,f.info)(`dist: ${h}`),(0,f.info)(`key: ${j}`),(0,f.info)(`appid: ${b}`),(0,f.info)(`version: ${t}`),(0,f.info)(`desc: ${r}`);const n=new m.Project({appid:b,type:"miniProgram",projectPath:h,privateKeyPath:j,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:b,options:{project:n,version:t,desc:r,setting:v(v({},y.setting),{},{es6:!1,es7:!1,minifyJS:!1,minifyWXML:!1,minifyWXSS:!1,minify:!1}),robot:s,qrcodeFormat:p,qrcodeOutputDest:d,pagePath:l,searchQuery:u}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${j})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${h})`)},D=()=>{let e="";try{e=(0,o.execSync)(`npm view ${u.default.name} version`,{timeout:3e3}).toString().replace(/\n/g,"")}catch(t){}(0,f.info)(`yolk version: ${u.default.version}${e&&e!==u.default.version?`(latest\uff1a${e})`:""}`),(0,f.info)(`node version: ${process.version}`),(0,f.info)(`platform: ${n.default.platform()}`),(0,f.info)(`memory: ${(0,a.floor)(n.default.freemem()/1024/1024)} MB(${(0,a.floor)(n.default.totalmem()/1024/1024)} MB)`)},N=e=>e.option("--appid, --mAppid <appid>","\u5c0f\u7a0b\u5e8fappid").option("--project, --mProject <project>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u5de5\u7a0b\u76ee\u5f55").option("--privateKeyPath, --mPrivateKeyPath <privateKeyPath>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20key\u6587\u4ef6\uff0c\u9ed8\u8ba4\uff1a{\u5f53\u524d\u76ee\u5f55}/private.{appid}.key").option("--version, --mVersion <version>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u7248\u672c\u53f7").option("--desc, --mDesc <desc>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u63cf\u8ff0").option("--robot, --mRobot <robot>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20ci\u673a\u5668\u4eba1~30").option("--qrcodeFormat, --mQrcodeFormat <qrcodeFormat>",'\u5c0f\u7a0b\u5e8f\u9884\u89c8\u8fd4\u56de\u4e8c\u7ef4\u7801\u6587\u4ef6\u7684\u683c\u5f0f "image" \u6216 "base64"\uff0c \u9ed8\u8ba4\u503c "terminal" \u4f9b\u8c03\u8bd5\u7528').option("--qrcodeOutputDest, --mQrcodeOutputDest <qrcodeOutputDest>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u4e8c\u7ef4\u7801\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84").option("--pagePath, --mPagePath <pagePath>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84").option("--searchQuery, --mSearchQuery <searchQuery>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84\u542f\u52a8\u53c2\u6570"),E=/(\w+)=('(.*)'|"(.*)"|(.*))/giu,_=e=>{process.env.DID_YOU_KNOW="none",process.env.VITE_CJS_IGNORE_WARNING="true";const t=[];return null===e||void 0===e||e.forEach((e=>{if(E.test(e)){const[t,o]=e.split("=");process.env[t]=o,(0,f.info)(`\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a${t}=${o}`)}else t.push(e)})),t},F=()=>{P(),process.argv.length>2?(d.program.version(u.default.version,"-v,--version","\u8f93\u51fa\u7248\u672c\u53f7").usage("[command] [options]"),d.program.command("init").description("\u521d\u59cb\u5316\u9879\u76ee").option("--clone <template>","\u5982\u679c\u9700\u8981\uff0c\u53ef\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248\uff0c\u9ed8\u8ba4\u53d6cli\u9ed8\u8ba4\u6a21\u7248").action((({clone:e},{args:t})=>{if(D(),(0,f.ready)("yolk init \u5f00\u59cb"),e){const o=".yolk",n=(0,i.join)(f.cwd,o);(0,r.existsSync)(n)&&(0,f.rimrafSync)(n)&&(0,f.ready)(`\u7f13\u5b58\u5220\u9664 success! ${n}`),(0,f.execCommand)({command:"git",args:["clone","-b","master","--depth","1",e,o].concat(t)}),x(f.cwd,n)}else j(f.cwd)})),d.program.command("start").description("\u542f\u52a8\u9879\u76ee").option("--docs","\u6587\u6863\u6a21\u5f0f").action((({docs:e},{args:t})=>{D();const o=_(t);w()?k()?(0,f.execCommand)({command:"taro",args:["build","--type","tt","--watch"].concat(o)}):$()?(0,f.execCommand)({command:"taro",args:["build","--type","alipay","--watch"].concat(o)}):(0,f.execCommand)({command:"taro",args:["build","--type","weapp","--watch"].concat(o)}):e?(0,f.execCommand)({command:"dumi",args:["dev"].concat(o)}):S()?(0,f.execCommand)({command:"max",args:["dev"].concat(o)}):(0,f.execCommand)({command:"umi",args:["dev"].concat(o)})})),d.program.command("build").description("\u7f16\u8bd1\u9879\u76ee").option("--docs","\u6587\u6863\u6a21\u5f0f").action((({docs:e},{args:t})=>{D();const o=_(t);w()?k()?(0,f.execCommand)({command:"taro",args:["build","--type","tt"].concat(o)}):$()?(0,f.execCommand)({command:"taro",args:["build","--type","alipay"].concat(o)}):(0,f.execCommand)({command:"taro",args:["build","--type","weapp"].concat(o)}):e?(0,f.execCommand)({command:"dumi",args:["build"].concat(o)}):S()?(0,f.execCommand)({command:"max",args:["setup"].concat(o),complete:()=>(0,f.execCommand)({command:"max",args:["build"].concat(o)}),exit:!1}):(0,f.execCommand)({command:"umi",args:["build"].concat(o)})})),d.program.command("init-pre-commit").description("\u521d\u59cb\u5316 commit hook").action(P),d.program.command("pre-commit").description("\u6267\u884ccommit hook").action(C),N(d.program.command("miniprogram-upload").description("\u4f7f\u7528 miniprogram-ci \u4e0a\u4f20\u5c0f\u7a0b\u5e8f")).action((e=>{if(w())if(k());else if($());else{const{appid:t,options:{project:o,version:r,desc:n,setting:i,robot:c}}=q(e);(0,f.info)(`${t} \u4e0a\u4f20\u5f00\u59cb`),m.upload({project:o,version:r,desc:n,setting:i,robot:c,onProgressUpdate:e=>{if((0,a.isString)(e))(0,f.info)(`task: ${e}`);else{const{status:t,message:o}=e;(0,f.info)(`task(${t}): ${o}`)}}}).then((()=>{(0,f.ready)(`${t} \u4e0a\u4f20\u5b8c\u6210`)}))}else(0,f.error)("\u975e\u5c0f\u7a0b\u5e8f\u9879\u76ee\u76ee\u5f55")})),N(d.program.command("miniprogram-preview").description("\u4f7f\u7528 miniprogram-ci \u9884\u89c8\u5c0f\u7a0b\u5e8f")).action((e=>{if(w())if(k());else if($());else{const{appid:t,options:{project:o,version:r,desc:n,setting:i,robot:c,qrcodeFormat:s,qrcodeOutputDest:p,pagePath:d,searchQuery:l}}=q(e);(0,f.info)(`${t} \u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),m.preview({project:o,version:r,desc:n,setting:i,robot:c,qrcodeFormat:s,qrcodeOutputDest:p,pagePath:d,searchQuery:l,onProgressUpdate:e=>{if((0,a.isString)(e))(0,f.info)(`task: ${e}`);else{const{status:t,message:o}=e;(0,f.info)(`task(${t}): ${o}`)}}}).then((()=>{(0,f.ready)(`${t} \u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}else(0,f.error)("\u975e\u5c0f\u7a0b\u5e8f\u9879\u76ee\u76ee\u5f55")})),d.program.command("exec").description("\u6267\u884cts\u6587\u4ef6").argument("<path>","\u6267\u884c\u7684ts\u6587\u4ef6").action(((e,t,{args:o})=>{const r=_(o);(0,f.execCommand)({command:"tsx",args:[e].concat(r)})})),d.program.command("test").description("\u6267\u884c\u6d4b\u8bd5").option("--config","\u914d\u7f6e\u6587\u4ef6\u5730\u5740").option("--framework <framework>","\u6d4b\u8bd5\u6846\u67b6").action((({config:e},{args:t})=>{const o=_(t);(0,f.execCommand)({command:"yest",args:["run"].concat(e?["--config",e]:[]).concat(o),exit:!1})})),d.program.parse(process.argv)):(0,f.breakExit)()};F();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baic/yolk-cli",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.252",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/303394539/yolk.git"
|
|
@@ -25,25 +25,25 @@
|
|
|
25
25
|
"prebundle": "father prebundle"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@baic/biome-config-yolk": "2.1.0-alpha.
|
|
29
|
-
"@baic/eslint-config-yolk": "2.1.0-alpha.
|
|
30
|
-
"@baic/prettier-config-yolk": "2.1.0-alpha.
|
|
31
|
-
"@baic/stylelint-config-yolk": "2.1.0-alpha.
|
|
32
|
-
"@baic/yolk-test": "2.1.0-alpha.
|
|
28
|
+
"@baic/biome-config-yolk": "2.1.0-alpha.252",
|
|
29
|
+
"@baic/eslint-config-yolk": "2.1.0-alpha.252",
|
|
30
|
+
"@baic/prettier-config-yolk": "2.1.0-alpha.252",
|
|
31
|
+
"@baic/stylelint-config-yolk": "2.1.0-alpha.252",
|
|
32
|
+
"@baic/yolk-test": "2.1.0-alpha.252",
|
|
33
33
|
"@democrance/imagemin-lint-staged": "5.0.x",
|
|
34
34
|
"@types/lodash": "4.x",
|
|
35
35
|
"chalk": "4.x",
|
|
36
36
|
"eslint": "8.x",
|
|
37
37
|
"glob": "10.4.x",
|
|
38
38
|
"inquirer": "8.x",
|
|
39
|
-
"lint-staged": "16.
|
|
39
|
+
"lint-staged": "16.1.x",
|
|
40
40
|
"lodash": "4.x",
|
|
41
|
-
"miniprogram-ci": "1.
|
|
41
|
+
"miniprogram-ci": "2.1.14",
|
|
42
42
|
"mkdirp": "3.0.x",
|
|
43
43
|
"postcss": "8.5.x",
|
|
44
44
|
"postcss-less": "6.0.x",
|
|
45
45
|
"postcss-scss": "4.0.x",
|
|
46
|
-
"prettier": "
|
|
46
|
+
"prettier": "3.x",
|
|
47
47
|
"rimraf": "5.0.x",
|
|
48
48
|
"stylelint": "14.x",
|
|
49
49
|
"tsx": "4.x"
|
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
"@types/inquirer": "8.x",
|
|
53
53
|
"@types/lint-staged": "13.x",
|
|
54
54
|
"@types/mustache": "4.x",
|
|
55
|
-
"commander": "
|
|
55
|
+
"commander": "13.1.x",
|
|
56
56
|
"mustache": "4.2.x"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
59
|
+
"node": ">=18"
|
|
60
60
|
},
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "62d9f80c0f7cbd5b52bf224d297b0df3aad329c0"
|
|
65
65
|
}
|