progy 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -15
- package/dist/cli.js +22 -26
- package/dist/public/index.html +4 -3
- package/dist/public/main.js +128 -128
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# app
|
|
2
|
-
|
|
3
|
-
To install dependencies:
|
|
4
|
-
|
|
5
|
-
```bash
|
|
6
|
-
bun install
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
To run:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
bun run index.ts
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
This project was created using `bun init` in bun v1.3.6. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
|
1
|
+
# app
|
|
2
|
+
|
|
3
|
+
To install dependencies:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun install
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
To run:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun run index.ts
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This project was created using `bun init` in bun v1.3.6. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
package/dist/cli.js
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
4
|
-
`)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
`)
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- too many short flags`);if(Y.test($))throw Error(`${R}
|
|
12
|
-
- too many long flags`);throw Error(`${R}
|
|
13
|
-
- unrecognised flag format`)}if(J===void 0&&Q===void 0)throw Error(`option creation failed due to no flags found in '${q}'.`);return{shortFlag:J,longFlag:Q}}yq.Option=p;yq.DualOptions=s});var i=S((kq)=>{function Fq(q,J){if(Math.abs(q.length-J.length)>3)return Math.max(q.length,J.length);let Q=[];for(let X=0;X<=q.length;X++)Q[X]=[X];for(let X=0;X<=J.length;X++)Q[0][X]=X;for(let X=1;X<=J.length;X++)for(let Y=1;Y<=q.length;Y++){let Z=1;if(q[Y-1]===J[X-1])Z=0;else Z=1;if(Q[Y][X]=Math.min(Q[Y-1][X]+1,Q[Y][X-1]+1,Q[Y-1][X-1]+Z),Y>1&&X>1&&q[Y-1]===J[X-2]&&q[Y-2]===J[X-1])Q[Y][X]=Math.min(Q[Y][X],Q[Y-2][X-2]+1)}return Q[q.length][J.length]}function Aq(q,J){if(!J||J.length===0)return"";J=Array.from(new Set(J));let Q=q.startsWith("--");if(Q)q=q.slice(2),J=J.map(($)=>$.slice(2));let X=[],Y=3,Z=0.4;if(J.forEach(($)=>{if($.length<=1)return;let R=Fq(q,$),T=Math.max(q.length,$.length);if((T-R)/T>Z){if(R<Y)Y=R,X=[$];else if(R===Y)X.push($)}}),X.sort(($,R)=>$.localeCompare(R)),Q)X=X.map(($)=>`--${$}`);if(X.length>1)return`
|
|
3
|
+
var Yq=Object.create;var{getPrototypeOf:Zq,defineProperty:g,getOwnPropertyNames:$q}=Object;var zq=Object.prototype.hasOwnProperty;var w=(q,J,Q)=>{Q=q!=null?Yq(Zq(q)):{};let X=J||!q||!q.__esModule?g(Q,"default",{value:q,enumerable:!0}):Q;for(let Y of $q(q))if(!zq.call(X,Y))g(X,Y,{get:()=>q[Y],enumerable:!0});return X};var L=(q,J)=>()=>(J||q((J={exports:{}}).exports,J),J.exports);var P=import.meta.require;var j=L((Rq)=>{class A extends Error{constructor(q,J,Q){super(Q);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=J,this.exitCode=q,this.nestedError=void 0}}class l extends A{constructor(q){super(1,"commander.invalidArgument",q);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}Rq.CommanderError=A;Rq.InvalidArgumentError=l});var D=L((Tq)=>{var{InvalidArgumentError:Gq}=j();class c{constructor(q,J){switch(this.description=J||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,q[0]){case"<":this.required=!0,this._name=q.slice(1,-1);break;case"[":this.required=!1,this._name=q.slice(1,-1);break;default:this.required=!0,this._name=q;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(q,J){if(J===this.defaultValue||!Array.isArray(J))return[q];return J.concat(q)}default(q,J){return this.defaultValue=q,this.defaultValueDescription=J,this}argParser(q){return this.parseArg=q,this}choices(q){return this.argChoices=q.slice(),this.parseArg=(J,Q)=>{if(!this.argChoices.includes(J))throw new Gq(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue(J,Q);return J},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function Uq(q){let J=q.name()+(q.variadic===!0?"...":"");return q.required?"<"+J+">":"["+J+"]"}Tq.Argument=c;Tq.humanReadableArgName=Uq});var k=L((_q)=>{var{humanReadableArgName:Kq}=D();class m{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(q){let J=q.commands.filter((X)=>!X._hidden),Q=q._getHelpCommand();if(Q&&!Q._hidden)J.push(Q);if(this.sortSubcommands)J.sort((X,Y)=>{return X.name().localeCompare(Y.name())});return J}compareOptions(q,J){let Q=(X)=>{return X.short?X.short.replace(/^-/,""):X.long.replace(/^--/,"")};return Q(q).localeCompare(Q(J))}visibleOptions(q){let J=q.options.filter((X)=>!X.hidden),Q=q._getHelpOption();if(Q&&!Q.hidden){let X=Q.short&&q._findOption(Q.short),Y=Q.long&&q._findOption(Q.long);if(!X&&!Y)J.push(Q);else if(Q.long&&!Y)J.push(q.createOption(Q.long,Q.description));else if(Q.short&&!X)J.push(q.createOption(Q.short,Q.description))}if(this.sortOptions)J.sort(this.compareOptions);return J}visibleGlobalOptions(q){if(!this.showGlobalOptions)return[];let J=[];for(let Q=q.parent;Q;Q=Q.parent){let X=Q.options.filter((Y)=>!Y.hidden);J.push(...X)}if(this.sortOptions)J.sort(this.compareOptions);return J}visibleArguments(q){if(q._argsDescription)q.registeredArguments.forEach((J)=>{J.description=J.description||q._argsDescription[J.name()]||""});if(q.registeredArguments.find((J)=>J.description))return q.registeredArguments;return[]}subcommandTerm(q){let J=q.registeredArguments.map((Q)=>Kq(Q)).join(" ");return q._name+(q._aliases[0]?"|"+q._aliases[0]:"")+(q.options.length?" [options]":"")+(J?" "+J:"")}optionTerm(q){return q.flags}argumentTerm(q){return q.name()}longestSubcommandTermLength(q,J){return J.visibleCommands(q).reduce((Q,X)=>{return Math.max(Q,J.subcommandTerm(X).length)},0)}longestOptionTermLength(q,J){return J.visibleOptions(q).reduce((Q,X)=>{return Math.max(Q,J.optionTerm(X).length)},0)}longestGlobalOptionTermLength(q,J){return J.visibleGlobalOptions(q).reduce((Q,X)=>{return Math.max(Q,J.optionTerm(X).length)},0)}longestArgumentTermLength(q,J){return J.visibleArguments(q).reduce((Q,X)=>{return Math.max(Q,J.argumentTerm(X).length)},0)}commandUsage(q){let J=q._name;if(q._aliases[0])J=J+"|"+q._aliases[0];let Q="";for(let X=q.parent;X;X=X.parent)Q=X.name()+" "+Q;return Q+J+" "+q.usage()}commandDescription(q){return q.description()}subcommandDescription(q){return q.summary()||q.description()}optionDescription(q){let J=[];if(q.argChoices)J.push(`choices: ${q.argChoices.map((Q)=>JSON.stringify(Q)).join(", ")}`);if(q.defaultValue!==void 0){if(q.required||q.optional||q.isBoolean()&&typeof q.defaultValue==="boolean")J.push(`default: ${q.defaultValueDescription||JSON.stringify(q.defaultValue)}`)}if(q.presetArg!==void 0&&q.optional)J.push(`preset: ${JSON.stringify(q.presetArg)}`);if(q.envVar!==void 0)J.push(`env: ${q.envVar}`);if(J.length>0)return`${q.description} (${J.join(", ")})`;return q.description}argumentDescription(q){let J=[];if(q.argChoices)J.push(`choices: ${q.argChoices.map((Q)=>JSON.stringify(Q)).join(", ")}`);if(q.defaultValue!==void 0)J.push(`default: ${q.defaultValueDescription||JSON.stringify(q.defaultValue)}`);if(J.length>0){let Q=`(${J.join(", ")})`;if(q.description)return`${q.description} ${Q}`;return Q}return q.description}formatHelp(q,J){let Q=J.padWidth(q,J),X=J.helpWidth||80,Y=2,Z=2;function R(G,M){if(M){let E=`${G.padEnd(Q+2)}${M}`;return J.wrap(E,X-2,Q+2)}return G}function $(G){return G.join(`
|
|
4
|
+
`).replace(/^/gm," ".repeat(2))}let z=[`Usage: ${J.commandUsage(q)}`,""],W=J.commandDescription(q);if(W.length>0)z=z.concat([J.wrap(W,X,0),""]);let B=J.visibleArguments(q).map((G)=>{return R(J.argumentTerm(G),J.argumentDescription(G))});if(B.length>0)z=z.concat(["Arguments:",$(B),""]);let T=J.visibleOptions(q).map((G)=>{return R(J.optionTerm(G),J.optionDescription(G))});if(T.length>0)z=z.concat(["Options:",$(T),""]);if(this.showGlobalOptions){let G=J.visibleGlobalOptions(q).map((M)=>{return R(J.optionTerm(M),J.optionDescription(M))});if(G.length>0)z=z.concat(["Global Options:",$(G),""])}let K=J.visibleCommands(q).map((G)=>{return R(J.subcommandTerm(G),J.subcommandDescription(G))});if(K.length>0)z=z.concat(["Commands:",$(K),""]);return z.join(`
|
|
5
|
+
`)}padWidth(q,J){return Math.max(J.longestOptionTermLength(q,J),J.longestGlobalOptionTermLength(q,J),J.longestSubcommandTermLength(q,J),J.longestArgumentTermLength(q,J))}wrap(q,J,Q,X=40){let Z=new RegExp(`[\\n][${" \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF"}]+`);if(q.match(Z))return q;let R=J-Q;if(R<X)return q;let $=q.slice(0,Q),z=q.slice(Q).replace(`\r
|
|
6
|
+
`,`
|
|
7
|
+
`),W=" ".repeat(Q),T=`\\s${"\u200B"}`,K=new RegExp(`
|
|
8
|
+
|.{1,${R-1}}([${T}]|$)|[^${T}]+?([${T}]|$)`,"g"),G=z.match(K)||[];return $+G.map((M,E)=>{if(M===`
|
|
9
|
+
`)return"";return(E>0?W:"")+M.trimEnd()}).join(`
|
|
10
|
+
`)}}_q.Help=m});var C=L((Vq)=>{var{InvalidArgumentError:Lq}=j();class d{constructor(q,J){this.flags=q,this.description=J||"",this.required=q.includes("<"),this.optional=q.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(q),this.mandatory=!1;let Q=Iq(q);if(this.short=Q.shortFlag,this.long=Q.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(q,J){return this.defaultValue=q,this.defaultValueDescription=J,this}preset(q){return this.presetArg=q,this}conflicts(q){return this.conflictsWith=this.conflictsWith.concat(q),this}implies(q){let J=q;if(typeof q==="string")J={[q]:!0};return this.implied=Object.assign(this.implied||{},J),this}env(q){return this.envVar=q,this}argParser(q){return this.parseArg=q,this}makeOptionMandatory(q=!0){return this.mandatory=!!q,this}hideHelp(q=!0){return this.hidden=!!q,this}_concatValue(q,J){if(J===this.defaultValue||!Array.isArray(J))return[q];return J.concat(q)}choices(q){return this.argChoices=q.slice(),this.parseArg=(J,Q)=>{if(!this.argChoices.includes(J))throw new Lq(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._concatValue(J,Q);return J},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){return Pq(this.name().replace(/^no-/,""))}is(q){return this.short===q||this.long===q}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class p{constructor(q){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,q.forEach((J)=>{if(J.negate)this.negativeOptions.set(J.attributeName(),J);else this.positiveOptions.set(J.attributeName(),J)}),this.negativeOptions.forEach((J,Q)=>{if(this.positiveOptions.has(Q))this.dualOptions.add(Q)})}valueFromOption(q,J){let Q=J.attributeName();if(!this.dualOptions.has(Q))return!0;let X=this.negativeOptions.get(Q).presetArg,Y=X!==void 0?X:!1;return J.negate===(Y===q)}}function Pq(q){return q.split("-").reduce((J,Q)=>{return J+Q[0].toUpperCase()+Q.slice(1)})}function Iq(q){let J,Q,X=q.split(/[ |,]+/);if(X.length>1&&!/^[[<]/.test(X[1]))J=X.shift();if(Q=X.shift(),!J&&/^-[^-]$/.test(Q))J=Q,Q=void 0;return{shortFlag:J,longFlag:Q}}Vq.Option=d;Vq.DualOptions=p});var s=L((Nq)=>{function Fq(q,J){if(Math.abs(q.length-J.length)>3)return Math.max(q.length,J.length);let Q=[];for(let X=0;X<=q.length;X++)Q[X]=[X];for(let X=0;X<=J.length;X++)Q[0][X]=X;for(let X=1;X<=J.length;X++)for(let Y=1;Y<=q.length;Y++){let Z=1;if(q[Y-1]===J[X-1])Z=0;else Z=1;if(Q[Y][X]=Math.min(Q[Y-1][X]+1,Q[Y][X-1]+1,Q[Y-1][X-1]+Z),Y>1&&X>1&&q[Y-1]===J[X-2]&&q[Y-2]===J[X-1])Q[Y][X]=Math.min(Q[Y][X],Q[Y-2][X-2]+1)}return Q[q.length][J.length]}function Dq(q,J){if(!J||J.length===0)return"";J=Array.from(new Set(J));let Q=q.startsWith("--");if(Q)q=q.slice(2),J=J.map((R)=>R.slice(2));let X=[],Y=3,Z=0.4;if(J.forEach((R)=>{if(R.length<=1)return;let $=Fq(q,R),z=Math.max(q.length,R.length);if((z-$)/z>Z){if($<Y)Y=$,X=[R];else if($===Y)X.push(R)}}),X.sort((R,$)=>R.localeCompare($)),Q)X=X.map((R)=>`--${R}`);if(X.length>1)return`
|
|
14
11
|
(Did you mean one of ${X.join(", ")}?)`;if(X.length===1)return`
|
|
15
|
-
(Did you mean ${X[0]}?)`;return""}
|
|
16
|
-
- specify the name in Command constructor or using .name()`);if(J=J||{},J.isDefault)this._defaultCommandName=q._name;if(J.noHelp||J.hidden)q._hidden=!0;return this._registerCommand(q),q.parent=this,q._checkForBrokenPassThrough(),this}createArgument(q,J){return new
|
|
17
|
-
Expecting one of '${Q.join("', '")}'`);if(this._lifeCycleHooks[q])this._lifeCycleHooks[q].push(J);else this._lifeCycleHooks[q]=[J];return this}exitOverride(q){if(q)this._exitCallback=q;else this._exitCallback=(J)=>{if(J.code!=="commander.executeSubCommandAsync")throw J};return this}_exit(q,J,Q){if(this._exitCallback)this._exitCallback(new O(q,J,Q));
|
|
18
|
-
- already used by option '${J.flags}'`)}this.
|
|
19
|
-
-
|
|
20
|
-
- if '${Q}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
12
|
+
(Did you mean ${X[0]}?)`;return""}Nq.suggestSimilar=Dq});var a=L((xq)=>{var wq=P("events").EventEmitter,b=P("child_process"),_=P("path"),x=P("fs"),U=P("process"),{Argument:Aq,humanReadableArgName:kq}=D(),{CommanderError:O}=j(),{Help:Cq}=k(),{Option:i,DualOptions:bq}=C(),{suggestSimilar:r}=s();class f extends wq{constructor(q){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!0,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=q||"",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._outputConfiguration={writeOut:(J)=>U.stdout.write(J),writeErr:(J)=>U.stderr.write(J),getOutHelpWidth:()=>U.stdout.isTTY?U.stdout.columns:void 0,getErrHelpWidth:()=>U.stderr.isTTY?U.stderr.columns:void 0,outputError:(J,Q)=>Q(J)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}copyInheritedSettings(q){return this._outputConfiguration=q._outputConfiguration,this._helpOption=q._helpOption,this._helpCommand=q._helpCommand,this._helpConfiguration=q._helpConfiguration,this._exitCallback=q._exitCallback,this._storeOptionsAsProperties=q._storeOptionsAsProperties,this._combineFlagAndOptionalValue=q._combineFlagAndOptionalValue,this._allowExcessArguments=q._allowExcessArguments,this._enablePositionalOptions=q._enablePositionalOptions,this._showHelpAfterError=q._showHelpAfterError,this._showSuggestionAfterError=q._showSuggestionAfterError,this}_getCommandAndAncestors(){let q=[];for(let J=this;J;J=J.parent)q.push(J);return q}command(q,J,Q){let X=J,Y=Q;if(typeof X==="object"&&X!==null)Y=X,X=null;Y=Y||{};let[,Z,R]=q.match(/([^ ]+) *(.*)/),$=this.createCommand(Z);if(X)$.description(X),$._executableHandler=!0;if(Y.isDefault)this._defaultCommandName=$._name;if($._hidden=!!(Y.noHelp||Y.hidden),$._executableFile=Y.executableFile||null,R)$.arguments(R);if(this._registerCommand($),$.parent=this,$.copyInheritedSettings(this),X)return this;return $}createCommand(q){return new f(q)}createHelp(){return Object.assign(new Cq,this.configureHelp())}configureHelp(q){if(q===void 0)return this._helpConfiguration;return this._helpConfiguration=q,this}configureOutput(q){if(q===void 0)return this._outputConfiguration;return Object.assign(this._outputConfiguration,q),this}showHelpAfterError(q=!0){if(typeof q!=="string")q=!!q;return this._showHelpAfterError=q,this}showSuggestionAfterError(q=!0){return this._showSuggestionAfterError=!!q,this}addCommand(q,J){if(!q._name)throw Error(`Command passed to .addCommand() must have a name
|
|
13
|
+
- specify the name in Command constructor or using .name()`);if(J=J||{},J.isDefault)this._defaultCommandName=q._name;if(J.noHelp||J.hidden)q._hidden=!0;return this._registerCommand(q),q.parent=this,q._checkForBrokenPassThrough(),this}createArgument(q,J){return new Aq(q,J)}argument(q,J,Q,X){let Y=this.createArgument(q,J);if(typeof Q==="function")Y.default(X).argParser(Q);else Y.default(Q);return this.addArgument(Y),this}arguments(q){return q.trim().split(/ +/).forEach((J)=>{this.argument(J)}),this}addArgument(q){let J=this.registeredArguments.slice(-1)[0];if(J&&J.variadic)throw Error(`only the last argument can be variadic '${J.name()}'`);if(q.required&&q.defaultValue!==void 0&&q.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${q.name()}'`);return this.registeredArguments.push(q),this}helpCommand(q,J){if(typeof q==="boolean")return this._addImplicitHelpCommand=q,this;q=q??"help [command]";let[,Q,X]=q.match(/([^ ]+) *(.*)/),Y=J??"display help for command",Z=this.createCommand(Q);if(Z.helpOption(!1),X)Z.arguments(X);if(Y)Z.description(Y);return this._addImplicitHelpCommand=!0,this._helpCommand=Z,this}addHelpCommand(q,J){if(typeof q!=="object")return this.helpCommand(q,J),this;return this._addImplicitHelpCommand=!0,this._helpCommand=q,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(q,J){let Q=["preSubcommand","preAction","postAction"];if(!Q.includes(q))throw Error(`Unexpected value for event passed to hook : '${q}'.
|
|
14
|
+
Expecting one of '${Q.join("', '")}'`);if(this._lifeCycleHooks[q])this._lifeCycleHooks[q].push(J);else this._lifeCycleHooks[q]=[J];return this}exitOverride(q){if(q)this._exitCallback=q;else this._exitCallback=(J)=>{if(J.code!=="commander.executeSubCommandAsync")throw J};return this}_exit(q,J,Q){if(this._exitCallback)this._exitCallback(new O(q,J,Q));U.exit(q)}action(q){let J=(Q)=>{let X=this.registeredArguments.length,Y=Q.slice(0,X);if(this._storeOptionsAsProperties)Y[X]=this;else Y[X]=this.opts();return Y.push(this),q.apply(this,Y)};return this._actionHandler=J,this}createOption(q,J){return new i(q,J)}_callParseArg(q,J,Q,X){try{return q.parseArg(J,Q)}catch(Y){if(Y.code==="commander.invalidArgument"){let Z=`${X} ${Y.message}`;this.error(Z,{exitCode:Y.exitCode,code:Y.code})}throw Y}}_registerOption(q){let J=q.short&&this._findOption(q.short)||q.long&&this._findOption(q.long);if(J){let Q=q.long&&this._findOption(q.long)?q.long:q.short;throw Error(`Cannot add option '${q.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${Q}'
|
|
15
|
+
- already used by option '${J.flags}'`)}this.options.push(q)}_registerCommand(q){let J=(X)=>{return[X.name()].concat(X.aliases())},Q=J(q).find((X)=>this._findCommand(X));if(Q){let X=J(this._findCommand(Q)).join("|"),Y=J(q).join("|");throw Error(`cannot add command '${Y}' as already have command '${X}'`)}this.commands.push(q)}addOption(q){this._registerOption(q);let J=q.name(),Q=q.attributeName();if(q.negate){let Y=q.long.replace(/^--no-/,"--");if(!this._findOption(Y))this.setOptionValueWithSource(Q,q.defaultValue===void 0?!0:q.defaultValue,"default")}else if(q.defaultValue!==void 0)this.setOptionValueWithSource(Q,q.defaultValue,"default");let X=(Y,Z,R)=>{if(Y==null&&q.presetArg!==void 0)Y=q.presetArg;let $=this.getOptionValue(Q);if(Y!==null&&q.parseArg)Y=this._callParseArg(q,Y,$,Z);else if(Y!==null&&q.variadic)Y=q._concatValue(Y,$);if(Y==null)if(q.negate)Y=!1;else if(q.isBoolean()||q.optional)Y=!0;else Y="";this.setOptionValueWithSource(Q,Y,R)};if(this.on("option:"+J,(Y)=>{let Z=`error: option '${q.flags}' argument '${Y}' is invalid.`;X(Y,Z,"cli")}),q.envVar)this.on("optionEnv:"+J,(Y)=>{let Z=`error: option '${q.flags}' value '${Y}' from env '${q.envVar}' is invalid.`;X(Y,Z,"env")});return this}_optionEx(q,J,Q,X,Y){if(typeof J==="object"&&J instanceof i)throw Error("To add an Option object use addOption() instead of option() or requiredOption()");let Z=this.createOption(J,Q);if(Z.makeOptionMandatory(!!q.mandatory),typeof X==="function")Z.default(Y).argParser(X);else if(X instanceof RegExp){let R=X;X=($,z)=>{let W=R.exec($);return W?W[0]:z},Z.default(Y).argParser(X)}else Z.default(X);return this.addOption(Z)}option(q,J,Q,X){return this._optionEx({},q,J,Q,X)}requiredOption(q,J,Q,X){return this._optionEx({mandatory:!0},q,J,Q,X)}combineFlagAndOptionalValue(q=!0){return this._combineFlagAndOptionalValue=!!q,this}allowUnknownOption(q=!0){return this._allowUnknownOption=!!q,this}allowExcessArguments(q=!0){return this._allowExcessArguments=!!q,this}enablePositionalOptions(q=!0){return this._enablePositionalOptions=!!q,this}passThroughOptions(q=!0){return this._passThroughOptions=!!q,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(q=!0){if(this.options.length)throw Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!q,this}getOptionValue(q){if(this._storeOptionsAsProperties)return this[q];return this._optionValues[q]}setOptionValue(q,J){return this.setOptionValueWithSource(q,J,void 0)}setOptionValueWithSource(q,J,Q){if(this._storeOptionsAsProperties)this[q]=J;else this._optionValues[q]=J;return this._optionValueSources[q]=Q,this}getOptionValueSource(q){return this._optionValueSources[q]}getOptionValueSourceWithGlobals(q){let J;return this._getCommandAndAncestors().forEach((Q)=>{if(Q.getOptionValueSource(q)!==void 0)J=Q.getOptionValueSource(q)}),J}_prepareUserArgs(q,J){if(q!==void 0&&!Array.isArray(q))throw Error("first parameter to parse must be array or undefined");if(J=J||{},q===void 0&&J.from===void 0){if(U.versions?.electron)J.from="electron";let X=U.execArgv??[];if(X.includes("-e")||X.includes("--eval")||X.includes("-p")||X.includes("--print"))J.from="eval"}if(q===void 0)q=U.argv;this.rawArgs=q.slice();let Q;switch(J.from){case void 0:case"node":this._scriptPath=q[1],Q=q.slice(2);break;case"electron":if(U.defaultApp)this._scriptPath=q[1],Q=q.slice(2);else Q=q.slice(1);break;case"user":Q=q.slice(0);break;case"eval":Q=q.slice(1);break;default:throw Error(`unexpected parse option { from: '${J.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",Q}parse(q,J){let Q=this._prepareUserArgs(q,J);return this._parseCommand([],Q),this}async parseAsync(q,J){let Q=this._prepareUserArgs(q,J);return await this._parseCommand([],Q),this}_executeSubCommand(q,J){J=J.slice();let Q=!1,X=[".js",".ts",".tsx",".mjs",".cjs"];function Y(W,B){let T=_.resolve(W,B);if(x.existsSync(T))return T;if(X.includes(_.extname(B)))return;let K=X.find((G)=>x.existsSync(`${T}${G}`));if(K)return`${T}${K}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let Z=q._executableFile||`${this._name}-${q._name}`,R=this._executableDir||"";if(this._scriptPath){let W;try{W=x.realpathSync(this._scriptPath)}catch(B){W=this._scriptPath}R=_.resolve(_.dirname(W),R)}if(R){let W=Y(R,Z);if(!W&&!q._executableFile&&this._scriptPath){let B=_.basename(this._scriptPath,_.extname(this._scriptPath));if(B!==this._name)W=Y(R,`${B}-${q._name}`)}Z=W||Z}Q=X.includes(_.extname(Z));let $;if(U.platform!=="win32")if(Q)J.unshift(Z),J=t(U.execArgv).concat(J),$=b.spawn(U.argv[0],J,{stdio:"inherit"});else $=b.spawn(Z,J,{stdio:"inherit"});else J.unshift(Z),J=t(U.execArgv).concat(J),$=b.spawn(U.execPath,J,{stdio:"inherit"});if(!$.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((B)=>{U.on(B,()=>{if($.killed===!1&&$.exitCode===null)$.kill(B)})});let z=this._exitCallback;$.on("close",(W)=>{if(W=W??1,!z)U.exit(W);else z(new O(W,"commander.executeSubCommandAsync","(close)"))}),$.on("error",(W)=>{if(W.code==="ENOENT"){let B=R?`searched for local subcommand relative to directory '${R}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",T=`'${Z}' does not exist
|
|
16
|
+
- if '${q._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
21
17
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
22
|
-
- ${
|
|
18
|
+
- ${B}`;throw Error(T)}else if(W.code==="EACCES")throw Error(`'${Z}' not executable`);if(!z)U.exit(1);else{let B=new O(1,"commander.executeSubCommandAsync","(error)");B.nestedError=W,z(B)}}),this.runningCommand=$}_dispatchSubcommand(q,J,Q){let X=this._findCommand(q);if(!X)this.help({error:!0});let Y;return Y=this._chainOrCallSubCommandHook(Y,X,"preSubcommand"),Y=this._chainOrCall(Y,()=>{if(X._executableHandler)this._executeSubCommand(X,J.concat(Q));else return X._parseCommand(J,Q)}),Y}_dispatchHelpCommand(q){if(!q)this.help();let J=this._findCommand(q);if(J&&!J._executableHandler)J.help();return this._dispatchSubcommand(q,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach((q,J)=>{if(q.required&&this.args[J]==null)this.missingArgument(q.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 q=(Q,X,Y)=>{let Z=X;if(X!==null&&Q.parseArg){let R=`error: command-argument value '${X}' is invalid for argument '${Q.name()}'.`;Z=this._callParseArg(Q,X,Y,R)}return Z};this._checkNumberOfArguments();let J=[];this.registeredArguments.forEach((Q,X)=>{let Y=Q.defaultValue;if(Q.variadic){if(X<this.args.length){if(Y=this.args.slice(X),Q.parseArg)Y=Y.reduce((Z,R)=>{return q(Q,R,Z)},Q.defaultValue)}else if(Y===void 0)Y=[]}else if(X<this.args.length){if(Y=this.args[X],Q.parseArg)Y=q(Q,Y,Q.defaultValue)}J[X]=Y}),this.processedArgs=J}_chainOrCall(q,J){if(q&&q.then&&typeof q.then==="function")return q.then(()=>J());return J()}_chainOrCallHooks(q,J){let Q=q,X=[];if(this._getCommandAndAncestors().reverse().filter((Y)=>Y._lifeCycleHooks[J]!==void 0).forEach((Y)=>{Y._lifeCycleHooks[J].forEach((Z)=>{X.push({hookedCommand:Y,callback:Z})})}),J==="postAction")X.reverse();return X.forEach((Y)=>{Q=this._chainOrCall(Q,()=>{return Y.callback(Y.hookedCommand,this)})}),Q}_chainOrCallSubCommandHook(q,J,Q){let X=q;if(this._lifeCycleHooks[Q]!==void 0)this._lifeCycleHooks[Q].forEach((Y)=>{X=this._chainOrCall(X,()=>{return Y(this,J)})});return X}_parseCommand(q,J){let Q=this.parseOptions(J);if(this._parseOptionsEnv(),this._parseOptionsImplied(),q=q.concat(Q.operands),J=Q.unknown,this.args=q.concat(J),q&&this._findCommand(q[0]))return this._dispatchSubcommand(q[0],q.slice(1),J);if(this._getHelpCommand()&&q[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(q[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(J),this._dispatchSubcommand(this._defaultCommandName,q,J);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(Q.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let X=()=>{if(Q.unknown.length>0)this.unknownOption(Q.unknown[0])},Y=`command:${this.name()}`;if(this._actionHandler){X(),this._processArguments();let Z;if(Z=this._chainOrCallHooks(Z,"preAction"),Z=this._chainOrCall(Z,()=>this._actionHandler(this.processedArgs)),this.parent)Z=this._chainOrCall(Z,()=>{this.parent.emit(Y,q,J)});return Z=this._chainOrCallHooks(Z,"postAction"),Z}if(this.parent&&this.parent.listenerCount(Y))X(),this._processArguments(),this.parent.emit(Y,q,J);else if(q.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",q,J);if(this.listenerCount("command:*"))this.emit("command:*",q,J);else if(this.commands.length)this.unknownCommand();else X(),this._processArguments()}else if(this.commands.length)X(),this.help({error:!0});else X(),this._processArguments()}_findCommand(q){if(!q)return;return this.commands.find((J)=>J._name===q||J._aliases.includes(q))}_findOption(q){return this.options.find((J)=>J.is(q))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((q)=>{q.options.forEach((J)=>{if(J.mandatory&&q.getOptionValue(J.attributeName())===void 0)q.missingMandatoryOptionValue(J)})})}_checkForConflictingLocalOptions(){let q=this.options.filter((Q)=>{let X=Q.attributeName();if(this.getOptionValue(X)===void 0)return!1;return this.getOptionValueSource(X)!=="default"});q.filter((Q)=>Q.conflictsWith.length>0).forEach((Q)=>{let X=q.find((Y)=>Q.conflictsWith.includes(Y.attributeName()));if(X)this._conflictingOption(Q,X)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((q)=>{q._checkForConflictingLocalOptions()})}parseOptions(q){let J=[],Q=[],X=J,Y=q.slice();function Z($){return $.length>1&&$[0]==="-"}let R=null;while(Y.length){let $=Y.shift();if($==="--"){if(X===Q)X.push($);X.push(...Y);break}if(R&&!Z($)){this.emit(`option:${R.name()}`,$);continue}if(R=null,Z($)){let z=this._findOption($);if(z){if(z.required){let W=Y.shift();if(W===void 0)this.optionMissingArgument(z);this.emit(`option:${z.name()}`,W)}else if(z.optional){let W=null;if(Y.length>0&&!Z(Y[0]))W=Y.shift();this.emit(`option:${z.name()}`,W)}else this.emit(`option:${z.name()}`);R=z.variadic?z:null;continue}}if($.length>2&&$[0]==="-"&&$[1]!=="-"){let z=this._findOption(`-${$[1]}`);if(z){if(z.required||z.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${z.name()}`,$.slice(2));else this.emit(`option:${z.name()}`),Y.unshift(`-${$.slice(2)}`);continue}}if(/^--[^=]+=/.test($)){let z=$.indexOf("="),W=this._findOption($.slice(0,z));if(W&&(W.required||W.optional)){this.emit(`option:${W.name()}`,$.slice(z+1));continue}}if(Z($))X=Q;if((this._enablePositionalOptions||this._passThroughOptions)&&J.length===0&&Q.length===0){if(this._findCommand($)){if(J.push($),Y.length>0)Q.push(...Y);break}else if(this._getHelpCommand()&&$===this._getHelpCommand().name()){if(J.push($),Y.length>0)J.push(...Y);break}else if(this._defaultCommandName){if(Q.push($),Y.length>0)Q.push(...Y);break}}if(this._passThroughOptions){if(X.push($),Y.length>0)X.push(...Y);break}X.push($)}return{operands:J,unknown:Q}}opts(){if(this._storeOptionsAsProperties){let q={},J=this.options.length;for(let Q=0;Q<J;Q++){let X=this.options[Q].attributeName();q[X]=X===this._versionOptionName?this._version:this[X]}return q}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((q,J)=>Object.assign(q,J.opts()),{})}error(q,J){if(this._outputConfiguration.outputError(`${q}
|
|
23
19
|
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
24
20
|
`);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(`
|
|
25
|
-
`),this.outputHelp({error:!0});let Q=J||{},X=Q.exitCode||1,Y=Q.code||"commander.error";this._exit(X,Y,q)}_parseOptionsEnv(){this.options.forEach((q)=>{if(q.envVar&&q.envVar in
|
|
26
|
-
`),this._exit(0,"commander.version",q)}),this}description(q,J){if(q===void 0&&J===void 0)return this._description;if(this._description=q,J)this._argsDescription=J;return this}summary(q){if(q===void 0)return this._summary;return this._summary=q,this}alias(q){if(q===void 0)return this._aliases[0];let J=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)J=this.commands[this.commands.length-1];if(q===J._name)throw Error("Command alias can't be the same as its name");let Q=this.parent?._findCommand(q);if(Q){let X=[Q.name()].concat(Q.aliases()).join("|");throw Error(`cannot add alias '${q}' to command '${this.name()}' as already have command '${X}'`)}return J._aliases.push(q),this}aliases(q){if(q===void 0)return this._aliases;return q.forEach((J)=>this.alias(J)),this}usage(q){if(q===void 0){if(this._usage)return this._usage;let J=this.registeredArguments.map((Q)=>{return
|
|
21
|
+
`),this.outputHelp({error:!0});let Q=J||{},X=Q.exitCode||1,Y=Q.code||"commander.error";this._exit(X,Y,q)}_parseOptionsEnv(){this.options.forEach((q)=>{if(q.envVar&&q.envVar in U.env){let J=q.attributeName();if(this.getOptionValue(J)===void 0||["default","config","env"].includes(this.getOptionValueSource(J)))if(q.required||q.optional)this.emit(`optionEnv:${q.name()}`,U.env[q.envVar]);else this.emit(`optionEnv:${q.name()}`)}})}_parseOptionsImplied(){let q=new bq(this.options),J=(Q)=>{return this.getOptionValue(Q)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(Q))};this.options.filter((Q)=>Q.implied!==void 0&&J(Q.attributeName())&&q.valueFromOption(this.getOptionValue(Q.attributeName()),Q)).forEach((Q)=>{Object.keys(Q.implied).filter((X)=>!J(X)).forEach((X)=>{this.setOptionValueWithSource(X,Q.implied[X],"implied")})})}missingArgument(q){let J=`error: missing required argument '${q}'`;this.error(J,{code:"commander.missingArgument"})}optionMissingArgument(q){let J=`error: option '${q.flags}' argument missing`;this.error(J,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(q){let J=`error: required option '${q.flags}' not specified`;this.error(J,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(q,J){let Q=(Z)=>{let R=Z.attributeName(),$=this.getOptionValue(R),z=this.options.find((B)=>B.negate&&R===B.attributeName()),W=this.options.find((B)=>!B.negate&&R===B.attributeName());if(z&&(z.presetArg===void 0&&$===!1||z.presetArg!==void 0&&$===z.presetArg))return z;return W||Z},X=(Z)=>{let R=Q(Z),$=R.attributeName();if(this.getOptionValueSource($)==="env")return`environment variable '${R.envVar}'`;return`option '${R.flags}'`},Y=`error: ${X(q)} cannot be used with ${X(J)}`;this.error(Y,{code:"commander.conflictingOption"})}unknownOption(q){if(this._allowUnknownOption)return;let J="";if(q.startsWith("--")&&this._showSuggestionAfterError){let X=[],Y=this;do{let Z=Y.createHelp().visibleOptions(Y).filter((R)=>R.long).map((R)=>R.long);X=X.concat(Z),Y=Y.parent}while(Y&&!Y._enablePositionalOptions);J=r(q,X)}let Q=`error: unknown option '${q}'${J}`;this.error(Q,{code:"commander.unknownOption"})}_excessArguments(q){if(this._allowExcessArguments)return;let J=this.registeredArguments.length,Q=J===1?"":"s",Y=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${J} argument${Q} but got ${q.length}.`;this.error(Y,{code:"commander.excessArguments"})}unknownCommand(){let q=this.args[0],J="";if(this._showSuggestionAfterError){let X=[];this.createHelp().visibleCommands(this).forEach((Y)=>{if(X.push(Y.name()),Y.alias())X.push(Y.alias())}),J=r(q,X)}let Q=`error: unknown command '${q}'${J}`;this.error(Q,{code:"commander.unknownCommand"})}version(q,J,Q){if(q===void 0)return this._version;this._version=q,J=J||"-V, --version",Q=Q||"output the version number";let X=this.createOption(J,Q);return this._versionOptionName=X.attributeName(),this._registerOption(X),this.on("option:"+X.name(),()=>{this._outputConfiguration.writeOut(`${q}
|
|
22
|
+
`),this._exit(0,"commander.version",q)}),this}description(q,J){if(q===void 0&&J===void 0)return this._description;if(this._description=q,J)this._argsDescription=J;return this}summary(q){if(q===void 0)return this._summary;return this._summary=q,this}alias(q){if(q===void 0)return this._aliases[0];let J=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)J=this.commands[this.commands.length-1];if(q===J._name)throw Error("Command alias can't be the same as its name");let Q=this.parent?._findCommand(q);if(Q){let X=[Q.name()].concat(Q.aliases()).join("|");throw Error(`cannot add alias '${q}' to command '${this.name()}' as already have command '${X}'`)}return J._aliases.push(q),this}aliases(q){if(q===void 0)return this._aliases;return q.forEach((J)=>this.alias(J)),this}usage(q){if(q===void 0){if(this._usage)return this._usage;let J=this.registeredArguments.map((Q)=>{return kq(Q)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?J:[]).join(" ")}return this._usage=q,this}name(q){if(q===void 0)return this._name;return this._name=q,this}nameFromFilename(q){return this._name=_.basename(q,_.extname(q)),this}executableDir(q){if(q===void 0)return this._executableDir;return this._executableDir=q,this}helpInformation(q){let J=this.createHelp();if(J.helpWidth===void 0)J.helpWidth=q&&q.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth();return J.formatHelp(this,J)}_getHelpContext(q){q=q||{};let J={error:!!q.error},Q;if(J.error)Q=(X)=>this._outputConfiguration.writeErr(X);else Q=(X)=>this._outputConfiguration.writeOut(X);return J.write=q.write||Q,J.command=this,J}outputHelp(q){let J;if(typeof q==="function")J=q,q=void 0;let Q=this._getHelpContext(q);this._getCommandAndAncestors().reverse().forEach((Y)=>Y.emit("beforeAllHelp",Q)),this.emit("beforeHelp",Q);let X=this.helpInformation(Q);if(J){if(X=J(X),typeof X!=="string"&&!Buffer.isBuffer(X))throw Error("outputHelp callback must return a string or a Buffer")}if(Q.write(X),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",Q),this._getCommandAndAncestors().forEach((Y)=>Y.emit("afterAllHelp",Q))}helpOption(q,J){if(typeof q==="boolean"){if(q)this._helpOption=this._helpOption??void 0;else this._helpOption=null;return this}return q=q??"-h, --help",J=J??"display help for command",this._helpOption=this.createOption(q,J),this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(q){return this._helpOption=q,this}help(q){this.outputHelp(q);let J=U.exitCode||0;if(J===0&&q&&typeof q!=="function"&&q.error)J=1;this._exit(J,"commander.help","(outputHelp)")}addHelpText(q,J){let Q=["beforeAll","before","after","afterAll"];if(!Q.includes(q))throw Error(`Unexpected value for position to addHelpText.
|
|
27
23
|
Expecting one of '${Q.join("', '")}'`);let X=`${q}Help`;return this.on(X,(Y)=>{let Z;if(typeof J==="function")Z=J({error:Y.error,command:Y.command});else Z=J;if(Z)Y.write(`${Z}
|
|
28
|
-
`)}),this}_outputHelpIfRequested(q){let J=this._getHelpOption();if(J&&q.find((X)=>J.is(X)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function
|
|
24
|
+
`)}),this}_outputHelpIfRequested(q){let J=this._getHelpOption();if(J&&q.find((X)=>J.is(X)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function t(q){return q.map((J)=>{if(!J.startsWith("--inspect"))return J;let Q,X="127.0.0.1",Y="9229",Z;if((Z=J.match(/^(--inspect(-brk)?)$/))!==null)Q=Z[1];else if((Z=J.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(Q=Z[1],/^\d+$/.test(Z[3]))Y=Z[3];else X=Z[3];else if((Z=J.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)Q=Z[1],X=Z[3],Y=Z[4];if(Q&&Y!=="0")return`${Q}=${X}:${parseInt(Y)+1}`;return J})}xq.Command=f});var qq=L((hq)=>{var{Argument:n}=D(),{Command:v}=a(),{CommanderError:fq,InvalidArgumentError:o}=j(),{Help:vq}=k(),{Option:e}=C();hq.program=new v;hq.createCommand=(q)=>new v(q);hq.createOption=(q,J)=>new e(q,J);hq.createArgument=(q,J)=>new n(q,J);hq.Command=v;hq.Option=e;hq.Argument=n;hq.Help=vq;hq.CommanderError=fq;hq.InvalidArgumentError=o;hq.InvalidOptionArgumentError=o});var Jq=w(qq(),1),{program:V,createCommand:GJ,createArgument:UJ,createOption:TJ,CommanderError:HJ,InvalidArgumentError:MJ,InvalidOptionArgumentError:KJ,Command:_J,Argument:SJ,Option:LJ,Help:PJ}=Jq.default;import{cp as Qq,exists as S,mkdir as N,writeFile as I,readFile as FJ}from"fs/promises";import{join as H}from"path";import{spawn as y}from"child_process";import{homedir as aq}from"os";var h={rust:{courseJson:{id:"{{id}}",name:"{{name}}",runner:{command:"cargo",args:["test","--quiet","--manifest-path","./content/{{id}}/Cargo.toml"],cwd:"."},content:{root:".",exercises:"content"},setup:{checks:[{name:"Rust Compiler",type:"command",command:"rustc --version"},{name:"Cargo Package Manager",type:"command",command:"cargo --version"}],guide:"SETUP.md"}},setupMd:`# \uD83E\uDD80 Rust Setup Guide
|
|
29
25
|
|
|
30
26
|
To run the exercises in this course, you need to have **Rust** installed on your system.
|
|
31
27
|
|
|
@@ -88,7 +84,7 @@ func Greeting() string {
|
|
|
88
84
|
func main() {
|
|
89
85
|
fmt.Println(Greeting())
|
|
90
86
|
}
|
|
91
|
-
`,introFilename:"main.go"}};var
|
|
87
|
+
`,introFilename:"main.go"}};var u=H(aq(),".progy"),nq=H(u,"config.json"),Xq=process.env.PROGY_API_URL||"https://progy.francy.workers.dev",oq=process.env.PROGY_FRONTEND_URL||Xq,F="course.json";async function eq(){let q=H(import.meta.dir,"../../../courses");if(await S(q))return q;return null}async function qJ(q){if(!await S(u))await N(u,{recursive:!0});await I(nq,JSON.stringify({token:q}))}function JJ(q){let J=process.platform==="win32"?"start":process.platform==="darwin"?"open":"xdg-open";y(J,[q],{shell:!0}).unref()}async function QJ(q,J){console.log(`[INFO] Local courses not found. Attempting to download ${q} from https://github.com/fhorray/rust-flow.git...`);let X=H(process.cwd(),".prog-temp-"+Date.now());try{console.log("[GIT] Cloning repository...");let Y=y("git",["clone","--depth","1","https://github.com/fhorray/rust-flow.git",X],{stdio:"inherit"});await new Promise(($,z)=>{Y.on("close",(W)=>W===0?$(null):z("Git clone failed"))});let Z=H(X,"courses",q);if(!await S(Z))throw Error(`Course '${q}' not found in repository.`);let R=["content","runner","Cargo.toml","go.mod","SETUP.md",F];for(let $ of R){let z=H(Z,$),W=H(J,$);if(await S(z))console.log(`[COPY] ${$}...`),await Qq(z,W,{recursive:!0})}}finally{try{if(await S(X))y("rm",["-rf",X],{stdio:"ignore"}).unref()}catch(Y){}}}V.name("progy").description("Universal programming course runner").version("0.0.1");V.command("init").description("Initialize a new course in the current directory").option("-c, --course <course>","Language/Course to initialize (e.g., rust)").action(async(q)=>{let J=process.cwd(),Q=H(J,F),X=await S(Q);if(!q.course)if(X)console.log(`[INFO] Detected '${F}'. Starting progy...`);else console.error(`[ERROR] No '${F}' found. Please specify a course to initialize:`),console.error(" progy init --course <rust|go|cloudflare...>"),process.exit(1);else{let z=q.course;console.log(`[INFO] Initializing ${z} course in ${J}...`);let W=await eq(),B=!1;if(W){console.log(`[INFO] Found local courses directory: ${W}`);let T=H(W,z);if(await S(T)){let K=["content","runner","Cargo.toml","go.mod","SETUP.md",F];for(let G of K){let M=H(T,G),E=H(J,G);if(await S(M))console.log(`[COPY] ${G}...`),await Qq(M,E,{recursive:!0})}B=!0}else console.warn(`[WARN] Course ${z} not found locally.`)}if(!B)try{await QJ(z,J)}catch(T){console.error(`[ERROR] Failed to initialize course: ${T}`),process.exit(1)}console.log("[INFO] Initialization complete!")}console.log("[INFO] Starting UI...");let Z=import.meta.file.endsWith(".ts")?"ts":"js",R=H(import.meta.dir,"backend",`server.${Z}`);y("bun",["run","--hot",R],{stdio:"inherit",env:{...process.env,PROG_CWD:J}}).on("close",(z)=>process.exit(z??0))});V.command("create-course").description("Scaffold a new course with standard directory structure").requiredOption("--name <name>","Name of the course (e.g., rust-advanced)").requiredOption("-c, --course <course>","Programming language template (rust, go)").action(async(q)=>{let J=process.cwd(),Q=q.name,X=q.course.toLowerCase(),Y=H(J,Q);if(await S(Y))console.error(`[ERROR] Directory '${Q}' already exists.`),process.exit(1);let Z=h[X];if(!Z)console.error(`[ERROR] Unsupported language '${X}'. Supported: ${Object.keys(h).join(", ")}`),process.exit(1);console.log(`[INFO] Creating course '${Q}' with template '${X}'...`),await N(Y,{recursive:!0}),await N(H(Y,"content","01_intro"),{recursive:!0});let R=JSON.stringify(Z.courseJson,null,2).replace(/{{id}}/g,Q).replace(/{{name}}/g,Q);if(await I(H(Y,"course.json"),R),await I(H(Y,"SETUP.md"),Z.setupMd),await I(H(Y,"content","01_intro","README.md"),Z.introReadme),await I(H(Y,"content","01_intro",Z.introFilename),Z.introCode),X==="go"){let $=H(Y,"runner");await N($,{recursive:!0});let z=`package main
|
|
92
88
|
import (
|
|
93
89
|
"bufio"
|
|
94
90
|
"encoding/json"
|
|
@@ -129,12 +125,12 @@ func main() {
|
|
|
129
125
|
fmt.Println("__SRP_END__")
|
|
130
126
|
if !srp.Success { os.Exit(0) }
|
|
131
127
|
}
|
|
132
|
-
`;await
|
|
128
|
+
`;await I(H($,"main.go"),z),await I(H(Y,"go.mod"),`module ${Q}
|
|
133
129
|
|
|
134
130
|
go 1.21
|
|
135
131
|
`)}console.log("[SUCCESS] Course created!"),console.log(`
|
|
136
132
|
To get started:
|
|
137
133
|
cd ${Q}
|
|
138
|
-
bunx progy init`)});
|
|
139
|
-
Please authenticate in your browser:`),console.log(`\x1B[36m${
|
|
140
|
-
`)
|
|
134
|
+
bunx progy init`)});V.command("login").description("Authenticate with Progy").action(async()=>{let{createAuthClient:q}=await import("better-auth/client"),{deviceAuthorizationClient:J}=await import("better-auth/client/plugins"),Q=q({baseURL:Xq,plugins:[J()]});try{console.log("[INFO] Requesting login session...");let{data:X,error:Y}=await Q.device.code({client_id:"progy-cli"});if(Y)throw Error(Y.error_description||"Failed to initiate device authorization");let{device_code:Z,user_code:R,verification_uri:$,interval:z}=X,W=$.startsWith("http")?$:`${oq}${$}`;console.log(`
|
|
135
|
+
Please authenticate in your browser:`),console.log(`\x1B[36m${W}\x1B[0m`),console.log(`Code: \x1B[33m${R}\x1B[0m
|
|
136
|
+
`),JJ(W),console.log("[WAIT] Waiting for authorization...");let T=await(async()=>{while(!0){let{data:K,error:G}=await Q.device.token({grant_type:"urn:ietf:params:oauth:grant-type:device_code",device_code:Z,client_id:"progy-cli"});if(K?.access_token)return K.access_token;if(G){let M=G.error;if(M==="access_denied"||M==="expired_token")throw Error(G.error_description||M)}await new Promise((M)=>setTimeout(M,(z||5)*1000))}})();if(T)await qJ(T),console.log("[SUCCESS] Logged in successfully!")}catch(X){console.error(`[ERROR] Login failed: ${X.message||X}`),process.exit(1)}});V.parse();
|
package/dist/public/index.html
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
--color-rust-light: #dea584;
|
|
15
15
|
}
|
|
16
16
|
</style>
|
|
17
|
-
|
|
18
|
-
<
|
|
17
|
+
|
|
18
|
+
<script type="module" src="/main.js"></script>
|
|
19
|
+
<link rel="stylesheet" href="/main.css">
|
|
19
20
|
</head>
|
|
20
21
|
|
|
21
22
|
<body class="bg-zinc-950 text-zinc-100">
|
|
@@ -23,4 +24,4 @@
|
|
|
23
24
|
|
|
24
25
|
</body>
|
|
25
26
|
|
|
26
|
-
</html>
|
|
27
|
+
</html>
|