@frontstackdev/cli 0.0.0-canary-20250619110349 → 0.0.0-canary-20250620124824
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/dist/frontstack.mjs +24 -23
- package/dist/version +1 -1
- package/package.json +2 -2
package/dist/frontstack.mjs
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`).replace(/^/gm," ".repeat(o))}l(
|
|
4
|
-
`)}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}wrap(e,t,n,i=40){const o=" \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF",a=new RegExp(`[\\n][${o}]+`);if(e.match(a))return e;const
|
|
2
|
+
var qe=Object.defineProperty;var l=(r,e)=>qe(r,"name",{value:e,configurable:!0});var R,H,N,F,I,V,j;import Me from"events";import Ue from"child_process";import g from"path";import _,{readFileSync as We}from"fs";import Ge from"process";import d from"chalk";import he from"js-yaml";import Je from"http";import Be from"open";import E from"handlebars";import Ke from"openapi-typescript";import M from"prompts";import{fileURLToPath as ze}from"url";var A={},D={},P={};let pe=(R=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},l(R,"CommanderError"),R),Qe=(H=class extends pe{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},l(H,"InvalidArgumentError"),H);P.CommanderError=pe,P.InvalidArgumentError=Qe;const{InvalidArgumentError:Ye}=P;let Ze=(N=class{constructor(e,t){switch(this.description=t||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.length>3&&this._name.slice(-3)==="..."&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:t.concat(e)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new Ye(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,n):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}},l(N,"Argument"),N);function Xe(r){const e=r.name()+(r.variadic===!0?"...":"");return r.required?"<"+e+">":"["+e+"]"}l(Xe,"humanReadableArgName$2"),D.Argument=Ze,D.humanReadableArgName=Xe;var fe={},J={};const{humanReadableArgName:et}=D;let tt=(F=class{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(e){const t=e.commands.filter(i=>!i._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((i,o)=>i.name().localeCompare(o.name())),t}compareOptions(e,t){const n=l(i=>i.short?i.short.replace(/^-/,""):i.long.replace(/^--/,""),"getSortKey");return n(e).localeCompare(n(t))}visibleOptions(e){const t=e.options.filter(i=>!i.hidden),n=e._getHelpOption();if(n&&!n.hidden){const i=n.short&&e._findOption(n.short),o=n.long&&e._findOption(n.long);!i&&!o?t.push(n):n.long&&!o?t.push(e.createOption(n.long,n.description)):n.short&&!i&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];const t=[];for(let n=e.parent;n;n=n.parent){const i=n.options.filter(o=>!o.hidden);t.push(...i)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e.registeredArguments.find(t=>t.description)?e.registeredArguments:[]}subcommandTerm(e){const t=e.registeredArguments.map(n=>et(n)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(t?" "+t:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((n,i)=>Math.max(n,t.subcommandTerm(i).length),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((n,i)=>Math.max(n,t.optionTerm(i).length),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((n,i)=>Math.max(n,t.optionTerm(i).length),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((n,i)=>Math.max(n,t.argumentTerm(i).length),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let n="";for(let i=e.parent;i;i=i.parent)n=i.name()+" "+n;return n+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){const t=[];return e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue=="boolean")&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0?`${e.description} (${t.join(", ")})`:e.description}argumentDescription(e){const t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){const n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}formatHelp(e,t){const n=t.padWidth(e,t),i=t.helpWidth||80,o=2,a=2;function u(m,b){if(b){const x=`${m.padEnd(n+a)}${b}`;return t.wrap(x,i-o,n+a)}return m}l(u,"formatItem");function c(m){return m.join(`
|
|
3
|
+
`).replace(/^/gm," ".repeat(o))}l(c,"formatList");let h=[`Usage: ${t.commandUsage(e)}`,""];const s=t.commandDescription(e);s.length>0&&(h=h.concat([t.wrap(s,i,0),""]));const p=t.visibleArguments(e).map(m=>u(t.argumentTerm(m),t.argumentDescription(m)));p.length>0&&(h=h.concat(["Arguments:",c(p),""]));const f=t.visibleOptions(e).map(m=>u(t.optionTerm(m),t.optionDescription(m)));if(f.length>0&&(h=h.concat(["Options:",c(f),""])),this.showGlobalOptions){const m=t.visibleGlobalOptions(e).map(b=>u(t.optionTerm(b),t.optionDescription(b)));m.length>0&&(h=h.concat(["Global Options:",c(m),""]))}const y=t.visibleCommands(e).map(m=>u(t.subcommandTerm(m),t.subcommandDescription(m)));return y.length>0&&(h=h.concat(["Commands:",c(y),""])),h.join(`
|
|
4
|
+
`)}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}wrap(e,t,n,i=40){const o=" \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF",a=new RegExp(`[\\n][${o}]+`);if(e.match(a))return e;const u=t-n;if(u<i)return e;const c=e.slice(0,n),h=e.slice(n).replace(`\r
|
|
5
5
|
`,`
|
|
6
|
-
`),s=" ".repeat(n),f="\\s\u200B",
|
|
7
|
-
|.{1,${
|
|
8
|
-
`?"":(
|
|
9
|
-
`)}},l(
|
|
6
|
+
`),s=" ".repeat(n),f="\\s\u200B",y=new RegExp(`
|
|
7
|
+
|.{1,${u-1}}([${f}]|$)|[^${f}]+?([${f}]|$)`,"g"),m=h.match(y)||[];return c+m.map((b,x)=>b===`
|
|
8
|
+
`?"":(x>0?s:"")+b.trimEnd()).join(`
|
|
9
|
+
`)}},l(F,"Help"),F);J.Help=tt;var U={};const{InvalidArgumentError:nt}=P;let it=(I=class{constructor(e,t){this.flags=e,this.description=t||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;const n=st(e);this.short=n.shortFlag,this.long=n.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(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e=="string"&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_concatValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:t.concat(e)}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new nt(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,n):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return ot(this.name().replace(/^no-/,""))}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},l(I,"Option"),I),rt=(V=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,n)=>{this.positiveOptions.has(n)&&this.dualOptions.add(n)})}valueFromOption(e,t){const n=t.attributeName();if(!this.dualOptions.has(n))return!0;const i=this.negativeOptions.get(n).presetArg,o=i!==void 0?i:!1;return t.negate===(o===e)}},l(V,"DualOptions"),V);function ot(r){return r.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}l(ot,"camelcase");function st(r){let e,t;const n=r.split(/[ |,]+/);return n.length>1&&!/^[[<]/.test(n[1])&&(e=n.shift()),t=n.shift(),!e&&/^-[^-]$/.test(t)&&(e=t,t=void 0),{shortFlag:e,longFlag:t}}l(st,"splitOptionFlags"),U.Option=it,U.DualOptions=rt;var de={};const me=3;function at(r,e){if(Math.abs(r.length-e.length)>me)return Math.max(r.length,e.length);const t=[];for(let n=0;n<=r.length;n++)t[n]=[n];for(let n=0;n<=e.length;n++)t[0][n]=n;for(let n=1;n<=e.length;n++)for(let i=1;i<=r.length;i++){let o=1;r[i-1]===e[n-1]?o=0:o=1,t[i][n]=Math.min(t[i-1][n]+1,t[i][n-1]+1,t[i-1][n-1]+o),i>1&&n>1&&r[i-1]===e[n-2]&&r[i-2]===e[n-1]&&(t[i][n]=Math.min(t[i][n],t[i-2][n-2]+1))}return t[r.length][e.length]}l(at,"editDistance");function ct(r,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));const t=r.startsWith("--");t&&(r=r.slice(2),e=e.map(a=>a.slice(2)));let n=[],i=me;const o=.4;return e.forEach(a=>{if(a.length<=1)return;const u=at(r,a),c=Math.max(r.length,a.length);(c-u)/c>o&&(u<i?(i=u,n=[a]):u===i&&n.push(a))}),n.sort((a,u)=>a.localeCompare(u)),t&&(n=n.map(a=>`--${a}`)),n.length>1?`
|
|
10
10
|
(Did you mean one of ${n.join(", ")}?)`:n.length===1?`
|
|
11
|
-
(Did you mean ${n[0]}?)`:""}l(
|
|
12
|
-
- specify the name in Command constructor or using .name()`);return t=t||{},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new
|
|
13
|
-
Expecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync")throw t},this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new
|
|
14
|
-
- already used by option '${t.flags}'`)}this.options.push(e)}_registerCommand(e){const t=l(i=>[i.name()].concat(i.aliases()),"knownBy"),n=t(e).find(i=>this._findCommand(i));if(n){const i=t(this._findCommand(n)).join("|"),o=t(e).join("|");throw new Error(`cannot add command '${o}' as already have command '${i}'`)}this.commands.push(e)}addOption(e){this._registerOption(e);const t=e.name(),n=e.attributeName();if(e.negate){const o=e.long.replace(/^--no-/,"--");this._findOption(o)||this.setOptionValueWithSource(n,e.defaultValue===void 0?!0:e.defaultValue,"default")}else e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,"default");const i=l((o,a,
|
|
11
|
+
(Did you mean ${n[0]}?)`:""}l(ct,"suggestSimilar$1"),de.suggestSimilar=ct;const lt=Me.EventEmitter,B=Ue,v=g,K=_,O=Ge,{Argument:ut,humanReadableArgName:ht}=D,{CommanderError:z}=P,{Help:pt}=J,{Option:ge,DualOptions:ft}=U,{suggestSimilar:_e}=de;let dt=(j=class extends lt{constructor(e){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=e||"",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:l(t=>O.stdout.write(t),"writeOut"),writeErr:l(t=>O.stderr.write(t),"writeErr"),getOutHelpWidth:l(()=>O.stdout.isTTY?O.stdout.columns:void 0,"getOutHelpWidth"),getErrHelpWidth:l(()=>O.stderr.isTTY?O.stderr.columns:void 0,"getErrHelpWidth"),outputError:l((t,n)=>n(t),"outputError")},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){const e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let i=t,o=n;typeof i=="object"&&i!==null&&(o=i,i=null),o=o||{};const[,a,u]=e.match(/([^ ]+) *(.*)/),c=this.createCommand(a);return i&&(c.description(i),c._executableHandler=!0),o.isDefault&&(this._defaultCommandName=c._name),c._hidden=!!(o.noHelp||o.hidden),c._executableFile=o.executableFile||null,u&&c.arguments(u),this._registerCommand(c),c.parent=this,c.copyInheritedSettings(this),i?this:c}createCommand(e){return new j(e)}createHelp(){return Object.assign(new pt,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(Object.assign(this._outputConfiguration,e),this)}showHelpAfterError(e=!0){return typeof e!="string"&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw new Error(`Command passed to .addCommand() must have a name
|
|
12
|
+
- specify the name in Command constructor or using .name()`);return t=t||{},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new ut(e,t)}argument(e,t,n,i){const o=this.createArgument(e,t);return typeof n=="function"?o.default(i).argParser(n):o.default(n),this.addArgument(o),this}arguments(e){return e.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(e){const t=this.registeredArguments.slice(-1)[0];if(t&&t.variadic)throw new Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e=="boolean")return this._addImplicitHelpCommand=e,this;e=e??"help [command]";const[,n,i]=e.match(/([^ ]+) *(.*)/),o=t??"display help for command",a=this.createCommand(n);return a.helpOption(!1),i&&a.arguments(i),o&&a.description(o),this._addImplicitHelpCommand=!0,this._helpCommand=a,this}addHelpCommand(e,t){return typeof e!="object"?(this.helpCommand(e,t),this):(this._addImplicitHelpCommand=!0,this._helpCommand=e,this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){const n=["preSubcommand","preAction","postAction"];if(!n.includes(e))throw new Error(`Unexpected value for event passed to hook : '${e}'.
|
|
13
|
+
Expecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync")throw t},this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new z(e,t,n)),O.exit(e)}action(e){const t=l(n=>{const i=this.registeredArguments.length,o=n.slice(0,i);return this._storeOptionsAsProperties?o[i]=this:o[i]=this.opts(),o.push(this),e.apply(this,o)},"listener");return this._actionHandler=t,this}createOption(e,t){return new ge(e,t)}_callParseArg(e,t,n,i){try{return e.parseArg(t,n)}catch(o){if(o.code==="commander.invalidArgument"){const a=`${i} ${o.message}`;this.error(a,{exitCode:o.exitCode,code:o.code})}throw o}}_registerOption(e){const t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){const n=e.long&&this._findOption(e.long)?e.long:e.short;throw new Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
|
|
14
|
+
- already used by option '${t.flags}'`)}this.options.push(e)}_registerCommand(e){const t=l(i=>[i.name()].concat(i.aliases()),"knownBy"),n=t(e).find(i=>this._findCommand(i));if(n){const i=t(this._findCommand(n)).join("|"),o=t(e).join("|");throw new Error(`cannot add command '${o}' as already have command '${i}'`)}this.commands.push(e)}addOption(e){this._registerOption(e);const t=e.name(),n=e.attributeName();if(e.negate){const o=e.long.replace(/^--no-/,"--");this._findOption(o)||this.setOptionValueWithSource(n,e.defaultValue===void 0?!0:e.defaultValue,"default")}else e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,"default");const i=l((o,a,u)=>{o==null&&e.presetArg!==void 0&&(o=e.presetArg);const c=this.getOptionValue(n);o!==null&&e.parseArg?o=this._callParseArg(e,o,c,a):o!==null&&e.variadic&&(o=e._concatValue(o,c)),o==null&&(e.negate?o=!1:e.isBoolean()||e.optional?o=!0:o=""),this.setOptionValueWithSource(n,o,u)},"handleOptionValue");return this.on("option:"+t,o=>{const a=`error: option '${e.flags}' argument '${o}' is invalid.`;i(o,a,"cli")}),e.envVar&&this.on("optionEnv:"+t,o=>{const a=`error: option '${e.flags}' value '${o}' from env '${e.envVar}' is invalid.`;i(o,a,"env")}),this}_optionEx(e,t,n,i,o){if(typeof t=="object"&&t instanceof ge)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const a=this.createOption(t,n);if(a.makeOptionMandatory(!!e.mandatory),typeof i=="function")a.default(o).argParser(i);else if(i instanceof RegExp){const u=i;i=l((c,h)=>{const s=u.exec(c);return s?s[0]:h},"fn"),a.default(o).argParser(i)}else a.default(i);return this.addOption(a)}option(e,t,n,i){return this._optionEx({},e,t,n,i)}requiredOption(e,t,n,i){return this._optionEx({mandatory:!0},e,t,n,i)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,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(e=!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=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw new Error("first parameter to parse must be array or undefined");t=t||{},e===void 0&&(e=O.argv,O.versions&&O.versions.electron&&(t.from="electron")),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case"node":this._scriptPath=e[1],n=e.slice(2);break;case"electron":O.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case"user":n=e.slice(0);break;default:throw new Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",n}parse(e,t){const n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){const n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_executeSubCommand(e,t){t=t.slice();let n=!1;const i=[".js",".ts",".tsx",".mjs",".cjs"];function o(s,p){const f=v.resolve(s,p);if(K.existsSync(f))return f;if(i.includes(v.extname(p)))return;const y=i.find(m=>K.existsSync(`${f}${m}`));if(y)return`${f}${y}`}l(o,"findFile"),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let a=e._executableFile||`${this._name}-${e._name}`,u=this._executableDir||"";if(this._scriptPath){let s;try{s=K.realpathSync(this._scriptPath)}catch{s=this._scriptPath}u=v.resolve(v.dirname(s),u)}if(u){let s=o(u,a);if(!s&&!e._executableFile&&this._scriptPath){const p=v.basename(this._scriptPath,v.extname(this._scriptPath));p!==this._name&&(s=o(u,`${p}-${e._name}`))}a=s||a}n=i.includes(v.extname(a));let c;O.platform!=="win32"?n?(t.unshift(a),t=ye(O.execArgv).concat(t),c=B.spawn(O.argv[0],t,{stdio:"inherit"})):c=B.spawn(a,t,{stdio:"inherit"}):(t.unshift(a),t=ye(O.execArgv).concat(t),c=B.spawn(O.execPath,t,{stdio:"inherit"})),c.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(p=>{O.on(p,()=>{c.killed===!1&&c.exitCode===null&&c.kill(p)})});const h=this._exitCallback;c.on("close",(s,p)=>{s=s??1,h?h(new z(s,"commander.executeSubCommandAsync","(close)")):O.exit(s)}),c.on("error",s=>{if(s.code==="ENOENT"){const p=u?`searched for local subcommand relative to directory '${u}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",f=`'${a}' does not exist
|
|
15
15
|
- if '${e._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
16
16
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
17
|
-
- ${
|
|
17
|
+
- ${p}`;throw new Error(f)}else if(s.code==="EACCES")throw new Error(`'${a}' not executable`);if(!h)O.exit(1);else{const p=new z(1,"commander.executeSubCommandAsync","(error)");p.nestedError=s,h(p)}}),this.runningCommand=c}_dispatchSubcommand(e,t,n){const i=this._findCommand(e);i||this.help({error:!0});let o;return o=this._chainOrCallSubCommandHook(o,i,"preSubcommand"),o=this._chainOrCall(o,()=>{if(i._executableHandler)this._executeSubCommand(i,t.concat(n));else return i._parseCommand(t,n)}),o}_dispatchHelpCommand(e){e||this.help();const t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){const e=l((n,i,o)=>{let a=i;if(i!==null&&n.parseArg){const u=`error: command-argument value '${i}' is invalid for argument '${n.name()}'.`;a=this._callParseArg(n,i,o,u)}return a},"myParseArg");this._checkNumberOfArguments();const t=[];this.registeredArguments.forEach((n,i)=>{let o=n.defaultValue;n.variadic?i<this.args.length?(o=this.args.slice(i),n.parseArg&&(o=o.reduce((a,u)=>e(n,u,a),n.defaultValue))):o===void 0&&(o=[]):i<this.args.length&&(o=this.args[i],n.parseArg&&(o=e(n,o,n.defaultValue))),t[i]=o}),this.processedArgs=t}_chainOrCall(e,t){return e&&e.then&&typeof e.then=="function"?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e;const i=[];return this._getCommandAndAncestors().reverse().filter(o=>o._lifeCycleHooks[t]!==void 0).forEach(o=>{o._lifeCycleHooks[t].forEach(a=>{i.push({hookedCommand:o,callback:a})})}),t==="postAction"&&i.reverse(),i.forEach(o=>{n=this._chainOrCall(n,()=>o.callback(o.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let i=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(o=>{i=this._chainOrCall(i,()=>o(this,t))}),i}_parseCommand(e,t){const n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const i=l(()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},"checkForUnknownOptions"),o=`command:${this.name()}`;if(this._actionHandler){i(),this._processArguments();let a;return a=this._chainOrCallHooks(a,"preAction"),a=this._chainOrCall(a,()=>this._actionHandler(this.processedArgs)),this.parent&&(a=this._chainOrCall(a,()=>{this.parent.emit(o,e,t)})),a=this._chainOrCallHooks(a,"postAction"),a}if(this.parent&&this.parent.listenerCount(o))i(),this._processArguments(),this.parent.emit(o,e,t);else if(e.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",e,t);this.listenerCount("command:*")?this.emit("command:*",e,t):this.commands.length?this.unknownCommand():(i(),this._processArguments())}else this.commands.length?(i(),this.help({error:!0})):(i(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){const e=this.options.filter(n=>{const i=n.attributeName();return this.getOptionValue(i)===void 0?!1:this.getOptionValueSource(i)!=="default"});e.filter(n=>n.conflictsWith.length>0).forEach(n=>{const i=e.find(o=>n.conflictsWith.includes(o.attributeName()));i&&this._conflictingOption(n,i)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){const t=[],n=[];let i=t;const o=e.slice();function a(c){return c.length>1&&c[0]==="-"}l(a,"maybeOption");let u=null;for(;o.length;){const c=o.shift();if(c==="--"){i===n&&i.push(c),i.push(...o);break}if(u&&!a(c)){this.emit(`option:${u.name()}`,c);continue}if(u=null,a(c)){const h=this._findOption(c);if(h){if(h.required){const s=o.shift();s===void 0&&this.optionMissingArgument(h),this.emit(`option:${h.name()}`,s)}else if(h.optional){let s=null;o.length>0&&!a(o[0])&&(s=o.shift()),this.emit(`option:${h.name()}`,s)}else this.emit(`option:${h.name()}`);u=h.variadic?h:null;continue}}if(c.length>2&&c[0]==="-"&&c[1]!=="-"){const h=this._findOption(`-${c[1]}`);if(h){h.required||h.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${h.name()}`,c.slice(2)):(this.emit(`option:${h.name()}`),o.unshift(`-${c.slice(2)}`));continue}}if(/^--[^=]+=/.test(c)){const h=c.indexOf("="),s=this._findOption(c.slice(0,h));if(s&&(s.required||s.optional)){this.emit(`option:${s.name()}`,c.slice(h+1));continue}}if(a(c)&&(i=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(c)){t.push(c),o.length>0&&n.push(...o);break}else if(this._getHelpCommand()&&c===this._getHelpCommand().name()){t.push(c),o.length>0&&t.push(...o);break}else if(this._defaultCommandName){n.push(c),o.length>0&&n.push(...o);break}}if(this._passThroughOptions){i.push(c),o.length>0&&i.push(...o);break}i.push(c)}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){const e={},t=this.options.length;for(let n=0;n<t;n++){const i=this.options[n].attributeName();e[i]=i===this._versionOptionName?this._version:this[i]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
|
|
18
18
|
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
19
19
|
`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
20
|
-
`),this.outputHelp({error:!0}));const n=t||{},i=n.exitCode||1,o=n.code||"commander.error";this._exit(i,o,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in O.env){const t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,O.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){const e=new
|
|
21
|
-
`),this._exit(0,"commander.version",e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw new Error("Command alias can't be the same as its name");const n=this.parent?._findCommand(e);if(n){const i=[n.name()].concat(n.aliases()).join("|");throw new Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${i}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(t=>this.alias(t)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;const t=this.registeredArguments.map(n=>
|
|
20
|
+
`),this.outputHelp({error:!0}));const n=t||{},i=n.exitCode||1,o=n.code||"commander.error";this._exit(i,o,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in O.env){const t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,O.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){const e=new ft(this.options),t=l(n=>this.getOptionValue(n)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(n)),"hasCustomOptionValue");this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(n=>{Object.keys(n.implied).filter(i=>!t(i)).forEach(i=>{this.setOptionValueWithSource(i,n.implied[i],"implied")})})}missingArgument(e){const t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){const t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){const t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){const n=l(a=>{const u=a.attributeName(),c=this.getOptionValue(u),h=this.options.find(p=>p.negate&&u===p.attributeName()),s=this.options.find(p=>!p.negate&&u===p.attributeName());return h&&(h.presetArg===void 0&&c===!1||h.presetArg!==void 0&&c===h.presetArg)?h:s||a},"findBestOptionFromValue"),i=l(a=>{const u=n(a),c=u.attributeName();return this.getOptionValueSource(c)==="env"?`environment variable '${u.envVar}'`:`option '${u.flags}'`},"getErrorMessage"),o=`error: ${i(e)} cannot be used with ${i(t)}`;this.error(o,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let i=[],o=this;do{const a=o.createHelp().visibleOptions(o).filter(u=>u.long).map(u=>u.long);i=i.concat(a),o=o.parent}while(o&&!o._enablePositionalOptions);t=_e(e,i)}const n=`error: unknown option '${e}'${t}`;this.error(n,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;const t=this.registeredArguments.length,n=t===1?"":"s",o=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${t} argument${n} but got ${e.length}.`;this.error(o,{code:"commander.excessArguments"})}unknownCommand(){const e=this.args[0];let t="";if(this._showSuggestionAfterError){const i=[];this.createHelp().visibleCommands(this).forEach(o=>{i.push(o.name()),o.alias()&&i.push(o.alias())}),t=_e(e,i)}const n=`error: unknown command '${e}'${t}`;this.error(n,{code:"commander.unknownCommand"})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",n=n||"output the version number";const i=this.createOption(t,n);return this._versionOptionName=i.attributeName(),this._registerOption(i),this.on("option:"+i.name(),()=>{this._outputConfiguration.writeOut(`${e}
|
|
21
|
+
`),this._exit(0,"commander.version",e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw new Error("Command alias can't be the same as its name");const n=this.parent?._findCommand(e);if(n){const i=[n.name()].concat(n.aliases()).join("|");throw new Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${i}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(t=>this.alias(t)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;const t=this.registeredArguments.map(n=>ht(n));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}nameFromFilename(e){return this._name=v.basename(e,v.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){const t=this.createHelp();return t.helpWidth===void 0&&(t.helpWidth=e&&e.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth()),t.formatHelp(this,t)}_getHelpContext(e){e=e||{};const t={error:!!e.error};let n;return t.error?n=l(i=>this._outputConfiguration.writeErr(i),"write"):n=l(i=>this._outputConfiguration.writeOut(i),"write"),t.write=e.write||n,t.command=this,t}outputHelp(e){let t;typeof e=="function"&&(t=e,e=void 0);const n=this._getHelpContext(e);this._getCommandAndAncestors().reverse().forEach(o=>o.emit("beforeAllHelp",n)),this.emit("beforeHelp",n);let i=this.helpInformation(n);if(t&&(i=t(i),typeof i!="string"&&!Buffer.isBuffer(i)))throw new Error("outputHelp callback must return a string or a Buffer");n.write(i),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",n),this._getCommandAndAncestors().forEach(o=>o.emit("afterAllHelp",n))}helpOption(e,t){return typeof e=="boolean"?(e?this._helpOption=this._helpOption??void 0:this._helpOption=null,this):(e=e??"-h, --help",t=t??"display help for command",this._helpOption=this.createOption(e,t),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this}help(e){this.outputHelp(e);let t=O.exitCode||0;t===0&&e&&typeof e!="function"&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){const n=["beforeAll","before","after","afterAll"];if(!n.includes(e))throw new Error(`Unexpected value for position to addHelpText.
|
|
22
22
|
Expecting one of '${n.join("', '")}'`);const i=`${e}Help`;return this.on(i,o=>{let a;typeof t=="function"?a=t({error:o.error,command:o.command}):a=t,a&&o.write(`${a}
|
|
23
|
-
`)}),this}_outputHelpIfRequested(e){const t=this._getHelpOption();t&&e.find(i=>t.is(i))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}},l(T,"Command"),T);function he(r){return r.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",i="9229",o;return(o=e.match(/^(--inspect(-brk)?)$/))!==null?t=o[1]:(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=o[1],/^\d+$/.test(o[3])?i=o[3]:n=o[3]):(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=o[1],n=o[3],i=o[4]),t&&i!=="0"?`${t}=${n}:${parseInt(i)+1}`:e})}l(he,"incrementNodeInspectorPort"),se.Command=it;const{Argument:pe}=D,{Command:B}=se,{CommanderError:rt,InvalidArgumentError:fe}=k,{Help:ot}=M,{Option:de}=q;C.program=new B,C.createCommand=r=>new B(r),C.createOption=(r,e)=>new de(r,e),C.createArgument=(r,e)=>new pe(r,e),C.Command=B,C.Option=de,C.Argument=pe,C.Help=ot,C.CommanderError=rt,C.InvalidArgumentError=fe,C.InvalidOptionArgumentError=fe;const{program:Hn,createCommand:Nn,createArgument:In,createOption:Vn,CommanderError:Fn,InvalidArgumentError:Dn,InvalidOptionArgumentError:Ln,Command:st,Argument:qn,Option:Un,Help:Mn}=C,at=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,ct=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,lt=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function ut(r,e){if(r==="__proto__"||r==="constructor"&&e&&typeof e=="object"&&"prototype"in e){ht(r);return}return e}l(ut,"jsonParseTransform");function ht(r){console.warn(`[destr] Dropping "${r}" key to prevent prototype pollution.`)}l(ht,"warnKeyDropped");function pt(r,e={}){if(typeof r!="string")return r;const t=r.trim();if(r[0]==='"'&&r.endsWith('"')&&!r.includes("\\"))return t.slice(1,-1);if(t.length<=9){const n=t.toLowerCase();if(n==="true")return!0;if(n==="false")return!1;if(n==="undefined")return;if(n==="null")return null;if(n==="nan")return Number.NaN;if(n==="infinity")return Number.POSITIVE_INFINITY;if(n==="-infinity")return Number.NEGATIVE_INFINITY}if(!lt.test(r)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return r}try{if(at.test(r)||ct.test(r)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(r,ut)}return JSON.parse(r)}catch(n){if(e.strict)throw n;return r}}l(pt,"destr");const ft=/#/g,dt=/&/g,mt=/\//g,gt=/=/g,K=/\+/g,_t=/%5e/gi,yt=/%60/gi,Ot=/%7c/gi,bt=/%20/gi;function wt(r){return encodeURI(""+r).replace(Ot,"|")}l(wt,"encode");function z(r){return wt(typeof r=="string"?r:JSON.stringify(r)).replace(K,"%2B").replace(bt,"+").replace(ft,"%23").replace(dt,"%26").replace(yt,"`").replace(_t,"^").replace(mt,"%2F")}l(z,"encodeQueryValue");function Q(r){return z(r).replace(gt,"%3D")}l(Q,"encodeQueryKey");function me(r=""){try{return decodeURIComponent(""+r)}catch{return""+r}}l(me,"decode");function Ct(r){return me(r.replace(K," "))}l(Ct,"decodeQueryKey");function At(r){return me(r.replace(K," "))}l(At,"decodeQueryValue");function Et(r=""){const e={};r[0]==="?"&&(r=r.slice(1));for(const t of r.split("&")){const n=t.match(/([^=]+)=?(.*)/)||[];if(n.length<2)continue;const i=Ct(n[1]);if(i==="__proto__"||i==="constructor")continue;const o=At(n[2]||"");e[i]===void 0?e[i]=o:Array.isArray(e[i])?e[i].push(o):e[i]=[e[i],o]}return e}l(Et,"parseQuery");function $t(r,e){return(typeof e=="number"||typeof e=="boolean")&&(e=String(e)),e?Array.isArray(e)?e.map(t=>`${Q(r)}=${z(t)}`).join("&"):`${Q(r)}=${z(e)}`:Q(r)}l($t,"encodeQueryItem");function vt(r){return Object.keys(r).filter(e=>r[e]!==void 0).map(e=>$t(e,r[e])).filter(Boolean).join("&")}l(vt,"stringifyQuery");const St=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,Tt=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,Rt=/^([/\\]\s*){2,}[^/\\]/,Pt=/^\.?\//;function ge(r,e={}){return typeof e=="boolean"&&(e={acceptRelative:e}),e.strict?St.test(r):Tt.test(r)||(e.acceptRelative?Rt.test(r):!1)}l(ge,"hasProtocol");function kt(r="",e){return r.endsWith("/")}l(kt,"hasTrailingSlash");function jt(r="",e){return(kt(r)?r.slice(0,-1):r)||"/"}l(jt,"withoutTrailingSlash");function xt(r="",e){return r.endsWith("/")?r:r+"/"}l(xt,"withTrailingSlash");function Ht(r,e){if(It(e)||ge(r))return r;const t=jt(e);return r.startsWith(t)?r:Ft(t,r)}l(Ht,"withBase");function Nt(r,e){const t=Dt(r),n={...Et(t.search),...e};return t.search=vt(n),Lt(t)}l(Nt,"withQuery");function It(r){return!r||r==="/"}l(It,"isEmptyURL");function Vt(r){return r&&r!=="/"}l(Vt,"isNonEmptyURL");function Ft(r,...e){let t=r||"";for(const n of e.filter(i=>Vt(i)))if(t){const i=n.replace(Pt,"");t=xt(t)+i}else t=n;return t}l(Ft,"joinURL");const _e=Symbol.for("ufo:protocolRelative");function Dt(r="",e){const t=r.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(t){const[,h,f=""]=t;return{protocol:h.toLowerCase(),pathname:f,href:h+f,auth:"",host:"",search:"",hash:""}}if(!ge(r,{acceptRelative:!0}))return ye(r);const[,n="",i,o=""]=r.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[];let[,a="",c=""]=o.match(/([^#/?]*)(.*)?/)||[];n==="file:"&&(c=c.replace(/\/(?=[A-Za-z]:)/,""));const{pathname:u,search:p,hash:s}=ye(c);return{protocol:n.toLowerCase(),auth:i?i.slice(0,Math.max(0,i.length-1)):"",host:a,pathname:u,search:p,hash:s,[_e]:!n}}l(Dt,"parseURL");function ye(r=""){const[e="",t="",n=""]=(r.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:e,search:t,hash:n}}l(ye,"parsePath");function Lt(r){const e=r.pathname||"",t=r.search?(r.search.startsWith("?")?"":"?")+r.search:"",n=r.hash||"",i=r.auth?r.auth+"@":"",o=r.host||"";return(r.protocol||r[_e]?(r.protocol||"")+"//":"")+i+o+e+t+n}l(Lt,"stringifyParsedURL");const ne=class ne extends Error{constructor(e,t){super(e,t),this.name="FetchError",t?.cause&&!this.cause&&(this.cause=t.cause)}};l(ne,"FetchError");let Y=ne;function qt(r){const e=r.error?.message||r.error?.toString()||"",t=r.request?.method||r.options?.method||"GET",n=r.request?.url||String(r.request)||"/",i=`[${t}] ${JSON.stringify(n)}`,o=r.response?`${r.response.status} ${r.response.statusText}`:"<no response>",a=`${i}: ${o}${e?` ${e}`:""}`,c=new Y(a,r.error?{cause:r.error}:void 0);for(const u of["request","options","response"])Object.defineProperty(c,u,{get(){return r[u]}});for(const[u,p]of[["data","_data"],["status","status"],["statusCode","status"],["statusText","statusText"],["statusMessage","statusText"]])Object.defineProperty(c,u,{get(){return r.response&&r.response[p]}});return c}l(qt,"createFetchError");const Ut=new Set(Object.freeze(["PATCH","POST","PUT","DELETE"]));function Oe(r="GET"){return Ut.has(r.toUpperCase())}l(Oe,"isPayloadMethod");function Mt(r){if(r===void 0)return!1;const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(r)?!0:r.buffer?!1:r.constructor&&r.constructor.name==="Object"||typeof r.toJSON=="function"}l(Mt,"isJSONSerializable");const Wt=new Set(["image/svg","application/xml","application/xhtml","application/html"]),Gt=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function Jt(r=""){if(!r)return"json";const e=r.split(";").shift()||"";return Gt.test(e)?"json":Wt.has(e)||e.startsWith("text/")?"text":"blob"}l(Jt,"detectResponseType");function Bt(r,e,t=globalThis.Headers){const n={...e,...r};if(e?.params&&r?.params&&(n.params={...e?.params,...r?.params}),e?.query&&r?.query&&(n.query={...e?.query,...r?.query}),e?.headers&&r?.headers){n.headers=new t(e?.headers||{});for(const[i,o]of new t(r?.headers||{}))n.headers.set(i,o)}return n}l(Bt,"mergeFetchOptions");const Kt=new Set([408,409,425,429,500,502,503,504]),zt=new Set([101,204,205,304]);function be(r={}){const{fetch:e=globalThis.fetch,Headers:t=globalThis.Headers,AbortController:n=globalThis.AbortController}=r;async function i(c){const u=c.error&&c.error.name==="AbortError"&&!c.options.timeout||!1;if(c.options.retry!==!1&&!u){let s;typeof c.options.retry=="number"?s=c.options.retry:s=Oe(c.options.method)?0:1;const h=c.response&&c.response.status||500;if(s>0&&(Array.isArray(c.options.retryStatusCodes)?c.options.retryStatusCodes.includes(h):Kt.has(h))){const f=c.options.retryDelay||0;return f>0&&await new Promise(m=>setTimeout(m,f)),o(c.request,{...c.options,retry:s-1})}}const p=qt(c);throw Error.captureStackTrace&&Error.captureStackTrace(p,o),p}l(i,"onError");const o=l(async function(u,p={}){const s={request:u,options:Bt(p,r.defaults,t),response:void 0,error:void 0};s.options.method=s.options.method?.toUpperCase(),s.options.onRequest&&await s.options.onRequest(s),typeof s.request=="string"&&(s.options.baseURL&&(s.request=Ht(s.request,s.options.baseURL)),(s.options.query||s.options.params)&&(s.request=Nt(s.request,{...s.options.params,...s.options.query}))),s.options.body&&Oe(s.options.method)&&(Mt(s.options.body)?(s.options.body=typeof s.options.body=="string"?s.options.body:JSON.stringify(s.options.body),s.options.headers=new t(s.options.headers||{}),s.options.headers.has("content-type")||s.options.headers.set("content-type","application/json"),s.options.headers.has("accept")||s.options.headers.set("accept","application/json")):("pipeTo"in s.options.body&&typeof s.options.body.pipeTo=="function"||typeof s.options.body.pipe=="function")&&("duplex"in s.options||(s.options.duplex="half")));let h;if(!s.options.signal&&s.options.timeout){const m=new n;h=setTimeout(()=>m.abort(),s.options.timeout),s.options.signal=m.signal}try{s.response=await e(s.request,s.options)}catch(m){return s.error=m,s.options.onRequestError&&await s.options.onRequestError(s),await i(s)}finally{h&&clearTimeout(h)}if(s.response.body&&!zt.has(s.response.status)&&s.options.method!=="HEAD"){const m=(s.options.parseResponse?"json":s.options.responseType)||Jt(s.response.headers.get("content-type")||"");switch(m){case"json":{const g=await s.response.text(),b=s.options.parseResponse||pt;s.response._data=b(g);break}case"stream":{s.response._data=s.response.body;break}default:s.response._data=await s.response[m]()}}return s.options.onResponse&&await s.options.onResponse(s),!s.options.ignoreResponseError&&s.response.status>=400&&s.response.status<600?(s.options.onResponseError&&await s.options.onResponseError(s),await i(s)):s.response},"$fetchRaw2"),a=l(async function(u,p){return(await o(u,p))._data},"$fetch2");return a.raw=o,a.native=(...c)=>e(...c),a.create=(c={})=>be({...r,defaults:{...r.defaults,...c}}),a}l(be,"createFetch");const Z=function(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global;throw new Error("unable to locate global object")}(),Qt=Z.fetch||(()=>Promise.reject(new Error("[ofetch] global.fetch is not supported!"))),Yt=Z.Headers,Zt=Z.AbortController,U=be({fetch:Qt,Headers:Yt,AbortController:Zt}),Xt={apiRoot:process.env.FRONTSTACK_CLI_API_ROOT||(process.env.FRONTSTACK_CLI_DEV_MODE=="1"?"https://backend.frontstack.test/":"https://backend.frontstack.dev/")},L=Xt.apiRoot,en=`${L}login`,tn=`${L}api/fetch-api/spec.yaml`,we=3008,Ce=`http://localhost:${we}`,Ae=`${en}?redirectUrl=${Ce}/callback`,nn=".frontstack-local/",v=_.join(process.cwd(),nn),X="api_session.jwt",Ee="project.json",j=l(()=>{const r=l(()=>{console.info("Not auth.login implemented yet")},"login"),e=l(async()=>{try{return a(),0}catch(h){console.log(h)}},"logout"),t=l(async(h=!1)=>{try{return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await U(`${L}profile`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i()}`}})}catch(f){return h&&console.log(f),1}},"getProfile"),n=l(async h=>{try{if(h==null)throw new Error(`You have no project selected
|
|
24
|
-
Run ${d.hex("#7c3bed")("frontstack project")} to select a frontstack project`);return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await
|
|
25
|
-
`+
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
`)}),this}_outputHelpIfRequested(e){const t=this._getHelpOption();t&&e.find(i=>t.is(i))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}},l(j,"Command"),j);function ye(r){return r.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",i="9229",o;return(o=e.match(/^(--inspect(-brk)?)$/))!==null?t=o[1]:(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=o[1],/^\d+$/.test(o[3])?i=o[3]:n=o[3]):(o=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=o[1],n=o[3],i=o[4]),t&&i!=="0"?`${t}=${n}:${parseInt(i)+1}`:e})}l(ye,"incrementNodeInspectorPort"),fe.Command=dt;const{Argument:Oe}=D,{Command:Q}=fe,{CommanderError:mt,InvalidArgumentError:be}=P,{Help:gt}=J,{Option:we}=U;A.program=new Q,A.createCommand=r=>new Q(r),A.createOption=(r,e)=>new we(r,e),A.createArgument=(r,e)=>new Oe(r,e),A.Command=Q,A.Option=we,A.Argument=Oe,A.Help=gt,A.CommanderError=mt,A.InvalidArgumentError=be,A.InvalidOptionArgumentError=be;const{program:Gn,createCommand:Jn,createArgument:Bn,createOption:Kn,CommanderError:zn,InvalidArgumentError:Qn,InvalidOptionArgumentError:Yn,Command:_t,Argument:Zn,Option:Xn,Help:ei}=A,yt=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,Ot=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,bt=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function wt(r,e){if(r==="__proto__"||r==="constructor"&&e&&typeof e=="object"&&"prototype"in e){At(r);return}return e}l(wt,"jsonParseTransform");function At(r){console.warn(`[destr] Dropping "${r}" key to prevent prototype pollution.`)}l(At,"warnKeyDropped");function Ct(r,e={}){if(typeof r!="string")return r;const t=r.trim();if(r[0]==='"'&&r.endsWith('"')&&!r.includes("\\"))return t.slice(1,-1);if(t.length<=9){const n=t.toLowerCase();if(n==="true")return!0;if(n==="false")return!1;if(n==="undefined")return;if(n==="null")return null;if(n==="nan")return Number.NaN;if(n==="infinity")return Number.POSITIVE_INFINITY;if(n==="-infinity")return Number.NEGATIVE_INFINITY}if(!bt.test(r)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return r}try{if(yt.test(r)||Ot.test(r)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(r,wt)}return JSON.parse(r)}catch(n){if(e.strict)throw n;return r}}l(Ct,"destr");const $t=/#/g,Et=/&/g,vt=/\//g,St=/=/g,Y=/\+/g,Tt=/%5e/gi,jt=/%60/gi,xt=/%7c/gi,Pt=/%20/gi;function kt(r){return encodeURI(""+r).replace(xt,"|")}l(kt,"encode");function Z(r){return kt(typeof r=="string"?r:JSON.stringify(r)).replace(Y,"%2B").replace(Pt,"+").replace($t,"%23").replace(Et,"%26").replace(jt,"`").replace(Tt,"^").replace(vt,"%2F")}l(Z,"encodeQueryValue");function X(r){return Z(r).replace(St,"%3D")}l(X,"encodeQueryKey");function Ae(r=""){try{return decodeURIComponent(""+r)}catch{return""+r}}l(Ae,"decode");function Rt(r){return Ae(r.replace(Y," "))}l(Rt,"decodeQueryKey");function Ht(r){return Ae(r.replace(Y," "))}l(Ht,"decodeQueryValue");function Nt(r=""){const e={};r[0]==="?"&&(r=r.slice(1));for(const t of r.split("&")){const n=t.match(/([^=]+)=?(.*)/)||[];if(n.length<2)continue;const i=Rt(n[1]);if(i==="__proto__"||i==="constructor")continue;const o=Ht(n[2]||"");e[i]===void 0?e[i]=o:Array.isArray(e[i])?e[i].push(o):e[i]=[e[i],o]}return e}l(Nt,"parseQuery");function Ft(r,e){return(typeof e=="number"||typeof e=="boolean")&&(e=String(e)),e?Array.isArray(e)?e.map(t=>`${X(r)}=${Z(t)}`).join("&"):`${X(r)}=${Z(e)}`:X(r)}l(Ft,"encodeQueryItem");function It(r){return Object.keys(r).filter(e=>r[e]!==void 0).map(e=>Ft(e,r[e])).filter(Boolean).join("&")}l(It,"stringifyQuery");const Vt=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,Dt=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,Lt=/^([/\\]\s*){2,}[^/\\]/,qt=/^\.?\//;function Ce(r,e={}){return typeof e=="boolean"&&(e={acceptRelative:e}),e.strict?Vt.test(r):Dt.test(r)||(e.acceptRelative?Lt.test(r):!1)}l(Ce,"hasProtocol");function Mt(r="",e){return r.endsWith("/")}l(Mt,"hasTrailingSlash");function Ut(r="",e){return(Mt(r)?r.slice(0,-1):r)||"/"}l(Ut,"withoutTrailingSlash");function Wt(r="",e){return r.endsWith("/")?r:r+"/"}l(Wt,"withTrailingSlash");function Gt(r,e){if(Bt(e)||Ce(r))return r;const t=Ut(e);return r.startsWith(t)?r:zt(t,r)}l(Gt,"withBase");function Jt(r,e){const t=Qt(r),n={...Nt(t.search),...e};return t.search=It(n),Yt(t)}l(Jt,"withQuery");function Bt(r){return!r||r==="/"}l(Bt,"isEmptyURL");function Kt(r){return r&&r!=="/"}l(Kt,"isNonEmptyURL");function zt(r,...e){let t=r||"";for(const n of e.filter(i=>Kt(i)))if(t){const i=n.replace(qt,"");t=Wt(t)+i}else t=n;return t}l(zt,"joinURL");const $e=Symbol.for("ufo:protocolRelative");function Qt(r="",e){const t=r.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(t){const[,p,f=""]=t;return{protocol:p.toLowerCase(),pathname:f,href:p+f,auth:"",host:"",search:"",hash:""}}if(!Ce(r,{acceptRelative:!0}))return Ee(r);const[,n="",i,o=""]=r.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[];let[,a="",u=""]=o.match(/([^#/?]*)(.*)?/)||[];n==="file:"&&(u=u.replace(/\/(?=[A-Za-z]:)/,""));const{pathname:c,search:h,hash:s}=Ee(u);return{protocol:n.toLowerCase(),auth:i?i.slice(0,Math.max(0,i.length-1)):"",host:a,pathname:c,search:h,hash:s,[$e]:!n}}l(Qt,"parseURL");function Ee(r=""){const[e="",t="",n=""]=(r.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:e,search:t,hash:n}}l(Ee,"parsePath");function Yt(r){const e=r.pathname||"",t=r.search?(r.search.startsWith("?")?"":"?")+r.search:"",n=r.hash||"",i=r.auth?r.auth+"@":"",o=r.host||"";return(r.protocol||r[$e]?(r.protocol||"")+"//":"")+i+o+e+t+n}l(Yt,"stringifyParsedURL");const oe=class oe extends Error{constructor(e,t){super(e,t),this.name="FetchError",t?.cause&&!this.cause&&(this.cause=t.cause)}};l(oe,"FetchError");let ee=oe;function Zt(r){const e=r.error?.message||r.error?.toString()||"",t=r.request?.method||r.options?.method||"GET",n=r.request?.url||String(r.request)||"/",i=`[${t}] ${JSON.stringify(n)}`,o=r.response?`${r.response.status} ${r.response.statusText}`:"<no response>",a=`${i}: ${o}${e?` ${e}`:""}`,u=new ee(a,r.error?{cause:r.error}:void 0);for(const c of["request","options","response"])Object.defineProperty(u,c,{get(){return r[c]}});for(const[c,h]of[["data","_data"],["status","status"],["statusCode","status"],["statusText","statusText"],["statusMessage","statusText"]])Object.defineProperty(u,c,{get(){return r.response&&r.response[h]}});return u}l(Zt,"createFetchError");const Xt=new Set(Object.freeze(["PATCH","POST","PUT","DELETE"]));function ve(r="GET"){return Xt.has(r.toUpperCase())}l(ve,"isPayloadMethod");function en(r){if(r===void 0)return!1;const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(r)?!0:r.buffer?!1:r.constructor&&r.constructor.name==="Object"||typeof r.toJSON=="function"}l(en,"isJSONSerializable");const tn=new Set(["image/svg","application/xml","application/xhtml","application/html"]),nn=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function rn(r=""){if(!r)return"json";const e=r.split(";").shift()||"";return nn.test(e)?"json":tn.has(e)||e.startsWith("text/")?"text":"blob"}l(rn,"detectResponseType");function on(r,e,t=globalThis.Headers){const n={...e,...r};if(e?.params&&r?.params&&(n.params={...e?.params,...r?.params}),e?.query&&r?.query&&(n.query={...e?.query,...r?.query}),e?.headers&&r?.headers){n.headers=new t(e?.headers||{});for(const[i,o]of new t(r?.headers||{}))n.headers.set(i,o)}return n}l(on,"mergeFetchOptions");const sn=new Set([408,409,425,429,500,502,503,504]),an=new Set([101,204,205,304]);function Se(r={}){const{fetch:e=globalThis.fetch,Headers:t=globalThis.Headers,AbortController:n=globalThis.AbortController}=r;async function i(u){const c=u.error&&u.error.name==="AbortError"&&!u.options.timeout||!1;if(u.options.retry!==!1&&!c){let s;typeof u.options.retry=="number"?s=u.options.retry:s=ve(u.options.method)?0:1;const p=u.response&&u.response.status||500;if(s>0&&(Array.isArray(u.options.retryStatusCodes)?u.options.retryStatusCodes.includes(p):sn.has(p))){const f=u.options.retryDelay||0;return f>0&&await new Promise(y=>setTimeout(y,f)),o(u.request,{...u.options,retry:s-1})}}const h=Zt(u);throw Error.captureStackTrace&&Error.captureStackTrace(h,o),h}l(i,"onError");const o=l(async function(c,h={}){const s={request:c,options:on(h,r.defaults,t),response:void 0,error:void 0};s.options.method=s.options.method?.toUpperCase(),s.options.onRequest&&await s.options.onRequest(s),typeof s.request=="string"&&(s.options.baseURL&&(s.request=Gt(s.request,s.options.baseURL)),(s.options.query||s.options.params)&&(s.request=Jt(s.request,{...s.options.params,...s.options.query}))),s.options.body&&ve(s.options.method)&&(en(s.options.body)?(s.options.body=typeof s.options.body=="string"?s.options.body:JSON.stringify(s.options.body),s.options.headers=new t(s.options.headers||{}),s.options.headers.has("content-type")||s.options.headers.set("content-type","application/json"),s.options.headers.has("accept")||s.options.headers.set("accept","application/json")):("pipeTo"in s.options.body&&typeof s.options.body.pipeTo=="function"||typeof s.options.body.pipe=="function")&&("duplex"in s.options||(s.options.duplex="half")));let p;if(!s.options.signal&&s.options.timeout){const y=new n;p=setTimeout(()=>y.abort(),s.options.timeout),s.options.signal=y.signal}try{s.response=await e(s.request,s.options)}catch(y){return s.error=y,s.options.onRequestError&&await s.options.onRequestError(s),await i(s)}finally{p&&clearTimeout(p)}if(s.response.body&&!an.has(s.response.status)&&s.options.method!=="HEAD"){const y=(s.options.parseResponse?"json":s.options.responseType)||rn(s.response.headers.get("content-type")||"");switch(y){case"json":{const m=await s.response.text(),b=s.options.parseResponse||Ct;s.response._data=b(m);break}case"stream":{s.response._data=s.response.body;break}default:s.response._data=await s.response[y]()}}return s.options.onResponse&&await s.options.onResponse(s),!s.options.ignoreResponseError&&s.response.status>=400&&s.response.status<600?(s.options.onResponseError&&await s.options.onResponseError(s),await i(s)):s.response},"$fetchRaw2"),a=l(async function(c,h){return(await o(c,h))._data},"$fetch2");return a.raw=o,a.native=(...u)=>e(...u),a.create=(u={})=>Se({...r,defaults:{...r.defaults,...u}}),a}l(Se,"createFetch");const te=function(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global;throw new Error("unable to locate global object")}(),cn=te.fetch||(()=>Promise.reject(new Error("[ofetch] global.fetch is not supported!"))),ln=te.Headers,un=te.AbortController,W=Se({fetch:cn,Headers:ln,AbortController:un}),hn={apiRoot:process.env.FRONTSTACK_CLI_API_ROOT||(process.env.FRONTSTACK_CLI_DEV_MODE=="1"?"https://backend.frontstack.test/":"https://backend.frontstack.dev/")},L=hn.apiRoot,pn=`${L}login`,fn=`${L}api/fetch-api/spec.yaml`,Te=3008,je=`http://localhost:${Te}`,xe=`${pn}?redirectUrl=${je}/callback`,dn=".frontstack-local/",S=g.join(process.cwd(),dn),ne="api_session.jwt",Pe="project.json",k=l(()=>{const r=l(()=>{console.info("Not auth.login implemented yet")},"login"),e=l(async()=>{try{return a(),0}catch(p){console.log(p)}},"logout"),t=l(async(p=!1)=>{try{return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await W(`${L}profile`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i()}`}})}catch(f){return p&&console.log(f),1}},"getProfile"),n=l(async p=>{try{if(p==null)throw new Error(`You have no project selected
|
|
24
|
+
Run ${d.hex("#7c3bed")("frontstack project")} to select a frontstack project`);return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await W(fn,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${i()}`,"FS-Project":p},parseResponse:l(y=>{try{return he.load(y)}catch{throw new Error("Invalid API specification. The API specification must be a valid YAML file.")}},"parseResponse")})}catch(f){throw"data"in f&&"message"in f.data?new Error(`Server error: ${f.data.message}`):f}},"getFetchApiSpec"),i=l(()=>{const p=g.join(S,ne);return _.existsSync(p)?_.readFileSync(p,"utf8"):null},"getToken"),o=l(p=>(_.existsSync(S)||_.mkdirSync(S),_.writeFileSync(g.join(S,ne),p),0),"writeToken"),a=l(()=>{const p=g.join(S,ne);_.existsSync(p)&&_.unlinkSync(p)},"deleteToken"),u=l(async()=>(process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await W(`${L}api/project`,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${i()}`},parseResponse:l(p=>JSON.parse(p),"parseResponse")})),"getProjects"),c=l(()=>{const p=g.join(S,Pe);if(!_.existsSync(p))return null;try{return JSON.parse(_.readFileSync(p,"utf8")).projectId}catch{console.error("[Error] Corrupt project file - please run 'frontstack project'")}},"getProjectId");return{login:r,logout:e,getProfile:t,getFetchApiSpec:n,getToken:i,writeToken:o,deleteToken:a,getProjects:u,getProject:l(async(p=void 0)=>{try{return p===void 0&&(p=c()),p===void 0?void 0:(process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await W(`${L}api/project/${p}`,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${i()}`},parseResponse:l(f=>JSON.parse(f),"parseResponse")}))}catch(f){return{error:f.message}}},"getProject"),getProjectId:c,writeProject:l(p=>(_.existsSync(S)||_.mkdirSync(S),_.writeFileSync(g.join(S,Pe),JSON.stringify({projectId:p})),0),"writeProject")}},"auth"),ke=l(()=>{const r=l(t=>{const n=g.join(t,"metadata.json");if(_.existsSync(n)){const i=_.readFileSync(n,"utf8");return JSON.parse(i)}return null},"getMetadata");return{getMetadata:r,projectGuard:l(t=>{r(t)||(console.log(`${d.hex("#FFA500")("[WARNING]")} No \`.frontstack/metadata.json\` found, run ${d.hex("#7c3bed")("frontstack generate")} to create a metadata file.`),console.log(`${d.hex("#FFA500")("[WARNING]")} Metadata files have been introduced to keep track of your generated code across multiple projects and organizations.`),console.log(`${d.hex("#FFA500")("[WARNING]")} If you only have a single project, you can ignore this message.`))},"projectGuard")}},"useMetadata"),{writeToken:mn}=k(),gn=l(async(r,e,t=!1)=>new Promise(n=>{const i=new Set,o=Je.createServer((a,u)=>{const c=je;if(a.url===void 0)return;const s=new URL(a.url,c).searchParams.get("token");s&&(u.writeHead(200,{"Content-Type":"text/html"}),u.end('<html><head><script>// window.close()<\/script></head><body style="font-family: sans-serif;"><div style="height: 100%; width: 100%; display: flex; justify-content: center; align-items: center;"><div style="text-align: center"><h1 style="color: #7c3bed;">Login Successful</h1><p>You can <a href="#" onClick="window.close()">close</a> this browser window and return to the terminal.<p style="font-size: .8rem; color: #666; text-align: left; margin-top: 20px;">© 2024 frontstack</p></div></div></html>'),u.on("finish",async()=>{for(const f of i)f.destroy();mn(s)!==0?(console.error("Login failed."),o.close(),n(!1)):(console.log(`${d.hex("#008000")("[SUCCESS]")} Login successful`),o.close(),n(!0)),t&&process.exit(0)}))}).listen(r,()=>{console.log(`Please continue login in your browser at ${d.hex("#7c3bed")(e)}`)});o.on("connection",a=>{i.add(a),a.on("close",()=>i.delete(a))}),setTimeout(()=>{o.close(),n(!1)},6e4)}),"login$1"),Re=l(async(r=!0)=>{await Be(xe),await gn(Te,xe,!1);let e=".frontstack";const{projectGuard:t}=ke();t(e),r&&process.exit(0)},"login"),_n=k(),yn=l(async r=>{await _n.logout()!==0&&(console.error("Logout failed."),process.exit(1)),console.log("Logout successful."),process.exit(0)},"logout"),{getFetchApiSpec:On}=k();E.registerHelper("eq",function(r,e){return r===e}),E.registerHelper("uc",function(r){return r.toUpperCase()}),E.registerHelper("and",function(r,e){return r&&e}),E.registerHelper("contains",function(r,e){return r===void 0?!1:r.includes(e)}),E.registerHelper("endsWith",function(r,e){return r===void 0?!1:r.endsWith(e)}),E.registerHelper("blockNameFromOperationId",function(r){return r.replace("get","").replace("Block","")});const ie=l(r=>r.$ref?`components['schemas']['${r.$ref.split("/").pop()}']`:r.type==="array"?`Array<${ie(r.items)}>`:r.type==="object"?`{ ${Object.keys(r.properties).map(t=>`${t}: ${ie(r.properties[t])}`).join("; ")} }`:r.type,"getSchemaType");E.registerHelper("getSchemaType",r=>ie(r)),E.registerHelper("stringInArray",function(r,e,t){return e==null||e.length===0?!1:t.fn?e.indexOf(r)>-1?t.fn(this):t.inverse(this):e.indexOf(r)>-1}),E.registerHelper("log",function(r){console.log(r)});var bn=l(async r=>{const e=g.dirname(new URL(import.meta.url).pathname),t=g.join(e,"src/commands/generate/templates"),n=g.join(t,"types.js.hbs"),i=_.readFileSync(n,"utf8"),o=E.compile(i),a=g.join(t,"client.js.hbs"),u=_.readFileSync(a,"utf8"),c=E.compile(u),h=g.join(t,"query.js.hbs"),s=_.readFileSync(h,"utf8");let p;if(p=await On(r),p.error)throw new Error(`Issue fetching API specification. Check more information below.
|
|
25
|
+
`+p.error);let f="";try{f=await Ke(p)}catch(b){throw new Error(`Invalid API Specification: ${b.message}`)}const y=o({paths:p.paths,components:p.components}),m=c({components:p.components,paths:p.paths,servers:p.servers});return{_schemaTypes:f,_types:y,_client:m,_query:s,_specFile:p}},"generate");const{getProjects:wn,writeProject:He}=k(),Ne=l(async r=>{let e=r.project??void 0,t=[];try{t=await wn()}catch{console.log(`You are not logged in. Please run ${d.hex("#7c3bed")("frontstack login")} to login`);return}if(t.length<1){console.log("No projects found. Please create a new project in your Admin dashboard");return}if(e!==void 0){const o=t.find(a=>a.id===e);if(o){console.log(`Project ${d.hex("#7c3bed")(o.name)} selected`),He(o.id);return}else{console.log(`Project with ID "${e}" not found. Please select a valid project ID`);return}}const n={type:"select",name:"projectId",message:"Pick a project (Use arrow keys and Enter)",choices:t.map(o=>({title:(o.id===e?"(\u2714) ":"")+`${o.name}`,value:o.id}))};async function i(){const o=await M(n),a=t.find(u=>u.id===o.projectId);if(a===void 0){console.log(`Project with ID "${o.projectId}" not found. Please select a valid project ID`);return}console.log(`Project ${d.hex("#7c3bed")(a.name)} selected`),He(o.projectId)}l(i,"getProject"),await i()},"project"),An=l(async r=>{const e=r.verbose||!1,t=r.persistOas||!1,{getProject:n,getProfile:i,getProjects:o,writeProject:a}=k(),u=await i(e);if(!u||u===1){console.info("User not logged in"),await Re(!1);const w=await i();(!w||w===1)&&(console.info(`${d.hex("#b90404")("[ERROR]")} Login failed`),process.exit(1))}let c=r.output||".frontstack",h=await n();(!h||"error"in h)&&(console.info("No project selected"),console.info("Running project selection..."),await Ne({}));const{getMetadata:s}=ke(),p=s(c);if(h=await n(),!h||"error"in h){console.info(`${d.hex("#b90404")("[ERROR]")} frontstack generate`),console.info(`${d.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`);return}if(p&&p.project.id!==h.id){const C=(await o()).find(G=>G.id===p.project.id),$=[];C&&$.push({title:`Switch to project ${d.hex("#7c3bed")(p.project.name)} and generate client`,value:"switch"}),$.push({title:`Overwrite client with project ${d.hex("#7c3bed")(h.name)}`,value:"overwrite"}),$.push({title:"Cancel",value:"cancel"}),console.log(`${d.hex("#FFA500")("[WARNING]")} Client mismatch detected`),console.log(`${d.hex("#FFA500")("[WARNING]")} The client in ${d.hex("#7c3bed")(c)} was generated for project ${d.hex("#7c3bed")(p.project.name)}.`),console.log(`${d.hex("#FFA500")("[WARNING]")} The selected project is ${d.hex("#7c3bed")(h.name)}.
|
|
26
|
+
`);const De={type:"select",name:"action",message:"How would you like to proceed?",choices:$},{action:q}=await M(De);if(q==="cancel"){console.info("Generation cancelled.");return}if(q==="switch"&&C&&(a(C.id),h=C,console.info(`Switched to project ${d.hex("#7c3bed")(h.name)}.`)),q==="overwrite"){const G={type:"text",name:"confirmation",message:'This is a destructive action and will overwrite the existing client. Type "confirm" to proceed.'},{confirmation:Le}=await M(G);if(Le!=="confirm"){console.info("Generation cancelled.");return}console.info(`Proceeding to generate client for project ${d.hex("#7c3bed")(h.name)}.`)}if(!q){console.info("Generation cancelled.");return}}let f=h;if(!h||"error"in h){console.info(`${d.hex("#b90404")("[ERROR]")} frontstack generate`),console.info(`${d.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`);return}if(r.env&&h.environments.length>0){let w;if(r.env!=="develop"){if(w=h.environments.find(C=>C.environment===r.env),!w){console.info(`${d.hex("#b90404")("[ERROR]")} frontstack generate`),console.info(`${d.hex("#b90404")("[ERROR]")} Environment ${r.env} not found`);return}f=w}}if(!r.env&&h.environments.length>0){const w={type:"select",name:"projectId",message:"Pick an environment (use arrow keys and enter)",choices:[{title:`${h.name} (${h.environment})`,value:h.id},...h.environments.map($=>({title:($.id===f?.id?"(\u2714) ":"")+`${$.name} (${$.environment})`,value:$.id}))]},C=await M(w);f=h.environments.find($=>$.id===C.projectId)??h}let y,m,b,x,se;try{e&&console.log("Generating Javascript client"),{_schemaTypes:y,_types:m,_client:b,_query:x,_specFile:se}=await bn(f.id)}catch(w){console.info(`${d.hex("#b90404")("[ERROR]")} frontstack generate`),console.info(`${d.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`),e?console.info(`${d.hex("#b90404")("[ERROR]")} ${w.message}`):(console.info("Are you..."),console.info(` * logged in using the ${d.hex("#7c3bed")("frontstack login")} command?`),console.info(" * connected to the internet?"),console.info(`Alternatively, run ${d.hex("#7c3bed")("frontstack generate -v")} for additional output.`));return}process.stdout.write("Generating Javascript client"),c.startsWith("/")||(c=g.join(process.cwd(),c)),c.endsWith("/")||(c+="/");const ae=g.join(c,"fetch-api.d.ts"),ce=g.join(c,"generated-types.d.ts"),le=g.join(c,"generated-client.ts"),Ie=g.join(c,"query-types.ts"),ue=g.join(c,"metadata.json"),Ve={project:{id:f.id,name:f.name}};if(e&&(console.log(`
|
|
27
|
+
Schema types path: ${d.dim(ae)}`),console.log(`Types path: ${d.dim(ce)}`),console.log(`Client path: ${d.dim(le)}`),console.log(`Target directory: ${d.dim(c)}`),console.log(`Metadata path: ${d.dim(ue)}`)),_.mkdirSync(c,{recursive:!0}),t){const w=he.dump(se,{indent:2}),C=g.join(c,"fetch-api.spec.yaml");console.log(`
|
|
28
|
+
Persisting OpenAPI Specification file in ${C}`),_.writeFileSync(g.join(C),w)}_.writeFileSync(g.join(ae),y),_.writeFileSync(g.join(ce),m),_.writeFileSync(g.join(le),b),_.writeFileSync(g.join(Ie),x),_.writeFileSync(g.join(ue),JSON.stringify(Ve,null,2)),e?console.log(`Javascript client generated for ${d.hex("#7c3bed")(`${f.name} (${f.environment})`)}`):(process.stdout.clearLine(0),process.stdout.cursorTo(0),process.stdout.write(d.green(`Javascript client generated for ${d.hex("#7c3bed")(`${f.name} (${f.environment})`)}
|
|
28
29
|
`))),console.log(`
|
|
29
|
-
Use the following
|
|
30
|
-
`),console.log(" "+d.hex("#7c3bed")("import client from '
|
|
30
|
+
Use the following import in your project:
|
|
31
|
+
`),console.log(" "+d.hex("#7c3bed")("import client from '.frontstack/generated-client';")),console.log(`
|
|
31
32
|
and use the client like this:
|
|
32
33
|
`),console.log(" "+d.hex("#7c3bed")("const productDetail = await client.block('DetailPage', { key: 'my-product-id' });")),console.log(`
|
|
33
|
-
If you make changes to your schema, run ${d.hex("#7c3bed")("frontstack generate")} again to update the client.`),process.exit(0)},"generateCommand"),{getToken:
|
|
34
|
+
If you make changes to your schema, run ${d.hex("#7c3bed")("frontstack generate")} again to update the client.`),process.exit(0)},"generateCommand"),{getToken:Cn,getProfile:$n,getProject:En}=k(),vn=l(async()=>{if(Cn()===null){console.log("Status: Not logged in."),console.log("Run "+d.hex("#7c3bed")("frontstack login")+" to login.");return}try{const e=await $n();if(e===void 0||e===1){console.log("Status: Not logged in."),console.log("Run "+d.hex("#7c3bed")("frontstack login")+" to login.");return}console.log("Logged in as "+d.hex("#7c3bed")(e.email)),console.log(`Organization: ${e.organization.name}`);const t=await En();if(t===void 0||"error"in t){console.log("Status: No project selected."),console.log("Run "+d.hex("#7c3bed")("frontstack project")+" to select a frontstack project");return}console.log(`Current Project: ${t.name??"[No active project selected]"}`)}catch(e){console.log(e)}},"info"),Sn=ze(import.meta.url),Tn=g.dirname(Sn),Fe=We(g.join(Tn,"version"),"utf8");let re="0.0.1-dev";Fe&&(re=Fe.trim());const T=new _t;T.name("frontstack").alias("fst").description(`${d.bgHex("#7c3bed").bold("frontstack CLI")}
|
|
34
35
|
Manage frontstack projects from the command line.
|
|
35
|
-
${d.dim(`Version: ${
|
|
36
|
+
${d.dim(`Version: ${re}`)}`).version(re),T.command("login").description("Login to frontstack account").action(()=>{Re()}),T.command("logout").description("Logout from frontstack account").action(async r=>{await yn()}),T.command("generate").description("Generate a JavaScript client for the current project").option("-o, --output <path>","Output path",".frontstack").option("-v, --verbose","Enable verbose logging").option("-e --env <alias>",'Pass an environment alias like "develop" or "preview"').option("-s --persist-oas","Persist OpenAPI specification file").action(async r=>{await An(r)}),T.command("info").description("Display information about the current organization, project, and user").action(async()=>{await vn()}),T.command("project").description("Select current working project which will be used for schema and client updates").option("-p --project <project-id>","Set current project ID").action(async r=>{await Ne(r)});const jn=l(()=>{try{T.parse(process.argv)}catch(r){console.log(r)}},"run");var xn=jn();export{xn as default};
|
package/dist/version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.0-canary-
|
|
1
|
+
0.0.0-canary-20250620124824
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontstackdev/cli",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-20250620124824",
|
|
4
4
|
"description": "frontstack CLI for managing projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/frontstack.mjs",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"@types/node": "^22.5.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/prompts": "^2.4.9",
|
|
30
29
|
"commander": "^12.0.0",
|
|
31
30
|
"msw": "^2.2.14",
|
|
32
31
|
"ofetch": "^1.3.4",
|
|
@@ -37,6 +36,7 @@
|
|
|
37
36
|
},
|
|
38
37
|
"dependencies": {
|
|
39
38
|
"@kinde-oss/kinde-nodejs-sdk": "^1.2.3",
|
|
39
|
+
"@types/prompts": "^2.4.9",
|
|
40
40
|
"chalk": "^5.3.0",
|
|
41
41
|
"handlebars": "^4.7.8",
|
|
42
42
|
"js-yaml": "^4.1.0",
|