@chneau/x 0.0.151 → 0.0.153
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/package.json +2 -2
- package/x +19 -19
- package/xx +2 -0
package/package.json
CHANGED
package/x
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
4
|
-
`)}displayWidth($){return
|
|
3
|
+
var qw=Object.create;var{getPrototypeOf:Xw,defineProperty:I$,getOwnPropertyNames:Qw}=Object;var Mw=Object.prototype.hasOwnProperty;var L$=($,w,G)=>{G=$!=null?qw(Xw($)):{};let H=w||!$||!$.__esModule?I$(G,"default",{value:$,enumerable:!0}):G;for(let Z of Qw($))if(!Mw.call(H,Z))I$(H,Z,{get:()=>$[Z],enumerable:!0});return H};var S=($,w)=>()=>(w||$((w={exports:{}}).exports,w),w.exports);var x=import.meta.require;var g=S((Rw)=>{class G$ extends Error{constructor($,w,G){super(G);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=w,this.exitCode=$,this.nestedError=void 0}}class F$ extends G${constructor($){super(1,"commander.invalidArgument",$);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}Rw.CommanderError=G$;Rw.InvalidArgumentError=F$});var C=S((jw)=>{var{InvalidArgumentError:Ww}=g();class T${constructor($,w){switch(this.description=w||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,$[0]){case"<":this.required=!0,this._name=$.slice(1,-1);break;case"[":this.required=!1,this._name=$.slice(1,-1);break;default:this.required=!0,this._name=$;break}if(this._name.length>3&&this._name.slice(-3)==="...")this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_concatValue($,w){if(w===this.defaultValue||!Array.isArray(w))return[$];return w.concat($)}default($,w){return this.defaultValue=$,this.defaultValueDescription=w,this}argParser($){return this.parseArg=$,this}choices($){return this.argChoices=$.slice(),this.parseArg=(w,G)=>{if(!this.argChoices.includes(w))throw new Ww(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue(w,G);return w},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function _w($){let w=$.name()+($.variadic===!0?"...":"");return $.required?"<"+w+">":"["+w+"]"}jw.Argument=T$;jw.humanReadableArgName=_w});var Z$=S((Fw)=>{var{humanReadableArgName:Lw}=C();class K${constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext($){this.helpWidth=this.helpWidth??$.helpWidth??80}visibleCommands($){let w=$.commands.filter((H)=>!H._hidden),G=$._getHelpCommand();if(G&&!G._hidden)w.push(G);if(this.sortSubcommands)w.sort((H,Z)=>{return H.name().localeCompare(Z.name())});return w}compareOptions($,w){let G=(H)=>{return H.short?H.short.replace(/^-/,""):H.long.replace(/^--/,"")};return G($).localeCompare(G(w))}visibleOptions($){let w=$.options.filter((H)=>!H.hidden),G=$._getHelpOption();if(G&&!G.hidden){let H=G.short&&$._findOption(G.short),Z=G.long&&$._findOption(G.long);if(!H&&!Z)w.push(G);else if(G.long&&!Z)w.push($.createOption(G.long,G.description));else if(G.short&&!H)w.push($.createOption(G.short,G.description))}if(this.sortOptions)w.sort(this.compareOptions);return w}visibleGlobalOptions($){if(!this.showGlobalOptions)return[];let w=[];for(let G=$.parent;G;G=G.parent){let H=G.options.filter((Z)=>!Z.hidden);w.push(...H)}if(this.sortOptions)w.sort(this.compareOptions);return w}visibleArguments($){if($._argsDescription)$.registeredArguments.forEach((w)=>{w.description=w.description||$._argsDescription[w.name()]||""});if($.registeredArguments.find((w)=>w.description))return $.registeredArguments;return[]}subcommandTerm($){let w=$.registeredArguments.map((G)=>Lw(G)).join(" ");return $._name+($._aliases[0]?"|"+$._aliases[0]:"")+($.options.length?" [options]":"")+(w?" "+w:"")}optionTerm($){return $.flags}argumentTerm($){return $.name()}longestSubcommandTermLength($,w){return w.visibleCommands($).reduce((G,H)=>{return Math.max(G,this.displayWidth(w.styleSubcommandTerm(w.subcommandTerm(H))))},0)}longestOptionTermLength($,w){return w.visibleOptions($).reduce((G,H)=>{return Math.max(G,this.displayWidth(w.styleOptionTerm(w.optionTerm(H))))},0)}longestGlobalOptionTermLength($,w){return w.visibleGlobalOptions($).reduce((G,H)=>{return Math.max(G,this.displayWidth(w.styleOptionTerm(w.optionTerm(H))))},0)}longestArgumentTermLength($,w){return w.visibleArguments($).reduce((G,H)=>{return Math.max(G,this.displayWidth(w.styleArgumentTerm(w.argumentTerm(H))))},0)}commandUsage($){let w=$._name;if($._aliases[0])w=w+"|"+$._aliases[0];let G="";for(let H=$.parent;H;H=H.parent)G=H.name()+" "+G;return G+w+" "+$.usage()}commandDescription($){return $.description()}subcommandDescription($){return $.summary()||$.description()}optionDescription($){let w=[];if($.argChoices)w.push(`choices: ${$.argChoices.map((G)=>JSON.stringify(G)).join(", ")}`);if($.defaultValue!==void 0){if($.required||$.optional||$.isBoolean()&&typeof $.defaultValue==="boolean")w.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`)}if($.presetArg!==void 0&&$.optional)w.push(`preset: ${JSON.stringify($.presetArg)}`);if($.envVar!==void 0)w.push(`env: ${$.envVar}`);if(w.length>0)return`${$.description} (${w.join(", ")})`;return $.description}argumentDescription($){let w=[];if($.argChoices)w.push(`choices: ${$.argChoices.map((G)=>JSON.stringify(G)).join(", ")}`);if($.defaultValue!==void 0)w.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`);if(w.length>0){let G=`(${w.join(", ")})`;if($.description)return`${$.description} ${G}`;return G}return $.description}formatHelp($,w){let G=w.padWidth($,w),H=w.helpWidth??80;function Z(X,Q){return w.formatItem(X,G,Q,w)}let Y=[`${w.styleTitle("Usage:")} ${w.styleUsage(w.commandUsage($))}`,""],z=w.commandDescription($);if(z.length>0)Y=Y.concat([w.boxWrap(w.styleCommandDescription(z),H),""]);let U=w.visibleArguments($).map((X)=>{return Z(w.styleArgumentTerm(w.argumentTerm(X)),w.styleArgumentDescription(w.argumentDescription(X)))});if(U.length>0)Y=Y.concat([w.styleTitle("Arguments:"),...U,""]);let J=w.visibleOptions($).map((X)=>{return Z(w.styleOptionTerm(w.optionTerm(X)),w.styleOptionDescription(w.optionDescription(X)))});if(J.length>0)Y=Y.concat([w.styleTitle("Options:"),...J,""]);if(w.showGlobalOptions){let X=w.visibleGlobalOptions($).map((Q)=>{return Z(w.styleOptionTerm(w.optionTerm(Q)),w.styleOptionDescription(w.optionDescription(Q)))});if(X.length>0)Y=Y.concat([w.styleTitle("Global Options:"),...X,""])}let q=w.visibleCommands($).map((X)=>{return Z(w.styleSubcommandTerm(w.subcommandTerm(X)),w.styleSubcommandDescription(w.subcommandDescription(X)))});if(q.length>0)Y=Y.concat([w.styleTitle("Commands:"),...q,""]);return Y.join(`
|
|
4
|
+
`)}displayWidth($){return N$($).length}styleTitle($){return $}styleUsage($){return $.split(" ").map((w)=>{if(w==="[options]")return this.styleOptionText(w);if(w==="[command]")return this.styleSubcommandText(w);if(w[0]==="["||w[0]==="<")return this.styleArgumentText(w);return this.styleCommandText(w)}).join(" ")}styleCommandDescription($){return this.styleDescriptionText($)}styleOptionDescription($){return this.styleDescriptionText($)}styleSubcommandDescription($){return this.styleDescriptionText($)}styleArgumentDescription($){return this.styleDescriptionText($)}styleDescriptionText($){return $}styleOptionTerm($){return this.styleOptionText($)}styleSubcommandTerm($){return $.split(" ").map((w)=>{if(w==="[options]")return this.styleOptionText(w);if(w[0]==="["||w[0]==="<")return this.styleArgumentText(w);return this.styleSubcommandText(w)}).join(" ")}styleArgumentTerm($){return this.styleArgumentText($)}styleOptionText($){return $}styleArgumentText($){return $}styleSubcommandText($){return $}styleCommandText($){return $}padWidth($,w){return Math.max(w.longestOptionTermLength($,w),w.longestGlobalOptionTermLength($,w),w.longestSubcommandTermLength($,w),w.longestArgumentTermLength($,w))}preformatted($){return/\n[^\S\r\n]/.test($)}formatItem($,w,G,H){let Y=" ".repeat(2);if(!G)return Y+$;let z=$.padEnd(w+$.length-H.displayWidth($)),U=2,q=(this.helpWidth??80)-w-U-2,X;if(q<this.minWidthToWrap||H.preformatted(G))X=G;else X=H.boxWrap(G,q).replace(/\n/g,`
|
|
5
5
|
`+" ".repeat(w+U));return Y+z+" ".repeat(U)+X.replace(/\n/g,`
|
|
6
6
|
${Y}`)}boxWrap($,w){if(w<this.minWidthToWrap)return $;let G=$.split(/\r\n|\n/),H=/[\s]*[^\s]+/g,Z=[];return G.forEach((Y)=>{let z=Y.match(H);if(z===null){Z.push("");return}let U=[z.shift()],J=this.displayWidth(U[0]);z.forEach((q)=>{let X=this.displayWidth(q);if(J+X<=w){U.push(q),J+=X;return}Z.push(U.join(""));let Q=q.trimStart();U=[Q],J=this.displayWidth(Q)}),Z.push(U.join(""))}),Z.join(`
|
|
7
|
-
`)}}function
|
|
7
|
+
`)}}function N$($){let w=/\x1b\[\d*(;\d*)*m/g;return $.replace(w,"")}Fw.Help=K$;Fw.stripColor=N$});var Y$=S((Aw)=>{var{InvalidArgumentError:Nw}=g();class A${constructor($,w){this.flags=$,this.description=w||"",this.required=$.includes("<"),this.optional=$.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test($),this.mandatory=!1;let G=bw($);if(this.short=G.shortFlag,this.long=G.longFlag,this.negate=!1,this.long)this.negate=this.long.startsWith("--no-");this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0}default($,w){return this.defaultValue=$,this.defaultValueDescription=w,this}preset($){return this.presetArg=$,this}conflicts($){return this.conflictsWith=this.conflictsWith.concat($),this}implies($){let w=$;if(typeof $==="string")w={[$]:!0};return this.implied=Object.assign(this.implied||{},w),this}env($){return this.envVar=$,this}argParser($){return this.parseArg=$,this}makeOptionMandatory($=!0){return this.mandatory=!!$,this}hideHelp($=!0){return this.hidden=!!$,this}_concatValue($,w){if(w===this.defaultValue||!Array.isArray(w))return[$];return w.concat($)}choices($){return this.argChoices=$.slice(),this.parseArg=(w,G)=>{if(!this.argChoices.includes(w))throw new Nw(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue(w,G);return w},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){if(this.negate)return b$(this.name().replace(/^no-/,""));return b$(this.name())}is($){return this.short===$||this.long===$}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class y${constructor($){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,$.forEach((w)=>{if(w.negate)this.negativeOptions.set(w.attributeName(),w);else this.positiveOptions.set(w.attributeName(),w)}),this.negativeOptions.forEach((w,G)=>{if(this.positiveOptions.has(G))this.dualOptions.add(G)})}valueFromOption($,w){let G=w.attributeName();if(!this.dualOptions.has(G))return!0;let H=this.negativeOptions.get(G).presetArg,Z=H!==void 0?H:!1;return w.negate===(Z===$)}}function b$($){return $.split("-").reduce((w,G)=>{return w+G[0].toUpperCase()+G.slice(1)})}function bw($){let w,G,H=/^-[^-]$/,Z=/^--[^-]/,Y=$.split(/[ |,]+/).concat("guard");if(H.test(Y[0]))w=Y.shift();if(Z.test(Y[0]))G=Y.shift();if(!w&&H.test(Y[0]))w=Y.shift();if(!w&&Z.test(Y[0]))w=G,G=Y.shift();if(Y[0].startsWith("-")){let z=Y[0],U=`option creation failed due to '${z}' in option flags '${$}'`;if(/^-[^-][^-]/.test(z))throw new Error(`${U}
|
|
8
8
|
- a short flag is a single dash and a single character
|
|
9
9
|
- either use a single dash and a single character (for a short flag)
|
|
10
10
|
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(H.test(z))throw new Error(`${U}
|
|
11
11
|
- too many short flags`);if(Z.test(z))throw new Error(`${U}
|
|
12
12
|
- too many long flags`);throw new Error(`${U}
|
|
13
|
-
- unrecognised flag format`)}if(w===void 0&&G===void 0)throw new Error(`option creation failed due to no flags found in '${$}'.`);return{shortFlag:w,longFlag:G}}
|
|
13
|
+
- unrecognised flag format`)}if(w===void 0&&G===void 0)throw new Error(`option creation failed due to no flags found in '${$}'.`);return{shortFlag:w,longFlag:G}}Aw.Option=A$;Aw.DualOptions=y$});var P$=S((Ow)=>{function kw($,w){if(Math.abs($.length-w.length)>3)return Math.max($.length,w.length);let G=[];for(let H=0;H<=$.length;H++)G[H]=[H];for(let H=0;H<=w.length;H++)G[0][H]=H;for(let H=1;H<=w.length;H++)for(let Z=1;Z<=$.length;Z++){let Y=1;if($[Z-1]===w[H-1])Y=0;else Y=1;if(G[Z][H]=Math.min(G[Z-1][H]+1,G[Z][H-1]+1,G[Z-1][H-1]+Y),Z>1&&H>1&&$[Z-1]===w[H-2]&&$[Z-2]===w[H-1])G[Z][H]=Math.min(G[Z][H],G[Z-2][H-2]+1)}return G[$.length][w.length]}function Sw($,w){if(!w||w.length===0)return"";w=Array.from(new Set(w));let G=$.startsWith("--");if(G)$=$.slice(2),w=w.map((z)=>z.slice(2));let H=[],Z=3,Y=0.4;if(w.forEach((z)=>{if(z.length<=1)return;let U=kw($,z),J=Math.max($.length,z.length);if((J-U)/J>Y){if(U<Z)Z=U,H=[z];else if(U===Z)H.push(z)}}),H.sort((z,U)=>z.localeCompare(U)),G)H=H.map((z)=>`--${z}`);if(H.length>1)return`
|
|
14
14
|
(Did you mean one of ${H.join(", ")}?)`;if(H.length===1)return`
|
|
15
|
-
(Did you mean ${H[0]}?)`;return""}
|
|
16
|
-
- specify the name in Command constructor or using .name()`);if(w=w||{},w.isDefault)this._defaultCommandName=$._name;if(w.noHelp||w.hidden)$._hidden=!0;return this._registerCommand($),$.parent=this,$._checkForBrokenPassThrough(),this}createArgument($,w){return new
|
|
17
|
-
Expecting one of '${G.join("', '")}'`);if(this._lifeCycleHooks[$])this._lifeCycleHooks[$].push(w);else this._lifeCycleHooks[$]=[w];return this}exitOverride($){if($)this._exitCallback=$;else this._exitCallback=(w)=>{if(w.code!=="commander.executeSubCommandAsync")throw w};return this}_exit($,w,G){if(this._exitCallback)this._exitCallback(new U$($,w,G));D.exit($)}action($){let w=(G)=>{let H=this.registeredArguments.length,Z=G.slice(0,H);if(this._storeOptionsAsProperties)Z[H]=this;else Z[H]=this.opts();return Z.push(this),$.apply(this,Z)};return this._actionHandler=w,this}createOption($,w){return new
|
|
18
|
-
- already used by option '${w.flags}'`)}this.options.push($)}_registerCommand($){let w=(H)=>{return[H.name()].concat(H.aliases())},G=w($).find((H)=>this._findCommand(H));if(G){let H=w(this._findCommand(G)).join("|"),Z=w($).join("|");throw new Error(`cannot add command '${Z}' as already have command '${H}'`)}this.commands.push($)}addOption($){this._registerOption($);let w=$.name(),G=$.attributeName();if($.negate){let Z=$.long.replace(/^--no-/,"--");if(!this._findOption(Z))this.setOptionValueWithSource(G,$.defaultValue===void 0?!0:$.defaultValue,"default")}else if($.defaultValue!==void 0)this.setOptionValueWithSource(G,$.defaultValue,"default");let H=(Z,Y,z)=>{if(Z==null&&$.presetArg!==void 0)Z=$.presetArg;let U=this.getOptionValue(G);if(Z!==null&&$.parseArg)Z=this._callParseArg($,Z,U,Y);else if(Z!==null&&$.variadic)Z=$._concatValue(Z,U);if(Z==null)if($.negate)Z=!1;else if($.isBoolean()||$.optional)Z=!0;else Z="";this.setOptionValueWithSource(G,Z,z)};if(this.on("option:"+w,(Z)=>{let Y=`error: option '${$.flags}' argument '${Z}' is invalid.`;H(Z,Y,"cli")}),$.envVar)this.on("optionEnv:"+w,(Z)=>{let Y=`error: option '${$.flags}' value '${Z}' from env '${$.envVar}' is invalid.`;H(Z,Y,"env")});return this}_optionEx($,w,G,H,Z){if(typeof w==="object"&&w instanceof
|
|
15
|
+
(Did you mean ${H[0]}?)`;return""}Ow.suggestSimilar=Sw});var E$=S((mw)=>{var fw=x("events").EventEmitter,z$=x("child_process"),P=x("path"),c=x("fs"),D=x("process"),{Argument:xw,humanReadableArgName:gw}=C(),{CommanderError:U$}=g(),{Help:vw,stripColor:uw}=Z$(),{Option:k$,DualOptions:hw}=Y$(),{suggestSimilar:S$}=P$();class q$ extends fw{constructor($){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=$||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:(w)=>D.stdout.write(w),writeErr:(w)=>D.stderr.write(w),outputError:(w,G)=>G(w),getOutHelpWidth:()=>D.stdout.isTTY?D.stdout.columns:void 0,getErrHelpWidth:()=>D.stderr.isTTY?D.stderr.columns:void 0,getOutHasColors:()=>J$()??(D.stdout.isTTY&&D.stdout.hasColors?.()),getErrHasColors:()=>J$()??(D.stderr.isTTY&&D.stderr.hasColors?.()),stripColor:(w)=>uw(w)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}copyInheritedSettings($){return this._outputConfiguration=$._outputConfiguration,this._helpOption=$._helpOption,this._helpCommand=$._helpCommand,this._helpConfiguration=$._helpConfiguration,this._exitCallback=$._exitCallback,this._storeOptionsAsProperties=$._storeOptionsAsProperties,this._combineFlagAndOptionalValue=$._combineFlagAndOptionalValue,this._allowExcessArguments=$._allowExcessArguments,this._enablePositionalOptions=$._enablePositionalOptions,this._showHelpAfterError=$._showHelpAfterError,this._showSuggestionAfterError=$._showSuggestionAfterError,this}_getCommandAndAncestors(){let $=[];for(let w=this;w;w=w.parent)$.push(w);return $}command($,w,G){let H=w,Z=G;if(typeof H==="object"&&H!==null)Z=H,H=null;Z=Z||{};let[,Y,z]=$.match(/([^ ]+) *(.*)/),U=this.createCommand(Y);if(H)U.description(H),U._executableHandler=!0;if(Z.isDefault)this._defaultCommandName=U._name;if(U._hidden=!!(Z.noHelp||Z.hidden),U._executableFile=Z.executableFile||null,z)U.arguments(z);if(this._registerCommand(U),U.parent=this,U.copyInheritedSettings(this),H)return this;return U}createCommand($){return new q$($)}createHelp(){return Object.assign(new vw,this.configureHelp())}configureHelp($){if($===void 0)return this._helpConfiguration;return this._helpConfiguration=$,this}configureOutput($){if($===void 0)return this._outputConfiguration;return Object.assign(this._outputConfiguration,$),this}showHelpAfterError($=!0){if(typeof $!=="string")$=!!$;return this._showHelpAfterError=$,this}showSuggestionAfterError($=!0){return this._showSuggestionAfterError=!!$,this}addCommand($,w){if(!$._name)throw new Error(`Command passed to .addCommand() must have a name
|
|
16
|
+
- specify the name in Command constructor or using .name()`);if(w=w||{},w.isDefault)this._defaultCommandName=$._name;if(w.noHelp||w.hidden)$._hidden=!0;return this._registerCommand($),$.parent=this,$._checkForBrokenPassThrough(),this}createArgument($,w){return new xw($,w)}argument($,w,G,H){let Z=this.createArgument($,w);if(typeof G==="function")Z.default(H).argParser(G);else Z.default(G);return this.addArgument(Z),this}arguments($){return $.trim().split(/ +/).forEach((w)=>{this.argument(w)}),this}addArgument($){let w=this.registeredArguments.slice(-1)[0];if(w&&w.variadic)throw new Error(`only the last argument can be variadic '${w.name()}'`);if($.required&&$.defaultValue!==void 0&&$.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${$.name()}'`);return this.registeredArguments.push($),this}helpCommand($,w){if(typeof $==="boolean")return this._addImplicitHelpCommand=$,this;$=$??"help [command]";let[,G,H]=$.match(/([^ ]+) *(.*)/),Z=w??"display help for command",Y=this.createCommand(G);if(Y.helpOption(!1),H)Y.arguments(H);if(Z)Y.description(Z);return this._addImplicitHelpCommand=!0,this._helpCommand=Y,this}addHelpCommand($,w){if(typeof $!=="object")return this.helpCommand($,w),this;return this._addImplicitHelpCommand=!0,this._helpCommand=$,this}_getHelpCommand(){if(this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))){if(this._helpCommand===void 0)this.helpCommand(void 0,void 0);return this._helpCommand}return null}hook($,w){let G=["preSubcommand","preAction","postAction"];if(!G.includes($))throw new Error(`Unexpected value for event passed to hook : '${$}'.
|
|
17
|
+
Expecting one of '${G.join("', '")}'`);if(this._lifeCycleHooks[$])this._lifeCycleHooks[$].push(w);else this._lifeCycleHooks[$]=[w];return this}exitOverride($){if($)this._exitCallback=$;else this._exitCallback=(w)=>{if(w.code!=="commander.executeSubCommandAsync")throw w};return this}_exit($,w,G){if(this._exitCallback)this._exitCallback(new U$($,w,G));D.exit($)}action($){let w=(G)=>{let H=this.registeredArguments.length,Z=G.slice(0,H);if(this._storeOptionsAsProperties)Z[H]=this;else Z[H]=this.opts();return Z.push(this),$.apply(this,Z)};return this._actionHandler=w,this}createOption($,w){return new k$($,w)}_callParseArg($,w,G,H){try{return $.parseArg(w,G)}catch(Z){if(Z.code==="commander.invalidArgument"){let Y=`${H} ${Z.message}`;this.error(Y,{exitCode:Z.exitCode,code:Z.code})}throw Z}}_registerOption($){let w=$.short&&this._findOption($.short)||$.long&&this._findOption($.long);if(w){let G=$.long&&this._findOption($.long)?$.long:$.short;throw new Error(`Cannot add option '${$.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${G}'
|
|
18
|
+
- already used by option '${w.flags}'`)}this.options.push($)}_registerCommand($){let w=(H)=>{return[H.name()].concat(H.aliases())},G=w($).find((H)=>this._findCommand(H));if(G){let H=w(this._findCommand(G)).join("|"),Z=w($).join("|");throw new Error(`cannot add command '${Z}' as already have command '${H}'`)}this.commands.push($)}addOption($){this._registerOption($);let w=$.name(),G=$.attributeName();if($.negate){let Z=$.long.replace(/^--no-/,"--");if(!this._findOption(Z))this.setOptionValueWithSource(G,$.defaultValue===void 0?!0:$.defaultValue,"default")}else if($.defaultValue!==void 0)this.setOptionValueWithSource(G,$.defaultValue,"default");let H=(Z,Y,z)=>{if(Z==null&&$.presetArg!==void 0)Z=$.presetArg;let U=this.getOptionValue(G);if(Z!==null&&$.parseArg)Z=this._callParseArg($,Z,U,Y);else if(Z!==null&&$.variadic)Z=$._concatValue(Z,U);if(Z==null)if($.negate)Z=!1;else if($.isBoolean()||$.optional)Z=!0;else Z="";this.setOptionValueWithSource(G,Z,z)};if(this.on("option:"+w,(Z)=>{let Y=`error: option '${$.flags}' argument '${Z}' is invalid.`;H(Z,Y,"cli")}),$.envVar)this.on("optionEnv:"+w,(Z)=>{let Y=`error: option '${$.flags}' value '${Z}' from env '${$.envVar}' is invalid.`;H(Z,Y,"env")});return this}_optionEx($,w,G,H,Z){if(typeof w==="object"&&w instanceof k$)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let Y=this.createOption(w,G);if(Y.makeOptionMandatory(!!$.mandatory),typeof H==="function")Y.default(Z).argParser(H);else if(H instanceof RegExp){let z=H;H=(U,J)=>{let q=z.exec(U);return q?q[0]:J},Y.default(Z).argParser(H)}else Y.default(H);return this.addOption(Y)}option($,w,G,H){return this._optionEx({},$,w,G,H)}requiredOption($,w,G,H){return this._optionEx({mandatory:!0},$,w,G,H)}combineFlagAndOptionalValue($=!0){return this._combineFlagAndOptionalValue=!!$,this}allowUnknownOption($=!0){return this._allowUnknownOption=!!$,this}allowExcessArguments($=!0){return this._allowExcessArguments=!!$,this}enablePositionalOptions($=!0){return this._enablePositionalOptions=!!$,this}passThroughOptions($=!0){return this._passThroughOptions=!!$,this._checkForBrokenPassThrough(),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($=!0){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");return this._storeOptionsAsProperties=!!$,this}getOptionValue($){if(this._storeOptionsAsProperties)return this[$];return this._optionValues[$]}setOptionValue($,w){return this.setOptionValueWithSource($,w,void 0)}setOptionValueWithSource($,w,G){if(this._storeOptionsAsProperties)this[$]=w;else this._optionValues[$]=w;return this._optionValueSources[$]=G,this}getOptionValueSource($){return this._optionValueSources[$]}getOptionValueSourceWithGlobals($){let w;return this._getCommandAndAncestors().forEach((G)=>{if(G.getOptionValueSource($)!==void 0)w=G.getOptionValueSource($)}),w}_prepareUserArgs($,w){if($!==void 0&&!Array.isArray($))throw new Error("first parameter to parse must be array or undefined");if(w=w||{},$===void 0&&w.from===void 0){if(D.versions?.electron)w.from="electron";let H=D.execArgv??[];if(H.includes("-e")||H.includes("--eval")||H.includes("-p")||H.includes("--print"))w.from="eval"}if($===void 0)$=D.argv;this.rawArgs=$.slice();let G;switch(w.from){case void 0:case"node":this._scriptPath=$[1],G=$.slice(2);break;case"electron":if(D.defaultApp)this._scriptPath=$[1],G=$.slice(2);else G=$.slice(1);break;case"user":G=$.slice(0);break;case"eval":G=$.slice(1);break;default:throw new Error(`unexpected parse option { from: '${w.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",G}parse($,w){this._prepareForParse();let G=this._prepareUserArgs($,w);return this._parseCommand([],G),this}async parseAsync($,w){this._prepareForParse();let G=this._prepareUserArgs($,w);return await this._parseCommand([],G),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.
|
|
19
19
|
- 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($,w,G){if(c.existsSync($))return;let H=w?`searched for local subcommand relative to directory '${w}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",Z=`'${$}' does not exist
|
|
20
20
|
- if '${G}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
21
21
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
22
|
-
- ${H}`;throw new Error(Z)}_executeSubCommand($,w){w=w.slice();let G=!1,H=[".js",".ts",".tsx",".mjs",".cjs"];function Z(q,X){let Q=P.resolve(q,X);if(c.existsSync(Q))return Q;if(H.includes(P.extname(X)))return;let j=H.find((b)=>c.existsSync(`${Q}${b}`));if(j)return`${Q}${j}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let Y=$._executableFile||`${this._name}-${$._name}`,z=this._executableDir||"";if(this._scriptPath){let q;try{q=c.realpathSync(this._scriptPath)}catch{q=this._scriptPath}z=P.resolve(P.dirname(q),z)}if(z){let q=Z(z,Y);if(!q&&!$._executableFile&&this._scriptPath){let X=P.basename(this._scriptPath,P.extname(this._scriptPath));if(X!==this._name)q=Z(z,`${X}-${$._name}`)}Y=q||Y}G=H.includes(P.extname(Y));let U;if(D.platform!=="win32")if(G)w.unshift(Y),w=
|
|
22
|
+
- ${H}`;throw new Error(Z)}_executeSubCommand($,w){w=w.slice();let G=!1,H=[".js",".ts",".tsx",".mjs",".cjs"];function Z(q,X){let Q=P.resolve(q,X);if(c.existsSync(Q))return Q;if(H.includes(P.extname(X)))return;let j=H.find((b)=>c.existsSync(`${Q}${b}`));if(j)return`${Q}${j}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let Y=$._executableFile||`${this._name}-${$._name}`,z=this._executableDir||"";if(this._scriptPath){let q;try{q=c.realpathSync(this._scriptPath)}catch{q=this._scriptPath}z=P.resolve(P.dirname(q),z)}if(z){let q=Z(z,Y);if(!q&&!$._executableFile&&this._scriptPath){let X=P.basename(this._scriptPath,P.extname(this._scriptPath));if(X!==this._name)q=Z(z,`${X}-${$._name}`)}Y=q||Y}G=H.includes(P.extname(Y));let U;if(D.platform!=="win32")if(G)w.unshift(Y),w=O$(D.execArgv).concat(w),U=z$.spawn(D.argv[0],w,{stdio:"inherit"});else U=z$.spawn(Y,w,{stdio:"inherit"});else this._checkForMissingExecutable(Y,z,$._name),w.unshift(Y),w=O$(D.execArgv).concat(w),U=z$.spawn(D.execPath,w,{stdio:"inherit"});if(!U.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((X)=>{D.on(X,()=>{if(U.killed===!1&&U.exitCode===null)U.kill(X)})});let J=this._exitCallback;U.on("close",(q)=>{if(q=q??1,!J)D.exit(q);else J(new U$(q,"commander.executeSubCommandAsync","(close)"))}),U.on("error",(q)=>{if(q.code==="ENOENT")this._checkForMissingExecutable(Y,z,$._name);else if(q.code==="EACCES")throw new Error(`'${Y}' not executable`);if(!J)D.exit(1);else{let X=new U$(1,"commander.executeSubCommandAsync","(error)");X.nestedError=q,J(X)}}),this.runningCommand=U}_dispatchSubcommand($,w,G){let H=this._findCommand($);if(!H)this.help({error:!0});H._prepareForParse();let Z;return Z=this._chainOrCallSubCommandHook(Z,H,"preSubcommand"),Z=this._chainOrCall(Z,()=>{if(H._executableHandler)this._executeSubCommand(H,w.concat(G));else return H._parseCommand(w,G)}),Z}_dispatchHelpCommand($){if(!$)this.help();let w=this._findCommand($);if(w&&!w._executableHandler)w.help();return this._dispatchSubcommand($,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach(($,w)=>{if($.required&&this.args[w]==null)this.missingArgument($.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let $=(G,H,Z)=>{let Y=H;if(H!==null&&G.parseArg){let z=`error: command-argument value '${H}' is invalid for argument '${G.name()}'.`;Y=this._callParseArg(G,H,Z,z)}return Y};this._checkNumberOfArguments();let w=[];this.registeredArguments.forEach((G,H)=>{let Z=G.defaultValue;if(G.variadic){if(H<this.args.length){if(Z=this.args.slice(H),G.parseArg)Z=Z.reduce((Y,z)=>{return $(G,z,Y)},G.defaultValue)}else if(Z===void 0)Z=[]}else if(H<this.args.length){if(Z=this.args[H],G.parseArg)Z=$(G,Z,G.defaultValue)}w[H]=Z}),this.processedArgs=w}_chainOrCall($,w){if($&&$.then&&typeof $.then==="function")return $.then(()=>w());return w()}_chainOrCallHooks($,w){let G=$,H=[];if(this._getCommandAndAncestors().reverse().filter((Z)=>Z._lifeCycleHooks[w]!==void 0).forEach((Z)=>{Z._lifeCycleHooks[w].forEach((Y)=>{H.push({hookedCommand:Z,callback:Y})})}),w==="postAction")H.reverse();return H.forEach((Z)=>{G=this._chainOrCall(G,()=>{return Z.callback(Z.hookedCommand,this)})}),G}_chainOrCallSubCommandHook($,w,G){let H=$;if(this._lifeCycleHooks[G]!==void 0)this._lifeCycleHooks[G].forEach((Z)=>{H=this._chainOrCall(H,()=>{return Z(this,w)})});return H}_parseCommand($,w){let G=this.parseOptions(w);if(this._parseOptionsEnv(),this._parseOptionsImplied(),$=$.concat(G.operands),w=G.unknown,this.args=$.concat(w),$&&this._findCommand($[0]))return this._dispatchSubcommand($[0],$.slice(1),w);if(this._getHelpCommand()&&$[0]===this._getHelpCommand().name())return this._dispatchHelpCommand($[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(w),this._dispatchSubcommand(this._defaultCommandName,$,w);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(G.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let H=()=>{if(G.unknown.length>0)this.unknownOption(G.unknown[0])},Z=`command:${this.name()}`;if(this._actionHandler){H(),this._processArguments();let Y;if(Y=this._chainOrCallHooks(Y,"preAction"),Y=this._chainOrCall(Y,()=>this._actionHandler(this.processedArgs)),this.parent)Y=this._chainOrCall(Y,()=>{this.parent.emit(Z,$,w)});return Y=this._chainOrCallHooks(Y,"postAction"),Y}if(this.parent&&this.parent.listenerCount(Z))H(),this._processArguments(),this.parent.emit(Z,$,w);else if($.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",$,w);if(this.listenerCount("command:*"))this.emit("command:*",$,w);else if(this.commands.length)this.unknownCommand();else H(),this._processArguments()}else if(this.commands.length)H(),this.help({error:!0});else H(),this._processArguments()}_findCommand($){if(!$)return;return this.commands.find((w)=>w._name===$||w._aliases.includes($))}_findOption($){return this.options.find((w)=>w.is($))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(($)=>{$.options.forEach((w)=>{if(w.mandatory&&$.getOptionValue(w.attributeName())===void 0)$.missingMandatoryOptionValue(w)})})}_checkForConflictingLocalOptions(){let $=this.options.filter((G)=>{let H=G.attributeName();if(this.getOptionValue(H)===void 0)return!1;return this.getOptionValueSource(H)!=="default"});$.filter((G)=>G.conflictsWith.length>0).forEach((G)=>{let H=$.find((Z)=>G.conflictsWith.includes(Z.attributeName()));if(H)this._conflictingOption(G,H)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(($)=>{$._checkForConflictingLocalOptions()})}parseOptions($){let w=[],G=[],H=w,Z=$.slice();function Y(U){return U.length>1&&U[0]==="-"}let z=null;while(Z.length){let U=Z.shift();if(U==="--"){if(H===G)H.push(U);H.push(...Z);break}if(z&&!Y(U)){this.emit(`option:${z.name()}`,U);continue}if(z=null,Y(U)){let J=this._findOption(U);if(J){if(J.required){let q=Z.shift();if(q===void 0)this.optionMissingArgument(J);this.emit(`option:${J.name()}`,q)}else if(J.optional){let q=null;if(Z.length>0&&!Y(Z[0]))q=Z.shift();this.emit(`option:${J.name()}`,q)}else this.emit(`option:${J.name()}`);z=J.variadic?J:null;continue}}if(U.length>2&&U[0]==="-"&&U[1]!=="-"){let J=this._findOption(`-${U[1]}`);if(J){if(J.required||J.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${J.name()}`,U.slice(2));else this.emit(`option:${J.name()}`),Z.unshift(`-${U.slice(2)}`);continue}}if(/^--[^=]+=/.test(U)){let J=U.indexOf("="),q=this._findOption(U.slice(0,J));if(q&&(q.required||q.optional)){this.emit(`option:${q.name()}`,U.slice(J+1));continue}}if(Y(U))H=G;if((this._enablePositionalOptions||this._passThroughOptions)&&w.length===0&&G.length===0){if(this._findCommand(U)){if(w.push(U),Z.length>0)G.push(...Z);break}else if(this._getHelpCommand()&&U===this._getHelpCommand().name()){if(w.push(U),Z.length>0)w.push(...Z);break}else if(this._defaultCommandName){if(G.push(U),Z.length>0)G.push(...Z);break}}if(this._passThroughOptions){if(H.push(U),Z.length>0)H.push(...Z);break}H.push(U)}return{operands:w,unknown:G}}opts(){if(this._storeOptionsAsProperties){let $={},w=this.options.length;for(let G=0;G<w;G++){let H=this.options[G].attributeName();$[H]=H===this._versionOptionName?this._version:this[H]}return $}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce(($,w)=>Object.assign($,w.opts()),{})}error($,w){if(this._outputConfiguration.outputError(`${$}
|
|
23
23
|
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
24
24
|
`);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(`
|
|
25
|
-
`),this.outputHelp({error:!0});let G=w||{},H=G.exitCode||1,Z=G.code||"commander.error";this._exit(H,Z,$)}_parseOptionsEnv(){this.options.forEach(($)=>{if($.envVar&&$.envVar in D.env){let w=$.attributeName();if(this.getOptionValue(w)===void 0||["default","config","env"].includes(this.getOptionValueSource(w)))if($.required||$.optional)this.emit(`optionEnv:${$.name()}`,D.env[$.envVar]);else this.emit(`optionEnv:${$.name()}`)}})}_parseOptionsImplied(){let $=new
|
|
26
|
-
`),this._exit(0,"commander.version",$)}),this}description($,w){if($===void 0&&w===void 0)return this._description;if(this._description=$,w)this._argsDescription=w;return this}summary($){if($===void 0)return this._summary;return this._summary=$,this}alias($){if($===void 0)return this._aliases[0];let w=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)w=this.commands[this.commands.length-1];if($===w._name)throw new Error("Command alias can't be the same as its name");let G=this.parent?._findCommand($);if(G){let H=[G.name()].concat(G.aliases()).join("|");throw new Error(`cannot add alias '${$}' to command '${this.name()}' as already have command '${H}'`)}return w._aliases.push($),this}aliases($){if($===void 0)return this._aliases;return $.forEach((w)=>this.alias(w)),this}usage($){if($===void 0){if(this._usage)return this._usage;let w=this.registeredArguments.map((G)=>{return
|
|
25
|
+
`),this.outputHelp({error:!0});let G=w||{},H=G.exitCode||1,Z=G.code||"commander.error";this._exit(H,Z,$)}_parseOptionsEnv(){this.options.forEach(($)=>{if($.envVar&&$.envVar in D.env){let w=$.attributeName();if(this.getOptionValue(w)===void 0||["default","config","env"].includes(this.getOptionValueSource(w)))if($.required||$.optional)this.emit(`optionEnv:${$.name()}`,D.env[$.envVar]);else this.emit(`optionEnv:${$.name()}`)}})}_parseOptionsImplied(){let $=new hw(this.options),w=(G)=>{return this.getOptionValue(G)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(G))};this.options.filter((G)=>G.implied!==void 0&&w(G.attributeName())&&$.valueFromOption(this.getOptionValue(G.attributeName()),G)).forEach((G)=>{Object.keys(G.implied).filter((H)=>!w(H)).forEach((H)=>{this.setOptionValueWithSource(H,G.implied[H],"implied")})})}missingArgument($){let w=`error: missing required argument '${$}'`;this.error(w,{code:"commander.missingArgument"})}optionMissingArgument($){let w=`error: option '${$.flags}' argument missing`;this.error(w,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue($){let w=`error: required option '${$.flags}' not specified`;this.error(w,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption($,w){let G=(Y)=>{let z=Y.attributeName(),U=this.getOptionValue(z),J=this.options.find((X)=>X.negate&&z===X.attributeName()),q=this.options.find((X)=>!X.negate&&z===X.attributeName());if(J&&(J.presetArg===void 0&&U===!1||J.presetArg!==void 0&&U===J.presetArg))return J;return q||Y},H=(Y)=>{let z=G(Y),U=z.attributeName();if(this.getOptionValueSource(U)==="env")return`environment variable '${z.envVar}'`;return`option '${z.flags}'`},Z=`error: ${H($)} cannot be used with ${H(w)}`;this.error(Z,{code:"commander.conflictingOption"})}unknownOption($){if(this._allowUnknownOption)return;let w="";if($.startsWith("--")&&this._showSuggestionAfterError){let H=[],Z=this;do{let Y=Z.createHelp().visibleOptions(Z).filter((z)=>z.long).map((z)=>z.long);H=H.concat(Y),Z=Z.parent}while(Z&&!Z._enablePositionalOptions);w=S$($,H)}let G=`error: unknown option '${$}'${w}`;this.error(G,{code:"commander.unknownOption"})}_excessArguments($){if(this._allowExcessArguments)return;let w=this.registeredArguments.length,G=w===1?"":"s",Z=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${w} argument${G} but got ${$.length}.`;this.error(Z,{code:"commander.excessArguments"})}unknownCommand(){let $=this.args[0],w="";if(this._showSuggestionAfterError){let H=[];this.createHelp().visibleCommands(this).forEach((Z)=>{if(H.push(Z.name()),Z.alias())H.push(Z.alias())}),w=S$($,H)}let G=`error: unknown command '${$}'${w}`;this.error(G,{code:"commander.unknownCommand"})}version($,w,G){if($===void 0)return this._version;this._version=$,w=w||"-V, --version",G=G||"output the version number";let H=this.createOption(w,G);return this._versionOptionName=H.attributeName(),this._registerOption(H),this.on("option:"+H.name(),()=>{this._outputConfiguration.writeOut(`${$}
|
|
26
|
+
`),this._exit(0,"commander.version",$)}),this}description($,w){if($===void 0&&w===void 0)return this._description;if(this._description=$,w)this._argsDescription=w;return this}summary($){if($===void 0)return this._summary;return this._summary=$,this}alias($){if($===void 0)return this._aliases[0];let w=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)w=this.commands[this.commands.length-1];if($===w._name)throw new Error("Command alias can't be the same as its name");let G=this.parent?._findCommand($);if(G){let H=[G.name()].concat(G.aliases()).join("|");throw new Error(`cannot add alias '${$}' to command '${this.name()}' as already have command '${H}'`)}return w._aliases.push($),this}aliases($){if($===void 0)return this._aliases;return $.forEach((w)=>this.alias(w)),this}usage($){if($===void 0){if(this._usage)return this._usage;let w=this.registeredArguments.map((G)=>{return gw(G)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?w:[]).join(" ")}return this._usage=$,this}name($){if($===void 0)return this._name;return this._name=$,this}nameFromFilename($){return this._name=P.basename($,P.extname($)),this}executableDir($){if($===void 0)return this._executableDir;return this._executableDir=$,this}helpInformation($){let w=this.createHelp(),G=this._getOutputContext($);w.prepareContext({error:G.error,helpWidth:G.helpWidth,outputHasColors:G.hasColors});let H=w.formatHelp(this,w);if(G.hasColors)return H;return this._outputConfiguration.stripColor(H)}_getOutputContext($){$=$||{};let w=!!$.error,G,H,Z;if(w)G=(z)=>this._outputConfiguration.writeErr(z),H=this._outputConfiguration.getErrHasColors(),Z=this._outputConfiguration.getErrHelpWidth();else G=(z)=>this._outputConfiguration.writeOut(z),H=this._outputConfiguration.getOutHasColors(),Z=this._outputConfiguration.getOutHelpWidth();return{error:w,write:(z)=>{if(!H)z=this._outputConfiguration.stripColor(z);return G(z)},hasColors:H,helpWidth:Z}}outputHelp($){let w;if(typeof $==="function")w=$,$=void 0;let G=this._getOutputContext($),H={error:G.error,write:G.write,command:this};this._getCommandAndAncestors().reverse().forEach((Y)=>Y.emit("beforeAllHelp",H)),this.emit("beforeHelp",H);let Z=this.helpInformation({error:G.error});if(w){if(Z=w(Z),typeof Z!=="string"&&!Buffer.isBuffer(Z))throw new Error("outputHelp callback must return a string or a Buffer")}if(G.write(Z),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",H),this._getCommandAndAncestors().forEach((Y)=>Y.emit("afterAllHelp",H))}helpOption($,w){if(typeof $==="boolean"){if($)this._helpOption=this._helpOption??void 0;else this._helpOption=null;return this}return $=$??"-h, --help",w=w??"display help for command",this._helpOption=this.createOption($,w),this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption($){return this._helpOption=$,this}help($){this.outputHelp($);let w=Number(D.exitCode??0);if(w===0&&$&&typeof $!=="function"&&$.error)w=1;this._exit(w,"commander.help","(outputHelp)")}addHelpText($,w){let G=["beforeAll","before","after","afterAll"];if(!G.includes($))throw new Error(`Unexpected value for position to addHelpText.
|
|
27
27
|
Expecting one of '${G.join("', '")}'`);let H=`${$}Help`;return this.on(H,(Z)=>{let Y;if(typeof w==="function")Y=w({error:Z.error,command:Z.command});else Y=w;if(Y)Z.write(`${Y}
|
|
28
|
-
`)}),this}_outputHelpIfRequested($){let w=this._getHelpOption();if(w&&$.find((H)=>w.is(H)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function
|
|
29
|
-
`;break;case 114:M+="\r";break;case 116:M+="\t";break;case 117:let
|
|
30
|
-
`;return U++,q=H,z=14}switch(M){case 123:return H++,z=1;case 125:return H++,z=2;case 91:return H++,z=3;case 93:return H++,z=4;case 58:return H++,z=6;case 44:return H++,z=5;case 34:return H++,Z=$$(),z=10;case 47:let V=H-1;if($.charCodeAt(H+1)===47){H+=2;while(H<G){if(v($.charCodeAt(H)))break;H++}return Z=$.substring(V,H),z=12}if($.charCodeAt(H+1)===42){H+=2;let N=G-1,W=!1;while(H<N){let
|
|
28
|
+
`)}),this}_outputHelpIfRequested($){let w=this._getHelpOption();if(w&&$.find((H)=>w.is(H)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function O$($){return $.map((w)=>{if(!w.startsWith("--inspect"))return w;let G,H="127.0.0.1",Z="9229",Y;if((Y=w.match(/^(--inspect(-brk)?)$/))!==null)G=Y[1];else if((Y=w.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(G=Y[1],/^\d+$/.test(Y[3]))Z=Y[3];else H=Y[3];else if((Y=w.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)G=Y[1],H=Y[3],Z=Y[4];if(G&&Z!=="0")return`${G}=${H}:${parseInt(Z)+1}`;return w})}function J$(){if(D.env.NO_COLOR||D.env.FORCE_COLOR==="0"||D.env.FORCE_COLOR==="false")return!1;if(D.env.FORCE_COLOR||D.env.CLICOLOR_FORCE!==void 0)return!0;return}mw.Command=q$;mw.useColor=J$});var v$=S((dw)=>{var{Argument:f$}=C(),{Command:X$}=E$(),{CommanderError:cw,InvalidArgumentError:x$}=g(),{Help:pw}=Z$(),{Option:g$}=Y$();dw.program=new X$;dw.createCommand=($)=>new X$($);dw.createOption=($,w)=>new g$($,w);dw.createArgument=($,w)=>new f$($,w);dw.Command=X$;dw.Option=g$;dw.Argument=f$;dw.Help=pw;dw.CommanderError=cw;dw.InvalidArgumentError=x$;dw.InvalidOptionArgumentError=x$});var s$=S((TH,M$)=>{var M0=Object.prototype.hasOwnProperty,L="~";function u(){}if(Object.create){if(u.prototype=Object.create(null),!new u().__proto__)L=!1}function R0($,w,G){this.fn=$,this.context=w,this.once=G||!1}function i$($,w,G,H,Z){if(typeof G!=="function")throw new TypeError("The listener must be a function");var Y=new R0(G,H||$,Z),z=L?L+w:w;if(!$._events[z])$._events[z]=Y,$._eventsCount++;else if(!$._events[z].fn)$._events[z].push(Y);else $._events[z]=[$._events[z],Y];return $}function i($,w){if(--$._eventsCount===0)$._events=new u;else delete $._events[w]}function I(){this._events=new u,this._eventsCount=0}I.prototype.eventNames=function $(){var w=[],G,H;if(this._eventsCount===0)return w;for(H in G=this._events)if(M0.call(G,H))w.push(L?H.slice(1):H);if(Object.getOwnPropertySymbols)return w.concat(Object.getOwnPropertySymbols(G));return w};I.prototype.listeners=function $(w){var G=L?L+w:w,H=this._events[G];if(!H)return[];if(H.fn)return[H.fn];for(var Z=0,Y=H.length,z=new Array(Y);Z<Y;Z++)z[Z]=H[Z].fn;return z};I.prototype.listenerCount=function $(w){var G=L?L+w:w,H=this._events[G];if(!H)return 0;if(H.fn)return 1;return H.length};I.prototype.emit=function $(w,G,H,Z,Y,z){var U=L?L+w:w;if(!this._events[U])return!1;var J=this._events[U],q=arguments.length,X,Q;if(J.fn){if(J.once)this.removeListener(w,J.fn,void 0,!0);switch(q){case 1:return J.fn.call(J.context),!0;case 2:return J.fn.call(J.context,G),!0;case 3:return J.fn.call(J.context,G,H),!0;case 4:return J.fn.call(J.context,G,H,Z),!0;case 5:return J.fn.call(J.context,G,H,Z,Y),!0;case 6:return J.fn.call(J.context,G,H,Z,Y,z),!0}for(Q=1,X=new Array(q-1);Q<q;Q++)X[Q-1]=arguments[Q];J.fn.apply(J.context,X)}else{var j=J.length,b;for(Q=0;Q<j;Q++){if(J[Q].once)this.removeListener(w,J[Q].fn,void 0,!0);switch(q){case 1:J[Q].fn.call(J[Q].context);break;case 2:J[Q].fn.call(J[Q].context,G);break;case 3:J[Q].fn.call(J[Q].context,G,H);break;case 4:J[Q].fn.call(J[Q].context,G,H,Z);break;default:if(!X)for(b=1,X=new Array(q-1);b<q;b++)X[b-1]=arguments[b];J[Q].fn.apply(J[Q].context,X)}}}return!0};I.prototype.on=function $(w,G,H){return i$(this,w,G,H,!1)};I.prototype.once=function $(w,G,H){return i$(this,w,G,H,!0)};I.prototype.removeListener=function $(w,G,H,Z){var Y=L?L+w:w;if(!this._events[Y])return this;if(!G)return i(this,Y),this;var z=this._events[Y];if(z.fn){if(z.fn===G&&(!Z||z.once)&&(!H||z.context===H))i(this,Y)}else{for(var U=0,J=[],q=z.length;U<q;U++)if(z[U].fn!==G||Z&&!z[U].once||H&&z[U].context!==H)J.push(z[U]);if(J.length)this._events[Y]=J.length===1?J[0]:J;else i(this,Y)}return this};I.prototype.removeAllListeners=function $(w){var G;if(w){if(G=L?L+w:w,this._events[G])i(this,G)}else this._events=new u,this._eventsCount=0;return this};I.prototype.off=I.prototype.removeListener;I.prototype.addListener=I.prototype.on;I.prefixed=L;I.EventEmitter=I;if(typeof M$!=="undefined")M$.exports=I});var u$=L$(v$(),1),{program:A,createCommand:o0,createArgument:t0,createOption:r0,CommanderError:e0,InvalidArgumentError:$H,InvalidOptionArgumentError:wH,Command:HH,Argument:GH,Option:ZH,Help:YH}=u$.default;import{readdir as B0}from"fs/promises";import{cpus as D0}from"os";function p($,w=!1){let G=$.length,H=0,Z="",Y=0,z=16,U=0,J=0,q=0,X=0,Q=0;function j(M,V){let N=0,W=0;while(N<M||!V){let R=$.charCodeAt(H);if(R>=48&&R<=57)W=W*16+R-48;else if(R>=65&&R<=70)W=W*16+R-65+10;else if(R>=97&&R<=102)W=W*16+R-97+10;else break;H++,N++}if(N<M)W=-1;return W}function b(M){H=M,Z="",Y=0,z=16,Q=0}function e(){let M=H;if($.charCodeAt(H)===48)H++;else{H++;while(H<$.length&&E($.charCodeAt(H)))H++}if(H<$.length&&$.charCodeAt(H)===46)if(H++,H<$.length&&E($.charCodeAt(H))){H++;while(H<$.length&&E($.charCodeAt(H)))H++}else return Q=3,$.substring(M,H);let V=H;if(H<$.length&&($.charCodeAt(H)===69||$.charCodeAt(H)===101)){if(H++,H<$.length&&$.charCodeAt(H)===43||$.charCodeAt(H)===45)H++;if(H<$.length&&E($.charCodeAt(H))){H++;while(H<$.length&&E($.charCodeAt(H)))H++;V=H}else Q=3}return $.substring(M,V)}function $$(){let M="",V=H;while(!0){if(H>=G){M+=$.substring(V,H),Q=2;break}let N=$.charCodeAt(H);if(N===34){M+=$.substring(V,H),H++;break}if(N===92){if(M+=$.substring(V,H),H++,H>=G){Q=2;break}switch($.charCodeAt(H++)){case 34:M+='"';break;case 92:M+="\\";break;case 47:M+="/";break;case 98:M+="\b";break;case 102:M+="\f";break;case 110:M+=`
|
|
29
|
+
`;break;case 114:M+="\r";break;case 116:M+="\t";break;case 117:let R=j(4,!0);if(R>=0)M+=String.fromCharCode(R);else Q=4;break;default:Q=5}V=H;continue}if(N>=0&&N<=31)if(v(N)){M+=$.substring(V,H),Q=2;break}else Q=6;H++}return M}function k(){if(Z="",Q=0,Y=H,J=U,X=q,H>=G)return Y=G,z=17;let M=$.charCodeAt(H);if(Q$(M)){do H++,Z+=String.fromCharCode(M),M=$.charCodeAt(H);while(Q$(M));return z=15}if(v(M)){if(H++,Z+=String.fromCharCode(M),M===13&&$.charCodeAt(H)===10)H++,Z+=`
|
|
30
|
+
`;return U++,q=H,z=14}switch(M){case 123:return H++,z=1;case 125:return H++,z=2;case 91:return H++,z=3;case 93:return H++,z=4;case 58:return H++,z=6;case 44:return H++,z=5;case 34:return H++,Z=$$(),z=10;case 47:let V=H-1;if($.charCodeAt(H+1)===47){H+=2;while(H<G){if(v($.charCodeAt(H)))break;H++}return Z=$.substring(V,H),z=12}if($.charCodeAt(H+1)===42){H+=2;let N=G-1,W=!1;while(H<N){let R=$.charCodeAt(H);if(R===42&&$.charCodeAt(H+1)===47){H+=2,W=!0;break}if(H++,v(R)){if(R===13&&$.charCodeAt(H)===10)H++;U++,q=H}}if(!W)H++,Q=1;return Z=$.substring(V,H),z=13}return Z+=String.fromCharCode(M),H++,z=16;case 45:if(Z+=String.fromCharCode(M),H++,H===G||!E($.charCodeAt(H)))return z=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return Z+=e(),z=11;default:while(H<G&&f(M))H++,M=$.charCodeAt(H);if(Y!==H){switch(Z=$.substring(Y,H),Z){case"true":return z=8;case"false":return z=9;case"null":return z=7}return z=16}return Z+=String.fromCharCode(M),H++,z=16}}function f(M){if(Q$(M)||v(M))return!1;switch(M){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function w$(){let M;do M=k();while(M>=12&&M<=15);return M}return{setPosition:b,getPosition:()=>H,scan:w?w$:k,getToken:()=>z,getTokenValue:()=>Z,getTokenOffset:()=>Y,getTokenLength:()=>H-Y,getTokenStartLine:()=>J,getTokenStartCharacter:()=>Y-X,getTokenError:()=>Q}}function Q$($){return $===32||$===9}function v($){return $===10||$===13}function E($){return $>=48&&$<=57}var h$;(function($){$[$.lineFeed=10]="lineFeed",$[$.carriageReturn=13]="carriageReturn",$[$.space=32]="space",$[$._0=48]="_0",$[$._1=49]="_1",$[$._2=50]="_2",$[$._3=51]="_3",$[$._4=52]="_4",$[$._5=53]="_5",$[$._6=54]="_6",$[$._7=55]="_7",$[$._8=56]="_8",$[$._9=57]="_9",$[$.a=97]="a",$[$.b=98]="b",$[$.c=99]="c",$[$.d=100]="d",$[$.e=101]="e",$[$.f=102]="f",$[$.g=103]="g",$[$.h=104]="h",$[$.i=105]="i",$[$.j=106]="j",$[$.k=107]="k",$[$.l=108]="l",$[$.m=109]="m",$[$.n=110]="n",$[$.o=111]="o",$[$.p=112]="p",$[$.q=113]="q",$[$.r=114]="r",$[$.s=115]="s",$[$.t=116]="t",$[$.u=117]="u",$[$.v=118]="v",$[$.w=119]="w",$[$.x=120]="x",$[$.y=121]="y",$[$.z=122]="z",$[$.A=65]="A",$[$.B=66]="B",$[$.C=67]="C",$[$.D=68]="D",$[$.E=69]="E",$[$.F=70]="F",$[$.G=71]="G",$[$.H=72]="H",$[$.I=73]="I",$[$.J=74]="J",$[$.K=75]="K",$[$.L=76]="L",$[$.M=77]="M",$[$.N=78]="N",$[$.O=79]="O",$[$.P=80]="P",$[$.Q=81]="Q",$[$.R=82]="R",$[$.S=83]="S",$[$.T=84]="T",$[$.U=85]="U",$[$.V=86]="V",$[$.W=87]="W",$[$.X=88]="X",$[$.Y=89]="Y",$[$.Z=90]="Z",$[$.asterisk=42]="asterisk",$[$.backslash=92]="backslash",$[$.closeBrace=125]="closeBrace",$[$.closeBracket=93]="closeBracket",$[$.colon=58]="colon",$[$.comma=44]="comma",$[$.dot=46]="dot",$[$.doubleQuote=34]="doubleQuote",$[$.minus=45]="minus",$[$.openBrace=123]="openBrace",$[$.openBracket=91]="openBracket",$[$.plus=43]="plus",$[$.slash=47]="slash",$[$.formFeed=12]="formFeed",$[$.tab=9]="tab"})(h$||(h$={}));var Z0=new Array(20).fill(0).map(($,w)=>{return" ".repeat(w)});var Y0={" ":{"\n":new Array(200).fill(0).map(($,w)=>{return`
|
|
31
31
|
`+" ".repeat(w)}),"\r":new Array(200).fill(0).map(($,w)=>{return"\r"+" ".repeat(w)}),"\r\n":new Array(200).fill(0).map(($,w)=>{return`\r
|
|
32
32
|
`+" ".repeat(w)})},"\t":{"\n":new Array(200).fill(0).map(($,w)=>{return`
|
|
33
33
|
`+"\t".repeat(w)}),"\r":new Array(200).fill(0).map(($,w)=>{return"\r"+"\t".repeat(w)}),"\r\n":new Array(200).fill(0).map(($,w)=>{return`\r
|
|
34
|
-
`+"\t".repeat(w)})}};var d;(function($){$.DEFAULT={allowTrailingComma:!1}})(d||(d={}));function l$($,w=[],G=d.DEFAULT){let H=null,Z=[],Y=[];function z(J){if(Array.isArray(Z))Z.push(J);else if(H!==null)Z[H]=J}return C$($,{onObjectBegin:()=>{let J={};z(J),Y.push(Z),Z=J,H=null},onObjectProperty:(J)=>{H=J},onObjectEnd:()=>{Z=Y.pop()},onArrayBegin:()=>{let J=[];z(J),Y.push(Z),Z=J,H=null},onArrayEnd:()=>{Z=Y.pop()},onLiteralValue:z,onError:(J,q,X)=>{w.push({error:J,offset:q,length:X})}},G),Z[0]}function C$($,w,G=d.DEFAULT){let H=p($,!1),Z=[],Y=0;function z(R){return R?()=>Y===0&&R(H.getTokenOffset(),H.getTokenLength(),H.getTokenStartLine(),H.getTokenStartCharacter()):()=>!0}function U(R){return R?(_)=>Y===0&&R(_,H.getTokenOffset(),H.getTokenLength(),H.getTokenStartLine(),H.getTokenStartCharacter()):()=>!0}function J(R){return R?(_)=>Y===0&&R(_,H.getTokenOffset(),H.getTokenLength(),H.getTokenStartLine(),H.getTokenStartCharacter(),()=>Z.slice()):()=>!0}function q(R){return R?()=>{if(Y>0)Y++;else if(R(H.getTokenOffset(),H.getTokenLength(),H.getTokenStartLine(),H.getTokenStartCharacter(),()=>Z.slice())===!1)Y=1}:()=>!0}function X(R){return R?()=>{if(Y>0)Y--;if(Y===0)R(H.getTokenOffset(),H.getTokenLength(),H.getTokenStartLine(),H.getTokenStartCharacter())}:()=>!0}let Q=q(w.onObjectBegin),j=J(w.onObjectProperty),b=X(w.onObjectEnd),e=q(w.onArrayBegin),$$=X(w.onArrayEnd),k=J(w.onLiteralValue),f=U(w.onSeparator),w$=z(w.onComment),M=U(w.onError),V=G&&G.disallowComments,N=G&&G.allowTrailingComma;function W(){while(!0){let R=H.scan();switch(H.getTokenError()){case 4:B(14);break;case 5:B(15);break;case 3:B(13);break;case 1:if(!V)B(11);break;case 2:B(12);break;case 6:B(16);break}switch(R){case 12:case 13:if(V)B(10);else w$();break;case 16:B(1);break;case 15:case 14:break;default:return R}}}function B(R,_=[],I$=[]){if(M(R),_.length+I$.length>0){let l=H.getToken();while(l!==17){if(_.indexOf(l)!==-1){W();break}else if(I$.indexOf(l)!==-1)break;l=W()}}}function V$(R){let _=H.getTokenValue();if(R)k(_);else j(_),Z.push(_);return W(),!0}function zw(){switch(H.getToken()){case 11:let R=H.getTokenValue(),_=Number(R);if(isNaN(_))B(2),_=0;k(_);break;case 7:k(null);break;case 8:k(!0);break;case 9:k(!1);break;default:return!1}return W(),!0}function Uw(){if(H.getToken()!==10)return B(3,[],[2,5]),!1;if(V$(!1),H.getToken()===6){if(f(":"),W(),!H$())B(4,[],[2,5])}else B(5,[],[2,5]);return Z.pop(),!0}function Jw(){Q(),W();let R=!1;while(H.getToken()!==2&&H.getToken()!==17){if(H.getToken()===5){if(!R)B(4,[],[]);if(f(","),W(),H.getToken()===2&&N)break}else if(R)B(6,[],[]);if(!Uw())B(4,[],[2,5]);R=!0}if(b(),H.getToken()!==2)B(7,[2],[]);else W();return!0}function qw(){e(),W();let R=!0,_=!1;while(H.getToken()!==4&&H.getToken()!==17){if(H.getToken()===5){if(!_)B(4,[],[]);if(f(","),W(),H.getToken()===4&&N)break}else if(_)B(6,[],[]);if(R)Z.push(0),R=!1;else Z[Z.length-1]++;if(!H$())B(4,[],[4,5]);_=!0}if($$(),!R)Z.pop();if(H.getToken()!==4)B(8,[4],[]);else W();return!0}function H$(){switch(H.getToken()){case 3:return qw();case 1:return Jw();case 10:return V$(!0);default:return zw()}}if(W(),H.getToken()===17){if(G.allowEmptyContent)return!0;return B(4,[],[]),!1}if(!H$())return B(4,[],[]),!1;if(H.getToken()!==17)B(9,[],[]);return!0}var c$;(function($){$[$.None=0]="None",$[$.UnexpectedEndOfComment=1]="UnexpectedEndOfComment",$[$.UnexpectedEndOfString=2]="UnexpectedEndOfString",$[$.UnexpectedEndOfNumber=3]="UnexpectedEndOfNumber",$[$.InvalidUnicode=4]="InvalidUnicode",$[$.InvalidEscapeCharacter=5]="InvalidEscapeCharacter",$[$.InvalidCharacter=6]="InvalidCharacter"})(c$||(c$={}));var p$;(function($){$[$.OpenBraceToken=1]="OpenBraceToken",$[$.CloseBraceToken=2]="CloseBraceToken",$[$.OpenBracketToken=3]="OpenBracketToken",$[$.CloseBracketToken=4]="CloseBracketToken",$[$.CommaToken=5]="CommaToken",$[$.ColonToken=6]="ColonToken",$[$.NullKeyword=7]="NullKeyword",$[$.TrueKeyword=8]="TrueKeyword",$[$.FalseKeyword=9]="FalseKeyword",$[$.StringLiteral=10]="StringLiteral",$[$.NumericLiteral=11]="NumericLiteral",$[$.LineCommentTrivia=12]="LineCommentTrivia",$[$.BlockCommentTrivia=13]="BlockCommentTrivia",$[$.LineBreakTrivia=14]="LineBreakTrivia",$[$.Trivia=15]="Trivia",$[$.Unknown=16]="Unknown",$[$.EOF=17]="EOF"})(p$||(p$={}));var i$=l$;var d$;(function($){$[$.InvalidSymbol=1]="InvalidSymbol",$[$.InvalidNumberFormat=2]="InvalidNumberFormat",$[$.PropertyNameExpected=3]="PropertyNameExpected",$[$.ValueExpected=4]="ValueExpected",$[$.ColonExpected=5]="ColonExpected",$[$.CommaExpected=6]="CommaExpected",$[$.CloseBraceExpected=7]="CloseBraceExpected",$[$.CloseBracketExpected=8]="CloseBracketExpected",$[$.EndOfFileExpected=9]="EndOfFileExpected",$[$.InvalidCommentToken=10]="InvalidCommentToken",$[$.UnexpectedEndOfComment=11]="UnexpectedEndOfComment",$[$.UnexpectedEndOfString=12]="UnexpectedEndOfString",$[$.UnexpectedEndOfNumber=13]="UnexpectedEndOfNumber",$[$.InvalidUnicode=14]="InvalidUnicode",$[$.InvalidEscapeCharacter=15]="InvalidEscapeCharacter",$[$.InvalidCharacter=16]="InvalidCharacter"})(d$||(d$={}));var B$=F$(n$(),1);class s extends Error{constructor($){super($);this.name="TimeoutError"}}class t$ extends Error{constructor($){super();this.name="AbortError",this.message=$}}var a$=($)=>globalThis.DOMException===void 0?new t$($):new DOMException($),o$=($)=>{let w=$.reason===void 0?a$("This operation was aborted."):$.reason;return w instanceof Error?w:a$(w)};function R$($,w){let{milliseconds:G,fallback:H,message:Z,customTimers:Y={setTimeout,clearTimeout}}=w,z,J=new Promise((q,X)=>{if(typeof G!=="number"||Math.sign(G)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${G}\``);if(w.signal){let{signal:j}=w;if(j.aborted)X(o$(j));j.addEventListener("abort",()=>{X(o$(j))})}if(G===Number.POSITIVE_INFINITY){$.then(q,X);return}let Q=new s;z=Y.setTimeout.call(void 0,()=>{if(H){try{q(H())}catch(j){X(j)}return}if(typeof $.cancel==="function")$.cancel();if(Z===!1)q();else if(Z instanceof Error)X(Z);else Q.message=Z??`Promise timed out after ${G} milliseconds`,X(Q)},G),(async()=>{try{q(await $)}catch(j){X(j)}})()}).finally(()=>{J.clear()});return J.clear=()=>{Y.clearTimeout.call(void 0,z),z=void 0},J}function D$($,w,G){let H=0,Z=$.length;while(Z>0){let Y=Math.trunc(Z/2),z=H+Y;if(G($[z],w)<=0)H=++z,Z-=Y+1;else Z=Y}return H}class n{#$=[];enqueue($,w){w={priority:0,...w};let G={priority:w.priority,id:w.id,run:$};if(this.size===0||this.#$[this.size-1].priority>=w.priority){this.#$.push(G);return}let H=D$(this.#$,G,(Z,Y)=>Y.priority-Z.priority);this.#$.splice(H,0,G)}setPriority($,w){let G=this.#$.findIndex((Z)=>Z.id===$);if(G===-1)throw new ReferenceError(`No promise function with the id "${$}" exists in the queue.`);let[H]=this.#$.splice(G,1);this.enqueue(H.run,{priority:w,id:$})}dequeue(){return this.#$.shift()?.run}filter($){return this.#$.filter((w)=>w.priority===$.priority).map((w)=>w.run)}get size(){return this.#$.length}}class a extends B$.default{#$;#z;#Y=0;#B;#U;#R=0;#H;#J;#w;#D;#G=0;#q;#Z;#W;#V=1n;timeout;constructor($){super();if($={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:n,...$},!(typeof $.intervalCap==="number"&&$.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${$.intervalCap?.toString()??""}\` (${typeof $.intervalCap})`);if($.interval===void 0||!(Number.isFinite($.interval)&&$.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${$.interval?.toString()??""}\` (${typeof $.interval})`);this.#$=$.carryoverConcurrencyCount,this.#z=$.intervalCap===Number.POSITIVE_INFINITY||$.interval===0,this.#B=$.intervalCap,this.#U=$.interval,this.#w=new $.queueClass,this.#D=$.queueClass,this.concurrency=$.concurrency,this.timeout=$.timeout,this.#W=$.throwOnTimeout===!0,this.#Z=$.autoStart===!1}get#I(){return this.#z||this.#Y<this.#B}get#L(){return this.#G<this.#q}#F(){this.#G--,this.#X(),this.emit("next")}#T(){this.#j(),this.#_(),this.#J=void 0}get#K(){let $=Date.now();if(this.#H===void 0){let w=this.#R-$;if(w<0)this.#Y=this.#$?this.#G:0;else{if(this.#J===void 0)this.#J=setTimeout(()=>{this.#T()},w);return!0}}return!1}#X(){if(this.#w.size===0){if(this.#H)clearInterval(this.#H);if(this.#H=void 0,this.emit("empty"),this.#G===0)this.emit("idle");return!1}if(!this.#Z){let $=!this.#K;if(this.#I&&this.#L){let w=this.#w.dequeue();if(!w)return!1;if(this.emit("active"),w(),$)this.#_();return!0}}return!1}#_(){if(this.#z||this.#H!==void 0)return;this.#H=setInterval(()=>{this.#j()},this.#U),this.#R=Date.now()+this.#U}#j(){if(this.#Y===0&&this.#G===0&&this.#H)clearInterval(this.#H),this.#H=void 0;this.#Y=this.#$?this.#G:0,this.#Q()}#Q(){while(this.#X());}get concurrency(){return this.#q}set concurrency($){if(!(typeof $==="number"&&$>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${$}\` (${typeof $})`);this.#q=$,this.#Q()}async#N($){return new Promise((w,G)=>{$.addEventListener("abort",()=>{G($.reason)},{once:!0})})}setPriority($,w){this.#w.setPriority($,w)}async add($,w={}){return w.id??=(this.#V++).toString(),w={timeout:this.timeout,throwOnTimeout:this.#W,...w},new Promise((G,H)=>{this.#w.enqueue(async()=>{this.#G++,this.#Y++;try{w.signal?.throwIfAborted();let Z=$({signal:w.signal});if(w.timeout)Z=R$(Promise.resolve(Z),{milliseconds:w.timeout});if(w.signal)Z=Promise.race([Z,this.#N(w.signal)]);let Y=await Z;G(Y),this.emit("completed",Y)}catch(Z){if(Z instanceof s&&!w.throwOnTimeout){G();return}H(Z),this.emit("error",Z)}finally{this.#F()}},w),this.emit("add"),this.#X()})}async addAll($,w){return Promise.all($.map(async(G)=>this.add(G,w)))}start(){if(!this.#Z)return this;return this.#Z=!1,this.#Q(),this}pause(){this.#Z=!0}clear(){this.#w=new this.#D}async onEmpty(){if(this.#w.size===0)return;await this.#M("empty")}async onSizeLessThan($){if(this.#w.size<$)return;await this.#M("next",()=>this.#w.size<$)}async onIdle(){if(this.#G===0&&this.#w.size===0)return;await this.#M("idle")}async#M($,w){return new Promise((G)=>{let H=()=>{if(w&&!w())return;this.off($,H),G()};this.on($,H)})}get size(){return this.#w.size}sizeBy($){return this.#w.filter($).length}get pending(){return this.#G}get isPaused(){return this.#Z}}var r$=async($=".")=>(await D0($,{withFileTypes:!0})).filter((w)=>w.isDirectory()).filter((w)=>!w.name.startsWith(".")).filter((w)=>!w.name.includes("node_modules")).filter((w)=>!w.name.includes(".git")).map((w)=>`${$}/${w.name}`),_0=async($=".",w=0)=>{if(w===0)return[$];let G=await r$($),H=w-1;while(H>0){for(let Z of G){let Y=await r$(Z);G.push(...Y)}H--}return G.push($),G},e$=async()=>{let $=A.processedArgs[0];if(typeof $!=="string")$=".";let w=A.opts().recursive;if(typeof w!=="number")w=0;if(w>4)console.error("\uD83D\uDC41\uFE0F Recursion level is too high"),process.exit(1);let G=await _0($,w),H=new a({concurrency:W0().length});await Promise.all(G.map((Z)=>H.add(()=>j0(Z).catch(console.error)))).catch(console.error)},j0=async($)=>{console.log(`\uD83D\uDE80 Managing files in ${$}`),await I0($).catch(console.error),await V0($).catch(console.error);let w=await T0($).catch(console.error),G=await F0($).catch(console.error);if(await L0($,w??!1).catch(console.error),w)console.log("\uD83D\uDE80 Updating everything!"),await Bun.$`timeout 20s bun run --cwd=${$} upgrade`.nothrow().catch(console.error);if(G)console.log("\uD83D\uDE80 Checking and linting!"),await Promise.all([Bun.$`timeout 6s bun run --cwd=${$} check`.nothrow(),Bun.$`timeout 3s bun run --cwd=${$} lint`.nothrow()]).catch(console.error);console.log("\uD83C\uDF89 Done with all files")},V0=async($)=>{let w=`${$}/yarn.lock`;if(!await Bun.file(w).exists())return!1;return await Bun.$`rm -f ${w}`.nothrow(),console.log(`\u2705 Done with ${w}`),!0},I0=async($)=>{let w=`${$}/package-lock.json`;if(!await Bun.file(w).exists())return!1;return await Bun.$`rm -f ${w}`.nothrow(),console.log(`\u2705 Done with ${w}`),!0},L0=async($,w)=>{let G=`${$}/.gitignore`,H=Bun.file(G);if(!await H.exists())return!1;let Y=(await H.text()).split(`
|
|
34
|
+
`+"\t".repeat(w)})}};var d;(function($){$.DEFAULT={allowTrailingComma:!1}})(d||(d={}));function m$($,w=[],G=d.DEFAULT){let H=null,Z=[],Y=[];function z(J){if(Array.isArray(Z))Z.push(J);else if(H!==null)Z[H]=J}return l$($,{onObjectBegin:()=>{let J={};z(J),Y.push(Z),Z=J,H=null},onObjectProperty:(J)=>{H=J},onObjectEnd:()=>{Z=Y.pop()},onArrayBegin:()=>{let J=[];z(J),Y.push(Z),Z=J,H=null},onArrayEnd:()=>{Z=Y.pop()},onLiteralValue:z,onError:(J,q,X)=>{w.push({error:J,offset:q,length:X})}},G),Z[0]}function l$($,w,G=d.DEFAULT){let H=p($,!1),Z=[],Y=0;function z(B){return B?()=>Y===0&&B(H.getTokenOffset(),H.getTokenLength(),H.getTokenStartLine(),H.getTokenStartCharacter()):()=>!0}function U(B){return B?(_)=>Y===0&&B(_,H.getTokenOffset(),H.getTokenLength(),H.getTokenStartLine(),H.getTokenStartCharacter()):()=>!0}function J(B){return B?(_)=>Y===0&&B(_,H.getTokenOffset(),H.getTokenLength(),H.getTokenStartLine(),H.getTokenStartCharacter(),()=>Z.slice()):()=>!0}function q(B){return B?()=>{if(Y>0)Y++;else if(B(H.getTokenOffset(),H.getTokenLength(),H.getTokenStartLine(),H.getTokenStartCharacter(),()=>Z.slice())===!1)Y=1}:()=>!0}function X(B){return B?()=>{if(Y>0)Y--;if(Y===0)B(H.getTokenOffset(),H.getTokenLength(),H.getTokenStartLine(),H.getTokenStartCharacter())}:()=>!0}let Q=q(w.onObjectBegin),j=J(w.onObjectProperty),b=X(w.onObjectEnd),e=q(w.onArrayBegin),$$=X(w.onArrayEnd),k=J(w.onLiteralValue),f=U(w.onSeparator),w$=z(w.onComment),M=U(w.onError),V=G&&G.disallowComments,N=G&&G.allowTrailingComma;function W(){while(!0){let B=H.scan();switch(H.getTokenError()){case 4:R(14);break;case 5:R(15);break;case 3:R(13);break;case 1:if(!V)R(11);break;case 2:R(12);break;case 6:R(16);break}switch(B){case 12:case 13:if(V)R(10);else w$();break;case 16:R(1);break;case 15:case 14:break;default:return B}}}function R(B,_=[],V$=[]){if(M(B),_.length+V$.length>0){let l=H.getToken();while(l!==17){if(_.indexOf(l)!==-1){W();break}else if(V$.indexOf(l)!==-1)break;l=W()}}}function j$(B){let _=H.getTokenValue();if(B)k(_);else j(_),Z.push(_);return W(),!0}function Yw(){switch(H.getToken()){case 11:let B=H.getTokenValue(),_=Number(B);if(isNaN(_))R(2),_=0;k(_);break;case 7:k(null);break;case 8:k(!0);break;case 9:k(!1);break;default:return!1}return W(),!0}function zw(){if(H.getToken()!==10)return R(3,[],[2,5]),!1;if(j$(!1),H.getToken()===6){if(f(":"),W(),!H$())R(4,[],[2,5])}else R(5,[],[2,5]);return Z.pop(),!0}function Uw(){Q(),W();let B=!1;while(H.getToken()!==2&&H.getToken()!==17){if(H.getToken()===5){if(!B)R(4,[],[]);if(f(","),W(),H.getToken()===2&&N)break}else if(B)R(6,[],[]);if(!zw())R(4,[],[2,5]);B=!0}if(b(),H.getToken()!==2)R(7,[2],[]);else W();return!0}function Jw(){e(),W();let B=!0,_=!1;while(H.getToken()!==4&&H.getToken()!==17){if(H.getToken()===5){if(!_)R(4,[],[]);if(f(","),W(),H.getToken()===4&&N)break}else if(_)R(6,[],[]);if(B)Z.push(0),B=!1;else Z[Z.length-1]++;if(!H$())R(4,[],[4,5]);_=!0}if($$(),!B)Z.pop();if(H.getToken()!==4)R(8,[4],[]);else W();return!0}function H$(){switch(H.getToken()){case 3:return Jw();case 1:return Uw();case 10:return j$(!0);default:return Yw()}}if(W(),H.getToken()===17){if(G.allowEmptyContent)return!0;return R(4,[],[]),!1}if(!H$())return R(4,[],[]),!1;if(H.getToken()!==17)R(9,[],[]);return!0}var C$;(function($){$[$.None=0]="None",$[$.UnexpectedEndOfComment=1]="UnexpectedEndOfComment",$[$.UnexpectedEndOfString=2]="UnexpectedEndOfString",$[$.UnexpectedEndOfNumber=3]="UnexpectedEndOfNumber",$[$.InvalidUnicode=4]="InvalidUnicode",$[$.InvalidEscapeCharacter=5]="InvalidEscapeCharacter",$[$.InvalidCharacter=6]="InvalidCharacter"})(C$||(C$={}));var c$;(function($){$[$.OpenBraceToken=1]="OpenBraceToken",$[$.CloseBraceToken=2]="CloseBraceToken",$[$.OpenBracketToken=3]="OpenBracketToken",$[$.CloseBracketToken=4]="CloseBracketToken",$[$.CommaToken=5]="CommaToken",$[$.ColonToken=6]="ColonToken",$[$.NullKeyword=7]="NullKeyword",$[$.TrueKeyword=8]="TrueKeyword",$[$.FalseKeyword=9]="FalseKeyword",$[$.StringLiteral=10]="StringLiteral",$[$.NumericLiteral=11]="NumericLiteral",$[$.LineCommentTrivia=12]="LineCommentTrivia",$[$.BlockCommentTrivia=13]="BlockCommentTrivia",$[$.LineBreakTrivia=14]="LineBreakTrivia",$[$.Trivia=15]="Trivia",$[$.Unknown=16]="Unknown",$[$.EOF=17]="EOF"})(c$||(c$={}));var d$=m$;var p$;(function($){$[$.InvalidSymbol=1]="InvalidSymbol",$[$.InvalidNumberFormat=2]="InvalidNumberFormat",$[$.PropertyNameExpected=3]="PropertyNameExpected",$[$.ValueExpected=4]="ValueExpected",$[$.ColonExpected=5]="ColonExpected",$[$.CommaExpected=6]="CommaExpected",$[$.CloseBraceExpected=7]="CloseBraceExpected",$[$.CloseBracketExpected=8]="CloseBracketExpected",$[$.EndOfFileExpected=9]="EndOfFileExpected",$[$.InvalidCommentToken=10]="InvalidCommentToken",$[$.UnexpectedEndOfComment=11]="UnexpectedEndOfComment",$[$.UnexpectedEndOfString=12]="UnexpectedEndOfString",$[$.UnexpectedEndOfNumber=13]="UnexpectedEndOfNumber",$[$.InvalidUnicode=14]="InvalidUnicode",$[$.InvalidEscapeCharacter=15]="InvalidEscapeCharacter",$[$.InvalidCharacter=16]="InvalidCharacter"})(p$||(p$={}));var R$=L$(s$(),1);class s extends Error{constructor($){super($);this.name="TimeoutError"}}class o$ extends Error{constructor($){super();this.name="AbortError",this.message=$}}var n$=($)=>globalThis.DOMException===void 0?new o$($):new DOMException($),a$=($)=>{let w=$.reason===void 0?n$("This operation was aborted."):$.reason;return w instanceof Error?w:n$(w)};function B$($,w){let{milliseconds:G,fallback:H,message:Z,customTimers:Y={setTimeout,clearTimeout}}=w,z,J=new Promise((q,X)=>{if(typeof G!=="number"||Math.sign(G)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${G}\``);if(w.signal){let{signal:j}=w;if(j.aborted)X(a$(j));j.addEventListener("abort",()=>{X(a$(j))})}if(G===Number.POSITIVE_INFINITY){$.then(q,X);return}let Q=new s;z=Y.setTimeout.call(void 0,()=>{if(H){try{q(H())}catch(j){X(j)}return}if(typeof $.cancel==="function")$.cancel();if(Z===!1)q();else if(Z instanceof Error)X(Z);else Q.message=Z??`Promise timed out after ${G} milliseconds`,X(Q)},G),(async()=>{try{q(await $)}catch(j){X(j)}})()}).finally(()=>{J.clear()});return J.clear=()=>{Y.clearTimeout.call(void 0,z),z=void 0},J}function D$($,w,G){let H=0,Z=$.length;while(Z>0){let Y=Math.trunc(Z/2),z=H+Y;if(G($[z],w)<=0)H=++z,Z-=Y+1;else Z=Y}return H}class n{#$=[];enqueue($,w){w={priority:0,...w};let G={priority:w.priority,id:w.id,run:$};if(this.size===0||this.#$[this.size-1].priority>=w.priority){this.#$.push(G);return}let H=D$(this.#$,G,(Z,Y)=>Y.priority-Z.priority);this.#$.splice(H,0,G)}setPriority($,w){let G=this.#$.findIndex((Z)=>Z.id===$);if(G===-1)throw new ReferenceError(`No promise function with the id "${$}" exists in the queue.`);let[H]=this.#$.splice(G,1);this.enqueue(H.run,{priority:w,id:$})}dequeue(){return this.#$.shift()?.run}filter($){return this.#$.filter((w)=>w.priority===$.priority).map((w)=>w.run)}get size(){return this.#$.length}}class a extends R$.default{#$;#z;#Y=0;#R;#U;#B=0;#H;#J;#w;#D;#G=0;#q;#Z;#W;#V=1n;timeout;constructor($){super();if($={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:n,...$},!(typeof $.intervalCap==="number"&&$.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${$.intervalCap?.toString()??""}\` (${typeof $.intervalCap})`);if($.interval===void 0||!(Number.isFinite($.interval)&&$.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${$.interval?.toString()??""}\` (${typeof $.interval})`);this.#$=$.carryoverConcurrencyCount,this.#z=$.intervalCap===Number.POSITIVE_INFINITY||$.interval===0,this.#R=$.intervalCap,this.#U=$.interval,this.#w=new $.queueClass,this.#D=$.queueClass,this.concurrency=$.concurrency,this.timeout=$.timeout,this.#W=$.throwOnTimeout===!0,this.#Z=$.autoStart===!1}get#I(){return this.#z||this.#Y<this.#R}get#L(){return this.#G<this.#q}#F(){this.#G--,this.#X(),this.emit("next")}#T(){this.#j(),this.#_(),this.#J=void 0}get#K(){let $=Date.now();if(this.#H===void 0){let w=this.#B-$;if(w<0)this.#Y=this.#$?this.#G:0;else{if(this.#J===void 0)this.#J=setTimeout(()=>{this.#T()},w);return!0}}return!1}#X(){if(this.#w.size===0){if(this.#H)clearInterval(this.#H);if(this.#H=void 0,this.emit("empty"),this.#G===0)this.emit("idle");return!1}if(!this.#Z){let $=!this.#K;if(this.#I&&this.#L){let w=this.#w.dequeue();if(!w)return!1;if(this.emit("active"),w(),$)this.#_();return!0}}return!1}#_(){if(this.#z||this.#H!==void 0)return;this.#H=setInterval(()=>{this.#j()},this.#U),this.#B=Date.now()+this.#U}#j(){if(this.#Y===0&&this.#G===0&&this.#H)clearInterval(this.#H),this.#H=void 0;this.#Y=this.#$?this.#G:0,this.#Q()}#Q(){while(this.#X());}get concurrency(){return this.#q}set concurrency($){if(!(typeof $==="number"&&$>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${$}\` (${typeof $})`);this.#q=$,this.#Q()}async#N($){return new Promise((w,G)=>{$.addEventListener("abort",()=>{G($.reason)},{once:!0})})}setPriority($,w){this.#w.setPriority($,w)}async add($,w={}){return w.id??=(this.#V++).toString(),w={timeout:this.timeout,throwOnTimeout:this.#W,...w},new Promise((G,H)=>{this.#w.enqueue(async()=>{this.#G++,this.#Y++;try{w.signal?.throwIfAborted();let Z=$({signal:w.signal});if(w.timeout)Z=B$(Promise.resolve(Z),{milliseconds:w.timeout});if(w.signal)Z=Promise.race([Z,this.#N(w.signal)]);let Y=await Z;G(Y),this.emit("completed",Y)}catch(Z){if(Z instanceof s&&!w.throwOnTimeout){G();return}H(Z),this.emit("error",Z)}finally{this.#F()}},w),this.emit("add"),this.#X()})}async addAll($,w){return Promise.all($.map(async(G)=>this.add(G,w)))}start(){if(!this.#Z)return this;return this.#Z=!1,this.#Q(),this}pause(){this.#Z=!0}clear(){this.#w=new this.#D}async onEmpty(){if(this.#w.size===0)return;await this.#M("empty")}async onSizeLessThan($){if(this.#w.size<$)return;await this.#M("next",()=>this.#w.size<$)}async onIdle(){if(this.#G===0&&this.#w.size===0)return;await this.#M("idle")}async#M($,w){return new Promise((G)=>{let H=()=>{if(w&&!w())return;this.off($,H),G()};this.on($,H)})}get size(){return this.#w.size}sizeBy($){return this.#w.filter($).length}get pending(){return this.#G}get isPaused(){return this.#Z}}var t$=async($=".")=>(await B0($,{withFileTypes:!0})).filter((w)=>w.isDirectory()).filter((w)=>!w.name.startsWith(".")).filter((w)=>!w.name.includes("node_modules")).filter((w)=>!w.name.includes(".git")).map((w)=>`${$}/${w.name}`),W0=async($=".",w=0)=>{if(w===0)return[$];let G=await t$($),H=w-1;while(H>0){for(let Z of G){let Y=await t$(Z);G.push(...Y)}H--}return G.push($),G},r$=async()=>{let $=A.processedArgs[0];if(typeof $!=="string")$=".";let w=A.opts().recursive;if(typeof w!=="number")w=0;if(w>4)console.error("\uD83D\uDC41\uFE0F Recursion level is too high"),process.exit(1);let G=await W0($,w),H=new a({concurrency:D0().length});await Promise.all(G.map((Z)=>H.add(()=>_0(Z).catch(console.error)))).catch(console.error)},_0=async($)=>{console.log(`\uD83D\uDE80 Managing files in ${$}`),await V0($).catch(console.error),await j0($).catch(console.error);let w=await F0($).catch(console.error),G=await L0($).catch(console.error);if(await I0($,w??!1).catch(console.error),w)console.log("\uD83D\uDE80 Updating everything!"),await Bun.$`timeout 20s bun run --cwd=${$} upgrade`.nothrow().catch(console.error);if(G)console.log("\uD83D\uDE80 Checking and linting!"),await Promise.all([Bun.$`timeout 6s bun run --cwd=${$} check`.nothrow(),Bun.$`timeout 3s bun run --cwd=${$} lint`.nothrow()]).catch(console.error);console.log("\uD83C\uDF89 Done with all files")},j0=async($)=>{let w=`${$}/yarn.lock`;if(!await Bun.file(w).exists())return!1;return await Bun.$`rm -f ${w}`.nothrow(),console.log(`\u2705 Done with ${w}`),!0},V0=async($)=>{let w=`${$}/package-lock.json`;if(!await Bun.file(w).exists())return!1;return await Bun.$`rm -f ${w}`.nothrow(),console.log(`\u2705 Done with ${w}`),!0},I0=async($,w)=>{let G=`${$}/.gitignore`,H=Bun.file(G);if(!await H.exists())return!1;let Y=(await H.text()).split(`
|
|
35
35
|
`).map((U)=>U.trim()).filter(Boolean);if(Y.length>10)console.error(`\uD83D\uDC41\uFE0F ${G} is too long`);if(w){if(!Y.includes("node_modules"))Y.push("node_modules")}return await Bun.write(H,Y.join(`
|
|
36
|
-
`)),console.log(`\u2705 Done with ${G}`),!0},
|
|
36
|
+
`)),console.log(`\u2705 Done with ${G}`),!0},L0=async($)=>{let w=`${$}/tsconfig.json`,G=Bun.file(w);if(!await G.exists())return!1;let H=d$(await G.text());if(!H.compilerOptions)return!1;let Z={noUnusedLocals:!0,noUnusedParameters:!0,noUncheckedIndexedAccess:!0,noFallthroughCasesInSwitch:!0,noEmit:!0,strict:!0,skipLibCheck:!0};for(let[Y,z]of Object.entries(Z)){if(H.compilerOptions[Y]===z)continue;H.compilerOptions[Y]=z}return await Bun.write(G,JSON.stringify(H,null,2)),await Bun.$`biome check --write --unsafe ${w}`.nothrow(),console.log(`\u2705 Done with ${w}`),!0},F0=async($)=>{let w=`${$}/package.json`,G=Bun.file(w);if(!await G.exists())return!1;let H=await G.json();if(H.scripts??={},!(H.dependencies||H.devDependencies))return!1;let Y={upgrade:"bun update --latest",check:"deno fmt --use-tabs --quiet; oxlint --fix-dangerously --quiet; biome check --write --unsafe .",lint:"tsc",all:"bun run upgrade; bun run check; bun run lint"};for(let[z,U]of Object.entries(Y)){if(typeof H.scripts[z]==="string"&&H.scripts[z].includes("bun")&&(H.scripts[z].includes("--filter")||H.scripts[z].includes("--cwd")))continue;if(H.scripts[z]===U)continue;H.scripts[z]=U}return H.prettier=void 0,await Bun.write(G,JSON.stringify(H,null,2)),await Bun.$`biome check --write --unsafe ${w}`.nothrow(),console.log(`\u2705 Done with ${w}`),!0};var{$:y}=globalThis.Bun;var{$:W$}=globalThis.Bun;var O=async($)=>(await W$`which ${$}`.text().catch(()=>"")).trim()!=="",o=async()=>{return(await W$`id -u`.text()).trim()==="0"},t=async()=>{return(await W$`sudo echo 0`.text().catch(()=>"")).trim()==="0"},r=async()=>await Bun.file(`${import.meta.dir}/package.json`).json().then(($)=>$.version).catch(()=>"UNKNOWN");var{$:m}=globalThis.Bun;var h=($)=>({name:$,check:async()=>O($),install:async()=>await m`sudo apt install -y ${$}`}),T0=[h("git"),h("curl"),h("wget"),h("unzip"),h("bash")],F=($,w)=>({name:$,check:async()=>O(w??$),install:async()=>await m`brew install ${$}`}),K0=[F("aichat"),F("bpytop"),F("docker-compose"),F("go"),F("graphviz","dot"),F("helm"),F("hyperfine"),F("kubecolor"),F("kubectx"),F("kubernetes-cli","kubectl"),F("lazygit"),F("node"),F("openjdk","javac"),F("pipx"),F("zsh")],T=($,w)=>({name:$,check:async()=>O(w??$),install:async()=>await m`bun install --force --global ${$}`}),N0=[T("@biomejs/biome","biome"),T("concurrently"),T("depcheck"),T("fkill-cli","fkill"),T("http-server"),T("live-server"),T("nodemon"),T("npm-check-updates"),T("npm-check"),T("oxlint"),T("prettier"),T("ts-unused-exports"),T("tsx"),T("typesync"),T("ungit")],e$=[...T0,{name:"brew",check:async()=>O("brew"),install:async()=>await m`HOME=/tmp CI=1 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`},{name:"deno",check:async()=>O("deno"),install:async()=>await m`curl -fsSL https://deno.land/install.sh | sh`},...K0,...N0];Bun.env.PATH=[Bun.env.PATH??"","/home/linuxbrew/.linuxbrew/bin","/home/linuxbrew/.linuxbrew/sbin","$BUN_INSTALL/bin","$HOME/go/bin","$HOME/.arkade/bin","${KREW_ROOT:-$HOME/.krew}/bin","$HOME/.cargo/bin","$HOME/.dotnet","$HOME/.dotnet/tools","$HOME/.go/bin","$HOME/.local/bin","$HOME/bin","/snap/bin","/usr/local/sbin","/usr/sbin","/sbin"].join(":");var b0=async()=>{if(!await o())console.log("\u2705 You are not root");else throw new Error("\u274C You are root")},A0=async()=>{if(await t())console.log("\u2705 You can sudo");else throw new Error("\u274C You cannot sudo")},y0=async()=>{let $=await Promise.all(e$.map(async(w)=>({name:w.name,exists:await w.check(),install:w.install}))).then((w)=>w.filter((G)=>!G.exists));if(!$.length)console.log("\u2705 All packages are installed");else{console.log("\u274C Some packages are not installed"),console.table($);for(let w of $)console.log(`\uD83D\uDD52 Installing ${w.name}`),await w.install().then(()=>console.log(`\u2705 Installed ${w.name}`)).catch(()=>console.log(`\u274C Failed to install ${w.name}`))}},P0=async()=>{if(await Bun.file(`${Bun.env.HOME}/.gitconfig`).text().catch(()=>"")!==`[user]
|
|
37
37
|
email = charles63500@gmail.com
|
|
38
38
|
name = chneau
|
|
39
39
|
[url "ssh://git@github.com/"]
|
|
@@ -61,7 +61,7 @@ Expecting one of '${G.join("', '")}'`);let H=`${$}Help`;return this.on(H,(Z)=>{l
|
|
|
61
61
|
whitespace = blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol
|
|
62
62
|
[fetch]
|
|
63
63
|
prune = true
|
|
64
|
-
`);console.log("\u2705 Git config is set")},
|
|
64
|
+
`);console.log("\u2705 Git config is set")},k0=async()=>{let w=await Promise.all([".bashrc",".zshrc",".aliases",".profile"].map(async(G)=>({name:G,content:await fetch(`https://raw.githubusercontent.com/chneau/dotfiles/HEAD/${G}`).then((H)=>H.text()),isPresent:await Bun.file(`${Bun.env.HOME}/${G}`).exists()})));if(w.every((G)=>G.isPresent))console.log("\u2705 Dotfiles are installed");else console.log("\u274C Dotfiles are not installed"),console.log("\uD83D\uDD52 Installing dotfiles"),await Promise.all(w.map(async(G)=>{console.log(`\uD83D\uDD52 Installing ${G.name}`),await Bun.write(`${Bun.env.HOME}/${G.name}`,G.content),console.log(`\u2705 Installed ${G.name}`)})),console.log("\u2705 Dotfiles are installed")},S0=async()=>{if(!(await y`which docker`.nothrow().text()).includes("not found"))console.log("\u2705 Docker is installed");else console.log("\u274C Docker is not installed"),console.log("\uD83D\uDD52 Installing Docker"),await y`curl -sSL get.docker.com | sh`,console.log("\u2705 Docker is installed")},O0=async()=>{if((await y`groups`.text()).includes("docker"))console.log("\u2705 User is in docker groups");else console.log("\u274C User is not in docker groups"),console.log("\uD83D\uDD52 Adding user to docker groups"),await y`sudo usermod -aG docker $USER`.catch(()=>{}),console.log("\u2705 User is in docker groups")},E0=async()=>{let $=`${Bun.env.HOME}/.ssh/id_rsa`;if(await Bun.file($).exists())console.log("\u2705 SSH key is set");else throw console.log("\u274C SSH key is not set"),console.log(`\u26A1 Please execute this command:
|
|
65
65
|
|
|
66
|
-
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -P ""`),new Error("\u274C SSH key is not set")},
|
|
67
|
-
`)),w=await y`which zsh`.nothrow().text();if($.includes(w))console.log("\u2705 Zsh is set as a valid shell");else console.log("\u274C Zsh is not set as a valid shell"),console.log("\uD83D\uDD52 Adding Zsh to /etc/shells"),await y`echo ${w} | sudo tee -a /etc/shells`,console.log("\u2705 Zsh is set as a valid shell");if((await y`cat /etc/passwd | grep "^$USER:"`.text()).includes(w))console.log("\u2705 Zsh is set as your shell");else console.log("\u274C Zsh is not set as your shell"),console.log("\uD83D\uDD52 Setting Zsh as your shell"),await y`sudo chsh -s ${w} $USER`,console.log("\u2705 Zsh is set as your shell")}
|
|
66
|
+
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -P ""`),new Error("\u274C SSH key is not set")},f0=async()=>{if(await y`ssh -o "StrictHostKeyChecking no" git@github.com 2>&1`.nothrow().text().then(($)=>$.includes("successfully authenticated")))console.log("\u2705 SSH key is set on GitHub");else console.log("\u274C SSH key is not set on GitHub"),console.log("\uD83D\uDD52 Adding SSH key to GitHub"),await y`cat ~/.ssh/id_rsa.pub`,console.log("\u26A1 Go to https://github.com/settings/ssh/new and past the text above")},x0=async()=>{let $=await Bun.file("/etc/shells").text().then((H)=>H.split(`
|
|
67
|
+
`)),w=await y`which zsh`.nothrow().text();if($.includes(w))console.log("\u2705 Zsh is set as a valid shell");else console.log("\u274C Zsh is not set as a valid shell"),console.log("\uD83D\uDD52 Adding Zsh to /etc/shells"),await y`echo ${w} | sudo tee -a /etc/shells`,console.log("\u2705 Zsh is set as a valid shell");if((await y`cat /etc/passwd | grep "^$USER:"`.text()).includes(w))console.log("\u2705 Zsh is set as your shell");else console.log("\u274C Zsh is not set as your shell"),console.log("\uD83D\uDD52 Setting Zsh as your shell"),await y`sudo chsh -s ${w} $USER`,console.log("\u2705 Zsh is set as your shell")},$w=async()=>{await Promise.all([b0(),A0()]),await Promise.all([k0(),y0().then(()=>Promise.all([P0().then(E0).then(f0),x0(),S0().then(O0)]))])};var{$:_$}=globalThis.Bun;var ww=async()=>void await Promise.all([_$`deno fmt --use-tabs --quiet; oxlint --fix-dangerously --quiet; biome check --write --unsafe .`.nothrow(),_$`go fmt ./...`.nothrow(),_$`dotnet csharpier .`.nothrow()]);var{$:K}=globalThis.Bun;var g0=async()=>{let $=await fetch("https://raw.githubusercontent.com/chneau/dotfiles/master/bootstrap.sh").then((w)=>w.text());await K`echo ${$} | sh`.nothrow()},v0=async()=>{let $=["@biomejs/biome","http-server","live-server","fkill-cli","ungit","npm-check","tsx","npm-check-updates","nodemon","prettier","typesync","depcheck","concurrently","ts-unused-exports"];await K`bun upgrade`.nothrow(),await K`bun install --force --global ${{raw:$.join(" ")}}`.nothrow(),await K`bun update --latest --force --global`.nothrow()},u0=async()=>{await K`sudo apt install -y ${{raw:["git","curl","wget","unzip","zsh","bash"].join(" ")}}`.nothrow(),await K`sudo apt update -y`.nothrow(),await K`sudo apt upgrade -y`.nothrow(),await K`sudo apt autoremove -y`.nothrow(),await K`sudo apt autoclean -y`.nothrow()},h0=async()=>{if(!await O("brew"))await K`CI=1 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`.nothrow();let $=["bpytop","dive","dldash/core/docker-color-output","docker-compose","go","helm","hyperfine","kubecolor","kubectx","kubernetes-cli","lazygit","node","pipx","zsh"],w=(await K`which brew`.text().catch(()=>"")).trim()||"/home/linuxbrew/.linuxbrew/bin/brew";await K`${w} install ${{raw:$.join(" ")}}`.nothrow(),await K`${w} update`.nothrow(),await K`${w} upgrade`.nothrow(),await K`${w} cleanup`.nothrow()},Hw=async()=>{if(await o())throw new Error("You cannot run this command as root");if(!await t())throw new Error("You cannot sudo");await g0(),await u0(),await v0(),await h0(),console.log("System updated")};var{$:m0}=globalThis.Bun;var Gw=async()=>await fetch("https://registry.npmjs.org/@chneau/x/latest").then(($)=>$.json().then((w)=>w.version)).catch(()=>"UNKNOWN");var Zw=async()=>{let $=await Gw(),w=await r();if($===w){console.log(`\u2705 You are already using the latest version ${w}`);return}console.log(`\uD83D\uDD52 You are using version ${w}`);while(!0){if(console.log(`\uD83D\uDD52 Updating to version ${$}`),await m0`bun i -fg @chneau/x@${$}`.quiet().then(()=>!0).catch(()=>!1))break;await Bun.sleep(1000)}console.log(`\u2705 Updated to version ${$}`)};var l0=await r();A.name("x").description("chneau's utility CLI").version(l0);A.option("-r, --recursive [number]","Recursion level",Number.parseFloat).argument("[dir]","Directory to manage",".").action(r$);A.command("fmt").description("Format all files").action(ww);A.command("upgrade").description("Uprade x to the latest version").action(Zw);A.command("system").description("Update/install the system packages").action(Hw);A.command("doctor").description("Check the system for issues").action($w);A.parse();
|
package/xx
ADDED