comp-hub 0.43.11 → 0.44.12

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 CHANGED
@@ -38,7 +38,13 @@ comphub
38
38
 
39
39
  Once started, open the URL shown in the terminal (default `http://localhost:5478`).
40
40
 
41
- > `ch` is a shorthand alias for `comphub` — all commands below work interchangeably, e.g. `ch`, `ch status`, `ch -p 8080`.
41
+ **Without installing** — npx fetches the CLI on demand:
42
+
43
+ ```bash
44
+ npx comp-hub
45
+ ```
46
+
47
+ > The CLI is published with three binary names — `comphub`, `ch` and `comp-hub` — all identical. Every command below works with any of them, e.g. `ch status`, `comp-hub -p 8080`.
42
48
 
43
49
  ### CLI Options
44
50
 
@@ -127,7 +133,7 @@ module.exports = {
127
133
  - Upload components as **folders** — folder name is the component name
128
134
  - Entry point: `index.vue` (Vue) or `index.jsx`/`index.tsx` (React)
129
135
  - Include a `README.md` describing usage
130
- - Optional `comp.json` for component metadata (name, version, dependencies, etc.)
136
+ - `comp.json` is generated by the platform and holds only `__id__`, `name` and `version` — dependencies are detected from your source `import` statements, not declared here
131
137
  - Optional `demo/` directory for preview configs
132
138
 
133
139
  ## Links
package/dist/cli.js CHANGED
@@ -1,44 +1,44 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var ir=Object.create;var Pe=Object.defineProperty;var sr=Object.getOwnPropertyDescriptor;var ar=Object.getOwnPropertyNames;var lr=Object.getPrototypeOf,cr=Object.prototype.hasOwnProperty;var S=(i,e)=>()=>{try{return e||i((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var ur=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ar(e))!cr.call(i,o)&&o!==t&&Pe(i,o,{get:()=>e[o],enumerable:!(r=sr(e,o))||r.enumerable});return i};var d=(i,e,t)=>(t=i!=null?ir(lr(i)):{},ur(e||!i||!i.__esModule?Pe(t,"default",{value:i,enumerable:!0}):t,i));var U=S(ee=>{var Y=class extends Error{constructor(e,t,r){super(r),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},Q=class extends Y{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};ee.CommanderError=Y;ee.InvalidArgumentError=Q});var j=S(re=>{var{InvalidArgumentError:ln}=U(),te=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,r)=>{if(!this.argChoices.includes(t))throw new ln(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,r):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function cn(i){let e=i.name()+(i.variadic===!0?"...":"");return i.required?"<"+e+">":"["+e+"]"}re.Argument=te;re.humanReadableArgName=cn});var ne=S(ft=>{var{humanReadableArgName:un}=j(),oe=class{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(e){let t=e.commands.filter(r=>!r._hidden);if(e._hasImplicitHelpCommand()){let[,r,o]=e._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/),n=e.createCommand(r).helpOption(!1);n.description(e._helpCommandDescription),o&&n.arguments(o),t.push(n)}return this.sortSubcommands&&t.sort((r,o)=>r.name().localeCompare(o.name())),t}compareOptions(e,t){let r=o=>o.short?o.short.replace(/^-/,""):o.long.replace(/^--/,"");return r(e).localeCompare(r(t))}visibleOptions(e){let t=e.options.filter(n=>!n.hidden),r=e._hasHelpOption&&e._helpShortFlag&&!e._findOption(e._helpShortFlag),o=e._hasHelpOption&&!e._findOption(e._helpLongFlag);if(r||o){let n;r?o?n=e.createOption(e._helpFlags,e._helpDescription):n=e.createOption(e._helpShortFlag,e._helpDescription):n=e.createOption(e._helpLongFlag,e._helpDescription),t.push(n)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let r=e.parent;r;r=r.parent){let o=r.options.filter(n=>!n.hidden);t.push(...o)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e._args.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e._args.find(t=>t.description)?e._args:[]}subcommandTerm(e){let t=e._args.map(r=>un(r)).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((r,o)=>Math.max(r,t.subcommandTerm(o).length),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((r,o)=>Math.max(r,t.optionTerm(o).length),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((r,o)=>Math.max(r,t.optionTerm(o).length),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((r,o)=>Math.max(r,t.argumentTerm(o).length),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let r="";for(let o=e.parent;o;o=o.parent)r=o.name()+" "+r;return r+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];return e.argChoices&&t.push(`choices: ${e.argChoices.map(r=>JSON.stringify(r)).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){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(r=>JSON.stringify(r)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let r=`(${t.join(", ")})`;return e.description?`${e.description} ${r}`:r}return e.description}formatHelp(e,t){let r=t.padWidth(e,t),o=t.helpWidth||80,n=2,s=2;function l(m,x){if(x){let nr=`${m.padEnd(r+s)}${x}`;return t.wrap(nr,o-n,r+s)}return m}function a(m){return m.join(`
3
- `).replace(/^/gm," ".repeat(n))}let c=[`Usage: ${t.commandUsage(e)}`,""],u=t.commandDescription(e);u.length>0&&(c=c.concat([u,""]));let p=t.visibleArguments(e).map(m=>l(t.argumentTerm(m),t.argumentDescription(m)));p.length>0&&(c=c.concat(["Arguments:",a(p),""]));let _=t.visibleOptions(e).map(m=>l(t.optionTerm(m),t.optionDescription(m)));if(_.length>0&&(c=c.concat(["Options:",a(_),""])),this.showGlobalOptions){let m=t.visibleGlobalOptions(e).map(x=>l(t.optionTerm(x),t.optionDescription(x)));m.length>0&&(c=c.concat(["Global Options:",a(m),""]))}let O=t.visibleCommands(e).map(m=>l(t.subcommandTerm(m),t.subcommandDescription(m)));return O.length>0&&(c=c.concat(["Commands:",a(O),""])),c.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,r,o=40){if(e.match(/[\n]\s+/))return e;let n=t-r;if(n<o)return e;let s=e.slice(0,r),l=e.slice(r),a=" ".repeat(r),c=new RegExp(".{1,"+(n-1)+"}([\\s\u200B]|$)|[^\\s\u200B]+?([\\s\u200B]|$)","g"),u=l.match(c)||[];return s+u.map((p,_)=>(p.slice(-1)===`
5
- `&&(p=p.slice(0,p.length-1)),(_>0?a:"")+p.trimRight())).join(`
6
- `)}};ft.Help=oe});var ae=S(G=>{var{InvalidArgumentError:pn}=U(),ie=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;let r=Et(e);this.short=r.shortFlag,this.long=r.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){return this.implied=Object.assign(this.implied||{},e),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,r)=>{if(!this.argChoices.includes(t))throw new pn(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,r):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return hn(this.name().replace(/^no-/,""))}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},se=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,r)=>{this.positiveOptions.has(r)&&this.dualOptions.add(r)})}valueFromOption(e,t){let r=t.attributeName();if(!this.dualOptions.has(r))return!0;let o=this.negativeOptions.get(r).presetArg,n=o!==void 0?o:!1;return t.negate===(n===e)}};function hn(i){return i.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function Et(i){let e,t,r=i.split(/[ |,]+/);return r.length>1&&!/^[[<]/.test(r[1])&&(e=r.shift()),t=r.shift(),!e&&/^-[^-]$/.test(t)&&(e=t,t=void 0),{shortFlag:e,longFlag:t}}G.Option=ie;G.splitOptionFlags=Et;G.DualOptions=se});var Ot=S(gt=>{function mn(i,e){if(Math.abs(i.length-e.length)>3)return Math.max(i.length,e.length);let t=[];for(let r=0;r<=i.length;r++)t[r]=[r];for(let r=0;r<=e.length;r++)t[0][r]=r;for(let r=1;r<=e.length;r++)for(let o=1;o<=i.length;o++){let n=1;i[o-1]===e[r-1]?n=0:n=1,t[o][r]=Math.min(t[o-1][r]+1,t[o][r-1]+1,t[o-1][r-1]+n),o>1&&r>1&&i[o-1]===e[r-2]&&i[o-2]===e[r-1]&&(t[o][r]=Math.min(t[o][r],t[o-2][r-2]+1))}return t[i.length][e.length]}function _n(i,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));let t=i.startsWith("--");t&&(i=i.slice(2),e=e.map(s=>s.slice(2)));let r=[],o=3,n=.4;return e.forEach(s=>{if(s.length<=1)return;let l=mn(i,s),a=Math.max(i.length,s.length);(a-l)/a>n&&(l<o?(o=l,r=[s]):l===o&&r.push(s))}),r.sort((s,l)=>s.localeCompare(l)),t&&(r=r.map(s=>`--${s}`)),r.length>1?`
2
+ "use strict";var sr=Object.create;var Se=Object.defineProperty;var ar=Object.getOwnPropertyDescriptor;var lr=Object.getOwnPropertyNames;var cr=Object.getPrototypeOf,ur=Object.prototype.hasOwnProperty;var S=(i,e)=>()=>{try{return e||i((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var pr=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of lr(e))!ur.call(i,o)&&o!==t&&Se(i,o,{get:()=>e[o],enumerable:!(r=ar(e,o))||r.enumerable});return i};var d=(i,e,t)=>(t=i!=null?sr(cr(i)):{},pr(e||!i||!i.__esModule?Se(t,"default",{value:i,enumerable:!0}):t,i));var U=S(te=>{var Y=class extends Error{constructor(e,t,r){super(r),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},ee=class extends Y{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};te.CommanderError=Y;te.InvalidArgumentError=ee});var G=S(oe=>{var{InvalidArgumentError:hn}=U(),re=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,r)=>{if(!this.argChoices.includes(t))throw new hn(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,r):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function _n(i){let e=i.name()+(i.variadic===!0?"...":"");return i.required?"<"+e+">":"["+e+"]"}oe.Argument=re;oe.humanReadableArgName=_n});var ie=S(ft=>{var{humanReadableArgName:mn}=G(),ne=class{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(e){let t=e.commands.filter(r=>!r._hidden);if(e._hasImplicitHelpCommand()){let[,r,o]=e._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/),n=e.createCommand(r).helpOption(!1);n.description(e._helpCommandDescription),o&&n.arguments(o),t.push(n)}return this.sortSubcommands&&t.sort((r,o)=>r.name().localeCompare(o.name())),t}compareOptions(e,t){let r=o=>o.short?o.short.replace(/^-/,""):o.long.replace(/^--/,"");return r(e).localeCompare(r(t))}visibleOptions(e){let t=e.options.filter(n=>!n.hidden),r=e._hasHelpOption&&e._helpShortFlag&&!e._findOption(e._helpShortFlag),o=e._hasHelpOption&&!e._findOption(e._helpLongFlag);if(r||o){let n;r?o?n=e.createOption(e._helpFlags,e._helpDescription):n=e.createOption(e._helpShortFlag,e._helpDescription):n=e.createOption(e._helpLongFlag,e._helpDescription),t.push(n)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let r=e.parent;r;r=r.parent){let o=r.options.filter(n=>!n.hidden);t.push(...o)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e._args.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e._args.find(t=>t.description)?e._args:[]}subcommandTerm(e){let t=e._args.map(r=>mn(r)).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((r,o)=>Math.max(r,t.subcommandTerm(o).length),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((r,o)=>Math.max(r,t.optionTerm(o).length),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((r,o)=>Math.max(r,t.optionTerm(o).length),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((r,o)=>Math.max(r,t.argumentTerm(o).length),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let r="";for(let o=e.parent;o;o=o.parent)r=o.name()+" "+r;return r+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];return e.argChoices&&t.push(`choices: ${e.argChoices.map(r=>JSON.stringify(r)).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){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(r=>JSON.stringify(r)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let r=`(${t.join(", ")})`;return e.description?`${e.description} ${r}`:r}return e.description}formatHelp(e,t){let r=t.padWidth(e,t),o=t.helpWidth||80,n=2,s=2;function l(_,x){if(x){let ir=`${_.padEnd(r+s)}${x}`;return t.wrap(ir,o-n,r+s)}return _}function a(_){return _.join(`
3
+ `).replace(/^/gm," ".repeat(n))}let c=[`Usage: ${t.commandUsage(e)}`,""],u=t.commandDescription(e);u.length>0&&(c=c.concat([u,""]));let p=t.visibleArguments(e).map(_=>l(t.argumentTerm(_),t.argumentDescription(_)));p.length>0&&(c=c.concat(["Arguments:",a(p),""]));let m=t.visibleOptions(e).map(_=>l(t.optionTerm(_),t.optionDescription(_)));if(m.length>0&&(c=c.concat(["Options:",a(m),""])),this.showGlobalOptions){let _=t.visibleGlobalOptions(e).map(x=>l(t.optionTerm(x),t.optionDescription(x)));_.length>0&&(c=c.concat(["Global Options:",a(_),""]))}let O=t.visibleCommands(e).map(_=>l(t.subcommandTerm(_),t.subcommandDescription(_)));return O.length>0&&(c=c.concat(["Commands:",a(O),""])),c.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,r,o=40){if(e.match(/[\n]\s+/))return e;let n=t-r;if(n<o)return e;let s=e.slice(0,r),l=e.slice(r),a=" ".repeat(r),c=new RegExp(".{1,"+(n-1)+"}([\\s\u200B]|$)|[^\\s\u200B]+?([\\s\u200B]|$)","g"),u=l.match(c)||[];return s+u.map((p,m)=>(p.slice(-1)===`
5
+ `&&(p=p.slice(0,p.length-1)),(m>0?a:"")+p.trimRight())).join(`
6
+ `)}};ft.Help=ne});var le=S(B=>{var{InvalidArgumentError:dn}=U(),se=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;let r=gt(e);this.short=r.shortFlag,this.long=r.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){return this.implied=Object.assign(this.implied||{},e),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,r)=>{if(!this.argChoices.includes(t))throw new dn(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,r):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return En(this.name().replace(/^no-/,""))}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},ae=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,r)=>{this.positiveOptions.has(r)&&this.dualOptions.add(r)})}valueFromOption(e,t){let r=t.attributeName();if(!this.dualOptions.has(r))return!0;let o=this.negativeOptions.get(r).presetArg,n=o!==void 0?o:!1;return t.negate===(n===e)}};function En(i){return i.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function gt(i){let e,t,r=i.split(/[ |,]+/);return r.length>1&&!/^[[<]/.test(r[1])&&(e=r.shift()),t=r.shift(),!e&&/^-[^-]$/.test(t)&&(e=t,t=void 0),{shortFlag:e,longFlag:t}}B.Option=se;B.splitOptionFlags=gt;B.DualOptions=ae});var At=S(Ot=>{function fn(i,e){if(Math.abs(i.length-e.length)>3)return Math.max(i.length,e.length);let t=[];for(let r=0;r<=i.length;r++)t[r]=[r];for(let r=0;r<=e.length;r++)t[0][r]=r;for(let r=1;r<=e.length;r++)for(let o=1;o<=i.length;o++){let n=1;i[o-1]===e[r-1]?n=0:n=1,t[o][r]=Math.min(t[o-1][r]+1,t[o][r-1]+1,t[o-1][r-1]+n),o>1&&r>1&&i[o-1]===e[r-2]&&i[o-2]===e[r-1]&&(t[o][r]=Math.min(t[o][r],t[o-2][r-2]+1))}return t[i.length][e.length]}function gn(i,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));let t=i.startsWith("--");t&&(i=i.slice(2),e=e.map(s=>s.slice(2)));let r=[],o=3,n=.4;return e.forEach(s=>{if(s.length<=1)return;let l=fn(i,s),a=Math.max(i.length,s.length);(a-l)/a>n&&(l<o?(o=l,r=[s]):l===o&&r.push(s))}),r.sort((s,l)=>s.localeCompare(l)),t&&(r=r.map(s=>`--${s}`)),r.length>1?`
7
7
  (Did you mean one of ${r.join(", ")}?)`:r.length===1?`
8
- (Did you mean ${r[0]}?)`:""}gt.suggestSimilar=_n});var Mt=S(St=>{var dn=require("events").EventEmitter,le=require("child_process"),P=require("path"),ce=require("fs"),h=require("process"),{Argument:fn,humanReadableArgName:En}=j(),{CommanderError:ue}=U(),{Help:gn}=ne(),{Option:Ct,splitOptionFlags:On,DualOptions:Cn}=ae(),{suggestSimilar:At}=Ot(),pe=class i extends dn{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!0,this._args=[],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:t=>h.stdout.write(t),writeErr:t=>h.stderr.write(t),getOutHelpWidth:()=>h.stdout.isTTY?h.stdout.columns:void 0,getErrHelpWidth:()=>h.stderr.isTTY?h.stderr.columns:void 0,outputError:(t,r)=>r(t)},this._hidden=!1,this._hasHelpOption=!0,this._helpFlags="-h, --help",this._helpDescription="display help for command",this._helpShortFlag="-h",this._helpLongFlag="--help",this._addImplicitHelpCommand=void 0,this._helpCommandName="help",this._helpCommandnameAndArgs="help [command]",this._helpCommandDescription="display help for command",this._helpConfiguration={}}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._hasHelpOption=e._hasHelpOption,this._helpFlags=e._helpFlags,this._helpDescription=e._helpDescription,this._helpShortFlag=e._helpShortFlag,this._helpLongFlag=e._helpLongFlag,this._helpCommandName=e._helpCommandName,this._helpCommandnameAndArgs=e._helpCommandnameAndArgs,this._helpCommandDescription=e._helpCommandDescription,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}command(e,t,r){let o=t,n=r;typeof o=="object"&&o!==null&&(n=o,o=null),n=n||{};let[,s,l]=e.match(/([^ ]+) *(.*)/),a=this.createCommand(s);return o&&(a.description(o),a._executableHandler=!0),n.isDefault&&(this._defaultCommandName=a._name),a._hidden=!!(n.noHelp||n.hidden),a._executableFile=n.executableFile||null,l&&a.arguments(l),this.commands.push(a),a.parent=this,a.copyInheritedSettings(this),o?this:a}createCommand(e){return new i(e)}createHelp(){return Object.assign(new gn,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
9
- - 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.commands.push(e),e.parent=this,this}createArgument(e,t){return new fn(e,t)}argument(e,t,r,o){let n=this.createArgument(e,t);return typeof r=="function"?n.default(o).argParser(r):n.default(r),this.addArgument(n),this}arguments(e){return e.split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(e){let t=this._args.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._args.push(e),this}addHelpCommand(e,t){return e===!1?this._addImplicitHelpCommand=!1:(this._addImplicitHelpCommand=!0,typeof e=="string"&&(this._helpCommandName=e.split(" ")[0],this._helpCommandnameAndArgs=e),this._helpCommandDescription=t||this._helpCommandDescription),this}_hasImplicitHelpCommand(){return this._addImplicitHelpCommand===void 0?this.commands.length&&!this._actionHandler&&!this._findCommand("help"):this._addImplicitHelpCommand}hook(e,t){let r=["preSubcommand","preAction","postAction"];if(!r.includes(e))throw new Error(`Unexpected value for event passed to hook : '${e}'.
10
- Expecting one of '${r.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,r){this._exitCallback&&this._exitCallback(new ue(e,t,r)),h.exit(e)}action(e){let t=r=>{let o=this._args.length,n=r.slice(0,o);return this._storeOptionsAsProperties?n[o]=this:n[o]=this.opts(),n.push(this),e.apply(this,n)};return this._actionHandler=t,this}createOption(e,t){return new Ct(e,t)}addOption(e){let t=e.name(),r=e.attributeName();if(e.negate){let n=e.long.replace(/^--no-/,"--");this._findOption(n)||this.setOptionValueWithSource(r,e.defaultValue===void 0?!0:e.defaultValue,"default")}else e.defaultValue!==void 0&&this.setOptionValueWithSource(r,e.defaultValue,"default");this.options.push(e);let o=(n,s,l)=>{n==null&&e.presetArg!==void 0&&(n=e.presetArg);let a=this.getOptionValue(r);if(n!==null&&e.parseArg)try{n=e.parseArg(n,a)}catch(c){if(c.code==="commander.invalidArgument"){let u=`${s} ${c.message}`;this.error(u,{exitCode:c.exitCode,code:c.code})}throw c}else n!==null&&e.variadic&&(n=e._concatValue(n,a));n==null&&(e.negate?n=!1:e.isBoolean()||e.optional?n=!0:n=""),this.setOptionValueWithSource(r,n,l)};return this.on("option:"+t,n=>{let s=`error: option '${e.flags}' argument '${n}' is invalid.`;o(n,s,"cli")}),e.envVar&&this.on("optionEnv:"+t,n=>{let s=`error: option '${e.flags}' value '${n}' from env '${e.envVar}' is invalid.`;o(n,s,"env")}),this}_optionEx(e,t,r,o,n){if(typeof t=="object"&&t instanceof Ct)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let s=this.createOption(t,r);if(s.makeOptionMandatory(!!e.mandatory),typeof o=="function")s.default(n).argParser(o);else if(o instanceof RegExp){let l=o;o=(a,c)=>{let u=l.exec(a);return u?u[0]:c},s.default(n).argParser(o)}else s.default(o);return this.addOption(s)}option(e,t,r,o){return this._optionEx({},e,t,r,o)}requiredOption(e,t,r,o){return this._optionEx({mandatory:!0},e,t,r,o)}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){if(this._passThroughOptions=!!e,this.parent&&e&&!this.parent._enablePositionalOptions)throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)");return this}storeOptionsAsProperties(e=!0){if(this._storeOptionsAsProperties=!!e,this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");return this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,r){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=r,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return H(this).forEach(r=>{r.getOptionValueSource(e)!==void 0&&(t=r.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=h.argv,h.versions&&h.versions.electron&&(t.from="electron")),this.rawArgs=e.slice();let r;switch(t.from){case void 0:case"node":this._scriptPath=e[1],r=e.slice(2);break;case"electron":h.defaultApp?(this._scriptPath=e[1],r=e.slice(2)):r=e.slice(1);break;case"user":r=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",r}parse(e,t){let r=this._prepareUserArgs(e,t);return this._parseCommand([],r),this}async parseAsync(e,t){let r=this._prepareUserArgs(e,t);return await this._parseCommand([],r),this}_executeSubCommand(e,t){t=t.slice();let r=!1,o=[".js",".ts",".tsx",".mjs",".cjs"];function n(u,p){let _=P.resolve(u,p);if(ce.existsSync(_))return _;if(o.includes(P.extname(p)))return;let O=o.find(m=>ce.existsSync(`${_}${m}`));if(O)return`${_}${O}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let s=e._executableFile||`${this._name}-${e._name}`,l=this._executableDir||"";if(this._scriptPath){let u;try{u=ce.realpathSync(this._scriptPath)}catch{u=this._scriptPath}l=P.resolve(P.dirname(u),l)}if(l){let u=n(l,s);if(!u&&!e._executableFile&&this._scriptPath){let p=P.basename(this._scriptPath,P.extname(this._scriptPath));p!==this._name&&(u=n(l,`${p}-${e._name}`))}s=u||s}r=o.includes(P.extname(s));let a;h.platform!=="win32"?r?(t.unshift(s),t=Pt(h.execArgv).concat(t),a=le.spawn(h.argv[0],t,{stdio:"inherit"})):a=le.spawn(s,t,{stdio:"inherit"}):(t.unshift(s),t=Pt(h.execArgv).concat(t),a=le.spawn(h.execPath,t,{stdio:"inherit"})),a.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(p=>{h.on(p,()=>{a.killed===!1&&a.exitCode===null&&a.kill(p)})});let c=this._exitCallback;c?a.on("close",()=>{c(new ue(h.exitCode||0,"commander.executeSubCommandAsync","(close)"))}):a.on("close",h.exit.bind(h)),a.on("error",u=>{if(u.code==="ENOENT"){let p=l?`searched for local subcommand relative to directory '${l}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",_=`'${s}' does not exist
8
+ (Did you mean ${r[0]}?)`:""}Ot.suggestSimilar=gn});var Rt=S(Mt=>{var On=require("events").EventEmitter,ce=require("child_process"),P=require("path"),ue=require("fs"),h=require("process"),{Argument:An,humanReadableArgName:Cn}=G(),{CommanderError:pe}=U(),{Help:Tn}=ie(),{Option:Ct,splitOptionFlags:Pn,DualOptions:Sn}=le(),{suggestSimilar:Tt}=At(),he=class i extends On{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!0,this._args=[],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:t=>h.stdout.write(t),writeErr:t=>h.stderr.write(t),getOutHelpWidth:()=>h.stdout.isTTY?h.stdout.columns:void 0,getErrHelpWidth:()=>h.stderr.isTTY?h.stderr.columns:void 0,outputError:(t,r)=>r(t)},this._hidden=!1,this._hasHelpOption=!0,this._helpFlags="-h, --help",this._helpDescription="display help for command",this._helpShortFlag="-h",this._helpLongFlag="--help",this._addImplicitHelpCommand=void 0,this._helpCommandName="help",this._helpCommandnameAndArgs="help [command]",this._helpCommandDescription="display help for command",this._helpConfiguration={}}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._hasHelpOption=e._hasHelpOption,this._helpFlags=e._helpFlags,this._helpDescription=e._helpDescription,this._helpShortFlag=e._helpShortFlag,this._helpLongFlag=e._helpLongFlag,this._helpCommandName=e._helpCommandName,this._helpCommandnameAndArgs=e._helpCommandnameAndArgs,this._helpCommandDescription=e._helpCommandDescription,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}command(e,t,r){let o=t,n=r;typeof o=="object"&&o!==null&&(n=o,o=null),n=n||{};let[,s,l]=e.match(/([^ ]+) *(.*)/),a=this.createCommand(s);return o&&(a.description(o),a._executableHandler=!0),n.isDefault&&(this._defaultCommandName=a._name),a._hidden=!!(n.noHelp||n.hidden),a._executableFile=n.executableFile||null,l&&a.arguments(l),this.commands.push(a),a.parent=this,a.copyInheritedSettings(this),o?this:a}createCommand(e){return new i(e)}createHelp(){return Object.assign(new Tn,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
9
+ - 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.commands.push(e),e.parent=this,this}createArgument(e,t){return new An(e,t)}argument(e,t,r,o){let n=this.createArgument(e,t);return typeof r=="function"?n.default(o).argParser(r):n.default(r),this.addArgument(n),this}arguments(e){return e.split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(e){let t=this._args.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._args.push(e),this}addHelpCommand(e,t){return e===!1?this._addImplicitHelpCommand=!1:(this._addImplicitHelpCommand=!0,typeof e=="string"&&(this._helpCommandName=e.split(" ")[0],this._helpCommandnameAndArgs=e),this._helpCommandDescription=t||this._helpCommandDescription),this}_hasImplicitHelpCommand(){return this._addImplicitHelpCommand===void 0?this.commands.length&&!this._actionHandler&&!this._findCommand("help"):this._addImplicitHelpCommand}hook(e,t){let r=["preSubcommand","preAction","postAction"];if(!r.includes(e))throw new Error(`Unexpected value for event passed to hook : '${e}'.
10
+ Expecting one of '${r.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,r){this._exitCallback&&this._exitCallback(new pe(e,t,r)),h.exit(e)}action(e){let t=r=>{let o=this._args.length,n=r.slice(0,o);return this._storeOptionsAsProperties?n[o]=this:n[o]=this.opts(),n.push(this),e.apply(this,n)};return this._actionHandler=t,this}createOption(e,t){return new Ct(e,t)}addOption(e){let t=e.name(),r=e.attributeName();if(e.negate){let n=e.long.replace(/^--no-/,"--");this._findOption(n)||this.setOptionValueWithSource(r,e.defaultValue===void 0?!0:e.defaultValue,"default")}else e.defaultValue!==void 0&&this.setOptionValueWithSource(r,e.defaultValue,"default");this.options.push(e);let o=(n,s,l)=>{n==null&&e.presetArg!==void 0&&(n=e.presetArg);let a=this.getOptionValue(r);if(n!==null&&e.parseArg)try{n=e.parseArg(n,a)}catch(c){if(c.code==="commander.invalidArgument"){let u=`${s} ${c.message}`;this.error(u,{exitCode:c.exitCode,code:c.code})}throw c}else n!==null&&e.variadic&&(n=e._concatValue(n,a));n==null&&(e.negate?n=!1:e.isBoolean()||e.optional?n=!0:n=""),this.setOptionValueWithSource(r,n,l)};return this.on("option:"+t,n=>{let s=`error: option '${e.flags}' argument '${n}' is invalid.`;o(n,s,"cli")}),e.envVar&&this.on("optionEnv:"+t,n=>{let s=`error: option '${e.flags}' value '${n}' from env '${e.envVar}' is invalid.`;o(n,s,"env")}),this}_optionEx(e,t,r,o,n){if(typeof t=="object"&&t instanceof Ct)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let s=this.createOption(t,r);if(s.makeOptionMandatory(!!e.mandatory),typeof o=="function")s.default(n).argParser(o);else if(o instanceof RegExp){let l=o;o=(a,c)=>{let u=l.exec(a);return u?u[0]:c},s.default(n).argParser(o)}else s.default(o);return this.addOption(s)}option(e,t,r,o){return this._optionEx({},e,t,r,o)}requiredOption(e,t,r,o){return this._optionEx({mandatory:!0},e,t,r,o)}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){if(this._passThroughOptions=!!e,this.parent&&e&&!this.parent._enablePositionalOptions)throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)");return this}storeOptionsAsProperties(e=!0){if(this._storeOptionsAsProperties=!!e,this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");return this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,r){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=r,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return H(this).forEach(r=>{r.getOptionValueSource(e)!==void 0&&(t=r.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=h.argv,h.versions&&h.versions.electron&&(t.from="electron")),this.rawArgs=e.slice();let r;switch(t.from){case void 0:case"node":this._scriptPath=e[1],r=e.slice(2);break;case"electron":h.defaultApp?(this._scriptPath=e[1],r=e.slice(2)):r=e.slice(1);break;case"user":r=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",r}parse(e,t){let r=this._prepareUserArgs(e,t);return this._parseCommand([],r),this}async parseAsync(e,t){let r=this._prepareUserArgs(e,t);return await this._parseCommand([],r),this}_executeSubCommand(e,t){t=t.slice();let r=!1,o=[".js",".ts",".tsx",".mjs",".cjs"];function n(u,p){let m=P.resolve(u,p);if(ue.existsSync(m))return m;if(o.includes(P.extname(p)))return;let O=o.find(_=>ue.existsSync(`${m}${_}`));if(O)return`${m}${O}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let s=e._executableFile||`${this._name}-${e._name}`,l=this._executableDir||"";if(this._scriptPath){let u;try{u=ue.realpathSync(this._scriptPath)}catch{u=this._scriptPath}l=P.resolve(P.dirname(u),l)}if(l){let u=n(l,s);if(!u&&!e._executableFile&&this._scriptPath){let p=P.basename(this._scriptPath,P.extname(this._scriptPath));p!==this._name&&(u=n(l,`${p}-${e._name}`))}s=u||s}r=o.includes(P.extname(s));let a;h.platform!=="win32"?r?(t.unshift(s),t=St(h.execArgv).concat(t),a=ce.spawn(h.argv[0],t,{stdio:"inherit"})):a=ce.spawn(s,t,{stdio:"inherit"}):(t.unshift(s),t=St(h.execArgv).concat(t),a=ce.spawn(h.execPath,t,{stdio:"inherit"})),a.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(p=>{h.on(p,()=>{a.killed===!1&&a.exitCode===null&&a.kill(p)})});let c=this._exitCallback;c?a.on("close",()=>{c(new pe(h.exitCode||0,"commander.executeSubCommandAsync","(close)"))}):a.on("close",h.exit.bind(h)),a.on("error",u=>{if(u.code==="ENOENT"){let p=l?`searched for local subcommand relative to directory '${l}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",m=`'${s}' does not exist
11
11
  - if '${e._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
12
12
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
13
- - ${p}`;throw new Error(_)}else if(u.code==="EACCES")throw new Error(`'${s}' not executable`);if(!c)h.exit(1);else{let p=new ue(1,"commander.executeSubCommandAsync","(error)");p.nestedError=u,c(p)}}),this.runningCommand=a}_dispatchSubcommand(e,t,r){let o=this._findCommand(e);o||this.help({error:!0});let n;return n=this._chainOrCallSubCommandHook(n,o,"preSubcommand"),n=this._chainOrCall(n,()=>{if(o._executableHandler)this._executeSubCommand(o,t.concat(r));else return o._parseCommand(t,r)}),n}_checkNumberOfArguments(){this._args.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this._args.length>0&&this._args[this._args.length-1].variadic)&&this.args.length>this._args.length&&this._excessArguments(this.args)}_processArguments(){let e=(r,o,n)=>{let s=o;if(o!==null&&r.parseArg)try{s=r.parseArg(o,n)}catch(l){if(l.code==="commander.invalidArgument"){let a=`error: command-argument value '${o}' is invalid for argument '${r.name()}'. ${l.message}`;this.error(a,{exitCode:l.exitCode,code:l.code})}throw l}return s};this._checkNumberOfArguments();let t=[];this._args.forEach((r,o)=>{let n=r.defaultValue;r.variadic?o<this.args.length?(n=this.args.slice(o),r.parseArg&&(n=n.reduce((s,l)=>e(r,l,s),r.defaultValue))):n===void 0&&(n=[]):o<this.args.length&&(n=this.args[o],r.parseArg&&(n=e(r,n,r.defaultValue))),t[o]=n}),this.processedArgs=t}_chainOrCall(e,t){return e&&e.then&&typeof e.then=="function"?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let r=e,o=[];return H(this).reverse().filter(n=>n._lifeCycleHooks[t]!==void 0).forEach(n=>{n._lifeCycleHooks[t].forEach(s=>{o.push({hookedCommand:n,callback:s})})}),t==="postAction"&&o.reverse(),o.forEach(n=>{r=this._chainOrCall(r,()=>n.callback(n.hookedCommand,this))}),r}_chainOrCallSubCommandHook(e,t,r){let o=e;return this._lifeCycleHooks[r]!==void 0&&this._lifeCycleHooks[r].forEach(n=>{o=this._chainOrCall(o,()=>n(this,t))}),o}_parseCommand(e,t){let r=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(r.operands),t=r.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._hasImplicitHelpCommand()&&e[0]===this._helpCommandName)return e.length===1&&this.help(),this._dispatchSubcommand(e[1],[],[this._helpLongFlag]);if(this._defaultCommandName)return Tt(this,t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),Tt(this,r.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=()=>{r.unknown.length>0&&this.unknownOption(r.unknown[0])},n=`command:${this.name()}`;if(this._actionHandler){o(),this._processArguments();let s;return s=this._chainOrCallHooks(s,"preAction"),s=this._chainOrCall(s,()=>this._actionHandler(this.processedArgs)),this.parent&&(s=this._chainOrCall(s,()=>{this.parent.emit(n,e,t)})),s=this._chainOrCallHooks(s,"postAction"),s}if(this.parent&&this.parent.listenerCount(n))o(),this._processArguments(),this.parent.emit(n,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():(o(),this._processArguments())}else this.commands.length?(o(),this.help({error:!0})):(o(),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(){for(let e=this;e;e=e.parent)e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})}_checkForConflictingLocalOptions(){let e=this.options.filter(r=>{let o=r.attributeName();return this.getOptionValue(o)===void 0?!1:this.getOptionValueSource(o)!=="default"});e.filter(r=>r.conflictsWith.length>0).forEach(r=>{let o=e.find(n=>r.conflictsWith.includes(n.attributeName()));o&&this._conflictingOption(r,o)})}_checkForConflictingOptions(){for(let e=this;e;e=e.parent)e._checkForConflictingLocalOptions()}parseOptions(e){let t=[],r=[],o=t,n=e.slice();function s(a){return a.length>1&&a[0]==="-"}let l=null;for(;n.length;){let a=n.shift();if(a==="--"){o===r&&o.push(a),o.push(...n);break}if(l&&!s(a)){this.emit(`option:${l.name()}`,a);continue}if(l=null,s(a)){let c=this._findOption(a);if(c){if(c.required){let u=n.shift();u===void 0&&this.optionMissingArgument(c),this.emit(`option:${c.name()}`,u)}else if(c.optional){let u=null;n.length>0&&!s(n[0])&&(u=n.shift()),this.emit(`option:${c.name()}`,u)}else this.emit(`option:${c.name()}`);l=c.variadic?c:null;continue}}if(a.length>2&&a[0]==="-"&&a[1]!=="-"){let c=this._findOption(`-${a[1]}`);if(c){c.required||c.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${c.name()}`,a.slice(2)):(this.emit(`option:${c.name()}`),n.unshift(`-${a.slice(2)}`));continue}}if(/^--[^=]+=/.test(a)){let c=a.indexOf("="),u=this._findOption(a.slice(0,c));if(u&&(u.required||u.optional)){this.emit(`option:${u.name()}`,a.slice(c+1));continue}}if(s(a)&&(o=r),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&r.length===0){if(this._findCommand(a)){t.push(a),n.length>0&&r.push(...n);break}else if(a===this._helpCommandName&&this._hasImplicitHelpCommand()){t.push(a),n.length>0&&t.push(...n);break}else if(this._defaultCommandName){r.push(a),n.length>0&&r.push(...n);break}}if(this._passThroughOptions){o.push(a),n.length>0&&o.push(...n);break}o.push(a)}return{operands:t,unknown:r}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let r=0;r<t;r++){let o=this.options[r].attributeName();e[o]=o===this._versionOptionName?this._version:this[o]}return e}return this._optionValues}optsWithGlobals(){return H(this).reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
13
+ - ${p}`;throw new Error(m)}else if(u.code==="EACCES")throw new Error(`'${s}' not executable`);if(!c)h.exit(1);else{let p=new pe(1,"commander.executeSubCommandAsync","(error)");p.nestedError=u,c(p)}}),this.runningCommand=a}_dispatchSubcommand(e,t,r){let o=this._findCommand(e);o||this.help({error:!0});let n;return n=this._chainOrCallSubCommandHook(n,o,"preSubcommand"),n=this._chainOrCall(n,()=>{if(o._executableHandler)this._executeSubCommand(o,t.concat(r));else return o._parseCommand(t,r)}),n}_checkNumberOfArguments(){this._args.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this._args.length>0&&this._args[this._args.length-1].variadic)&&this.args.length>this._args.length&&this._excessArguments(this.args)}_processArguments(){let e=(r,o,n)=>{let s=o;if(o!==null&&r.parseArg)try{s=r.parseArg(o,n)}catch(l){if(l.code==="commander.invalidArgument"){let a=`error: command-argument value '${o}' is invalid for argument '${r.name()}'. ${l.message}`;this.error(a,{exitCode:l.exitCode,code:l.code})}throw l}return s};this._checkNumberOfArguments();let t=[];this._args.forEach((r,o)=>{let n=r.defaultValue;r.variadic?o<this.args.length?(n=this.args.slice(o),r.parseArg&&(n=n.reduce((s,l)=>e(r,l,s),r.defaultValue))):n===void 0&&(n=[]):o<this.args.length&&(n=this.args[o],r.parseArg&&(n=e(r,n,r.defaultValue))),t[o]=n}),this.processedArgs=t}_chainOrCall(e,t){return e&&e.then&&typeof e.then=="function"?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let r=e,o=[];return H(this).reverse().filter(n=>n._lifeCycleHooks[t]!==void 0).forEach(n=>{n._lifeCycleHooks[t].forEach(s=>{o.push({hookedCommand:n,callback:s})})}),t==="postAction"&&o.reverse(),o.forEach(n=>{r=this._chainOrCall(r,()=>n.callback(n.hookedCommand,this))}),r}_chainOrCallSubCommandHook(e,t,r){let o=e;return this._lifeCycleHooks[r]!==void 0&&this._lifeCycleHooks[r].forEach(n=>{o=this._chainOrCall(o,()=>n(this,t))}),o}_parseCommand(e,t){let r=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(r.operands),t=r.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._hasImplicitHelpCommand()&&e[0]===this._helpCommandName)return e.length===1&&this.help(),this._dispatchSubcommand(e[1],[],[this._helpLongFlag]);if(this._defaultCommandName)return Pt(this,t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),Pt(this,r.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=()=>{r.unknown.length>0&&this.unknownOption(r.unknown[0])},n=`command:${this.name()}`;if(this._actionHandler){o(),this._processArguments();let s;return s=this._chainOrCallHooks(s,"preAction"),s=this._chainOrCall(s,()=>this._actionHandler(this.processedArgs)),this.parent&&(s=this._chainOrCall(s,()=>{this.parent.emit(n,e,t)})),s=this._chainOrCallHooks(s,"postAction"),s}if(this.parent&&this.parent.listenerCount(n))o(),this._processArguments(),this.parent.emit(n,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():(o(),this._processArguments())}else this.commands.length?(o(),this.help({error:!0})):(o(),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(){for(let e=this;e;e=e.parent)e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})}_checkForConflictingLocalOptions(){let e=this.options.filter(r=>{let o=r.attributeName();return this.getOptionValue(o)===void 0?!1:this.getOptionValueSource(o)!=="default"});e.filter(r=>r.conflictsWith.length>0).forEach(r=>{let o=e.find(n=>r.conflictsWith.includes(n.attributeName()));o&&this._conflictingOption(r,o)})}_checkForConflictingOptions(){for(let e=this;e;e=e.parent)e._checkForConflictingLocalOptions()}parseOptions(e){let t=[],r=[],o=t,n=e.slice();function s(a){return a.length>1&&a[0]==="-"}let l=null;for(;n.length;){let a=n.shift();if(a==="--"){o===r&&o.push(a),o.push(...n);break}if(l&&!s(a)){this.emit(`option:${l.name()}`,a);continue}if(l=null,s(a)){let c=this._findOption(a);if(c){if(c.required){let u=n.shift();u===void 0&&this.optionMissingArgument(c),this.emit(`option:${c.name()}`,u)}else if(c.optional){let u=null;n.length>0&&!s(n[0])&&(u=n.shift()),this.emit(`option:${c.name()}`,u)}else this.emit(`option:${c.name()}`);l=c.variadic?c:null;continue}}if(a.length>2&&a[0]==="-"&&a[1]!=="-"){let c=this._findOption(`-${a[1]}`);if(c){c.required||c.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${c.name()}`,a.slice(2)):(this.emit(`option:${c.name()}`),n.unshift(`-${a.slice(2)}`));continue}}if(/^--[^=]+=/.test(a)){let c=a.indexOf("="),u=this._findOption(a.slice(0,c));if(u&&(u.required||u.optional)){this.emit(`option:${u.name()}`,a.slice(c+1));continue}}if(s(a)&&(o=r),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&r.length===0){if(this._findCommand(a)){t.push(a),n.length>0&&r.push(...n);break}else if(a===this._helpCommandName&&this._hasImplicitHelpCommand()){t.push(a),n.length>0&&t.push(...n);break}else if(this._defaultCommandName){r.push(a),n.length>0&&r.push(...n);break}}if(this._passThroughOptions){o.push(a),n.length>0&&o.push(...n);break}o.push(a)}return{operands:t,unknown:r}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let r=0;r<t;r++){let o=this.options[r].attributeName();e[o]=o===this._versionOptionName?this._version:this[o]}return e}return this._optionValues}optsWithGlobals(){return H(this).reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
14
14
  `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
15
15
  `):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
16
- `),this.outputHelp({error:!0}));let r=t||{},o=r.exitCode||1,n=r.code||"commander.error";this._exit(o,n,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in h.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,h.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new Cn(this.options),t=r=>this.getOptionValue(r)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(r));this.options.filter(r=>r.implied!==void 0&&t(r.attributeName())&&e.valueFromOption(this.getOptionValue(r.attributeName()),r)).forEach(r=>{Object.keys(r.implied).filter(o=>!t(o)).forEach(o=>{this.setOptionValueWithSource(o,r.implied[o],"implied")})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){let r=s=>{let l=s.attributeName(),a=this.getOptionValue(l),c=this.options.find(p=>p.negate&&l===p.attributeName()),u=this.options.find(p=>!p.negate&&l===p.attributeName());return c&&(c.presetArg===void 0&&a===!1||c.presetArg!==void 0&&a===c.presetArg)?c:u||s},o=s=>{let l=r(s),a=l.attributeName();return this.getOptionValueSource(a)==="env"?`environment variable '${l.envVar}'`:`option '${l.flags}'`},n=`error: ${o(e)} cannot be used with ${o(t)}`;this.error(n,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let o=[],n=this;do{let s=n.createHelp().visibleOptions(n).filter(l=>l.long).map(l=>l.long);o=o.concat(s),n=n.parent}while(n&&!n._enablePositionalOptions);t=At(e,o)}let r=`error: unknown option '${e}'${t}`;this.error(r,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this._args.length,r=t===1?"":"s",n=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${t} argument${r} but got ${e.length}.`;this.error(n,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let o=[];this.createHelp().visibleCommands(this).forEach(n=>{o.push(n.name()),n.alias()&&o.push(n.alias())}),t=At(e,o)}let r=`error: unknown command '${e}'${t}`;this.error(r,{code:"commander.unknownCommand"})}version(e,t,r){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",r=r||"output the version number";let o=this.createOption(t,r);return this._versionOptionName=o.attributeName(),this.options.push(o),this.on("option:"+o.name(),()=>{this._outputConfiguration.writeOut(`${e}
17
- `),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");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;let t=this._args.map(r=>En(r));return[].concat(this.options.length||this._hasHelpOption?"[options]":[],this.commands.length?"[command]":[],this._args.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=P.basename(e,P.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let 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||{};let t={error:!!e.error},r;return t.error?r=o=>this._outputConfiguration.writeErr(o):r=o=>this._outputConfiguration.writeOut(o),t.write=e.write||r,t.command=this,t}outputHelp(e){let t;typeof e=="function"&&(t=e,e=void 0);let r=this._getHelpContext(e);H(this).reverse().forEach(n=>n.emit("beforeAllHelp",r)),this.emit("beforeHelp",r);let o=this.helpInformation(r);if(t&&(o=t(o),typeof o!="string"&&!Buffer.isBuffer(o)))throw new Error("outputHelp callback must return a string or a Buffer");r.write(o),this.emit(this._helpLongFlag),this.emit("afterHelp",r),H(this).forEach(n=>n.emit("afterAllHelp",r))}helpOption(e,t){if(typeof e=="boolean")return this._hasHelpOption=e,this;this._helpFlags=e||this._helpFlags,this._helpDescription=t||this._helpDescription;let r=On(this._helpFlags);return this._helpShortFlag=r.shortFlag,this._helpLongFlag=r.longFlag,this}help(e){this.outputHelp(e);let t=h.exitCode||0;t===0&&e&&typeof e!="function"&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){let r=["beforeAll","before","after","afterAll"];if(!r.includes(e))throw new Error(`Unexpected value for position to addHelpText.
16
+ `),this.outputHelp({error:!0}));let r=t||{},o=r.exitCode||1,n=r.code||"commander.error";this._exit(o,n,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in h.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,h.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new Sn(this.options),t=r=>this.getOptionValue(r)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(r));this.options.filter(r=>r.implied!==void 0&&t(r.attributeName())&&e.valueFromOption(this.getOptionValue(r.attributeName()),r)).forEach(r=>{Object.keys(r.implied).filter(o=>!t(o)).forEach(o=>{this.setOptionValueWithSource(o,r.implied[o],"implied")})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){let r=s=>{let l=s.attributeName(),a=this.getOptionValue(l),c=this.options.find(p=>p.negate&&l===p.attributeName()),u=this.options.find(p=>!p.negate&&l===p.attributeName());return c&&(c.presetArg===void 0&&a===!1||c.presetArg!==void 0&&a===c.presetArg)?c:u||s},o=s=>{let l=r(s),a=l.attributeName();return this.getOptionValueSource(a)==="env"?`environment variable '${l.envVar}'`:`option '${l.flags}'`},n=`error: ${o(e)} cannot be used with ${o(t)}`;this.error(n,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let o=[],n=this;do{let s=n.createHelp().visibleOptions(n).filter(l=>l.long).map(l=>l.long);o=o.concat(s),n=n.parent}while(n&&!n._enablePositionalOptions);t=Tt(e,o)}let r=`error: unknown option '${e}'${t}`;this.error(r,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this._args.length,r=t===1?"":"s",n=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${t} argument${r} but got ${e.length}.`;this.error(n,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let o=[];this.createHelp().visibleCommands(this).forEach(n=>{o.push(n.name()),n.alias()&&o.push(n.alias())}),t=Tt(e,o)}let r=`error: unknown command '${e}'${t}`;this.error(r,{code:"commander.unknownCommand"})}version(e,t,r){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",r=r||"output the version number";let o=this.createOption(t,r);return this._versionOptionName=o.attributeName(),this.options.push(o),this.on("option:"+o.name(),()=>{this._outputConfiguration.writeOut(`${e}
17
+ `),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");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;let t=this._args.map(r=>Cn(r));return[].concat(this.options.length||this._hasHelpOption?"[options]":[],this.commands.length?"[command]":[],this._args.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=P.basename(e,P.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let 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||{};let t={error:!!e.error},r;return t.error?r=o=>this._outputConfiguration.writeErr(o):r=o=>this._outputConfiguration.writeOut(o),t.write=e.write||r,t.command=this,t}outputHelp(e){let t;typeof e=="function"&&(t=e,e=void 0);let r=this._getHelpContext(e);H(this).reverse().forEach(n=>n.emit("beforeAllHelp",r)),this.emit("beforeHelp",r);let o=this.helpInformation(r);if(t&&(o=t(o),typeof o!="string"&&!Buffer.isBuffer(o)))throw new Error("outputHelp callback must return a string or a Buffer");r.write(o),this.emit(this._helpLongFlag),this.emit("afterHelp",r),H(this).forEach(n=>n.emit("afterAllHelp",r))}helpOption(e,t){if(typeof e=="boolean")return this._hasHelpOption=e,this;this._helpFlags=e||this._helpFlags,this._helpDescription=t||this._helpDescription;let r=Pn(this._helpFlags);return this._helpShortFlag=r.shortFlag,this._helpLongFlag=r.longFlag,this}help(e){this.outputHelp(e);let t=h.exitCode||0;t===0&&e&&typeof e!="function"&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){let r=["beforeAll","before","after","afterAll"];if(!r.includes(e))throw new Error(`Unexpected value for position to addHelpText.
18
18
  Expecting one of '${r.join("', '")}'`);let o=`${e}Help`;return this.on(o,n=>{let s;typeof t=="function"?s=t({error:n.error,command:n.command}):s=t,s&&n.write(`${s}
19
- `)}),this}};function Tt(i,e){i._hasHelpOption&&e.find(r=>r===i._helpLongFlag||r===i._helpShortFlag)&&(i.outputHelp(),i._exit(0,"commander.helpDisplayed","(outputHelp)"))}function Pt(i){return i.map(e=>{if(!e.startsWith("--inspect"))return e;let t,r="127.0.0.1",o="9229",n;return(n=e.match(/^(--inspect(-brk)?)$/))!==null?t=n[1]:(n=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=n[1],/^\d+$/.test(n[3])?o=n[3]:r=n[3]):(n=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=n[1],r=n[3],o=n[4]),t&&o!=="0"?`${t}=${r}:${parseInt(o)+1}`:e})}function H(i){let e=[];for(let t=i;t;t=t.parent)e.push(t);return e}St.Command=pe});var Lt=S((C,bt)=>{var{Argument:An}=j(),{Command:Rt}=Mt(),{CommanderError:Tn,InvalidArgumentError:It}=U(),{Help:Pn}=ne(),{Option:Sn}=ae();C=bt.exports=new Rt;C.program=C;C.Argument=An;C.Command=Rt;C.CommanderError=Tn;C.Help=Pn;C.InvalidArgumentError=It;C.InvalidOptionArgumentError=It;C.Option=Sn});var Ht=S((Ai,me)=>{"use strict";var Dn=require("net"),W=class extends Error{constructor(e){super(`${e} is locked`)}},N={old:new Set,young:new Set},wn=1e3*15,B,Ut=i=>new Promise((e,t)=>{let r=Dn.createServer();r.unref(),r.on("error",t),r.listen(i,()=>{let{port:o}=r.address();r.close(()=>{e(o)})})}),yn=function*(i){i&&(yield*i),yield 0};me.exports=async i=>{let e;i&&(e=typeof i.port=="number"?[i.port]:i.port),B===void 0&&(B=setInterval(()=>{N.old=N.young,N.young=new Set},wn),B.unref&&B.unref());for(let t of yn(e))try{let r=await Ut({...i,port:t});for(;N.old.has(r)||N.young.has(r);){if(t!==0)throw new W(t);r=await Ut({...i,port:t})}return N.young.add(r),r}catch(r){if(!["EADDRINUSE","EACCES"].includes(r.code)&&!(r instanceof W))throw r}throw new Error("No available ports found")};me.exports.makeRange=(i,e)=>{if(!Number.isInteger(i)||!Number.isInteger(e))throw new TypeError("`from` and `to` must be integer numbers");if(i<1024||i>65535)throw new RangeError("`from` must be between 1024 and 65535");if(e<1024||e>65536)throw new RangeError("`to` must be between 1024 and 65536");if(e<i)throw new RangeError("`to` must be greater than or equal to `from`");return function*(r,o){for(let n=r;n<=o;n++)yield n}(i,e)}});var w=d(require("fs")),mt=d(require("http")),y=d(require("path"));var nt=d(require("path")),it=d(require("os"));var pr="Comp Hub",hr="main",mr="container",_r="item",dr="/__global_config__",fr="local://",Er="comphubConfig",gr="https://intranet.comphub.cn",Or="https://iframe.comphub.cn",Cr="__remote__",Ar="__local__",Tr="__admin__",Pr="https://api.comphub.cn",Sr="http://localhost:7002",Mr="http://127.0.0.1:5000",Rr="http://localhost:5001",Ir="http://localhost:3580",br="https://apiadmin.comphub.cn",Lr="https://admin.comphub.cn",Dr="/_module_load_prefix_",wr="/_node_modules_load_prefix_",yr="/_comp_preview_prefix_local_",Nr="/__proxy__",xr="/__master__",Ur="authorization",Hr="x-refresh-token",$r="accept-language",vr="X-Token-Refreshed",Fr="team-id",Vr="comp-hub-db",kr="file-compiled",Yr="https://oss.comphub.cn",jr="oss:sts:token",Gr="oss:sts:expire",Br="https://prebuild.comphub.cn",Wr="/dev",Kr="/prod",qr="/node_modules/.prebuild_module",Xr="_metadata.json",Jr="vue/dist/vue.esm-bundler.js",Zr="react-jsx-loader",zr="vue3-sfc-loader",Qr="vue2-sfc-loader",eo="sass-compiler",to="less-compiler",Se="react",ro={COMP_FRAMEWORK_VUE:"vue",COMP_FRAMEWORK_REACT:Se},oo="comp.json",no="README.md",io="main.js",so="index.vue",ao=["index.jsx","index.js","index.tsx"],lo="/.comp_hub_temp",co="screenshot_mini.png",uo=1024*1024*10,po=1024*1024*3,ho=30,Me="list_local",Re="list_remote",mo={COMP_LIST_TYPE_LOCAL:Me,COMP_LIST_TYPE_REMOTE:Re},Ie="config",be="error",Le="dir",De="preview",we="extra",ye="deps",Ne="readme",xe="upgradeLog",_o={TAB_TYPE_CONFIG:Ie,TAB_TYPE_ERROR:be,TAB_TYPE_DIR:Le,TAB_TYPE_PREVIEW:De,TAB_TYPE_EXTRA:we,TAB_TYPE_DEPS:ye,TAB_TYPE_README:Ne,TAB_TYPE_UPGRADE_LOG:xe},Ue="mini",He="full",fo={COMP_EDIT_TAB_TYPE_MINI:Ue,COMP_EDIT_TAB_TYPE_FULL:He},$e="EDIT",ve="ADD",Eo={DIALOG_TYPE_EDIT:$e,DIALOG_TYPE_ADD:ve},Fe="ONLY_INSTALL",Ve="AUTO",ke="MAJOR_VERSION",Ye="MINOR_VERSION",je="EXACT_VERSION",go={COMP_MATCH_TYPE_ONLY_INSTALL:Fe,COMP_MATCH_TYPE_AUTO:Ve,COMP_MATCH_TYPE_MAJOR_VERSION:ke,COMP_MATCH_TYPE_MINOR_VERSION:Ye,COMP_MATCH_TYPE_EXACT_VERSION:je},Ge="online",Be="offline",Oo={COMP_UPDATE_TYPE_ONLINE:Ge,COMP_UPDATE_TYPE_OFFLINE:Be},We="NOT_EXIST",Ke="EXIST",Co={COMP_CHECK_STATUS_NOT_EXIST:We,COMP_CHECK_STATUS_EXIST:Ke},Ao="__id__",To=0,Po=1,So=-1,qe="checkPreviewListForm",Xe="checkExtraInfoForm",Je="checkCompConfig",Ze="checkUpgradeLogForm",ze="getCompError",Qe="afterCompDel",et="afterCompCancelCollect",tt="afterCompRenderRetry",rt="openCompTerminal",Mo={COMP_METHOD_KEY_CHECK_PREVIEW_LIST_FORM:qe,COMP_METHOD_KEY_CHECK_EXTRA_INFO_FORM:Xe,COMP_METHOD_KEY_CHECK_COMP_CONFIG:Je,COMP_METHOD_KEY_CHECK_UPGRADE_LOG_FORM:Ze,COMP_METHOD_KEY_GET_COMP_ERROR:ze,COMP_METHOD_KEY_AFTER_COMP_DEL:Qe,COMP_METHOD_KEY_AFTER_COMP_CANCEL_COLLECT:et,COMP_METHOD_KEY_AFTER_COMP_RENDER_RETRY:tt,COMP_METHOD_KEY_OPEN_COMP_TERMINAL:rt},Ro="compListStore",Io="compEditStore",bo="callbacks",Lo={CONTAINER:{SHARE:"share",COLLECT:"collect",LOCAL:"local",MINE:"mine",SIMILAR:"similar",TEAM_ALL:"teamAll",TEAM_MINE:"teamMine",TEAM_GROUP:"teamGroup",TEAM_ADD:"teamAdd"},ITEM:{PREVIEW_REMOTE:"previewRemote",PREVIEW_LOCAL:"previewLocal",CAROUSEL_REMOTE:"carouselRemote",CAROUSEL_LOCAL:"carouselLocal",EDIT_PANEL:"editPanel",STORAGE_WORKER:"storageWorker"}},Do="http://127.0.0.1",wo="http://localhost:8095",yo="http://localhost:8096",No="http://localhost:5198",xo="http://localhost:3056",Uo="https://www.comphub.cn",Ho="http://localhost:8101",$o="https://render.comphub.cn",vo="/item",Fo="/container",Vo="CREATE",ko="JOIN",Yo="EXIT",jo="teamAddMyComp",Go="teamCompList",Bo="teamCompGroupList",Wo="teamMyCompList",Ko="teamMyCompUpdate",qo="__v__",Xo="local",Jo="prod",Zo="local",zo="prod",Qo="http://localhost:5173",en="https://docs.comphub.cn",tn=20,rn=20,on="SUPER_ADMIN",nn="ADMIN",ot=Object.freeze(Object.defineProperty({__proto__:null,ACCEPT_LANGUAGE_HEADER_NAME:$r,ADMIN_SERVICE_PREFIX:Tr,ADMIN_SERVICE_URL_DEV:Ir,ADMIN_SERVICE_URL_PROD:br,ADMIN_WEB_URL_PROD:Lr,AUTHORIZATION_HEADER_NAME:Ur,CACHE_KEY_STS_EXPIRE_TIME:Gr,CACHE_KEY_STS_TOKEN:jr,COMPHUB_CONFIG_KEY:Er,COMP_ACTION_ICON_HEIGHT:rn,COMP_ACTION_ICON_WIDTH:tn,COMP_CHECK_STATUSES:Co,COMP_CHECK_STATUS_EXIST:Ke,COMP_CHECK_STATUS_NOT_EXIST:We,COMP_CONFIG_FILENAME:oo,COMP_EDIT_TAB_TYPES:fo,COMP_EDIT_TAB_TYPE_FULL:He,COMP_EDIT_TAB_TYPE_MINI:Ue,COMP_ENTRY_FILE:io,COMP_FIELD_COMP_ID:Ao,COMP_FRAMEWORK_REACT:Se,COMP_FRAMEWORK_TYPES:ro,COMP_FRAMEWORK_VUE:"vue",COMP_HUB_DEV_DOCS_URL:Qo,COMP_HUB_PROD_DOCS_URL:en,COMP_LIST_TYPES:mo,COMP_LIST_TYPE_LOCAL:Me,COMP_LIST_TYPE_REMOTE:Re,COMP_MATCH_TYPES:go,COMP_MATCH_TYPE_AUTO:Ve,COMP_MATCH_TYPE_EXACT_VERSION:je,COMP_MATCH_TYPE_MAJOR_VERSION:ke,COMP_MATCH_TYPE_MINOR_VERSION:Ye,COMP_MATCH_TYPE_ONLY_INSTALL:Fe,COMP_METHOD_KEY_AFTER_COMP_CANCEL_COLLECT:et,COMP_METHOD_KEY_AFTER_COMP_DEL:Qe,COMP_METHOD_KEY_AFTER_COMP_RENDER_RETRY:tt,COMP_METHOD_KEY_CHECK_COMP_CONFIG:Je,COMP_METHOD_KEY_CHECK_EXTRA_INFO_FORM:Xe,COMP_METHOD_KEY_CHECK_PREVIEW_LIST_FORM:qe,COMP_METHOD_KEY_CHECK_UPGRADE_LOG_FORM:Ze,COMP_METHOD_KEY_GET_COMP_ERROR:ze,COMP_METHOD_KEY_OPEN_COMP_TERMINAL:rt,COMP_PREVIEW_PREFIX_LOCAL:yr,COMP_README_FILENAME:no,COMP_SCREENSHOT_MINI_FILENAME:co,COMP_SUBMIT_MAX_FILE_COUNT:ho,COMP_SUBMIT_MAX_SINGLE_FILE_SIZE:po,COMP_SUBMIT_MAX_TOTAL_SIZE:uo,COMP_TEMP_DIR:lo,COMP_UPDATE_TYPES:Oo,COMP_UPDATE_TYPE_OFFLINE:Be,COMP_UPDATE_TYPE_ONLINE:Ge,COMP_USE_ENTRY_FILE:so,COMP_USE_ENTRY_FILE_REACT:ao,DIALOG_TYPES:Eo,DIALOG_TYPE_ADD:ve,DIALOG_TYPE_EDIT:$e,FILE_MANAGER_DIRNAME:fr,GLOBAL_CONFIG_PATH:dr,IFRAME_CONTAINER_WEBSITE_PATH:Fo,IFRAME_HOST:Do,IFRAME_ITEM_WEBSITE_PATH:vo,IFRAME_ROUTES:Lo,INDEX_DB_NAME:Vr,INDEX_DB_TABLE_NAME:kr,LESS_COMPILER_KEY:to,LOCAL_CHILD_IFRAME_URL:wo,LOCAL_ITEM_EXTRANET_URL:Ho,LOCAL_LEAF_IFRAME_URL:yo,LOCAL_MAIN_EXTRANET_URL:xo,LOCAL_MIDWAY_ENV_LOCAL:Xo,LOCAL_MIDWAY_ENV_PROD:Jo,LOCAL_SERVICE_PREFIX:Ar,LOCAL_SERVICE_URL_DEV:Mr,LOCAL_SERVICE_URL_DEV_SUB:Rr,LOCAL_TOP_IFRAME_URL:No,MASTER_API_PREFIX:xr,META_FILE_NAME:Xr,MODULE_LOAD_PREFIX:Dr,NODE_MODULES_LOAD_PREFIX:wr,OSS_CUSTOM_DOMAIN:Yr,PREBUILD_HOST:Br,PREBUILD_MAX_SINGLE_FILE_SIZE:52428800,PREBUILD_MODULE_DIR:qr,PREBUILD_MODULE_DIR_DEV:Wr,PREBUILD_MODULE_DIR_PROD:Kr,PROVIDE_KEYS:Mo,PROVIDE_KEY_CALLBACKS:bo,PROVIDE_KEY_COMP_EDIT_STORE:Io,PROVIDE_KEY_COMP_LIST_STORE:Ro,PROXY_PATH_PREFIX:Nr,REACT_JSX_LOADER_KEY:Zr,REFRESH_TOKEN_HEADER_NAME:Hr,REMOTE_ITEM_EXTRANET_URL:$o,REMOTE_MAIN_EXTRANET_URL:Uo,REMOTE_MIDWAY_ENV_LOCAL:Zo,REMOTE_MIDWAY_ENV_PROD:zo,REMOTE_SERVICE_PREFIX:Cr,REMOTE_SERVICE_URL_DEV:Sr,REMOTE_SERVICE_URL_PROD:Pr,ROLE_CODE_ADMIN:nn,ROLE_CODE_SUPER_ADMIN:on,ROUTE_STATE_KEY_VERSION:qo,SASS_COMPILER_KEY:eo,SCOPE_ID_TEAM_ADD_MY_COMP:jo,SCOPE_ID_TEAM_COMP_GROUP_LIST:Bo,SCOPE_ID_TEAM_COMP_LIST:Go,SCOPE_ID_TEAM_MY_COMP_LIST:Wo,SCOPE_ID_TEAM_MY_COMP_UPDATE:Ko,SITE_TITLE:pr,TAB_TYPES:_o,TAB_TYPE_CONFIG:Ie,TAB_TYPE_DEPS:ye,TAB_TYPE_DIR:Le,TAB_TYPE_ERROR:be,TAB_TYPE_EXTRA:we,TAB_TYPE_PREVIEW:De,TAB_TYPE_README:Ne,TAB_TYPE_UPGRADE_LOG:xe,TEAM_ID_HEADER_NAME:Fr,TEAM_OPERATE_TYPE_CREATE:Vo,TEAM_OPERATE_TYPE_EXIT:Yo,TEAM_OPERATE_TYPE_JOIN:ko,VERSION_COMPARE_GREATER:Po,VERSION_COMPARE_LESS:So,VERSION_COMPARE_SAME:To,VUE2_SFC_LOADER_KEY:Qr,VUE3_SFC_LOADER_KEY:zr,VUE_ESM_BUNDLER:Jr,WEBSITE_OSS_URL_IFRAME:Or,WEBSITE_OSS_URL_MAIN:gr,WEBSITE_PATH_CONTAINER:mr,WEBSITE_PATH_ITEM:_r,WEBSITE_PATH_MAIN:hr,X_TOKEN_REFRESHED_HEADER_NAME:vr},Symbol.toStringTag,{value:"Module"}));var v=5478,st=ot.REMOTE_SERVICE_URL_PROD,I=nt.default.join(it.default.tmpdir(),".comphub","master.json"),E={PREFIX:"/__master__",HEALTH:"/__master__/health",REGISTER:"/__master__/register",DEREGISTER:"/__master__/deregister",PROJECTS:"/__master__/projects",SHUTDOWN:"/__master__/shutdown"},at=500,lt=40,ct=2e3,F=5e3;var z=d(require("fs")),Z=d(require("path")),ut=d(require("crypto"));function V(i){return JSON.parse(z.default.readFileSync(i,"utf8"))}function pt(i){let e=i;for(let t=0;t<12;t++){try{let o=Z.default.join(e,"package.json");if(z.default.existsSync(o)){let n=V(o);if(n&&n.name==="comp-hub")return e}}catch{}let r=Z.default.dirname(e);if(r===e)break;e=r}return null}function ht(i){return ut.default.createHash("sha256").update(i).digest("hex").slice(0,8)}function g(i,e){return`http://localhost:${i}${e}`}var f={cyan:i=>`\x1B[36m${i}\x1B[0m`,green:i=>`\x1B[32m${i}\x1B[0m`,white:i=>`\x1B[37m${i}\x1B[0m`,yellow:i=>`\x1B[33m${i}\x1B[0m`,red:i=>`\x1B[31m${i}\x1B[0m`};var k=pt(__dirname)||y.default.resolve(__dirname,"..");function _t(){let i=y.default.join(k,"package.json"),e=V(i),t=y.default.join(k,e.main||"dist/index.js");return{pkg:e,entry:t}}function sn(i){let e=y.default.join(i,".comphub.json"),t=y.default.join(i,".comphub.js");try{if(w.default.existsSync(e))return V(e)}catch{}try{if(w.default.existsSync(t)){let r=require(t);return r.default||r}}catch{}return{}}function dt(i,e){let t=sn(e);return{dir:i.dir||t.dir||"./",api:i.api||t.api,allowDebug:i.allowDebug!=null?i.allowDebug:t.allowDebug!=null?t.allowDebug:!1,proxy:i.proxy||t.proxy,port:i.port,logLevel:i.logLevel||t.logLevel||"info"}}async function T(){try{if(w.default.existsSync(I)){let i=JSON.parse(w.default.readFileSync(I,"utf8"));try{if(process.kill(i.pid,0),await an(i.managementPort))return i}catch{}try{w.default.unlinkSync(I)}catch{}}}catch{}return null}function an(i){return new Promise(e=>{let t=mt.default.get(`http://localhost:${i}${E.HEALTH}`,r=>{let o="";r.on("data",n=>o+=n),r.on("end",()=>{try{let n=JSON.parse(o);e(typeof n.status=="string")}catch{e(!1)}})});t.on("error",()=>e(!1)),t.setTimeout(2e3,()=>{t.destroy(),e(!1)})})}var Dt=d(Lt(),1),{program:si,createCommand:ai,createArgument:li,createOption:ci,CommanderError:ui,InvalidArgumentError:pi,InvalidOptionArgumentError:hi,Command:wt,Argument:mi,Option:b,Help:_i}=Dt.default;function he(i){let e=[{label:"d",divisor:86400},{label:"h",divisor:3600},{label:"m",divisor:60},{label:"s",divisor:1}],t=Math.floor(i),r=[];for(let{label:o,divisor:n}of e)if(t>=n){let s=Math.floor(t/n);t=t%n,r.push(`${s}${o}`)}return r.length>0?r.join(" "):"0s"}async function L(i){if(i.port!=null)return i.port;let e=await T();return e?e.managementPort:v}var Jt=d(require("fs")),Zt=d(require("path"));var yt=d(require("http")),Nt=d(require("https"));var Mn="/api/v2/upgrade/check";function Rn(i){return(i||st).replace(/\/+$/,"")}function In(i,e,t){return new Promise((r,o)=>{let n=i.startsWith("https:")?Nt.default:yt.default,s=JSON.stringify(e),l=new URL(i),a={hostname:l.hostname,port:l.port||(l.protocol==="https:"?443:80),path:l.pathname+l.search,method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},c=n.request(a,u=>{let p="";u.setEncoding("utf8"),u.on("data",_=>p+=_),u.on("end",()=>{let _=p;try{_=JSON.parse(p)}catch{}r({status:u.statusCode||0,body:_})})});c.on("error",o),c.setTimeout(t||F,()=>{c.destroy(new Error("Request timeout"))}),c.write(s),c.end()})}function bn(i){if(!i||i.status!==200)throw new Error(i.status?`HTTP ${i.status}`:"No response");let e=i.body?.data;if(!e||typeof e.hasUpgrade!="boolean")throw new Error("Invalid response format");return{hasUpgrade:e.hasUpgrade,isForce:!!e.isForce,latestVersion:typeof e.latestVersion=="string"?e.latestVersion:""}}function Ln(i){return i.hasUpgrade&&i.isForce?"block":i.hasUpgrade?"notice":"none"}async function xt(i){let{base:e,compHubVersion:t,timeout:r,request:o=In}=i,n=`${Rn(e)}${Mn}`;try{let s=await o(n,{compHubVersion:t},r),l=bn(s);return{ok:!0,...l,verdict:Ln(l)}}catch(s){return{ok:!1,error:s?.message||String(s)}}}var Ft=d(require("fs")),Vt=d(require("path")),kt=require("child_process"),_e=d(Ht());var K=d(require("http"));function Nn(i){try{return JSON.parse(i)}catch{return i}}function $(i){return new Promise(e=>{let t=K.default.get(i,r=>{let o="";r.on("data",n=>o+=n),r.on("end",()=>e({ok:!0,status:r.statusCode,body:Nn(o)}))});t.on("error",r=>e({ok:!1,error:r.message})),t.setTimeout(ct,()=>{t.destroy(),e({ok:!1,error:"Request timeout"})})})}function M(i,e){return new Promise(t=>{let r=JSON.stringify(e),o=new URL(i),n={hostname:o.hostname,port:o.port,path:o.pathname,method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},s=K.default.request(n,l=>{let a="";l.on("data",c=>a+=c),l.on("end",()=>{try{t({ok:!0,body:JSON.parse(a)})}catch{t({ok:!1,error:"Invalid JSON response"})}})});s.on("error",l=>t({ok:!1,error:l.message})),s.setTimeout(F,()=>{s.destroy(),t({ok:!1,error:"Request timeout"})}),s.write(r),s.end()})}function $t(i,e){return new Promise((t,r)=>{let o=new URL(i),n={hostname:o.hostname,port:o.port,path:o.pathname,method:"GET",headers:{Accept:"text/event-stream"}},s=K.default.request(n,l=>{if(l.statusCode!==200){r(new Error(`SSE connection failed (HTTP ${l.statusCode})`));return}let a="";l.on("data",c=>{a+=c.toString();let u=a.split(`
19
+ `)}),this}};function Pt(i,e){i._hasHelpOption&&e.find(r=>r===i._helpLongFlag||r===i._helpShortFlag)&&(i.outputHelp(),i._exit(0,"commander.helpDisplayed","(outputHelp)"))}function St(i){return i.map(e=>{if(!e.startsWith("--inspect"))return e;let t,r="127.0.0.1",o="9229",n;return(n=e.match(/^(--inspect(-brk)?)$/))!==null?t=n[1]:(n=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=n[1],/^\d+$/.test(n[3])?o=n[3]:r=n[3]):(n=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=n[1],r=n[3],o=n[4]),t&&o!=="0"?`${t}=${r}:${parseInt(o)+1}`:e})}function H(i){let e=[];for(let t=i;t;t=t.parent)e.push(t);return e}Mt.Command=he});var Lt=S((A,Dt)=>{var{Argument:Mn}=G(),{Command:It}=Rt(),{CommanderError:Rn,InvalidArgumentError:bt}=U(),{Help:In}=ie(),{Option:bn}=le();A=Dt.exports=new It;A.program=A;A.Argument=Mn;A.Command=It;A.CommanderError=Rn;A.Help=In;A.InvalidArgumentError=bt;A.InvalidOptionArgumentError=bt;A.Option=bn});var $t=S((Mi,me)=>{"use strict";var xn=require("net"),K=class extends Error{constructor(e){super(`${e} is locked`)}},y={old:new Set,young:new Set},Un=1e3*15,W,Ht=i=>new Promise((e,t)=>{let r=xn.createServer();r.unref(),r.on("error",t),r.listen(i,()=>{let{port:o}=r.address();r.close(()=>{e(o)})})}),Hn=function*(i){i&&(yield*i),yield 0};me.exports=async i=>{let e;i&&(e=typeof i.port=="number"?[i.port]:i.port),W===void 0&&(W=setInterval(()=>{y.old=y.young,y.young=new Set},Un),W.unref&&W.unref());for(let t of Hn(e))try{let r=await Ht({...i,port:t});for(;y.old.has(r)||y.young.has(r);){if(t!==0)throw new K(t);r=await Ht({...i,port:t})}return y.young.add(r),r}catch(r){if(!["EADDRINUSE","EACCES"].includes(r.code)&&!(r instanceof K))throw r}throw new Error("No available ports found")};me.exports.makeRange=(i,e)=>{if(!Number.isInteger(i)||!Number.isInteger(e))throw new TypeError("`from` and `to` must be integer numbers");if(i<1024||i>65535)throw new RangeError("`from` must be between 1024 and 65535");if(e<1024||e>65536)throw new RangeError("`to` must be between 1024 and 65536");if(e<i)throw new RangeError("`to` must be greater than or equal to `from`");return function*(r,o){for(let n=r;n<=o;n++)yield n}(i,e)}});var N=d(require("fs")),mt=d(require("http")),w=d(require("path"));var it=d(require("path")),st=d(require("os"));var hr="Comp Hub",_r="main",mr="container",dr="item",Er="/__global_config__",fr="local://",gr="comphubConfig",Or="https://intranet.comphub.cn",Ar="https://iframe.comphub.cn",Cr="https://cdn.comphub.cn/vendor",Tr="__remote__",Pr="__local__",Sr="__admin__",Mr="https://api.comphub.cn",Rr="http://localhost:7002",Ir="http://127.0.0.1:5000",br="http://localhost:5001",Dr="http://localhost:3580",Lr="https://apiadmin.comphub.cn",Nr="https://admin.comphub.cn",wr="/_module_load_prefix_",yr="/_node_modules_load_prefix_",xr="/_comp_preview_prefix_local_",Ur="/__proxy__",Hr="/__master__",$r="authorization",vr="x-refresh-token",Fr="accept-language",Vr="X-Token-Refreshed",kr="team-id",jr="comp-hub-db",Yr="file-compiled",Gr="https://oss.comphub.cn",Br="oss:sts:token",Wr="oss:sts:expire",Kr="https://prebuild.comphub.cn",qr="/dev",Xr="/prod",Jr="/node_modules/.prebuild_module",zr="_metadata.json",Zr="vue/dist/vue.esm-bundler.js",Qr="react-jsx-loader",eo="vue3-sfc-loader",to="vue2-sfc-loader",ro="sass-compiler",oo="less-compiler",Me="react",no={COMP_FRAMEWORK_VUE:"vue",COMP_FRAMEWORK_REACT:Me},io="comp.json",so="README.md",ao="main.js",lo="index.vue",co=["index.jsx","index.js","index.tsx"],uo="/.comp_hub_temp",po="screenshot_mini.png",ho=1024*1024*10,_o=1024*1024*3,mo=30,Re="list_local",Ie="list_remote",Eo={COMP_LIST_TYPE_LOCAL:Re,COMP_LIST_TYPE_REMOTE:Ie},be="config",De="error",Le="dir",Ne="preview",we="extra",ye="deps",xe="readme",Ue="upgradeLog",fo={TAB_TYPE_CONFIG:be,TAB_TYPE_ERROR:De,TAB_TYPE_DIR:Le,TAB_TYPE_PREVIEW:Ne,TAB_TYPE_EXTRA:we,TAB_TYPE_DEPS:ye,TAB_TYPE_README:xe,TAB_TYPE_UPGRADE_LOG:Ue},He="mini",$e="full",go={COMP_EDIT_TAB_TYPE_MINI:He,COMP_EDIT_TAB_TYPE_FULL:$e},ve="EDIT",Fe="ADD",Oo={DIALOG_TYPE_EDIT:ve,DIALOG_TYPE_ADD:Fe},Ve="ONLY_INSTALL",ke="AUTO",je="MAJOR_VERSION",Ye="MINOR_VERSION",Ge="EXACT_VERSION",Ao={COMP_MATCH_TYPE_ONLY_INSTALL:Ve,COMP_MATCH_TYPE_AUTO:ke,COMP_MATCH_TYPE_MAJOR_VERSION:je,COMP_MATCH_TYPE_MINOR_VERSION:Ye,COMP_MATCH_TYPE_EXACT_VERSION:Ge},Be="online",We="offline",Co={COMP_UPDATE_TYPE_ONLINE:Be,COMP_UPDATE_TYPE_OFFLINE:We},Ke="NOT_EXIST",qe="EXIST",To={COMP_CHECK_STATUS_NOT_EXIST:Ke,COMP_CHECK_STATUS_EXIST:qe},Po="__id__",So=0,Mo=1,Ro=-1,Xe="checkPreviewListForm",Je="checkExtraInfoForm",ze="checkCompConfig",Ze="checkUpgradeLogForm",Qe="getCompError",et="afterCompDel",tt="afterCompCancelCollect",rt="afterCompRenderRetry",ot="openCompTerminal",Io={COMP_METHOD_KEY_CHECK_PREVIEW_LIST_FORM:Xe,COMP_METHOD_KEY_CHECK_EXTRA_INFO_FORM:Je,COMP_METHOD_KEY_CHECK_COMP_CONFIG:ze,COMP_METHOD_KEY_CHECK_UPGRADE_LOG_FORM:Ze,COMP_METHOD_KEY_GET_COMP_ERROR:Qe,COMP_METHOD_KEY_AFTER_COMP_DEL:et,COMP_METHOD_KEY_AFTER_COMP_CANCEL_COLLECT:tt,COMP_METHOD_KEY_AFTER_COMP_RENDER_RETRY:rt,COMP_METHOD_KEY_OPEN_COMP_TERMINAL:ot},bo="compListStore",Do="compEditStore",Lo="callbacks",No={CONTAINER:{SHARE:"share",COLLECT:"collect",LOCAL:"local",MINE:"mine",SIMILAR:"similar",TEAM_ALL:"teamAll",TEAM_MINE:"teamMine",TEAM_GROUP:"teamGroup",TEAM_ADD:"teamAdd"},ITEM:{PREVIEW_REMOTE:"previewRemote",PREVIEW_LOCAL:"previewLocal",CAROUSEL_REMOTE:"carouselRemote",CAROUSEL_LOCAL:"carouselLocal",EDIT_PANEL:"editPanel",STORAGE_WORKER:"storageWorker"}},wo="http://127.0.0.1",yo="http://localhost:8095",xo="http://localhost:8096",Uo="http://localhost:5198",Ho="http://localhost:3056",$o="https://www.comphub.cn",vo="http://localhost:8101",Fo="https://render.comphub.cn",Vo="/item",ko="/container",jo="CREATE",Yo="JOIN",Go="EXIT",Bo="teamAddMyComp",Wo="teamCompList",Ko="teamCompGroupList",qo="teamMyCompList",Xo="teamMyCompUpdate",Jo="__v__",zo="local",Zo="prod",Qo="local",en="prod",tn="http://localhost:5173",rn="https://docs.comphub.cn",on="1.5em",nn="1.5em",sn="SUPER_ADMIN",an="ADMIN",v={MAIN:"main",IFRAME_CONTAINER:"iframeContainer",IFRAME_ITEM:"iframeItem"},ln={[v.MAIN]:{ENABLED:!0,DSN:"https://eb372d9ca4c4b35497e99966cae2c1b2@o4512055411146752.ingest.us.sentry.io/4512055626891264",TRACES_SAMPLE_RATE:1,TRACE_PROPAGATION_TARGETS:["localhost"]},[v.IFRAME_CONTAINER]:{ENABLED:!0,DSN:"https://09eacfc954a80beb1aed90bbdb09b3f6@o4512055411146752.ingest.us.sentry.io/4512055609720832",TRACES_SAMPLE_RATE:1,TRACE_PROPAGATION_TARGETS:["localhost"]},[v.IFRAME_ITEM]:{ENABLED:!0,DSN:"https://0a564c86371356eccceff7854690e489@o4512055411146752.ingest.us.sentry.io/4512055615029249",TRACES_SAMPLE_RATE:1,TRACE_PROPAGATION_TARGETS:["localhost"]}},cn={"vue3-sfc-loader":"vue3-sfc-loader-f3c985c9.js","vue2-sfc-loader":"vue2-sfc-loader-445fb53a.js","react-jsx-loader":"react-jsx-loader-b8a3bbcb.js","sass-compiler":"sass-compiler-482885df.js","less-compiler":"less-compiler-0cc8346f.js"},nt=Object.freeze(Object.defineProperty({__proto__:null,ACCEPT_LANGUAGE_HEADER_NAME:Fr,ADMIN_SERVICE_PREFIX:Sr,ADMIN_SERVICE_URL_DEV:Dr,ADMIN_SERVICE_URL_PROD:Lr,ADMIN_WEB_URL_PROD:Nr,AUTHORIZATION_HEADER_NAME:$r,CACHE_KEY_STS_EXPIRE_TIME:Wr,CACHE_KEY_STS_TOKEN:Br,COMPHUB_CONFIG_KEY:gr,COMP_ACTION_ICON_HEIGHT:nn,COMP_ACTION_ICON_WIDTH:on,COMP_CHECK_STATUSES:To,COMP_CHECK_STATUS_EXIST:qe,COMP_CHECK_STATUS_NOT_EXIST:Ke,COMP_CONFIG_FILENAME:io,COMP_EDIT_TAB_TYPES:go,COMP_EDIT_TAB_TYPE_FULL:$e,COMP_EDIT_TAB_TYPE_MINI:He,COMP_ENTRY_FILE:ao,COMP_FIELD_COMP_ID:Po,COMP_FRAMEWORK_REACT:Me,COMP_FRAMEWORK_TYPES:no,COMP_FRAMEWORK_VUE:"vue",COMP_HUB_DEV_DOCS_URL:tn,COMP_HUB_PROD_DOCS_URL:rn,COMP_LIST_TYPES:Eo,COMP_LIST_TYPE_LOCAL:Re,COMP_LIST_TYPE_REMOTE:Ie,COMP_MATCH_TYPES:Ao,COMP_MATCH_TYPE_AUTO:ke,COMP_MATCH_TYPE_EXACT_VERSION:Ge,COMP_MATCH_TYPE_MAJOR_VERSION:je,COMP_MATCH_TYPE_MINOR_VERSION:Ye,COMP_MATCH_TYPE_ONLY_INSTALL:Ve,COMP_METHOD_KEY_AFTER_COMP_CANCEL_COLLECT:tt,COMP_METHOD_KEY_AFTER_COMP_DEL:et,COMP_METHOD_KEY_AFTER_COMP_RENDER_RETRY:rt,COMP_METHOD_KEY_CHECK_COMP_CONFIG:ze,COMP_METHOD_KEY_CHECK_EXTRA_INFO_FORM:Je,COMP_METHOD_KEY_CHECK_PREVIEW_LIST_FORM:Xe,COMP_METHOD_KEY_CHECK_UPGRADE_LOG_FORM:Ze,COMP_METHOD_KEY_GET_COMP_ERROR:Qe,COMP_METHOD_KEY_OPEN_COMP_TERMINAL:ot,COMP_PREVIEW_PREFIX_LOCAL:xr,COMP_README_FILENAME:so,COMP_SCREENSHOT_MINI_FILENAME:po,COMP_SUBMIT_MAX_FILE_COUNT:mo,COMP_SUBMIT_MAX_SINGLE_FILE_SIZE:_o,COMP_SUBMIT_MAX_TOTAL_SIZE:ho,COMP_TEMP_DIR:uo,COMP_UPDATE_TYPES:Co,COMP_UPDATE_TYPE_OFFLINE:We,COMP_UPDATE_TYPE_ONLINE:Be,COMP_USE_ENTRY_FILE:lo,COMP_USE_ENTRY_FILE_REACT:co,DIALOG_TYPES:Oo,DIALOG_TYPE_ADD:Fe,DIALOG_TYPE_EDIT:ve,FILE_MANAGER_DIRNAME:fr,GLOBAL_CONFIG_PATH:Er,IFRAME_CONTAINER_WEBSITE_PATH:ko,IFRAME_HOST:wo,IFRAME_ITEM_WEBSITE_PATH:Vo,IFRAME_ROUTES:No,INDEX_DB_NAME:jr,INDEX_DB_TABLE_NAME:Yr,LESS_COMPILER_KEY:oo,LOCAL_CHILD_IFRAME_URL:yo,LOCAL_ITEM_EXTRANET_URL:vo,LOCAL_LEAF_IFRAME_URL:xo,LOCAL_MAIN_EXTRANET_URL:Ho,LOCAL_MIDWAY_ENV_LOCAL:zo,LOCAL_MIDWAY_ENV_PROD:Zo,LOCAL_SERVICE_PREFIX:Pr,LOCAL_SERVICE_URL_DEV:Ir,LOCAL_SERVICE_URL_DEV_SUB:br,LOCAL_TOP_IFRAME_URL:Uo,MASTER_API_PREFIX:Hr,META_FILE_NAME:zr,MODULE_LOAD_PREFIX:wr,NODE_MODULES_LOAD_PREFIX:yr,OSS_CUSTOM_DOMAIN:Gr,PREBUILD_HOST:Kr,PREBUILD_MAX_SINGLE_FILE_SIZE:52428800,PREBUILD_MODULE_DIR:Jr,PREBUILD_MODULE_DIR_DEV:qr,PREBUILD_MODULE_DIR_PROD:Xr,PROVIDE_KEYS:Io,PROVIDE_KEY_CALLBACKS:Lo,PROVIDE_KEY_COMP_EDIT_STORE:Do,PROVIDE_KEY_COMP_LIST_STORE:bo,PROXY_PATH_PREFIX:Ur,REACT_JSX_LOADER_KEY:Qr,REFRESH_TOKEN_HEADER_NAME:vr,REMOTE_ITEM_EXTRANET_URL:Fo,REMOTE_MAIN_EXTRANET_URL:$o,REMOTE_MIDWAY_ENV_LOCAL:Qo,REMOTE_MIDWAY_ENV_PROD:en,REMOTE_SERVICE_PREFIX:Tr,REMOTE_SERVICE_URL_DEV:Rr,REMOTE_SERVICE_URL_PROD:Mr,ROLE_CODE_ADMIN:an,ROLE_CODE_SUPER_ADMIN:sn,ROUTE_STATE_KEY_VERSION:Jo,SASS_COMPILER_KEY:ro,SCOPE_ID_TEAM_ADD_MY_COMP:Bo,SCOPE_ID_TEAM_COMP_GROUP_LIST:Ko,SCOPE_ID_TEAM_COMP_LIST:Wo,SCOPE_ID_TEAM_MY_COMP_LIST:qo,SCOPE_ID_TEAM_MY_COMP_UPDATE:Xo,SENTRY_PROJECTS:ln,SENTRY_PROJECT_NAMES:v,SITE_TITLE:hr,TAB_TYPES:fo,TAB_TYPE_CONFIG:be,TAB_TYPE_DEPS:ye,TAB_TYPE_DIR:Le,TAB_TYPE_ERROR:De,TAB_TYPE_EXTRA:we,TAB_TYPE_PREVIEW:Ne,TAB_TYPE_README:xe,TAB_TYPE_UPGRADE_LOG:Ue,TEAM_ID_HEADER_NAME:kr,TEAM_OPERATE_TYPE_CREATE:jo,TEAM_OPERATE_TYPE_EXIT:Go,TEAM_OPERATE_TYPE_JOIN:Yo,VENDOR_CDN_BASE:Cr,VENDOR_LOADER_FILES:cn,VERSION_COMPARE_GREATER:Mo,VERSION_COMPARE_LESS:Ro,VERSION_COMPARE_SAME:So,VUE2_SFC_LOADER_KEY:to,VUE3_SFC_LOADER_KEY:eo,VUE_ESM_BUNDLER:Zr,WEBSITE_OSS_URL_IFRAME:Ar,WEBSITE_OSS_URL_MAIN:Or,WEBSITE_PATH_CONTAINER:mr,WEBSITE_PATH_ITEM:dr,WEBSITE_PATH_MAIN:_r,X_TOKEN_REFRESHED_HEADER_NAME:Vr},Symbol.toStringTag,{value:"Module"}));var F=5478,at=nt.REMOTE_SERVICE_URL_PROD,I=it.default.join(st.default.tmpdir(),".comphub","master.json"),f={PREFIX:"/__master__",HEALTH:"/__master__/health",REGISTER:"/__master__/register",DEREGISTER:"/__master__/deregister",PROJECTS:"/__master__/projects",SHUTDOWN:"/__master__/shutdown"},lt=500,ct=40,ut=2e3,V=5e3;var Q=d(require("fs")),Z=d(require("path")),pt=d(require("crypto"));function k(i){return JSON.parse(Q.default.readFileSync(i,"utf8"))}function ht(i){let e=i;for(let t=0;t<12;t++){try{let o=Z.default.join(e,"package.json");if(Q.default.existsSync(o)){let n=k(o);if(n&&n.name==="comp-hub")return e}}catch{}let r=Z.default.dirname(e);if(r===e)break;e=r}return null}function _t(i){return pt.default.createHash("sha256").update(i).digest("hex").slice(0,8)}function g(i,e){return`http://localhost:${i}${e}`}var E={cyan:i=>`\x1B[36m${i}\x1B[0m`,green:i=>`\x1B[32m${i}\x1B[0m`,white:i=>`\x1B[37m${i}\x1B[0m`,yellow:i=>`\x1B[33m${i}\x1B[0m`,red:i=>`\x1B[31m${i}\x1B[0m`};var j=ht(__dirname)||w.default.resolve(__dirname,"..");function dt(){let i=w.default.join(j,"package.json"),e=k(i),t=w.default.join(j,e.main||"dist/index.js");return{pkg:e,entry:t}}function un(i){let e=w.default.join(i,".comphub.json"),t=w.default.join(i,".comphub.js");try{if(N.default.existsSync(e))return k(e)}catch{}try{if(N.default.existsSync(t)){let r=require(t);return r.default||r}}catch{}return{}}function Et(i,e){let t=un(e);return{dir:i.dir||t.dir||"./",api:i.api||t.api,allowDebug:i.allowDebug!=null?i.allowDebug:t.allowDebug!=null?t.allowDebug:!1,proxy:i.proxy||t.proxy,port:i.port,logLevel:i.logLevel||t.logLevel||"info"}}async function T(){try{if(N.default.existsSync(I)){let i=JSON.parse(N.default.readFileSync(I,"utf8"));try{if(process.kill(i.pid,0),await pn(i.managementPort))return i}catch{}try{N.default.unlinkSync(I)}catch{}}}catch{}return null}function pn(i){return new Promise(e=>{let t=mt.default.get(`http://localhost:${i}${f.HEALTH}`,r=>{let o="";r.on("data",n=>o+=n),r.on("end",()=>{try{let n=JSON.parse(o);e(typeof n.status=="string")}catch{e(!1)}})});t.on("error",()=>e(!1)),t.setTimeout(2e3,()=>{t.destroy(),e(!1)})})}var Nt=d(Lt(),1),{program:ui,createCommand:pi,createArgument:hi,createOption:_i,CommanderError:mi,InvalidArgumentError:di,InvalidOptionArgumentError:Ei,Command:wt,Argument:fi,Option:b,Help:gi}=Nt.default;function _e(i){let e=[{label:"d",divisor:86400},{label:"h",divisor:3600},{label:"m",divisor:60},{label:"s",divisor:1}],t=Math.floor(i),r=[];for(let{label:o,divisor:n}of e)if(t>=n){let s=Math.floor(t/n);t=t%n,r.push(`${s}${o}`)}return r.length>0?r.join(" "):"0s"}async function D(i){if(i.port!=null)return i.port;let e=await T();return e?e.managementPort:F}var zt=d(require("fs")),Zt=d(require("path"));var yt=d(require("http")),xt=d(require("https"));var Dn="/api/v2/upgrade/check";function Ln(i){return(i||at).replace(/\/+$/,"")}function Nn(i,e,t){return new Promise((r,o)=>{let n=i.startsWith("https:")?xt.default:yt.default,s=JSON.stringify(e),l=new URL(i),a={hostname:l.hostname,port:l.port||(l.protocol==="https:"?443:80),path:l.pathname+l.search,method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},c=n.request(a,u=>{let p="";u.setEncoding("utf8"),u.on("data",m=>p+=m),u.on("end",()=>{let m=p;try{m=JSON.parse(p)}catch{}r({status:u.statusCode||0,body:m})})});c.on("error",o),c.setTimeout(t||V,()=>{c.destroy(new Error("Request timeout"))}),c.write(s),c.end()})}function wn(i){if(!i||i.status!==200)throw new Error(i.status?`HTTP ${i.status}`:"No response");let e=i.body?.data;if(!e||typeof e.hasUpgrade!="boolean")throw new Error("Invalid response format");return{hasUpgrade:e.hasUpgrade,isForce:!!e.isForce,latestVersion:typeof e.latestVersion=="string"?e.latestVersion:""}}function yn(i){return i.hasUpgrade&&i.isForce?"block":i.hasUpgrade?"notice":"none"}async function Ut(i){let{base:e,compHubVersion:t,timeout:r,request:o=Nn}=i,n=`${Ln(e)}${Dn}`;try{let s=await o(n,{compHubVersion:t},r),l=wn(s);return{ok:!0,...l,verdict:yn(l)}}catch(s){return{ok:!1,error:s?.message||String(s)}}}var Vt=d(require("fs")),kt=d(require("path")),jt=require("child_process"),de=d($t());var q=d(require("http"));function $n(i){try{return JSON.parse(i)}catch{return i}}function $(i){return new Promise(e=>{let t=q.default.get(i,r=>{let o="";r.on("data",n=>o+=n),r.on("end",()=>e({ok:!0,status:r.statusCode,body:$n(o)}))});t.on("error",r=>e({ok:!1,error:r.message})),t.setTimeout(ut,()=>{t.destroy(),e({ok:!1,error:"Request timeout"})})})}function M(i,e){return new Promise(t=>{let r=JSON.stringify(e),o=new URL(i),n={hostname:o.hostname,port:o.port,path:o.pathname,method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},s=q.default.request(n,l=>{let a="";l.on("data",c=>a+=c),l.on("end",()=>{try{t({ok:!0,body:JSON.parse(a)})}catch{t({ok:!1,error:"Invalid JSON response"})}})});s.on("error",l=>t({ok:!1,error:l.message})),s.setTimeout(V,()=>{s.destroy(),t({ok:!1,error:"Request timeout"})}),s.write(r),s.end()})}function vt(i,e){return new Promise((t,r)=>{let o=new URL(i),n={hostname:o.hostname,port:o.port,path:o.pathname,method:"GET",headers:{Accept:"text/event-stream"}},s=q.default.request(n,l=>{if(l.statusCode!==200){r(new Error(`SSE connection failed (HTTP ${l.statusCode})`));return}let a="";l.on("data",c=>{a+=c.toString();let u=a.split(`
20
20
 
21
- `);a=u.pop()||"";for(let p of u){let _=p.startsWith("data: ")?p.slice(6):p;try{let O=JSON.parse(_);process.stdout.write(O)}catch{}}}),l.on("end",()=>t()),l.on("error",c=>r(c))});s.on("error",l=>r(l)),s.setTimeout(0),s.end()})}function vt(i,e){return M(g(i,"/__master__/deregister"),{hash:e})}var{green:xn}=f;async function Un(){for(let i=0;i<lt;i++){let e=await T();if(e)return e;await new Promise(t=>setTimeout(t,at))}return null}async function Hn(i,e,t){let r=Vt.default.join(k,"dist/master.js");if(!Ft.default.existsSync(r))throw new Error("Master entry file not found, startup failed");let o=["--port",String(i),"--public-port",String(i)],n=(0,kt.spawn)(process.execPath,["--no-deprecation",r,...o],{stdio:["inherit","pipe","pipe"],cwd:t,env:{...process.env,COMP_HUB_VERSION:e.version}}),s="";n.stderr&&n.stderr.on("data",a=>{process.stderr.write(a)}),n.stdout&&n.stdout.on("data",a=>{s+=a.toString();let c=s.split(`
21
+ `);a=u.pop()||"";for(let p of u){let m=p.startsWith("data: ")?p.slice(6):p;try{let O=JSON.parse(m);process.stdout.write(O)}catch{}}}),l.on("end",()=>t()),l.on("error",c=>r(c))});s.on("error",l=>r(l)),s.setTimeout(0),s.end()})}function Ft(i,e){return M(g(i,"/__master__/deregister"),{hash:e})}var{green:vn}=E;async function Fn(){for(let i=0;i<ct;i++){let e=await T();if(e)return e;await new Promise(t=>setTimeout(t,lt))}return null}async function Vn(i,e,t){let r=kt.default.join(j,"dist/master.js");if(!Vt.default.existsSync(r))throw new Error("Master entry file not found, startup failed");let o=["--port",String(i),"--public-port",String(i)],n=(0,jt.spawn)(process.execPath,["--no-deprecation",r,...o],{stdio:["inherit","pipe","pipe"],cwd:t,env:{...process.env,COMP_HUB_VERSION:e.version}}),s="";n.stderr&&n.stderr.on("data",a=>{process.stderr.write(a)}),n.stdout&&n.stdout.on("data",a=>{s+=a.toString();let c=s.split(`
22
22
  `);s=c.pop()||"";for(let u of c)/^\[[0-9a-f]{8}\]/.test(u)||process.stdout.write(u+`
23
- `)}),["SIGINT","SIGTERM"].forEach(a=>{process.on(a,()=>{n.kill(a)})}),n.on("exit",a=>{s&&!/^\[[0-9a-f]{8}\]/.test(s)&&process.stdout.write(s),process.exit(a||0)});let l=await Un();if(!l)throw n.kill(),new Error("Master startup timeout");return{runtime:l}}async function Yt(i,e){let t=!1,r=0,o=await T();if(o){let a=i.port!=null?i.port:o.publicPort;return i.port!=null&&o.publicPort!==a&&(t=!0,r=o.publicPort),{runtime:o,portMismatch:t,runningPublicPort:r}}let n=i.port!=null?i.port:v,s=await(0,_e.default)({port:_e.default.makeRange(n,n+100)}),{runtime:l}=await Hn(s,e,process.cwd());return{runtime:l,portMismatch:t,runningPublicPort:r}}async function jt(i,e,t,r){let o={hash:e,cwd:t,dir:r.dir||"./"};r.api&&(o.api=r.api),r.allowDebug&&(o.allowDebug=!0),r.proxy&&(o.proxy=r.proxy),r.logLevel&&(o.logLevel=r.logLevel);let n=await M(g(i,E.REGISTER),o);if(!n.ok)throw new Error(n.error||"Registration failed");console.log(`${xn("\u2713")} Project registered (hash: ${e})`)}var{cyan:D,green:q,white:Gt,yellow:$n,red:Bt}=f;function Wt(i,e,t,r,o,n){let{portMismatch:s,runningPublicPort:l}=n,a=`http://localhost:${r}/${t}/main/`,c=["",D(" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 "),D(" \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557"),D(" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D"),D(" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557"),D(" \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D"),D(" \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D "),"","",` ${q("Version")} ${i.version}`,` ${q("Project")} ${e}`,` ${q("Hash")} ${t}`,` ${q("Port")} ${r}`,"",` ${$n("URL")} ${D(a)}`,"",Gt(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),"",` ${"comphub status".padEnd(30)}View all projects`,` ${`comphub stop ${t}`.padEnd(30)}Stop current project`,` ${"comphub stop --all".padEnd(30)}Stop all projects`,` ${"comphub kill".padEnd(30)}Shutdown master`,""];s&&c.push(Gt(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),"",Bt(` \u26A0 Master is already running on port ${l}, ignoring -p ${o.port}`),Bt(" To change port, please run comphub kill first"),""),console.log(c.join(`
24
- `))}var{cyan:Kt,green:vn,white:qt,yellow:Xt,red:de}=f;async function fe(i,e){Jt.default.existsSync(Zt.default.join(process.cwd(),"package.json"))||(console.error(`${de("\u2717")} Current directory is not a Node.js project`),process.exit(1));let t=process.cwd(),r=ht(t);e=dt(e,t);let o=await xt({base:e.api,compHubVersion:i.version});if(o.ok&&o.verdict==="block"){let m=o.latestVersion&&o.latestVersion!==i.version?`, latest version v${o.latestVersion}`:"";console.error(""),console.error(`${de("\u2717")} comp-hub must be upgraded before it can start (current v${i.version}${m})`),console.error(` Please run the upgrade command: ${Kt("npm install comp-hub@latest -g")}`),console.error(" Then run comphub again after upgrading"),console.error(""),process.exit(1)}console.log(`${vn("\u2713")} ${i.name} v${i.version}`);let{runtime:n,portMismatch:s,runningPublicPort:l}=await Yt(e,i),a=n.managementPort,c=n.publicPort;if(await jt(a,r,t,e),Wt(i,t,r,c,e,{portMismatch:s,runningPublicPort:l}),o.ok&&o.verdict==="notice"){let m=o.latestVersion&&o.latestVersion!==i.version?` (latest version v${o.latestVersion})`:"";console.log(""),console.log(`${Xt("\u2139")} comp-hub has a new version available${m}; run the upgrade command to update:`),console.log(` ${Kt("npm install comp-hub@latest -g")}`),console.log("")}else o.ok||(console.log(""),console.log(`${Xt("\u26A0")} comp-hub version check failed (${o.error}); skipping the version check for this run`),console.log(""));let u=!1,p=async()=>{if(!u){u=!0;try{await vt(a,r)}catch{}process.exit(0)}};process.on("SIGINT",p),process.on("SIGTERM",p),console.log(`
25
- ${qt("\u2500")} Streaming logs from MidwayJS (${r}) ${qt("\u2500")}
26
- `);let _=`http://localhost:${a}/__master__/projects/${r}/logs`;try{await $t(_,r)}catch(O){console.error(`
27
- ${de("\u2717")} Log stream error: ${O.message}`)}}var{green:R,yellow:zt,cyan:Qt,white:A,red:Fn}=f;async function Ee(i){let e=await L(i),t=await T(),r=t?t.publicPort:e;console.log(`
28
- ${zt("\u25CF")} Master Status
29
- `);let o=await $(g(e,E.HEALTH));(!o.ok||!o.body||typeof o.body.status!="string")&&(console.error(`${Fn("\u2717")} Master service is not running`),process.exit(1));let n=o.body,s=n.status==="running"?R("\u25CF"):Qt("\u25CF");console.log(` ${R("Status")} ${s} ${n.status}`),console.log(` ${R("Version")} ${A(n.version||"")}`),console.log(` ${R("Uptime")} ${A(he(n.uptime??0))}`),console.log(` ${R("Projects")} ${A(String(n.projects??0))}`),console.log("");let l=await $(g(e,E.PROJECTS));if(l.ok&&l.body){let a=l.body.projects;if(Array.isArray(a)&&a.length>0){console.log(` ${zt("\u25B8")} Registered Projects (${a.length}):`),console.log(" "+A("\u2500".repeat(56)));for(let c of a)console.log(` ${R("hash")} ${A(c.hash)}`),console.log(` ${R("path")} ${A(c.cwd||"")}`),console.log(` ${R("url")} ${Qt(`http://localhost:${r}/${c.hash}/main/`)}`),console.log(" "+A("\u2500".repeat(56)))}else console.log(` ${A("\u2500".repeat(58))}`),console.log(` ${A("(No registered projects)")}`),console.log(` ${A("\u2500".repeat(58))}`)}console.log(""),process.exit(0)}var{green:er,yellow:ge,red:X}=f;async function Oe(i,e){let t=await L(e);if(e.all){let o=await $(g(t,E.PROJECTS));(!o.ok||!o.body)&&(console.error(`${X("\u2717")} Cannot connect to master service`),process.exit(1));let n=o.body.projects;(!Array.isArray(n)||n.length===0)&&(console.log(`${ge("\u2139")} No running projects`),process.exit(0)),console.log(`
30
- ${ge("\u25B8")} Stopping all ${n.length} projects...
31
- `);for(let s of n){let l=await M(g(t,E.DEREGISTER),{hash:s.hash});l.ok?console.log(` ${er("\u2713")} Stopped: ${s.hash} (${s.cwd||""})`):console.error(` ${X("\u2717")} Failed to stop: ${s.hash} - ${l.error}`)}console.log(""),process.exit(0)}i||(console.error(`${X("\u2717")} Please specify project hash or use --all to stop all projects`),console.error(" Usage: comphub stop <hash>"),console.error(" Usage: comphub stop --all"),process.exit(1)),console.log(`
32
- ${ge("\u25B8")} Stopping project ${i}...`);let r=await M(g(t,E.DEREGISTER),{hash:i});r.ok?console.log(` ${er("\u2713")} Stopped: ${i}
33
- `):(console.error(` ${X("\u2717")} Failed to stop: ${r.error}
34
- `),process.exit(1)),process.exit(0)}var{green:Vn,yellow:kn,red:Yn}=f;async function Ce(i){let e=await L(i);console.log(`
35
- ${kn("\u25B8")} Shutting down master process...
36
- `);let t=await M(g(e,E.SHUTDOWN),{});t.ok?console.log(`${Vn("\u2713")} Master process has been shut down
37
- `):(console.error(`${Yn("\u2717")} Shutdown failed: ${t.error}
38
- `),process.exit(1)),process.exit(0)}var Ae=d(require("fs"));var{green:tr,yellow:rr,red:jn}=f;async function Te(){console.log(`
39
- ${rr("\u25B8")} Checking master runtime...
40
- `);let i=await T();if(i&&(console.log(` ${tr("\u2713")} Master is running normally on port ${i.publicPort}
41
- `),process.exit(0)),Ae.default.existsSync(I))try{Ae.default.unlinkSync(I),console.log(` ${tr("\u2713")} Removed stale runtime file
42
- `)}catch{console.error(` ${jn("\u2717")} Failed to remove runtime file
43
- `),process.exit(1)}else console.log(` ${rr("\u2139")} No stale runtime file found
44
- `);process.exit(0)}function J(i){return parseInt(i,10)}function or(i){let e=new wt;return e.name("comphub").addOption(new b("-p, --port <number>","Startup port").argParser(J)).option("-d, --dir <path>","Resource directory relative path").option("-l, --log-level <level>","Log level: debug, info, warn, error (default: info)","error").version(i.version,"-v, --version","Show version").addOption(new b("--allow-debug","Enable debug mode").hideHelp()).addOption(new b("--api <url>","API URL").hideHelp()).helpOption("-h, --help","Show help"),e.command("status").description("View master service status and all running projects").addOption(new b("-p, --port <number>","Master port").argParser(J).hideHelp()).action(t=>Ee(t)),e.command("stop [hash]").description("Stop a specific project (by hash) or stop all projects (--all)").addOption(new b("-p, --port <number>","Master port").argParser(J).hideHelp()).option("-a, --all","Stop all projects").action((t,r)=>Oe(t,r)),e.command("kill").description("Shutdown master process").addOption(new b("-p, --port <number>","Master port").argParser(J).hideHelp()).action(t=>Ce(t)),e.command("fix").description("Fix common issues (stale runtime file, etc.)").action(()=>Te()),e.action(async()=>{try{await fe(i,e.opts())}catch(t){console.error(`\u2717 Startup failed: ${t.message}`),process.exit(1)}}),e}var{pkg:Gn}=_t(),Bn=or(Gn);Bn.parseAsync(process.argv).catch(i=>{console.error(`\u2717 CLI error: ${i.message}`),process.exit(1)});
23
+ `)}),["SIGINT","SIGTERM"].forEach(a=>{process.on(a,()=>{n.kill(a)})}),n.on("exit",a=>{s&&!/^\[[0-9a-f]{8}\]/.test(s)&&process.stdout.write(s),process.exit(a||0)});let l=await Fn();if(!l)throw n.kill(),new Error("Master startup timeout");return{runtime:l}}async function Yt(i,e){let t=!1,r=0,o=await T();if(o){let a=i.port!=null?i.port:o.publicPort;return i.port!=null&&o.publicPort!==a&&(t=!0,r=o.publicPort),{runtime:o,portMismatch:t,runningPublicPort:r}}let n=i.port!=null?i.port:F,s=await(0,de.default)({port:de.default.makeRange(n,n+100)}),{runtime:l}=await Vn(s,e,process.cwd());return{runtime:l,portMismatch:t,runningPublicPort:r}}async function Gt(i,e,t,r){let o={hash:e,cwd:t,dir:r.dir||"./"};r.api&&(o.api=r.api),r.allowDebug&&(o.allowDebug=!0),r.proxy&&(o.proxy=r.proxy),r.logLevel&&(o.logLevel=r.logLevel);let n=await M(g(i,f.REGISTER),o);if(!n.ok)throw new Error(n.error||"Registration failed");console.log(`${vn("\u2713")} Project registered (hash: ${e})`)}var{cyan:L,green:X,white:Bt,yellow:kn,red:Wt}=E;function Kt(i,e,t,r,o,n){let{portMismatch:s,runningPublicPort:l}=n,a=`http://localhost:${r}/${t}/main/`,c=["",L(" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 "),L(" \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557"),L(" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D"),L(" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557"),L(" \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D"),L(" \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D "),"","",` ${X("Version")} ${i.version}`,` ${X("Project")} ${e}`,` ${X("Hash")} ${t}`,` ${X("Port")} ${r}`,"",` ${kn("URL")} ${L(a)}`,"",Bt(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),"",` ${"comphub status".padEnd(30)}View all projects`,` ${`comphub stop ${t}`.padEnd(30)}Stop current project`,` ${"comphub stop --all".padEnd(30)}Stop all projects`,` ${"comphub kill".padEnd(30)}Shutdown master`,""];s&&c.push(Bt(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),"",Wt(` \u26A0 Master is already running on port ${l}, ignoring -p ${o.port}`),Wt(" To change port, please run comphub kill first"),""),console.log(c.join(`
24
+ `))}var{cyan:qt,green:jn,white:Xt,yellow:Jt,red:Ee}=E;async function fe(i,e){zt.default.existsSync(Zt.default.join(process.cwd(),"package.json"))||(console.error(`${Ee("\u2717")} Current directory is not a Node.js project`),process.exit(1));let t=process.cwd(),r=_t(t);e=Et(e,t);let o=await Ut({base:e.api,compHubVersion:i.version});if(o.ok&&o.verdict==="block"){let _=o.latestVersion&&o.latestVersion!==i.version?`, latest version v${o.latestVersion}`:"";console.error(""),console.error(`${Ee("\u2717")} comp-hub must be upgraded before it can start (current v${i.version}${_})`),console.error(` Please run the upgrade command: ${qt("npm install comp-hub@latest -g")}`),console.error(" Then run comphub again after upgrading"),console.error(""),process.exit(1)}console.log(`${jn("\u2713")} ${i.name} v${i.version}`);let{runtime:n,portMismatch:s,runningPublicPort:l}=await Yt(e,i),a=n.managementPort,c=n.publicPort;if(await Gt(a,r,t,e),Kt(i,t,r,c,e,{portMismatch:s,runningPublicPort:l}),o.ok&&o.verdict==="notice"){let _=o.latestVersion&&o.latestVersion!==i.version?` (latest version v${o.latestVersion})`:"";console.log(""),console.log(`${Jt("\u2139")} comp-hub has a new version available${_}; run the upgrade command to update:`),console.log(` ${qt("npm install comp-hub@latest -g")}`),console.log("")}else o.ok||(console.log(""),console.log(`${Jt("\u26A0")} comp-hub version check failed (${o.error}); skipping the version check for this run`),console.log(""));let u=!1,p=async()=>{if(!u){u=!0;try{await Ft(a,r)}catch{}process.exit(0)}};process.on("SIGINT",p),process.on("SIGTERM",p),console.log(`
25
+ ${Xt("\u2500")} Streaming logs from MidwayJS (${r}) ${Xt("\u2500")}
26
+ `);let m=`http://localhost:${a}/__master__/projects/${r}/logs`;try{await vt(m,r)}catch(O){console.error(`
27
+ ${Ee("\u2717")} Log stream error: ${O.message}`)}}var{green:R,yellow:Qt,cyan:er,white:C,red:Yn}=E;async function ge(i){let e=await D(i),t=await T(),r=t?t.publicPort:e;console.log(`
28
+ ${Qt("\u25CF")} Master Status
29
+ `);let o=await $(g(e,f.HEALTH));(!o.ok||!o.body||typeof o.body.status!="string")&&(console.error(`${Yn("\u2717")} Master service is not running`),process.exit(1));let n=o.body,s=n.status==="running"?R("\u25CF"):er("\u25CF");console.log(` ${R("Status")} ${s} ${n.status}`),console.log(` ${R("Version")} ${C(n.version||"")}`),console.log(` ${R("Uptime")} ${C(_e(n.uptime??0))}`),console.log(` ${R("Projects")} ${C(String(n.projects??0))}`),console.log("");let l=await $(g(e,f.PROJECTS));if(l.ok&&l.body){let a=l.body.projects;if(Array.isArray(a)&&a.length>0){console.log(` ${Qt("\u25B8")} Registered Projects (${a.length}):`),console.log(" "+C("\u2500".repeat(56)));for(let c of a)console.log(` ${R("hash")} ${C(c.hash)}`),console.log(` ${R("path")} ${C(c.cwd||"")}`),console.log(` ${R("url")} ${er(`http://localhost:${r}/${c.hash}/main/`)}`),console.log(" "+C("\u2500".repeat(56)))}else console.log(` ${C("\u2500".repeat(58))}`),console.log(` ${C("(No registered projects)")}`),console.log(` ${C("\u2500".repeat(58))}`)}console.log(""),process.exit(0)}var{green:tr,yellow:Oe,red:J}=E;async function Ae(i,e){let t=await D(e);if(e.all){let o=await $(g(t,f.PROJECTS));(!o.ok||!o.body)&&(console.error(`${J("\u2717")} Cannot connect to master service`),process.exit(1));let n=o.body.projects;(!Array.isArray(n)||n.length===0)&&(console.log(`${Oe("\u2139")} No running projects`),process.exit(0)),console.log(`
30
+ ${Oe("\u25B8")} Stopping all ${n.length} projects...
31
+ `);for(let s of n){let l=await M(g(t,f.DEREGISTER),{hash:s.hash});l.ok?console.log(` ${tr("\u2713")} Stopped: ${s.hash} (${s.cwd||""})`):console.error(` ${J("\u2717")} Failed to stop: ${s.hash} - ${l.error}`)}console.log(""),process.exit(0)}i||(console.error(`${J("\u2717")} Please specify project hash or use --all to stop all projects`),console.error(" Usage: comphub stop <hash>"),console.error(" Usage: comphub stop --all"),process.exit(1)),console.log(`
32
+ ${Oe("\u25B8")} Stopping project ${i}...`);let r=await M(g(t,f.DEREGISTER),{hash:i});r.ok?console.log(` ${tr("\u2713")} Stopped: ${i}
33
+ `):(console.error(` ${J("\u2717")} Failed to stop: ${r.error}
34
+ `),process.exit(1)),process.exit(0)}var{green:Gn,yellow:Bn,red:Wn}=E;async function Ce(i){let e=await D(i);console.log(`
35
+ ${Bn("\u25B8")} Shutting down master process...
36
+ `);let t=await M(g(e,f.SHUTDOWN),{});t.ok?console.log(`${Gn("\u2713")} Master process has been shut down
37
+ `):(console.error(`${Wn("\u2717")} Shutdown failed: ${t.error}
38
+ `),process.exit(1)),process.exit(0)}var Te=d(require("fs"));var{green:rr,yellow:or,red:Kn}=E;async function Pe(){console.log(`
39
+ ${or("\u25B8")} Checking master runtime...
40
+ `);let i=await T();if(i&&(console.log(` ${rr("\u2713")} Master is running normally on port ${i.publicPort}
41
+ `),process.exit(0)),Te.default.existsSync(I))try{Te.default.unlinkSync(I),console.log(` ${rr("\u2713")} Removed stale runtime file
42
+ `)}catch{console.error(` ${Kn("\u2717")} Failed to remove runtime file
43
+ `),process.exit(1)}else console.log(` ${or("\u2139")} No stale runtime file found
44
+ `);process.exit(0)}function z(i){return parseInt(i,10)}function nr(i){let e=new wt;return e.name("comphub").addOption(new b("-p, --port <number>","Startup port").argParser(z)).option("-d, --dir <path>","Resource directory relative path").option("-l, --log-level <level>","Log level: debug, info, warn, error (default: info)","error").version(i.version,"-v, --version","Show version").addOption(new b("--allow-debug","Enable debug mode").hideHelp()).addOption(new b("--api <url>","API URL").hideHelp()).helpOption("-h, --help","Show help"),e.command("status").description("View master service status and all running projects").addOption(new b("-p, --port <number>","Master port").argParser(z).hideHelp()).action(t=>ge(t)),e.command("stop [hash]").description("Stop a specific project (by hash) or stop all projects (--all)").addOption(new b("-p, --port <number>","Master port").argParser(z).hideHelp()).option("-a, --all","Stop all projects").action((t,r)=>Ae(t,r)),e.command("kill").description("Shutdown master process").addOption(new b("-p, --port <number>","Master port").argParser(z).hideHelp()).action(t=>Ce(t)),e.command("fix").description("Fix common issues (stale runtime file, etc.)").action(()=>Pe()),e.action(async()=>{try{await fe(i,e.opts())}catch(t){console.error(`\u2717 Startup failed: ${t.message}`),process.exit(1)}}),e}var{pkg:qn}=dt(),Xn=nr(qn);Xn.parseAsync(process.argv).catch(i=>{console.error(`\u2717 CLI error: ${i.message}`),process.exit(1)});