gstatx 0.2.2 → 0.2.4

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
@@ -28,6 +28,12 @@ gstatx contributors ./repo1 ./repo2 ./repo3
28
28
  # Hide commit counts
29
29
  gstatx contributors --no-commits ./my-repo
30
30
 
31
+ # Output as JSON
32
+ gstatx contributors --format json ./my-repo
33
+
34
+ # List unique email addresses
35
+ gstatx contributors --unique-emails ./my-repo
36
+
31
37
  # Generate commit history report
32
38
  gstatx hist ./my-repo
33
39
 
@@ -50,11 +56,13 @@ gstatx contributors [options] [repo-paths...]
50
56
 
51
57
  **Options:**
52
58
  - `--no-commits` - Hide commit counts in contributor list
59
+ - `-f, --format <format>` - Output format: `json` or `text` (default: `text`)
60
+ - `-u, --unique-emails` - List unique email addresses only (deduplicates by email across all repositories)
53
61
  - `--help, -h` - Show help message
54
62
 
55
63
  **Examples:**
56
64
  ```bash
57
- # List contributors with commit counts
65
+ # List contributors with commit counts (text format)
58
66
  gstatx contributors ./my-repo
59
67
 
60
68
  # List contributors without commit counts
@@ -63,10 +71,26 @@ gstatx contributors --no-commits ./my-repo
63
71
  # List contributors for multiple repositories
64
72
  gstatx contributors ./repo1 ./repo2 ./repo3
65
73
 
74
+ # Output as JSON
75
+ gstatx contributors --format json ./my-repo
76
+
77
+ # Output as JSON without commit counts
78
+ gstatx contributors --format json --no-commits ./my-repo
79
+
80
+ # List unique email addresses (deduplicates by email)
81
+ gstatx contributors --unique-emails ./my-repo
82
+
83
+ # List unique emails as JSON
84
+ gstatx contributors --unique-emails --format json ./my-repo
85
+
66
86
  # Use repositories from config file
67
87
  gstatx contributors
68
88
  ```
69
89
 
90
+ **Output Formats:**
91
+ - `text` (default): Human-readable format with emojis and formatting
92
+ - `json`: Machine-readable JSON format, useful for scripting or integration with other tools
93
+
70
94
  #### `hist`
71
95
 
72
96
  Generate commit history report with detailed statistics.
@@ -105,6 +129,27 @@ The report includes:
105
129
  - File-level statistics (files changed, insertions, deletions)
106
130
  - Summary statistics per repository
107
131
 
132
+ ### .mailmap Support
133
+
134
+ gstatx automatically detects and uses `.mailmap` files if they exist in your git repositories. The `.mailmap` file allows you to consolidate contributors who use different names or email addresses across commits.
135
+
136
+ **How it works:**
137
+ - If a `.mailmap` file exists in a repository, gstatx automatically uses it when retrieving contributor and commit information
138
+ - This helps normalize author names and emails, making contributor lists more accurate
139
+ - The `.mailmap` file follows Git's standard format
140
+
141
+ **Example `.mailmap` file:**
142
+ ```
143
+ Proper Name <proper.email@example.com> <old.email@example.com>
144
+ Proper Name <proper.email@example.com> <nickname@example.com>
145
+ ```
146
+
147
+ **Benefits:**
148
+ - Consolidates multiple email addresses for the same person
149
+ - Normalizes different name variations
150
+ - Works automatically - no configuration needed
151
+ - Applies to both `contributors` and `hist` commands
152
+
108
153
  ### Configuration File
109
154
 
110
155
  You can create a `.gstatxrc.json` file to set default options and repository paths. The config file is automatically searched in the current directory and parent directories.
package/dist/index.js CHANGED
@@ -1,48 +1,57 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as W1}from"node:module";var M1=Object.create;var{getPrototypeOf:L1,defineProperty:l,getOwnPropertyNames:U1}=Object;var S1=Object.prototype.hasOwnProperty;var K1=($,q,z)=>{z=$!=null?M1(L1($)):{};let J=q||!$||!$.__esModule?l(z,"default",{value:$,enumerable:!0}):z;for(let Q of U1($))if(!S1.call(J,Q))l(J,Q,{get:()=>$[Q],enumerable:!0});return J};var U=($,q)=>()=>(q||$((q={exports:{}}).exports,q),q.exports);var I=W1(import.meta.url);var E=U((j1)=>{class w extends Error{constructor($,q,z){super(z);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=q,this.exitCode=$,this.nestedError=void 0}}class c extends w{constructor($){super(1,"commander.invalidArgument",$);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}j1.CommanderError=w;j1.InvalidArgumentError=c});var y=U((N1)=>{var{InvalidArgumentError:V1}=E();class m{constructor($,q){switch(this.description=q||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,$[0]){case"<":this.required=!0,this._name=$.slice(1,-1);break;case"[":this.required=!1,this._name=$.slice(1,-1);break;default:this.required=!0,this._name=$;break}if(this._name.endsWith("..."))this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_collectValue($,q){if(q===this.defaultValue||!Array.isArray(q))return[$];return q.push($),q}default($,q){return this.defaultValue=$,this.defaultValueDescription=q,this}argParser($){return this.parseArg=$,this}choices($){return this.argChoices=$.slice(),this.parseArg=(q,z)=>{if(!this.argChoices.includes(q))throw new V1(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(q,z);return q},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function D1($){let q=$.name()+($.variadic===!0?"...":"");return $.required?"<"+q+">":"["+q+"]"}N1.Argument=m;N1.humanReadableArgName=D1});var A=U((A1)=>{var{humanReadableArgName:w1}=y();class d{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext($){this.helpWidth=this.helpWidth??$.helpWidth??80}visibleCommands($){let q=$.commands.filter((J)=>!J._hidden),z=$._getHelpCommand();if(z&&!z._hidden)q.push(z);if(this.sortSubcommands)q.sort((J,Q)=>{return J.name().localeCompare(Q.name())});return q}compareOptions($,q){let z=(J)=>{return J.short?J.short.replace(/^-/,""):J.long.replace(/^--/,"")};return z($).localeCompare(z(q))}visibleOptions($){let q=$.options.filter((J)=>!J.hidden),z=$._getHelpOption();if(z&&!z.hidden){let J=z.short&&$._findOption(z.short),Q=z.long&&$._findOption(z.long);if(!J&&!Q)q.push(z);else if(z.long&&!Q)q.push($.createOption(z.long,z.description));else if(z.short&&!J)q.push($.createOption(z.short,z.description))}if(this.sortOptions)q.sort(this.compareOptions);return q}visibleGlobalOptions($){if(!this.showGlobalOptions)return[];let q=[];for(let z=$.parent;z;z=z.parent){let J=z.options.filter((Q)=>!Q.hidden);q.push(...J)}if(this.sortOptions)q.sort(this.compareOptions);return q}visibleArguments($){if($._argsDescription)$.registeredArguments.forEach((q)=>{q.description=q.description||$._argsDescription[q.name()]||""});if($.registeredArguments.find((q)=>q.description))return $.registeredArguments;return[]}subcommandTerm($){let q=$.registeredArguments.map((z)=>w1(z)).join(" ");return $._name+($._aliases[0]?"|"+$._aliases[0]:"")+($.options.length?" [options]":"")+(q?" "+q:"")}optionTerm($){return $.flags}argumentTerm($){return $.name()}longestSubcommandTermLength($,q){return q.visibleCommands($).reduce((z,J)=>{return Math.max(z,this.displayWidth(q.styleSubcommandTerm(q.subcommandTerm(J))))},0)}longestOptionTermLength($,q){return q.visibleOptions($).reduce((z,J)=>{return Math.max(z,this.displayWidth(q.styleOptionTerm(q.optionTerm(J))))},0)}longestGlobalOptionTermLength($,q){return q.visibleGlobalOptions($).reduce((z,J)=>{return Math.max(z,this.displayWidth(q.styleOptionTerm(q.optionTerm(J))))},0)}longestArgumentTermLength($,q){return q.visibleArguments($).reduce((z,J)=>{return Math.max(z,this.displayWidth(q.styleArgumentTerm(q.argumentTerm(J))))},0)}commandUsage($){let q=$._name;if($._aliases[0])q=q+"|"+$._aliases[0];let z="";for(let J=$.parent;J;J=J.parent)z=J.name()+" "+z;return z+q+" "+$.usage()}commandDescription($){return $.description()}subcommandDescription($){return $.summary()||$.description()}optionDescription($){let q=[];if($.argChoices)q.push(`choices: ${$.argChoices.map((z)=>JSON.stringify(z)).join(", ")}`);if($.defaultValue!==void 0){if($.required||$.optional||$.isBoolean()&&typeof $.defaultValue==="boolean")q.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`)}if($.presetArg!==void 0&&$.optional)q.push(`preset: ${JSON.stringify($.presetArg)}`);if($.envVar!==void 0)q.push(`env: ${$.envVar}`);if(q.length>0){let z=`(${q.join(", ")})`;if($.description)return`${$.description} ${z}`;return z}return $.description}argumentDescription($){let q=[];if($.argChoices)q.push(`choices: ${$.argChoices.map((z)=>JSON.stringify(z)).join(", ")}`);if($.defaultValue!==void 0)q.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`);if(q.length>0){let z=`(${q.join(", ")})`;if($.description)return`${$.description} ${z}`;return z}return $.description}formatItemList($,q,z){if(q.length===0)return[];return[z.styleTitle($),...q,""]}groupItems($,q,z){let J=new Map;return $.forEach((Q)=>{let X=z(Q);if(!J.has(X))J.set(X,[])}),q.forEach((Q)=>{let X=z(Q);if(!J.has(X))J.set(X,[]);J.get(X).push(Q)}),J}formatHelp($,q){let z=q.padWidth($,q),J=q.helpWidth??80;function Q(R,B){return q.formatItem(R,z,B,q)}let X=[`${q.styleTitle("Usage:")} ${q.styleUsage(q.commandUsage($))}`,""],Y=q.commandDescription($);if(Y.length>0)X=X.concat([q.boxWrap(q.styleCommandDescription(Y),J),""]);let Z=q.visibleArguments($).map((R)=>{return Q(q.styleArgumentTerm(q.argumentTerm(R)),q.styleArgumentDescription(q.argumentDescription(R)))});if(X=X.concat(this.formatItemList("Arguments:",Z,q)),this.groupItems($.options,q.visibleOptions($),(R)=>R.helpGroupHeading??"Options:").forEach((R,B)=>{let G=R.map((M)=>{return Q(q.styleOptionTerm(q.optionTerm(M)),q.styleOptionDescription(q.optionDescription(M)))});X=X.concat(this.formatItemList(B,G,q))}),q.showGlobalOptions){let R=q.visibleGlobalOptions($).map((B)=>{return Q(q.styleOptionTerm(q.optionTerm(B)),q.styleOptionDescription(q.optionDescription(B)))});X=X.concat(this.formatItemList("Global Options:",R,q))}return this.groupItems($.commands,q.visibleCommands($),(R)=>R.helpGroup()||"Commands:").forEach((R,B)=>{let G=R.map((M)=>{return Q(q.styleSubcommandTerm(q.subcommandTerm(M)),q.styleSubcommandDescription(q.subcommandDescription(M)))});X=X.concat(this.formatItemList(B,G,q))}),X.join(`
3
- `)}displayWidth($){return p($).length}styleTitle($){return $}styleUsage($){return $.split(" ").map((q)=>{if(q==="[options]")return this.styleOptionText(q);if(q==="[command]")return this.styleSubcommandText(q);if(q[0]==="["||q[0]==="<")return this.styleArgumentText(q);return this.styleCommandText(q)}).join(" ")}styleCommandDescription($){return this.styleDescriptionText($)}styleOptionDescription($){return this.styleDescriptionText($)}styleSubcommandDescription($){return this.styleDescriptionText($)}styleArgumentDescription($){return this.styleDescriptionText($)}styleDescriptionText($){return $}styleOptionTerm($){return this.styleOptionText($)}styleSubcommandTerm($){return $.split(" ").map((q)=>{if(q==="[options]")return this.styleOptionText(q);if(q[0]==="["||q[0]==="<")return this.styleArgumentText(q);return this.styleSubcommandText(q)}).join(" ")}styleArgumentTerm($){return this.styleArgumentText($)}styleOptionText($){return $}styleArgumentText($){return $}styleSubcommandText($){return $}styleCommandText($){return $}padWidth($,q){return Math.max(q.longestOptionTermLength($,q),q.longestGlobalOptionTermLength($,q),q.longestSubcommandTermLength($,q),q.longestArgumentTermLength($,q))}preformatted($){return/\n[^\S\r\n]/.test($)}formatItem($,q,z,J){let X=" ".repeat(2);if(!z)return X+$;let Y=$.padEnd(q+$.length-J.displayWidth($)),Z=2,H=(this.helpWidth??80)-q-Z-2,R;if(H<this.minWidthToWrap||J.preformatted(z))R=z;else R=J.boxWrap(z,H).replace(/\n/g,`
4
- `+" ".repeat(q+Z));return X+Y+" ".repeat(Z)+R.replace(/\n/g,`
5
- ${X}`)}boxWrap($,q){if(q<this.minWidthToWrap)return $;let z=$.split(/\r\n|\n/),J=/[\s]*[^\s]+/g,Q=[];return z.forEach((X)=>{let Y=X.match(J);if(Y===null){Q.push("");return}let Z=[Y.shift()],T=this.displayWidth(Z[0]);Y.forEach((H)=>{let R=this.displayWidth(H);if(T+R<=q){Z.push(H),T+=R;return}Q.push(Z.join(""));let B=H.trimStart();Z=[B],T=this.displayWidth(B)}),Q.push(Z.join(""))}),Q.join(`
6
- `)}}function p($){let q=/\x1b\[\d*(;\d*)*m/g;return $.replace(q,"")}A1.Help=d;A1.stripColor=p});var P=U((b1)=>{var{InvalidArgumentError:O1}=E();class i{constructor($,q){this.flags=$,this.description=q||"",this.required=$.includes("<"),this.optional=$.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test($),this.mandatory=!1;let z=x1($);if(this.short=z.shortFlag,this.long=z.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,this.helpGroupHeading=void 0}default($,q){return this.defaultValue=$,this.defaultValueDescription=q,this}preset($){return this.presetArg=$,this}conflicts($){return this.conflictsWith=this.conflictsWith.concat($),this}implies($){let q=$;if(typeof $==="string")q={[$]:!0};return this.implied=Object.assign(this.implied||{},q),this}env($){return this.envVar=$,this}argParser($){return this.parseArg=$,this}makeOptionMandatory($=!0){return this.mandatory=!!$,this}hideHelp($=!0){return this.hidden=!!$,this}_collectValue($,q){if(q===this.defaultValue||!Array.isArray(q))return[$];return q.push($),q}choices($){return this.argChoices=$.slice(),this.parseArg=(q,z)=>{if(!this.argChoices.includes(q))throw new O1(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(q,z);return q},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){if(this.negate)return s(this.name().replace(/^no-/,""));return s(this.name())}helpGroup($){return this.helpGroupHeading=$,this}is($){return this.short===$||this.long===$}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class t{constructor($){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,$.forEach((q)=>{if(q.negate)this.negativeOptions.set(q.attributeName(),q);else this.positiveOptions.set(q.attributeName(),q)}),this.negativeOptions.forEach((q,z)=>{if(this.positiveOptions.has(z))this.dualOptions.add(z)})}valueFromOption($,q){let z=q.attributeName();if(!this.dualOptions.has(z))return!0;let J=this.negativeOptions.get(z).presetArg,Q=J!==void 0?J:!1;return q.negate===(Q===$)}}function s($){return $.split("-").reduce((q,z)=>{return q+z[0].toUpperCase()+z.slice(1)})}function x1($){let q,z,J=/^-[^-]$/,Q=/^--[^-]/,X=$.split(/[ |,]+/).concat("guard");if(J.test(X[0]))q=X.shift();if(Q.test(X[0]))z=X.shift();if(!q&&J.test(X[0]))q=X.shift();if(!q&&Q.test(X[0]))q=z,z=X.shift();if(X[0].startsWith("-")){let Y=X[0],Z=`option creation failed due to '${Y}' in option flags '${$}'`;if(/^-[^-][^-]/.test(Y))throw new Error(`${Z}
2
+ import{createRequire as DQ}from"node:module";var jQ=Object.create;var{getPrototypeOf:IQ,defineProperty:p,getOwnPropertyNames:VQ}=Object;var MQ=Object.prototype.hasOwnProperty;var EQ=(Q,X,Y)=>{Y=Q!=null?jQ(IQ(Q)):{};let Z=X||!Q||!Q.__esModule?p(Y,"default",{value:Q,enumerable:!0}):Y;for(let $ of VQ(Q))if(!MQ.call(Z,$))p(Z,$,{get:()=>Q[$],enumerable:!0});return Z};var S=(Q,X)=>()=>(X||Q((X={exports:{}}).exports,X),X.exports);var E=DQ(import.meta.url);var D=S((NQ)=>{class P extends Error{constructor(Q,X,Y){super(Y);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=X,this.exitCode=Q,this.nestedError=void 0}}class s extends P{constructor(Q){super(1,"commander.invalidArgument",Q);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}NQ.CommanderError=P;NQ.InvalidArgumentError=s});var A=S((PQ)=>{var{InvalidArgumentError:AQ}=D();class i{constructor(Q,X){switch(this.description=X||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,Q[0]){case"<":this.required=!0,this._name=Q.slice(1,-1);break;case"[":this.required=!1,this._name=Q.slice(1,-1);break;default:this.required=!0,this._name=Q;break}if(this._name.endsWith("..."))this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_collectValue(Q,X){if(X===this.defaultValue||!Array.isArray(X))return[Q];return X.push(Q),X}default(Q,X){return this.defaultValue=Q,this.defaultValueDescription=X,this}argParser(Q){return this.parseArg=Q,this}choices(Q){return this.argChoices=Q.slice(),this.parseArg=(X,Y)=>{if(!this.argChoices.includes(X))throw new AQ(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(X,Y);return X},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function kQ(Q){let X=Q.name()+(Q.variadic===!0?"...":"");return Q.required?"<"+X+">":"["+X+"]"}PQ.Argument=i;PQ.humanReadableArgName=kQ});var w=S((CQ)=>{var{humanReadableArgName:xQ}=A();class n{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(Q){this.helpWidth=this.helpWidth??Q.helpWidth??80}visibleCommands(Q){let X=Q.commands.filter((Z)=>!Z._hidden),Y=Q._getHelpCommand();if(Y&&!Y._hidden)X.push(Y);if(this.sortSubcommands)X.sort((Z,$)=>{return Z.name().localeCompare($.name())});return X}compareOptions(Q,X){let Y=(Z)=>{return Z.short?Z.short.replace(/^-/,""):Z.long.replace(/^--/,"")};return Y(Q).localeCompare(Y(X))}visibleOptions(Q){let X=Q.options.filter((Z)=>!Z.hidden),Y=Q._getHelpOption();if(Y&&!Y.hidden){let Z=Y.short&&Q._findOption(Y.short),$=Y.long&&Q._findOption(Y.long);if(!Z&&!$)X.push(Y);else if(Y.long&&!$)X.push(Q.createOption(Y.long,Y.description));else if(Y.short&&!Z)X.push(Q.createOption(Y.short,Y.description))}if(this.sortOptions)X.sort(this.compareOptions);return X}visibleGlobalOptions(Q){if(!this.showGlobalOptions)return[];let X=[];for(let Y=Q.parent;Y;Y=Y.parent){let Z=Y.options.filter(($)=>!$.hidden);X.push(...Z)}if(this.sortOptions)X.sort(this.compareOptions);return X}visibleArguments(Q){if(Q._argsDescription)Q.registeredArguments.forEach((X)=>{X.description=X.description||Q._argsDescription[X.name()]||""});if(Q.registeredArguments.find((X)=>X.description))return Q.registeredArguments;return[]}subcommandTerm(Q){let X=Q.registeredArguments.map((Y)=>xQ(Y)).join(" ");return Q._name+(Q._aliases[0]?"|"+Q._aliases[0]:"")+(Q.options.length?" [options]":"")+(X?" "+X:"")}optionTerm(Q){return Q.flags}argumentTerm(Q){return Q.name()}longestSubcommandTermLength(Q,X){return X.visibleCommands(Q).reduce((Y,Z)=>{return Math.max(Y,this.displayWidth(X.styleSubcommandTerm(X.subcommandTerm(Z))))},0)}longestOptionTermLength(Q,X){return X.visibleOptions(Q).reduce((Y,Z)=>{return Math.max(Y,this.displayWidth(X.styleOptionTerm(X.optionTerm(Z))))},0)}longestGlobalOptionTermLength(Q,X){return X.visibleGlobalOptions(Q).reduce((Y,Z)=>{return Math.max(Y,this.displayWidth(X.styleOptionTerm(X.optionTerm(Z))))},0)}longestArgumentTermLength(Q,X){return X.visibleArguments(Q).reduce((Y,Z)=>{return Math.max(Y,this.displayWidth(X.styleArgumentTerm(X.argumentTerm(Z))))},0)}commandUsage(Q){let X=Q._name;if(Q._aliases[0])X=X+"|"+Q._aliases[0];let Y="";for(let Z=Q.parent;Z;Z=Z.parent)Y=Z.name()+" "+Y;return Y+X+" "+Q.usage()}commandDescription(Q){return Q.description()}subcommandDescription(Q){return Q.summary()||Q.description()}optionDescription(Q){let X=[];if(Q.argChoices)X.push(`choices: ${Q.argChoices.map((Y)=>JSON.stringify(Y)).join(", ")}`);if(Q.defaultValue!==void 0){if(Q.required||Q.optional||Q.isBoolean()&&typeof Q.defaultValue==="boolean")X.push(`default: ${Q.defaultValueDescription||JSON.stringify(Q.defaultValue)}`)}if(Q.presetArg!==void 0&&Q.optional)X.push(`preset: ${JSON.stringify(Q.presetArg)}`);if(Q.envVar!==void 0)X.push(`env: ${Q.envVar}`);if(X.length>0){let Y=`(${X.join(", ")})`;if(Q.description)return`${Q.description} ${Y}`;return Y}return Q.description}argumentDescription(Q){let X=[];if(Q.argChoices)X.push(`choices: ${Q.argChoices.map((Y)=>JSON.stringify(Y)).join(", ")}`);if(Q.defaultValue!==void 0)X.push(`default: ${Q.defaultValueDescription||JSON.stringify(Q.defaultValue)}`);if(X.length>0){let Y=`(${X.join(", ")})`;if(Q.description)return`${Q.description} ${Y}`;return Y}return Q.description}formatItemList(Q,X,Y){if(X.length===0)return[];return[Y.styleTitle(Q),...X,""]}groupItems(Q,X,Y){let Z=new Map;return Q.forEach(($)=>{let q=Y($);if(!Z.has(q))Z.set(q,[])}),X.forEach(($)=>{let q=Y($);if(!Z.has(q))Z.set(q,[]);Z.get(q).push($)}),Z}formatHelp(Q,X){let Y=X.padWidth(Q,X),Z=X.helpWidth??80;function $(z,G){return X.formatItem(z,Y,G,X)}let q=[`${X.styleTitle("Usage:")} ${X.styleUsage(X.commandUsage(Q))}`,""],B=X.commandDescription(Q);if(B.length>0)q=q.concat([X.boxWrap(X.styleCommandDescription(B),Z),""]);let _=X.visibleArguments(Q).map((z)=>{return $(X.styleArgumentTerm(X.argumentTerm(z)),X.styleArgumentDescription(X.argumentDescription(z)))});if(q=q.concat(this.formatItemList("Arguments:",_,X)),this.groupItems(Q.options,X.visibleOptions(Q),(z)=>z.helpGroupHeading??"Options:").forEach((z,G)=>{let T=z.map((U)=>{return $(X.styleOptionTerm(X.optionTerm(U)),X.styleOptionDescription(X.optionDescription(U)))});q=q.concat(this.formatItemList(G,T,X))}),X.showGlobalOptions){let z=X.visibleGlobalOptions(Q).map((G)=>{return $(X.styleOptionTerm(X.optionTerm(G)),X.styleOptionDescription(X.optionDescription(G)))});q=q.concat(this.formatItemList("Global Options:",z,X))}return this.groupItems(Q.commands,X.visibleCommands(Q),(z)=>z.helpGroup()||"Commands:").forEach((z,G)=>{let T=z.map((U)=>{return $(X.styleSubcommandTerm(X.subcommandTerm(U)),X.styleSubcommandDescription(X.subcommandDescription(U)))});q=q.concat(this.formatItemList(G,T,X))}),q.join(`
3
+ `)}displayWidth(Q){return a(Q).length}styleTitle(Q){return Q}styleUsage(Q){return Q.split(" ").map((X)=>{if(X==="[options]")return this.styleOptionText(X);if(X==="[command]")return this.styleSubcommandText(X);if(X[0]==="["||X[0]==="<")return this.styleArgumentText(X);return this.styleCommandText(X)}).join(" ")}styleCommandDescription(Q){return this.styleDescriptionText(Q)}styleOptionDescription(Q){return this.styleDescriptionText(Q)}styleSubcommandDescription(Q){return this.styleDescriptionText(Q)}styleArgumentDescription(Q){return this.styleDescriptionText(Q)}styleDescriptionText(Q){return Q}styleOptionTerm(Q){return this.styleOptionText(Q)}styleSubcommandTerm(Q){return Q.split(" ").map((X)=>{if(X==="[options]")return this.styleOptionText(X);if(X[0]==="["||X[0]==="<")return this.styleArgumentText(X);return this.styleSubcommandText(X)}).join(" ")}styleArgumentTerm(Q){return this.styleArgumentText(Q)}styleOptionText(Q){return Q}styleArgumentText(Q){return Q}styleSubcommandText(Q){return Q}styleCommandText(Q){return Q}padWidth(Q,X){return Math.max(X.longestOptionTermLength(Q,X),X.longestGlobalOptionTermLength(Q,X),X.longestSubcommandTermLength(Q,X),X.longestArgumentTermLength(Q,X))}preformatted(Q){return/\n[^\S\r\n]/.test(Q)}formatItem(Q,X,Y,Z){let q=" ".repeat(2);if(!Y)return q+Q;let B=Q.padEnd(X+Q.length-Z.displayWidth(Q)),_=2,J=(this.helpWidth??80)-X-_-2,z;if(J<this.minWidthToWrap||Z.preformatted(Y))z=Y;else z=Z.boxWrap(Y,J).replace(/\n/g,`
4
+ `+" ".repeat(X+_));return q+B+" ".repeat(_)+z.replace(/\n/g,`
5
+ ${q}`)}boxWrap(Q,X){if(X<this.minWidthToWrap)return Q;let Y=Q.split(/\r\n|\n/),Z=/[\s]*[^\s]+/g,$=[];return Y.forEach((q)=>{let B=q.match(Z);if(B===null){$.push("");return}let _=[B.shift()],R=this.displayWidth(_[0]);B.forEach((J)=>{let z=this.displayWidth(J);if(R+z<=X){_.push(J),R+=z;return}$.push(_.join(""));let G=J.trimStart();_=[G],R=this.displayWidth(G)}),$.push(_.join(""))}),$.join(`
6
+ `)}}function a(Q){let X=/\x1b\[\d*(;\d*)*m/g;return Q.replace(X,"")}CQ.Help=n;CQ.stripColor=a});var O=S((gQ)=>{var{InvalidArgumentError:vQ}=D();class t{constructor(Q,X){this.flags=Q,this.description=X||"",this.required=Q.includes("<"),this.optional=Q.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(Q),this.mandatory=!1;let Y=hQ(Q);if(this.short=Y.shortFlag,this.long=Y.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,this.helpGroupHeading=void 0}default(Q,X){return this.defaultValue=Q,this.defaultValueDescription=X,this}preset(Q){return this.presetArg=Q,this}conflicts(Q){return this.conflictsWith=this.conflictsWith.concat(Q),this}implies(Q){let X=Q;if(typeof Q==="string")X={[Q]:!0};return this.implied=Object.assign(this.implied||{},X),this}env(Q){return this.envVar=Q,this}argParser(Q){return this.parseArg=Q,this}makeOptionMandatory(Q=!0){return this.mandatory=!!Q,this}hideHelp(Q=!0){return this.hidden=!!Q,this}_collectValue(Q,X){if(X===this.defaultValue||!Array.isArray(X))return[Q];return X.push(Q),X}choices(Q){return this.argChoices=Q.slice(),this.parseArg=(X,Y)=>{if(!this.argChoices.includes(X))throw new vQ(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(X,Y);return X},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){if(this.negate)return r(this.name().replace(/^no-/,""));return r(this.name())}helpGroup(Q){return this.helpGroupHeading=Q,this}is(Q){return this.short===Q||this.long===Q}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class o{constructor(Q){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,Q.forEach((X)=>{if(X.negate)this.negativeOptions.set(X.attributeName(),X);else this.positiveOptions.set(X.attributeName(),X)}),this.negativeOptions.forEach((X,Y)=>{if(this.positiveOptions.has(Y))this.dualOptions.add(Y)})}valueFromOption(Q,X){let Y=X.attributeName();if(!this.dualOptions.has(Y))return!0;let Z=this.negativeOptions.get(Y).presetArg,$=Z!==void 0?Z:!1;return X.negate===($===Q)}}function r(Q){return Q.split("-").reduce((X,Y)=>{return X+Y[0].toUpperCase()+Y.slice(1)})}function hQ(Q){let X,Y,Z=/^-[^-]$/,$=/^--[^-]/,q=Q.split(/[ |,]+/).concat("guard");if(Z.test(q[0]))X=q.shift();if($.test(q[0]))Y=q.shift();if(!X&&Z.test(q[0]))X=q.shift();if(!X&&$.test(q[0]))X=Y,Y=q.shift();if(q[0].startsWith("-")){let B=q[0],_=`option creation failed due to '${B}' in option flags '${Q}'`;if(/^-[^-][^-]/.test(B))throw Error(`${_}
7
7
  - a short flag is a single dash and a single character
8
8
  - either use a single dash and a single character (for a short flag)
9
- - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(J.test(Y))throw new Error(`${Z}
10
- - too many short flags`);if(Q.test(Y))throw new Error(`${Z}
11
- - too many long flags`);throw new Error(`${Z}
12
- - unrecognised flag format`)}if(q===void 0&&z===void 0)throw new Error(`option creation failed due to no flags found in '${$}'.`);return{shortFlag:q,longFlag:z}}b1.Option=i;b1.DualOptions=t});var n=U((u1)=>{function v1($,q){if(Math.abs($.length-q.length)>3)return Math.max($.length,q.length);let z=[];for(let J=0;J<=$.length;J++)z[J]=[J];for(let J=0;J<=q.length;J++)z[0][J]=J;for(let J=1;J<=q.length;J++)for(let Q=1;Q<=$.length;Q++){let X=1;if($[Q-1]===q[J-1])X=0;else X=1;if(z[Q][J]=Math.min(z[Q-1][J]+1,z[Q][J-1]+1,z[Q-1][J-1]+X),Q>1&&J>1&&$[Q-1]===q[J-2]&&$[Q-2]===q[J-1])z[Q][J]=Math.min(z[Q][J],z[Q-2][J-2]+1)}return z[$.length][q.length]}function h1($,q){if(!q||q.length===0)return"";q=Array.from(new Set(q));let z=$.startsWith("--");if(z)$=$.slice(2),q=q.map((Y)=>Y.slice(2));let J=[],Q=3,X=0.4;if(q.forEach((Y)=>{if(Y.length<=1)return;let Z=v1($,Y),T=Math.max($.length,Y.length);if((T-Z)/T>X){if(Z<Q)Q=Z,J=[Y];else if(Z===Q)J.push(Y)}}),J.sort((Y,Z)=>Y.localeCompare(Z)),z)J=J.map((Y)=>`--${Y}`);if(J.length>1)return`
13
- (Did you mean one of ${J.join(", ")}?)`;if(J.length===1)return`
14
- (Did you mean ${J[0]}?)`;return""}u1.suggestSimilar=h1});var e=U((i1)=>{var l1=I("node:events").EventEmitter,k=I("node:child_process"),L=I("node:path"),F=I("node:fs"),_=I("node:process"),{Argument:c1,humanReadableArgName:m1}=y(),{CommanderError:O}=E(),{Help:d1,stripColor:p1}=A(),{Option:r,DualOptions:s1}=P(),{suggestSimilar:a}=n();class b extends l1{constructor($){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=$||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:(q)=>_.stdout.write(q),writeErr:(q)=>_.stderr.write(q),outputError:(q,z)=>z(q),getOutHelpWidth:()=>_.stdout.isTTY?_.stdout.columns:void 0,getErrHelpWidth:()=>_.stderr.isTTY?_.stderr.columns:void 0,getOutHasColors:()=>x()??(_.stdout.isTTY&&_.stdout.hasColors?.()),getErrHasColors:()=>x()??(_.stderr.isTTY&&_.stderr.hasColors?.()),stripColor:(q)=>p1(q)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings($){return this._outputConfiguration=$._outputConfiguration,this._helpOption=$._helpOption,this._helpCommand=$._helpCommand,this._helpConfiguration=$._helpConfiguration,this._exitCallback=$._exitCallback,this._storeOptionsAsProperties=$._storeOptionsAsProperties,this._combineFlagAndOptionalValue=$._combineFlagAndOptionalValue,this._allowExcessArguments=$._allowExcessArguments,this._enablePositionalOptions=$._enablePositionalOptions,this._showHelpAfterError=$._showHelpAfterError,this._showSuggestionAfterError=$._showSuggestionAfterError,this}_getCommandAndAncestors(){let $=[];for(let q=this;q;q=q.parent)$.push(q);return $}command($,q,z){let J=q,Q=z;if(typeof J==="object"&&J!==null)Q=J,J=null;Q=Q||{};let[,X,Y]=$.match(/([^ ]+) *(.*)/),Z=this.createCommand(X);if(J)Z.description(J),Z._executableHandler=!0;if(Q.isDefault)this._defaultCommandName=Z._name;if(Z._hidden=!!(Q.noHelp||Q.hidden),Z._executableFile=Q.executableFile||null,Y)Z.arguments(Y);if(this._registerCommand(Z),Z.parent=this,Z.copyInheritedSettings(this),J)return this;return Z}createCommand($){return new b($)}createHelp(){return Object.assign(new d1,this.configureHelp())}configureHelp($){if($===void 0)return this._helpConfiguration;return this._helpConfiguration=$,this}configureOutput($){if($===void 0)return this._outputConfiguration;return this._outputConfiguration={...this._outputConfiguration,...$},this}showHelpAfterError($=!0){if(typeof $!=="string")$=!!$;return this._showHelpAfterError=$,this}showSuggestionAfterError($=!0){return this._showSuggestionAfterError=!!$,this}addCommand($,q){if(!$._name)throw new Error(`Command passed to .addCommand() must have a name
15
- - specify the name in Command constructor or using .name()`);if(q=q||{},q.isDefault)this._defaultCommandName=$._name;if(q.noHelp||q.hidden)$._hidden=!0;return this._registerCommand($),$.parent=this,$._checkForBrokenPassThrough(),this}createArgument($,q){return new c1($,q)}argument($,q,z,J){let Q=this.createArgument($,q);if(typeof z==="function")Q.default(J).argParser(z);else Q.default(z);return this.addArgument(Q),this}arguments($){return $.trim().split(/ +/).forEach((q)=>{this.argument(q)}),this}addArgument($){let q=this.registeredArguments.slice(-1)[0];if(q?.variadic)throw new Error(`only the last argument can be variadic '${q.name()}'`);if($.required&&$.defaultValue!==void 0&&$.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${$.name()}'`);return this.registeredArguments.push($),this}helpCommand($,q){if(typeof $==="boolean"){if(this._addImplicitHelpCommand=$,$&&this._defaultCommandGroup)this._initCommandGroup(this._getHelpCommand());return this}let z=$??"help [command]",[,J,Q]=z.match(/([^ ]+) *(.*)/),X=q??"display help for command",Y=this.createCommand(J);if(Y.helpOption(!1),Q)Y.arguments(Q);if(X)Y.description(X);if(this._addImplicitHelpCommand=!0,this._helpCommand=Y,$||q)this._initCommandGroup(Y);return this}addHelpCommand($,q){if(typeof $!=="object")return this.helpCommand($,q),this;return this._addImplicitHelpCommand=!0,this._helpCommand=$,this._initCommandGroup($),this}_getHelpCommand(){if(this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))){if(this._helpCommand===void 0)this.helpCommand(void 0,void 0);return this._helpCommand}return null}hook($,q){let z=["preSubcommand","preAction","postAction"];if(!z.includes($))throw new Error(`Unexpected value for event passed to hook : '${$}'.
16
- Expecting one of '${z.join("', '")}'`);if(this._lifeCycleHooks[$])this._lifeCycleHooks[$].push(q);else this._lifeCycleHooks[$]=[q];return this}exitOverride($){if($)this._exitCallback=$;else this._exitCallback=(q)=>{if(q.code!=="commander.executeSubCommandAsync")throw q};return this}_exit($,q,z){if(this._exitCallback)this._exitCallback(new O($,q,z));_.exit($)}action($){let q=(z)=>{let J=this.registeredArguments.length,Q=z.slice(0,J);if(this._storeOptionsAsProperties)Q[J]=this;else Q[J]=this.opts();return Q.push(this),$.apply(this,Q)};return this._actionHandler=q,this}createOption($,q){return new r($,q)}_callParseArg($,q,z,J){try{return $.parseArg(q,z)}catch(Q){if(Q.code==="commander.invalidArgument"){let X=`${J} ${Q.message}`;this.error(X,{exitCode:Q.exitCode,code:Q.code})}throw Q}}_registerOption($){let q=$.short&&this._findOption($.short)||$.long&&this._findOption($.long);if(q){let z=$.long&&this._findOption($.long)?$.long:$.short;throw new Error(`Cannot add option '${$.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${z}'
17
- - already used by option '${q.flags}'`)}this._initOptionGroup($),this.options.push($)}_registerCommand($){let q=(J)=>{return[J.name()].concat(J.aliases())},z=q($).find((J)=>this._findCommand(J));if(z){let J=q(this._findCommand(z)).join("|"),Q=q($).join("|");throw new Error(`cannot add command '${Q}' as already have command '${J}'`)}this._initCommandGroup($),this.commands.push($)}addOption($){this._registerOption($);let q=$.name(),z=$.attributeName();if($.negate){let Q=$.long.replace(/^--no-/,"--");if(!this._findOption(Q))this.setOptionValueWithSource(z,$.defaultValue===void 0?!0:$.defaultValue,"default")}else if($.defaultValue!==void 0)this.setOptionValueWithSource(z,$.defaultValue,"default");let J=(Q,X,Y)=>{if(Q==null&&$.presetArg!==void 0)Q=$.presetArg;let Z=this.getOptionValue(z);if(Q!==null&&$.parseArg)Q=this._callParseArg($,Q,Z,X);else if(Q!==null&&$.variadic)Q=$._collectValue(Q,Z);if(Q==null)if($.negate)Q=!1;else if($.isBoolean()||$.optional)Q=!0;else Q="";this.setOptionValueWithSource(z,Q,Y)};if(this.on("option:"+q,(Q)=>{let X=`error: option '${$.flags}' argument '${Q}' is invalid.`;J(Q,X,"cli")}),$.envVar)this.on("optionEnv:"+q,(Q)=>{let X=`error: option '${$.flags}' value '${Q}' from env '${$.envVar}' is invalid.`;J(Q,X,"env")});return this}_optionEx($,q,z,J,Q){if(typeof q==="object"&&q instanceof r)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let X=this.createOption(q,z);if(X.makeOptionMandatory(!!$.mandatory),typeof J==="function")X.default(Q).argParser(J);else if(J instanceof RegExp){let Y=J;J=(Z,T)=>{let H=Y.exec(Z);return H?H[0]:T},X.default(Q).argParser(J)}else X.default(J);return this.addOption(X)}option($,q,z,J){return this._optionEx({},$,q,z,J)}requiredOption($,q,z,J){return this._optionEx({mandatory:!0},$,q,z,J)}combineFlagAndOptionalValue($=!0){return this._combineFlagAndOptionalValue=!!$,this}allowUnknownOption($=!0){return this._allowUnknownOption=!!$,this}allowExcessArguments($=!0){return this._allowExcessArguments=!!$,this}enablePositionalOptions($=!0){return this._enablePositionalOptions=!!$,this}passThroughOptions($=!0){return this._passThroughOptions=!!$,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties($=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!$,this}getOptionValue($){if(this._storeOptionsAsProperties)return this[$];return this._optionValues[$]}setOptionValue($,q){return this.setOptionValueWithSource($,q,void 0)}setOptionValueWithSource($,q,z){if(this._storeOptionsAsProperties)this[$]=q;else this._optionValues[$]=q;return this._optionValueSources[$]=z,this}getOptionValueSource($){return this._optionValueSources[$]}getOptionValueSourceWithGlobals($){let q;return this._getCommandAndAncestors().forEach((z)=>{if(z.getOptionValueSource($)!==void 0)q=z.getOptionValueSource($)}),q}_prepareUserArgs($,q){if($!==void 0&&!Array.isArray($))throw new Error("first parameter to parse must be array or undefined");if(q=q||{},$===void 0&&q.from===void 0){if(_.versions?.electron)q.from="electron";let J=_.execArgv??[];if(J.includes("-e")||J.includes("--eval")||J.includes("-p")||J.includes("--print"))q.from="eval"}if($===void 0)$=_.argv;this.rawArgs=$.slice();let z;switch(q.from){case void 0:case"node":this._scriptPath=$[1],z=$.slice(2);break;case"electron":if(_.defaultApp)this._scriptPath=$[1],z=$.slice(2);else z=$.slice(1);break;case"user":z=$.slice(0);break;case"eval":z=$.slice(1);break;default:throw new Error(`unexpected parse option { from: '${q.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",z}parse($,q){this._prepareForParse();let z=this._prepareUserArgs($,q);return this._parseCommand([],z),this}async parseAsync($,q){this._prepareForParse();let z=this._prepareUserArgs($,q);return await this._parseCommand([],z),this}_prepareForParse(){if(this._savedState===null)this.saveStateBeforeParse();else this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
18
- - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable($,q,z){if(F.existsSync($))return;let J=q?`searched for local subcommand relative to directory '${q}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",Q=`'${$}' does not exist
19
- - if '${z}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
9
+ - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(Z.test(B))throw Error(`${_}
10
+ - too many short flags`);if($.test(B))throw Error(`${_}
11
+ - too many long flags`);throw Error(`${_}
12
+ - unrecognised flag format`)}if(X===void 0&&Y===void 0)throw Error(`option creation failed due to no flags found in '${Q}'.`);return{shortFlag:X,longFlag:Y}}gQ.Option=t;gQ.DualOptions=o});var e=S((mQ)=>{function dQ(Q,X){if(Math.abs(Q.length-X.length)>3)return Math.max(Q.length,X.length);let Y=[];for(let Z=0;Z<=Q.length;Z++)Y[Z]=[Z];for(let Z=0;Z<=X.length;Z++)Y[0][Z]=Z;for(let Z=1;Z<=X.length;Z++)for(let $=1;$<=Q.length;$++){let q=1;if(Q[$-1]===X[Z-1])q=0;else q=1;if(Y[$][Z]=Math.min(Y[$-1][Z]+1,Y[$][Z-1]+1,Y[$-1][Z-1]+q),$>1&&Z>1&&Q[$-1]===X[Z-2]&&Q[$-2]===X[Z-1])Y[$][Z]=Math.min(Y[$][Z],Y[$-2][Z-2]+1)}return Y[Q.length][X.length]}function lQ(Q,X){if(!X||X.length===0)return"";X=Array.from(new Set(X));let Y=Q.startsWith("--");if(Y)Q=Q.slice(2),X=X.map((B)=>B.slice(2));let Z=[],$=3,q=0.4;if(X.forEach((B)=>{if(B.length<=1)return;let _=dQ(Q,B),R=Math.max(Q.length,B.length);if((R-_)/R>q){if(_<$)$=_,Z=[B];else if(_===$)Z.push(B)}}),Z.sort((B,_)=>B.localeCompare(_)),Y)Z=Z.map((B)=>`--${B}`);if(Z.length>1)return`
13
+ (Did you mean one of ${Z.join(", ")}?)`;if(Z.length===1)return`
14
+ (Did you mean ${Z[0]}?)`;return""}mQ.suggestSimilar=lQ});var ZQ=S((oQ)=>{var sQ=E("node:events").EventEmitter,x=E("node:child_process"),L=E("node:path"),k=E("node:fs"),H=E("node:process"),{Argument:iQ,humanReadableArgName:nQ}=A(),{CommanderError:C}=D(),{Help:aQ,stripColor:rQ}=w(),{Option:QQ,DualOptions:tQ}=O(),{suggestSimilar:XQ}=e();class f extends sQ{constructor(Q){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=Q||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:(X)=>H.stdout.write(X),writeErr:(X)=>H.stderr.write(X),outputError:(X,Y)=>Y(X),getOutHelpWidth:()=>H.stdout.isTTY?H.stdout.columns:void 0,getErrHelpWidth:()=>H.stderr.isTTY?H.stderr.columns:void 0,getOutHasColors:()=>b()??(H.stdout.isTTY&&H.stdout.hasColors?.()),getErrHasColors:()=>b()??(H.stderr.isTTY&&H.stderr.hasColors?.()),stripColor:(X)=>rQ(X)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(Q){return this._outputConfiguration=Q._outputConfiguration,this._helpOption=Q._helpOption,this._helpCommand=Q._helpCommand,this._helpConfiguration=Q._helpConfiguration,this._exitCallback=Q._exitCallback,this._storeOptionsAsProperties=Q._storeOptionsAsProperties,this._combineFlagAndOptionalValue=Q._combineFlagAndOptionalValue,this._allowExcessArguments=Q._allowExcessArguments,this._enablePositionalOptions=Q._enablePositionalOptions,this._showHelpAfterError=Q._showHelpAfterError,this._showSuggestionAfterError=Q._showSuggestionAfterError,this}_getCommandAndAncestors(){let Q=[];for(let X=this;X;X=X.parent)Q.push(X);return Q}command(Q,X,Y){let Z=X,$=Y;if(typeof Z==="object"&&Z!==null)$=Z,Z=null;$=$||{};let[,q,B]=Q.match(/([^ ]+) *(.*)/),_=this.createCommand(q);if(Z)_.description(Z),_._executableHandler=!0;if($.isDefault)this._defaultCommandName=_._name;if(_._hidden=!!($.noHelp||$.hidden),_._executableFile=$.executableFile||null,B)_.arguments(B);if(this._registerCommand(_),_.parent=this,_.copyInheritedSettings(this),Z)return this;return _}createCommand(Q){return new f(Q)}createHelp(){return Object.assign(new aQ,this.configureHelp())}configureHelp(Q){if(Q===void 0)return this._helpConfiguration;return this._helpConfiguration=Q,this}configureOutput(Q){if(Q===void 0)return this._outputConfiguration;return this._outputConfiguration={...this._outputConfiguration,...Q},this}showHelpAfterError(Q=!0){if(typeof Q!=="string")Q=!!Q;return this._showHelpAfterError=Q,this}showSuggestionAfterError(Q=!0){return this._showSuggestionAfterError=!!Q,this}addCommand(Q,X){if(!Q._name)throw Error(`Command passed to .addCommand() must have a name
15
+ - specify the name in Command constructor or using .name()`);if(X=X||{},X.isDefault)this._defaultCommandName=Q._name;if(X.noHelp||X.hidden)Q._hidden=!0;return this._registerCommand(Q),Q.parent=this,Q._checkForBrokenPassThrough(),this}createArgument(Q,X){return new iQ(Q,X)}argument(Q,X,Y,Z){let $=this.createArgument(Q,X);if(typeof Y==="function")$.default(Z).argParser(Y);else $.default(Y);return this.addArgument($),this}arguments(Q){return Q.trim().split(/ +/).forEach((X)=>{this.argument(X)}),this}addArgument(Q){let X=this.registeredArguments.slice(-1)[0];if(X?.variadic)throw Error(`only the last argument can be variadic '${X.name()}'`);if(Q.required&&Q.defaultValue!==void 0&&Q.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${Q.name()}'`);return this.registeredArguments.push(Q),this}helpCommand(Q,X){if(typeof Q==="boolean"){if(this._addImplicitHelpCommand=Q,Q&&this._defaultCommandGroup)this._initCommandGroup(this._getHelpCommand());return this}let Y=Q??"help [command]",[,Z,$]=Y.match(/([^ ]+) *(.*)/),q=X??"display help for command",B=this.createCommand(Z);if(B.helpOption(!1),$)B.arguments($);if(q)B.description(q);if(this._addImplicitHelpCommand=!0,this._helpCommand=B,Q||X)this._initCommandGroup(B);return this}addHelpCommand(Q,X){if(typeof Q!=="object")return this.helpCommand(Q,X),this;return this._addImplicitHelpCommand=!0,this._helpCommand=Q,this._initCommandGroup(Q),this}_getHelpCommand(){if(this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))){if(this._helpCommand===void 0)this.helpCommand(void 0,void 0);return this._helpCommand}return null}hook(Q,X){let Y=["preSubcommand","preAction","postAction"];if(!Y.includes(Q))throw Error(`Unexpected value for event passed to hook : '${Q}'.
16
+ Expecting one of '${Y.join("', '")}'`);if(this._lifeCycleHooks[Q])this._lifeCycleHooks[Q].push(X);else this._lifeCycleHooks[Q]=[X];return this}exitOverride(Q){if(Q)this._exitCallback=Q;else this._exitCallback=(X)=>{if(X.code!=="commander.executeSubCommandAsync")throw X};return this}_exit(Q,X,Y){if(this._exitCallback)this._exitCallback(new C(Q,X,Y));H.exit(Q)}action(Q){let X=(Y)=>{let Z=this.registeredArguments.length,$=Y.slice(0,Z);if(this._storeOptionsAsProperties)$[Z]=this;else $[Z]=this.opts();return $.push(this),Q.apply(this,$)};return this._actionHandler=X,this}createOption(Q,X){return new QQ(Q,X)}_callParseArg(Q,X,Y,Z){try{return Q.parseArg(X,Y)}catch($){if($.code==="commander.invalidArgument"){let q=`${Z} ${$.message}`;this.error(q,{exitCode:$.exitCode,code:$.code})}throw $}}_registerOption(Q){let X=Q.short&&this._findOption(Q.short)||Q.long&&this._findOption(Q.long);if(X){let Y=Q.long&&this._findOption(Q.long)?Q.long:Q.short;throw Error(`Cannot add option '${Q.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${Y}'
17
+ - already used by option '${X.flags}'`)}this._initOptionGroup(Q),this.options.push(Q)}_registerCommand(Q){let X=(Z)=>{return[Z.name()].concat(Z.aliases())},Y=X(Q).find((Z)=>this._findCommand(Z));if(Y){let Z=X(this._findCommand(Y)).join("|"),$=X(Q).join("|");throw Error(`cannot add command '${$}' as already have command '${Z}'`)}this._initCommandGroup(Q),this.commands.push(Q)}addOption(Q){this._registerOption(Q);let X=Q.name(),Y=Q.attributeName();if(Q.negate){let $=Q.long.replace(/^--no-/,"--");if(!this._findOption($))this.setOptionValueWithSource(Y,Q.defaultValue===void 0?!0:Q.defaultValue,"default")}else if(Q.defaultValue!==void 0)this.setOptionValueWithSource(Y,Q.defaultValue,"default");let Z=($,q,B)=>{if($==null&&Q.presetArg!==void 0)$=Q.presetArg;let _=this.getOptionValue(Y);if($!==null&&Q.parseArg)$=this._callParseArg(Q,$,_,q);else if($!==null&&Q.variadic)$=Q._collectValue($,_);if($==null)if(Q.negate)$=!1;else if(Q.isBoolean()||Q.optional)$=!0;else $="";this.setOptionValueWithSource(Y,$,B)};if(this.on("option:"+X,($)=>{let q=`error: option '${Q.flags}' argument '${$}' is invalid.`;Z($,q,"cli")}),Q.envVar)this.on("optionEnv:"+X,($)=>{let q=`error: option '${Q.flags}' value '${$}' from env '${Q.envVar}' is invalid.`;Z($,q,"env")});return this}_optionEx(Q,X,Y,Z,$){if(typeof X==="object"&&X instanceof QQ)throw Error("To add an Option object use addOption() instead of option() or requiredOption()");let q=this.createOption(X,Y);if(q.makeOptionMandatory(!!Q.mandatory),typeof Z==="function")q.default($).argParser(Z);else if(Z instanceof RegExp){let B=Z;Z=(_,R)=>{let J=B.exec(_);return J?J[0]:R},q.default($).argParser(Z)}else q.default(Z);return this.addOption(q)}option(Q,X,Y,Z){return this._optionEx({},Q,X,Y,Z)}requiredOption(Q,X,Y,Z){return this._optionEx({mandatory:!0},Q,X,Y,Z)}combineFlagAndOptionalValue(Q=!0){return this._combineFlagAndOptionalValue=!!Q,this}allowUnknownOption(Q=!0){return this._allowUnknownOption=!!Q,this}allowExcessArguments(Q=!0){return this._allowExcessArguments=!!Q,this}enablePositionalOptions(Q=!0){return this._enablePositionalOptions=!!Q,this}passThroughOptions(Q=!0){return this._passThroughOptions=!!Q,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(Q=!0){if(this.options.length)throw Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!Q,this}getOptionValue(Q){if(this._storeOptionsAsProperties)return this[Q];return this._optionValues[Q]}setOptionValue(Q,X){return this.setOptionValueWithSource(Q,X,void 0)}setOptionValueWithSource(Q,X,Y){if(this._storeOptionsAsProperties)this[Q]=X;else this._optionValues[Q]=X;return this._optionValueSources[Q]=Y,this}getOptionValueSource(Q){return this._optionValueSources[Q]}getOptionValueSourceWithGlobals(Q){let X;return this._getCommandAndAncestors().forEach((Y)=>{if(Y.getOptionValueSource(Q)!==void 0)X=Y.getOptionValueSource(Q)}),X}_prepareUserArgs(Q,X){if(Q!==void 0&&!Array.isArray(Q))throw Error("first parameter to parse must be array or undefined");if(X=X||{},Q===void 0&&X.from===void 0){if(H.versions?.electron)X.from="electron";let Z=H.execArgv??[];if(Z.includes("-e")||Z.includes("--eval")||Z.includes("-p")||Z.includes("--print"))X.from="eval"}if(Q===void 0)Q=H.argv;this.rawArgs=Q.slice();let Y;switch(X.from){case void 0:case"node":this._scriptPath=Q[1],Y=Q.slice(2);break;case"electron":if(H.defaultApp)this._scriptPath=Q[1],Y=Q.slice(2);else Y=Q.slice(1);break;case"user":Y=Q.slice(0);break;case"eval":Y=Q.slice(1);break;default:throw Error(`unexpected parse option { from: '${X.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",Y}parse(Q,X){this._prepareForParse();let Y=this._prepareUserArgs(Q,X);return this._parseCommand([],Y),this}async parseAsync(Q,X){this._prepareForParse();let Y=this._prepareUserArgs(Q,X);return await this._parseCommand([],Y),this}_prepareForParse(){if(this._savedState===null)this.saveStateBeforeParse();else this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw Error(`Can not call parse again when storeOptionsAsProperties is true.
18
+ - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(Q,X,Y){if(k.existsSync(Q))return;let Z=X?`searched for local subcommand relative to directory '${X}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",$=`'${Q}' does not exist
19
+ - if '${Y}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
20
20
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
21
- - ${J}`;throw new Error(Q)}_executeSubCommand($,q){q=q.slice();let z=!1,J=[".js",".ts",".tsx",".mjs",".cjs"];function Q(H,R){let B=L.resolve(H,R);if(F.existsSync(B))return B;if(J.includes(L.extname(R)))return;let G=J.find((M)=>F.existsSync(`${B}${M}`));if(G)return`${B}${G}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let X=$._executableFile||`${this._name}-${$._name}`,Y=this._executableDir||"";if(this._scriptPath){let H;try{H=F.realpathSync(this._scriptPath)}catch{H=this._scriptPath}Y=L.resolve(L.dirname(H),Y)}if(Y){let H=Q(Y,X);if(!H&&!$._executableFile&&this._scriptPath){let R=L.basename(this._scriptPath,L.extname(this._scriptPath));if(R!==this._name)H=Q(Y,`${R}-${$._name}`)}X=H||X}z=J.includes(L.extname(X));let Z;if(_.platform!=="win32")if(z)q.unshift(X),q=o(_.execArgv).concat(q),Z=k.spawn(_.argv[0],q,{stdio:"inherit"});else Z=k.spawn(X,q,{stdio:"inherit"});else this._checkForMissingExecutable(X,Y,$._name),q.unshift(X),q=o(_.execArgv).concat(q),Z=k.spawn(_.execPath,q,{stdio:"inherit"});if(!Z.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((R)=>{_.on(R,()=>{if(Z.killed===!1&&Z.exitCode===null)Z.kill(R)})});let T=this._exitCallback;Z.on("close",(H)=>{if(H=H??1,!T)_.exit(H);else T(new O(H,"commander.executeSubCommandAsync","(close)"))}),Z.on("error",(H)=>{if(H.code==="ENOENT")this._checkForMissingExecutable(X,Y,$._name);else if(H.code==="EACCES")throw new Error(`'${X}' not executable`);if(!T)_.exit(1);else{let R=new O(1,"commander.executeSubCommandAsync","(error)");R.nestedError=H,T(R)}}),this.runningCommand=Z}_dispatchSubcommand($,q,z){let J=this._findCommand($);if(!J)this.help({error:!0});J._prepareForParse();let Q;return Q=this._chainOrCallSubCommandHook(Q,J,"preSubcommand"),Q=this._chainOrCall(Q,()=>{if(J._executableHandler)this._executeSubCommand(J,q.concat(z));else return J._parseCommand(q,z)}),Q}_dispatchHelpCommand($){if(!$)this.help();let q=this._findCommand($);if(q&&!q._executableHandler)q.help();return this._dispatchSubcommand($,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach(($,q)=>{if($.required&&this.args[q]==null)this.missingArgument($.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let $=(z,J,Q)=>{let X=J;if(J!==null&&z.parseArg){let Y=`error: command-argument value '${J}' is invalid for argument '${z.name()}'.`;X=this._callParseArg(z,J,Q,Y)}return X};this._checkNumberOfArguments();let q=[];this.registeredArguments.forEach((z,J)=>{let Q=z.defaultValue;if(z.variadic){if(J<this.args.length){if(Q=this.args.slice(J),z.parseArg)Q=Q.reduce((X,Y)=>{return $(z,Y,X)},z.defaultValue)}else if(Q===void 0)Q=[]}else if(J<this.args.length){if(Q=this.args[J],z.parseArg)Q=$(z,Q,z.defaultValue)}q[J]=Q}),this.processedArgs=q}_chainOrCall($,q){if($?.then&&typeof $.then==="function")return $.then(()=>q());return q()}_chainOrCallHooks($,q){let z=$,J=[];if(this._getCommandAndAncestors().reverse().filter((Q)=>Q._lifeCycleHooks[q]!==void 0).forEach((Q)=>{Q._lifeCycleHooks[q].forEach((X)=>{J.push({hookedCommand:Q,callback:X})})}),q==="postAction")J.reverse();return J.forEach((Q)=>{z=this._chainOrCall(z,()=>{return Q.callback(Q.hookedCommand,this)})}),z}_chainOrCallSubCommandHook($,q,z){let J=$;if(this._lifeCycleHooks[z]!==void 0)this._lifeCycleHooks[z].forEach((Q)=>{J=this._chainOrCall(J,()=>{return Q(this,q)})});return J}_parseCommand($,q){let z=this.parseOptions(q);if(this._parseOptionsEnv(),this._parseOptionsImplied(),$=$.concat(z.operands),q=z.unknown,this.args=$.concat(q),$&&this._findCommand($[0]))return this._dispatchSubcommand($[0],$.slice(1),q);if(this._getHelpCommand()&&$[0]===this._getHelpCommand().name())return this._dispatchHelpCommand($[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(q),this._dispatchSubcommand(this._defaultCommandName,$,q);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(z.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let J=()=>{if(z.unknown.length>0)this.unknownOption(z.unknown[0])},Q=`command:${this.name()}`;if(this._actionHandler){J(),this._processArguments();let X;if(X=this._chainOrCallHooks(X,"preAction"),X=this._chainOrCall(X,()=>this._actionHandler(this.processedArgs)),this.parent)X=this._chainOrCall(X,()=>{this.parent.emit(Q,$,q)});return X=this._chainOrCallHooks(X,"postAction"),X}if(this.parent?.listenerCount(Q))J(),this._processArguments(),this.parent.emit(Q,$,q);else if($.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",$,q);if(this.listenerCount("command:*"))this.emit("command:*",$,q);else if(this.commands.length)this.unknownCommand();else J(),this._processArguments()}else if(this.commands.length)J(),this.help({error:!0});else J(),this._processArguments()}_findCommand($){if(!$)return;return this.commands.find((q)=>q._name===$||q._aliases.includes($))}_findOption($){return this.options.find((q)=>q.is($))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(($)=>{$.options.forEach((q)=>{if(q.mandatory&&$.getOptionValue(q.attributeName())===void 0)$.missingMandatoryOptionValue(q)})})}_checkForConflictingLocalOptions(){let $=this.options.filter((z)=>{let J=z.attributeName();if(this.getOptionValue(J)===void 0)return!1;return this.getOptionValueSource(J)!=="default"});$.filter((z)=>z.conflictsWith.length>0).forEach((z)=>{let J=$.find((Q)=>z.conflictsWith.includes(Q.attributeName()));if(J)this._conflictingOption(z,J)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(($)=>{$._checkForConflictingLocalOptions()})}parseOptions($){let q=[],z=[],J=q;function Q(H){return H.length>1&&H[0]==="-"}let X=(H)=>{if(!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(H))return!1;return!this._getCommandAndAncestors().some((R)=>R.options.map((B)=>B.short).some((B)=>/^-\d$/.test(B)))},Y=null,Z=null,T=0;while(T<$.length||Z){let H=Z??$[T++];if(Z=null,H==="--"){if(J===z)J.push(H);J.push(...$.slice(T));break}if(Y&&(!Q(H)||X(H))){this.emit(`option:${Y.name()}`,H);continue}if(Y=null,Q(H)){let R=this._findOption(H);if(R){if(R.required){let B=$[T++];if(B===void 0)this.optionMissingArgument(R);this.emit(`option:${R.name()}`,B)}else if(R.optional){let B=null;if(T<$.length&&(!Q($[T])||X($[T])))B=$[T++];this.emit(`option:${R.name()}`,B)}else this.emit(`option:${R.name()}`);Y=R.variadic?R:null;continue}}if(H.length>2&&H[0]==="-"&&H[1]!=="-"){let R=this._findOption(`-${H[1]}`);if(R){if(R.required||R.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${R.name()}`,H.slice(2));else this.emit(`option:${R.name()}`),Z=`-${H.slice(2)}`;continue}}if(/^--[^=]+=/.test(H)){let R=H.indexOf("="),B=this._findOption(H.slice(0,R));if(B&&(B.required||B.optional)){this.emit(`option:${B.name()}`,H.slice(R+1));continue}}if(J===q&&Q(H)&&!(this.commands.length===0&&X(H)))J=z;if((this._enablePositionalOptions||this._passThroughOptions)&&q.length===0&&z.length===0){if(this._findCommand(H)){q.push(H),z.push(...$.slice(T));break}else if(this._getHelpCommand()&&H===this._getHelpCommand().name()){q.push(H,...$.slice(T));break}else if(this._defaultCommandName){z.push(H,...$.slice(T));break}}if(this._passThroughOptions){J.push(H,...$.slice(T));break}J.push(H)}return{operands:q,unknown:z}}opts(){if(this._storeOptionsAsProperties){let $={},q=this.options.length;for(let z=0;z<q;z++){let J=this.options[z].attributeName();$[J]=J===this._versionOptionName?this._version:this[J]}return $}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce(($,q)=>Object.assign($,q.opts()),{})}error($,q){if(this._outputConfiguration.outputError(`${$}
21
+ - ${Z}`;throw Error($)}_executeSubCommand(Q,X){X=X.slice();let Y=!1,Z=[".js",".ts",".tsx",".mjs",".cjs"];function $(J,z){let G=L.resolve(J,z);if(k.existsSync(G))return G;if(Z.includes(L.extname(z)))return;let T=Z.find((U)=>k.existsSync(`${G}${U}`));if(T)return`${G}${T}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let q=Q._executableFile||`${this._name}-${Q._name}`,B=this._executableDir||"";if(this._scriptPath){let J;try{J=k.realpathSync(this._scriptPath)}catch{J=this._scriptPath}B=L.resolve(L.dirname(J),B)}if(B){let J=$(B,q);if(!J&&!Q._executableFile&&this._scriptPath){let z=L.basename(this._scriptPath,L.extname(this._scriptPath));if(z!==this._name)J=$(B,`${z}-${Q._name}`)}q=J||q}Y=Z.includes(L.extname(q));let _;if(H.platform!=="win32")if(Y)X.unshift(q),X=YQ(H.execArgv).concat(X),_=x.spawn(H.argv[0],X,{stdio:"inherit"});else _=x.spawn(q,X,{stdio:"inherit"});else this._checkForMissingExecutable(q,B,Q._name),X.unshift(q),X=YQ(H.execArgv).concat(X),_=x.spawn(H.execPath,X,{stdio:"inherit"});if(!_.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((z)=>{H.on(z,()=>{if(_.killed===!1&&_.exitCode===null)_.kill(z)})});let R=this._exitCallback;_.on("close",(J)=>{if(J=J??1,!R)H.exit(J);else R(new C(J,"commander.executeSubCommandAsync","(close)"))}),_.on("error",(J)=>{if(J.code==="ENOENT")this._checkForMissingExecutable(q,B,Q._name);else if(J.code==="EACCES")throw Error(`'${q}' not executable`);if(!R)H.exit(1);else{let z=new C(1,"commander.executeSubCommandAsync","(error)");z.nestedError=J,R(z)}}),this.runningCommand=_}_dispatchSubcommand(Q,X,Y){let Z=this._findCommand(Q);if(!Z)this.help({error:!0});Z._prepareForParse();let $;return $=this._chainOrCallSubCommandHook($,Z,"preSubcommand"),$=this._chainOrCall($,()=>{if(Z._executableHandler)this._executeSubCommand(Z,X.concat(Y));else return Z._parseCommand(X,Y)}),$}_dispatchHelpCommand(Q){if(!Q)this.help();let X=this._findCommand(Q);if(X&&!X._executableHandler)X.help();return this._dispatchSubcommand(Q,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach((Q,X)=>{if(Q.required&&this.args[X]==null)this.missingArgument(Q.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let Q=(Y,Z,$)=>{let q=Z;if(Z!==null&&Y.parseArg){let B=`error: command-argument value '${Z}' is invalid for argument '${Y.name()}'.`;q=this._callParseArg(Y,Z,$,B)}return q};this._checkNumberOfArguments();let X=[];this.registeredArguments.forEach((Y,Z)=>{let $=Y.defaultValue;if(Y.variadic){if(Z<this.args.length){if($=this.args.slice(Z),Y.parseArg)$=$.reduce((q,B)=>{return Q(Y,B,q)},Y.defaultValue)}else if($===void 0)$=[]}else if(Z<this.args.length){if($=this.args[Z],Y.parseArg)$=Q(Y,$,Y.defaultValue)}X[Z]=$}),this.processedArgs=X}_chainOrCall(Q,X){if(Q?.then&&typeof Q.then==="function")return Q.then(()=>X());return X()}_chainOrCallHooks(Q,X){let Y=Q,Z=[];if(this._getCommandAndAncestors().reverse().filter(($)=>$._lifeCycleHooks[X]!==void 0).forEach(($)=>{$._lifeCycleHooks[X].forEach((q)=>{Z.push({hookedCommand:$,callback:q})})}),X==="postAction")Z.reverse();return Z.forEach(($)=>{Y=this._chainOrCall(Y,()=>{return $.callback($.hookedCommand,this)})}),Y}_chainOrCallSubCommandHook(Q,X,Y){let Z=Q;if(this._lifeCycleHooks[Y]!==void 0)this._lifeCycleHooks[Y].forEach(($)=>{Z=this._chainOrCall(Z,()=>{return $(this,X)})});return Z}_parseCommand(Q,X){let Y=this.parseOptions(X);if(this._parseOptionsEnv(),this._parseOptionsImplied(),Q=Q.concat(Y.operands),X=Y.unknown,this.args=Q.concat(X),Q&&this._findCommand(Q[0]))return this._dispatchSubcommand(Q[0],Q.slice(1),X);if(this._getHelpCommand()&&Q[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(Q[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(X),this._dispatchSubcommand(this._defaultCommandName,Q,X);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(Y.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let Z=()=>{if(Y.unknown.length>0)this.unknownOption(Y.unknown[0])},$=`command:${this.name()}`;if(this._actionHandler){Z(),this._processArguments();let q;if(q=this._chainOrCallHooks(q,"preAction"),q=this._chainOrCall(q,()=>this._actionHandler(this.processedArgs)),this.parent)q=this._chainOrCall(q,()=>{this.parent.emit($,Q,X)});return q=this._chainOrCallHooks(q,"postAction"),q}if(this.parent?.listenerCount($))Z(),this._processArguments(),this.parent.emit($,Q,X);else if(Q.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",Q,X);if(this.listenerCount("command:*"))this.emit("command:*",Q,X);else if(this.commands.length)this.unknownCommand();else Z(),this._processArguments()}else if(this.commands.length)Z(),this.help({error:!0});else Z(),this._processArguments()}_findCommand(Q){if(!Q)return;return this.commands.find((X)=>X._name===Q||X._aliases.includes(Q))}_findOption(Q){return this.options.find((X)=>X.is(Q))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((Q)=>{Q.options.forEach((X)=>{if(X.mandatory&&Q.getOptionValue(X.attributeName())===void 0)Q.missingMandatoryOptionValue(X)})})}_checkForConflictingLocalOptions(){let Q=this.options.filter((Y)=>{let Z=Y.attributeName();if(this.getOptionValue(Z)===void 0)return!1;return this.getOptionValueSource(Z)!=="default"});Q.filter((Y)=>Y.conflictsWith.length>0).forEach((Y)=>{let Z=Q.find(($)=>Y.conflictsWith.includes($.attributeName()));if(Z)this._conflictingOption(Y,Z)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((Q)=>{Q._checkForConflictingLocalOptions()})}parseOptions(Q){let X=[],Y=[],Z=X;function $(J){return J.length>1&&J[0]==="-"}let q=(J)=>{if(!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(J))return!1;return!this._getCommandAndAncestors().some((z)=>z.options.map((G)=>G.short).some((G)=>/^-\d$/.test(G)))},B=null,_=null,R=0;while(R<Q.length||_){let J=_??Q[R++];if(_=null,J==="--"){if(Z===Y)Z.push(J);Z.push(...Q.slice(R));break}if(B&&(!$(J)||q(J))){this.emit(`option:${B.name()}`,J);continue}if(B=null,$(J)){let z=this._findOption(J);if(z){if(z.required){let G=Q[R++];if(G===void 0)this.optionMissingArgument(z);this.emit(`option:${z.name()}`,G)}else if(z.optional){let G=null;if(R<Q.length&&(!$(Q[R])||q(Q[R])))G=Q[R++];this.emit(`option:${z.name()}`,G)}else this.emit(`option:${z.name()}`);B=z.variadic?z:null;continue}}if(J.length>2&&J[0]==="-"&&J[1]!=="-"){let z=this._findOption(`-${J[1]}`);if(z){if(z.required||z.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${z.name()}`,J.slice(2));else this.emit(`option:${z.name()}`),_=`-${J.slice(2)}`;continue}}if(/^--[^=]+=/.test(J)){let z=J.indexOf("="),G=this._findOption(J.slice(0,z));if(G&&(G.required||G.optional)){this.emit(`option:${G.name()}`,J.slice(z+1));continue}}if(Z===X&&$(J)&&!(this.commands.length===0&&q(J)))Z=Y;if((this._enablePositionalOptions||this._passThroughOptions)&&X.length===0&&Y.length===0){if(this._findCommand(J)){X.push(J),Y.push(...Q.slice(R));break}else if(this._getHelpCommand()&&J===this._getHelpCommand().name()){X.push(J,...Q.slice(R));break}else if(this._defaultCommandName){Y.push(J,...Q.slice(R));break}}if(this._passThroughOptions){Z.push(J,...Q.slice(R));break}Z.push(J)}return{operands:X,unknown:Y}}opts(){if(this._storeOptionsAsProperties){let Q={},X=this.options.length;for(let Y=0;Y<X;Y++){let Z=this.options[Y].attributeName();Q[Z]=Z===this._versionOptionName?this._version:this[Z]}return Q}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((Q,X)=>Object.assign(Q,X.opts()),{})}error(Q,X){if(this._outputConfiguration.outputError(`${Q}
22
22
  `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError}
23
23
  `);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(`
24
- `),this.outputHelp({error:!0});let z=q||{},J=z.exitCode||1,Q=z.code||"commander.error";this._exit(J,Q,$)}_parseOptionsEnv(){this.options.forEach(($)=>{if($.envVar&&$.envVar in _.env){let q=$.attributeName();if(this.getOptionValue(q)===void 0||["default","config","env"].includes(this.getOptionValueSource(q)))if($.required||$.optional)this.emit(`optionEnv:${$.name()}`,_.env[$.envVar]);else this.emit(`optionEnv:${$.name()}`)}})}_parseOptionsImplied(){let $=new s1(this.options),q=(z)=>{return this.getOptionValue(z)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(z))};this.options.filter((z)=>z.implied!==void 0&&q(z.attributeName())&&$.valueFromOption(this.getOptionValue(z.attributeName()),z)).forEach((z)=>{Object.keys(z.implied).filter((J)=>!q(J)).forEach((J)=>{this.setOptionValueWithSource(J,z.implied[J],"implied")})})}missingArgument($){let q=`error: missing required argument '${$}'`;this.error(q,{code:"commander.missingArgument"})}optionMissingArgument($){let q=`error: option '${$.flags}' argument missing`;this.error(q,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue($){let q=`error: required option '${$.flags}' not specified`;this.error(q,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption($,q){let z=(X)=>{let Y=X.attributeName(),Z=this.getOptionValue(Y),T=this.options.find((R)=>R.negate&&Y===R.attributeName()),H=this.options.find((R)=>!R.negate&&Y===R.attributeName());if(T&&(T.presetArg===void 0&&Z===!1||T.presetArg!==void 0&&Z===T.presetArg))return T;return H||X},J=(X)=>{let Y=z(X),Z=Y.attributeName();if(this.getOptionValueSource(Z)==="env")return`environment variable '${Y.envVar}'`;return`option '${Y.flags}'`},Q=`error: ${J($)} cannot be used with ${J(q)}`;this.error(Q,{code:"commander.conflictingOption"})}unknownOption($){if(this._allowUnknownOption)return;let q="";if($.startsWith("--")&&this._showSuggestionAfterError){let J=[],Q=this;do{let X=Q.createHelp().visibleOptions(Q).filter((Y)=>Y.long).map((Y)=>Y.long);J=J.concat(X),Q=Q.parent}while(Q&&!Q._enablePositionalOptions);q=a($,J)}let z=`error: unknown option '${$}'${q}`;this.error(z,{code:"commander.unknownOption"})}_excessArguments($){if(this._allowExcessArguments)return;let q=this.registeredArguments.length,z=q===1?"":"s",Q=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${q} argument${z} but got ${$.length}.`;this.error(Q,{code:"commander.excessArguments"})}unknownCommand(){let $=this.args[0],q="";if(this._showSuggestionAfterError){let J=[];this.createHelp().visibleCommands(this).forEach((Q)=>{if(J.push(Q.name()),Q.alias())J.push(Q.alias())}),q=a($,J)}let z=`error: unknown command '${$}'${q}`;this.error(z,{code:"commander.unknownCommand"})}version($,q,z){if($===void 0)return this._version;this._version=$,q=q||"-V, --version",z=z||"output the version number";let J=this.createOption(q,z);return this._versionOptionName=J.attributeName(),this._registerOption(J),this.on("option:"+J.name(),()=>{this._outputConfiguration.writeOut(`${$}
25
- `),this._exit(0,"commander.version",$)}),this}description($,q){if($===void 0&&q===void 0)return this._description;if(this._description=$,q)this._argsDescription=q;return this}summary($){if($===void 0)return this._summary;return this._summary=$,this}alias($){if($===void 0)return this._aliases[0];let q=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)q=this.commands[this.commands.length-1];if($===q._name)throw new Error("Command alias can't be the same as its name");let z=this.parent?._findCommand($);if(z){let J=[z.name()].concat(z.aliases()).join("|");throw new Error(`cannot add alias '${$}' to command '${this.name()}' as already have command '${J}'`)}return q._aliases.push($),this}aliases($){if($===void 0)return this._aliases;return $.forEach((q)=>this.alias(q)),this}usage($){if($===void 0){if(this._usage)return this._usage;let q=this.registeredArguments.map((z)=>{return m1(z)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?q:[]).join(" ")}return this._usage=$,this}name($){if($===void 0)return this._name;return this._name=$,this}helpGroup($){if($===void 0)return this._helpGroupHeading??"";return this._helpGroupHeading=$,this}commandsGroup($){if($===void 0)return this._defaultCommandGroup??"";return this._defaultCommandGroup=$,this}optionsGroup($){if($===void 0)return this._defaultOptionGroup??"";return this._defaultOptionGroup=$,this}_initOptionGroup($){if(this._defaultOptionGroup&&!$.helpGroupHeading)$.helpGroup(this._defaultOptionGroup)}_initCommandGroup($){if(this._defaultCommandGroup&&!$.helpGroup())$.helpGroup(this._defaultCommandGroup)}nameFromFilename($){return this._name=L.basename($,L.extname($)),this}executableDir($){if($===void 0)return this._executableDir;return this._executableDir=$,this}helpInformation($){let q=this.createHelp(),z=this._getOutputContext($);q.prepareContext({error:z.error,helpWidth:z.helpWidth,outputHasColors:z.hasColors});let J=q.formatHelp(this,q);if(z.hasColors)return J;return this._outputConfiguration.stripColor(J)}_getOutputContext($){$=$||{};let q=!!$.error,z,J,Q;if(q)z=(Y)=>this._outputConfiguration.writeErr(Y),J=this._outputConfiguration.getErrHasColors(),Q=this._outputConfiguration.getErrHelpWidth();else z=(Y)=>this._outputConfiguration.writeOut(Y),J=this._outputConfiguration.getOutHasColors(),Q=this._outputConfiguration.getOutHelpWidth();return{error:q,write:(Y)=>{if(!J)Y=this._outputConfiguration.stripColor(Y);return z(Y)},hasColors:J,helpWidth:Q}}outputHelp($){let q;if(typeof $==="function")q=$,$=void 0;let z=this._getOutputContext($),J={error:z.error,write:z.write,command:this};this._getCommandAndAncestors().reverse().forEach((X)=>X.emit("beforeAllHelp",J)),this.emit("beforeHelp",J);let Q=this.helpInformation({error:z.error});if(q){if(Q=q(Q),typeof Q!=="string"&&!Buffer.isBuffer(Q))throw new Error("outputHelp callback must return a string or a Buffer")}if(z.write(Q),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",J),this._getCommandAndAncestors().forEach((X)=>X.emit("afterAllHelp",J))}helpOption($,q){if(typeof $==="boolean"){if($){if(this._helpOption===null)this._helpOption=void 0;if(this._defaultOptionGroup)this._initOptionGroup(this._getHelpOption())}else this._helpOption=null;return this}if(this._helpOption=this.createOption($??"-h, --help",q??"display help for command"),$||q)this._initOptionGroup(this._helpOption);return this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption($){return this._helpOption=$,this._initOptionGroup($),this}help($){this.outputHelp($);let q=Number(_.exitCode??0);if(q===0&&$&&typeof $!=="function"&&$.error)q=1;this._exit(q,"commander.help","(outputHelp)")}addHelpText($,q){let z=["beforeAll","before","after","afterAll"];if(!z.includes($))throw new Error(`Unexpected value for position to addHelpText.
26
- Expecting one of '${z.join("', '")}'`);let J=`${$}Help`;return this.on(J,(Q)=>{let X;if(typeof q==="function")X=q({error:Q.error,command:Q.command});else X=q;if(X)Q.write(`${X}
27
- `)}),this}_outputHelpIfRequested($){let q=this._getHelpOption();if(q&&$.find((J)=>q.is(J)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function o($){return $.map((q)=>{if(!q.startsWith("--inspect"))return q;let z,J="127.0.0.1",Q="9229",X;if((X=q.match(/^(--inspect(-brk)?)$/))!==null)z=X[1];else if((X=q.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(z=X[1],/^\d+$/.test(X[3]))Q=X[3];else J=X[3];else if((X=q.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)z=X[1],J=X[3],Q=X[4];if(z&&Q!=="0")return`${z}=${J}:${parseInt(Q)+1}`;return q})}function x(){if(_.env.NO_COLOR||_.env.FORCE_COLOR==="0"||_.env.FORCE_COLOR==="false")return!1;if(_.env.FORCE_COLOR||_.env.CLICOLOR_FORCE!==void 0)return!0;return}i1.Command=b;i1.useColor=x});var J1=U((o1)=>{var{Argument:$1}=y(),{Command:C}=e(),{CommanderError:r1,InvalidArgumentError:q1}=E(),{Help:a1}=A(),{Option:z1}=P();o1.program=new C;o1.createCommand=($)=>new C($);o1.createOption=($,q)=>new z1($,q);o1.createArgument=($,q)=>new $1($,q);o1.Command=C;o1.Option=z1;o1.Argument=$1;o1.Help=a1;o1.CommanderError=r1;o1.InvalidArgumentError=q1;o1.InvalidOptionArgumentError=q1});import{readFileSync as y2}from"node:fs";import{dirname as F2,join as w2}from"node:path";import{fileURLToPath as A2}from"node:url";var Q1=K1(J1(),1),{program:d2,createCommand:p2,createArgument:s2,createOption:i2,CommanderError:t2,InvalidArgumentError:n2,InvalidOptionArgumentError:r2,Command:X1,Argument:a2,Option:o2,Help:e2}=Q1.default;import{join as V2}from"node:path";import{existsSync as Y1}from"node:fs";import{readFile as T2}from"node:fs/promises";import{dirname as Z1,join as H1,resolve as f}from"node:path";var B2=".gstatxrc.json";function v($){let z=$.replace(/\.git$/,"").split(/[/:]/);return z[z.length-1]||"repository"}function _2($){let q=f($),z=20,J=0;while(J<z){let Q=H1(q,B2);if(Y1(Q))return Q;let X=Z1(q);if(X===q)break;q=X,J++}return null}async function V($,q=process.cwd()){try{let z;if($){let Y=f($);if(!Y1(Y))return console.error(`Error: Config file not found: ${Y}`),null;z=Y}else if(z=_2(q),!z)return null;let J=await T2(z,"utf-8"),Q=JSON.parse(J),X=Z1(z);if(Q.repositories)Q.repositories=Q.repositories.map((Y)=>{if(!Y.path&&Y.url){let Z=v(Y.url);return{...Y,path:H1(X,Z),name:Y.name||Z}}if(Y.path)return{...Y,path:f(X,Y.path)};return Y});return{config:Q,configDir:X}}catch(z){if($)console.error(`Error: Failed to load config file: ${z}`);return null}}import{exec as G2,execSync as M2}from"node:child_process";import{access as L2}from"node:fs/promises";import{join as U2}from"node:path";import{promisify as S2}from"node:util";var R1=S2(G2);async function W($){try{return await L2(U2($,".git")),!0}catch{return!1}}async function h($){try{let{stdout:q}=await R1("git shortlog -sn --all",{cwd:$}),z=[],J=q.trim().split(`
28
- `);for(let Q of J){let X=Q.match(/^\s*(\d+)\s+(.+)$/);if(X){let Y=parseInt(X[1]||"0",10),Z=X[2]||"",{stdout:T}=await R1(`git log --format='%aE' --author="${Z.replace(/"/g,"\\\"")}" -1`,{cwd:$}),H=T.trim().split(`
29
- `)[0]||"";z.push({name:Z,email:H,commits:Y})}}return z.sort((Q,X)=>X.commits-Q.commits)}catch(q){throw new Error(`Failed to get contributors from ${$}: ${q}`)}}function u($,q,z){let J='git log --format="%H|%an|%ae|%ad|%s" --date=iso-strict --numstat';if(q)J+=` --since="${q}"`;if(z)J+=` --until="${z}"`;let Q=M2(J,{encoding:"utf-8",cwd:$,maxBuffer:10485760}),X=[],Y=Q.split(`
30
- `).filter((G)=>G.trim()),Z=null,T=0,H=0,R=0,B=[];for(let G of Y)if(G.includes("|")){if(Z?.hash&&Z?.author&&Z?.email&&Z?.date&&Z?.message)X.push({hash:Z.hash,author:Z.author,email:Z.email,date:Z.date,message:Z.message,filesChanged:T,insertions:H,deletions:R,files:B});let[M,S,K,j,...G1]=G.split("|");if(M&&S&&K&&j)Z={hash:M.trim(),author:S.trim(),email:K.trim(),date:j.trim(),message:G1.join("|").trim()},T=0,H=0,R=0,B=[]}else{let M=G.trim().split(/\s+/);if(M.length>=2&&M[0]&&M[1]){let S=parseInt(M[0],10)||0,K=parseInt(M[1],10)||0,j=M.slice(2).join(" ");if(j&&!Number.isNaN(S)&&!Number.isNaN(K))T++,H+=S,R+=K,B.push({path:j,insertions:S,deletions:K})}}if(Z?.hash&&Z?.author&&Z?.email&&Z?.date&&Z?.message)X.push({hash:Z.hash,author:Z.author,email:Z.email,date:Z.date,message:Z.message,filesChanged:T,insertions:H,deletions:R,files:B});return X}import{exec as K2}from"node:child_process";import{existsSync as T1}from"node:fs";import{mkdir as W2}from"node:fs/promises";import{dirname as j2}from"node:path";import{promisify as I2}from"node:util";var E2=I2(K2);async function g($){if(!$.path)return console.error(`Error: Repository ${$.name||"unknown"} has no path specified`),null;if(T1($.path)&&await W($.path))return $.path;if(T1($.path))return console.error(`Error: Path exists but is not a git repository: ${$.path}`),null;if(!$.url)return console.error(`Error: Repository not found at ${$.path} and no URL provided for cloning`),null;try{console.log(`Cloning repository from ${$.url} to ${$.path}...`);let q=j2($.path),z=$.path.split("/").pop()||"repository";try{await W2(q,{recursive:!0})}catch(J){}return await E2(`git clone "${$.url}" "${$.path}"`),console.log(`✓ Successfully cloned ${$.name||z}`),$.path}catch(q){return console.error(`Error: Failed to clone repository: ${q}`),null}}class D{config;loadedConfig=null;constructor($={}){this.config=$}async initialize(){if(!this.config.repositories){if(this.loadedConfig=await V(this.config.configPath),this.loadedConfig?.config.repositories)this.config.repositories=this.loadedConfig.config.repositories;if(this.loadedConfig?.config)this.config={...this.loadedConfig.config,...this.config,repositories:this.config.repositories||this.loadedConfig.config.repositories}}if(this.config.repositories)this.config.repositories=this.config.repositories.map(($)=>{if(!$.path&&$.url){let q=this.loadedConfig?.configDir||process.cwd(),z=v($.url);return{...$,path:V2(q,z),name:$.name||z}}return $});if(this.config.cloneIfNotExists&&this.config.repositories){let $=[];for(let q of this.config.repositories){if(!q.path){console.error(`Error: Repository ${q.name||"unknown"} has no path and no URL`),$.push("");continue}let z=await g(q);if(z)$.push(z);else $.push(q.path)}this.config.repositories=this.config.repositories.map((q,z)=>({...q,path:$[z]||q.path}))}}getRepoPaths($){if($&&$.length>0)return $;if(this.config.repositories)return this.config.repositories.map((q)=>q.path).filter((q)=>q!==void 0);return[]}async listContributors($){await this.initialize();let q=this.getRepoPaths($);if(q.length===0)throw new Error("No repository paths specified");let z=[];for(let J of q){if(!await W(J))throw new Error(`${J} is not a git repository`);try{let X=await h(J);z.push({path:J,contributors:X})}catch(X){throw new Error(`Failed to get contributors from ${J}: ${X}`)}}return z}async getHistory($,q,z){await this.initialize();let J=this.getRepoPaths($);if(J.length===0)throw new Error("No repository paths specified");let Q=[];for(let X of J){if(!await W(X))throw new Error(`${X} is not a git repository`);try{let Z=u(X,q,z);Q.push({path:X,commits:Z})}catch(Z){throw new Error(`Failed to get commit history from ${X}: ${Z}`)}}return Q}}async function B1($,q=!0,z){let J=new D({configPath:z});try{let Q=await J.listContributors($);for(let X of Q)if(console.log(`
31
- \uD83D\uDCCA Contributors for ${X.path}:`),console.log("".repeat(60)),X.contributors.length===0)console.log(" No contributors found");else for(let Y of X.contributors)if(q)console.log(` ${Y.name} <${Y.email}> (${Y.commits} commits)`);else console.log(` ${Y.name} <${Y.email}>`)}catch(Q){console.error("Error processing repositories:",Q)}}import{writeFileSync as D2}from"node:fs";import{resolve as N2}from"node:path";async function _1($,q={},z){let J=new D({configPath:z});try{let Q=await J.getHistory($,q.since,q.until),X={generatedAt:new Date().toISOString(),period:{since:q.since,until:q.until},repositories:Q.map((Z)=>{let T=new Set(Z.commits.flatMap((B)=>B.files.map((G)=>G.path))).size,H=Z.commits.reduce((B,G)=>B+G.insertions,0),R=Z.commits.reduce((B,G)=>B+G.deletions,0);return{path:Z.path,commits:Z.commits,summary:{totalCommits:Z.commits.length,totalFilesChanged:T,totalInsertions:H,totalDeletions:R}}})},Y=JSON.stringify(X,null,2);if(q.out){let Z=N2(process.cwd(),q.out);D2(Z,Y,"utf-8"),console.log(`✅ Report saved to: ${Z}`),console.log(`
32
- \uD83D\uDCCA Summary:`);for(let T of X.repositories)console.log(`
33
- Repository: ${T.path}`),console.log(` Commits: ${T.summary.totalCommits}`),console.log(` Files Changed: ${T.summary.totalFilesChanged}`),console.log(` Lines Added: ${T.summary.totalInsertions.toLocaleString()}`),console.log(` Lines Removed: ${T.summary.totalDeletions.toLocaleString()}`)}else console.log(Y)}catch(Q){throw console.error("Error generating history report:",Q),Q}}var P2=A2(import.meta.url),k2=F2(P2),O2=w2(k2,"..","package.json"),x2=JSON.parse(y2(O2,"utf-8")),b2=x2.version,N=new X1;N.name("gstatx").description("A CLI tool to export statistics from git repositories").version(b2).option("-c, --config <path>","Specify custom config file path").configureHelp({helpWidth:100});N.command("contributors").description("List contributors for specified repositories").option("--no-commits","Hide commit counts in contributor list").argument("[repo-paths...]","Repository paths").action(async($,q,z)=>{let J=z.parent?.opts().config,X=(await V(J))?.config.contributors?.["no-commits"]??!1,Y=!(q.noCommits||X),Z=$.length===0?void 0:$;await B1(Z,Y,J)}).addHelpText("after",`
24
+ `),this.outputHelp({error:!0});let Y=X||{},Z=Y.exitCode||1,$=Y.code||"commander.error";this._exit(Z,$,Q)}_parseOptionsEnv(){this.options.forEach((Q)=>{if(Q.envVar&&Q.envVar in H.env){let X=Q.attributeName();if(this.getOptionValue(X)===void 0||["default","config","env"].includes(this.getOptionValueSource(X)))if(Q.required||Q.optional)this.emit(`optionEnv:${Q.name()}`,H.env[Q.envVar]);else this.emit(`optionEnv:${Q.name()}`)}})}_parseOptionsImplied(){let Q=new tQ(this.options),X=(Y)=>{return this.getOptionValue(Y)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(Y))};this.options.filter((Y)=>Y.implied!==void 0&&X(Y.attributeName())&&Q.valueFromOption(this.getOptionValue(Y.attributeName()),Y)).forEach((Y)=>{Object.keys(Y.implied).filter((Z)=>!X(Z)).forEach((Z)=>{this.setOptionValueWithSource(Z,Y.implied[Z],"implied")})})}missingArgument(Q){let X=`error: missing required argument '${Q}'`;this.error(X,{code:"commander.missingArgument"})}optionMissingArgument(Q){let X=`error: option '${Q.flags}' argument missing`;this.error(X,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(Q){let X=`error: required option '${Q.flags}' not specified`;this.error(X,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(Q,X){let Y=(q)=>{let B=q.attributeName(),_=this.getOptionValue(B),R=this.options.find((z)=>z.negate&&B===z.attributeName()),J=this.options.find((z)=>!z.negate&&B===z.attributeName());if(R&&(R.presetArg===void 0&&_===!1||R.presetArg!==void 0&&_===R.presetArg))return R;return J||q},Z=(q)=>{let B=Y(q),_=B.attributeName();if(this.getOptionValueSource(_)==="env")return`environment variable '${B.envVar}'`;return`option '${B.flags}'`},$=`error: ${Z(Q)} cannot be used with ${Z(X)}`;this.error($,{code:"commander.conflictingOption"})}unknownOption(Q){if(this._allowUnknownOption)return;let X="";if(Q.startsWith("--")&&this._showSuggestionAfterError){let Z=[],$=this;do{let q=$.createHelp().visibleOptions($).filter((B)=>B.long).map((B)=>B.long);Z=Z.concat(q),$=$.parent}while($&&!$._enablePositionalOptions);X=XQ(Q,Z)}let Y=`error: unknown option '${Q}'${X}`;this.error(Y,{code:"commander.unknownOption"})}_excessArguments(Q){if(this._allowExcessArguments)return;let X=this.registeredArguments.length,Y=X===1?"":"s",$=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${X} argument${Y} but got ${Q.length}.`;this.error($,{code:"commander.excessArguments"})}unknownCommand(){let Q=this.args[0],X="";if(this._showSuggestionAfterError){let Z=[];this.createHelp().visibleCommands(this).forEach(($)=>{if(Z.push($.name()),$.alias())Z.push($.alias())}),X=XQ(Q,Z)}let Y=`error: unknown command '${Q}'${X}`;this.error(Y,{code:"commander.unknownCommand"})}version(Q,X,Y){if(Q===void 0)return this._version;this._version=Q,X=X||"-V, --version",Y=Y||"output the version number";let Z=this.createOption(X,Y);return this._versionOptionName=Z.attributeName(),this._registerOption(Z),this.on("option:"+Z.name(),()=>{this._outputConfiguration.writeOut(`${Q}
25
+ `),this._exit(0,"commander.version",Q)}),this}description(Q,X){if(Q===void 0&&X===void 0)return this._description;if(this._description=Q,X)this._argsDescription=X;return this}summary(Q){if(Q===void 0)return this._summary;return this._summary=Q,this}alias(Q){if(Q===void 0)return this._aliases[0];let X=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)X=this.commands[this.commands.length-1];if(Q===X._name)throw Error("Command alias can't be the same as its name");let Y=this.parent?._findCommand(Q);if(Y){let Z=[Y.name()].concat(Y.aliases()).join("|");throw Error(`cannot add alias '${Q}' to command '${this.name()}' as already have command '${Z}'`)}return X._aliases.push(Q),this}aliases(Q){if(Q===void 0)return this._aliases;return Q.forEach((X)=>this.alias(X)),this}usage(Q){if(Q===void 0){if(this._usage)return this._usage;let X=this.registeredArguments.map((Y)=>{return nQ(Y)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?X:[]).join(" ")}return this._usage=Q,this}name(Q){if(Q===void 0)return this._name;return this._name=Q,this}helpGroup(Q){if(Q===void 0)return this._helpGroupHeading??"";return this._helpGroupHeading=Q,this}commandsGroup(Q){if(Q===void 0)return this._defaultCommandGroup??"";return this._defaultCommandGroup=Q,this}optionsGroup(Q){if(Q===void 0)return this._defaultOptionGroup??"";return this._defaultOptionGroup=Q,this}_initOptionGroup(Q){if(this._defaultOptionGroup&&!Q.helpGroupHeading)Q.helpGroup(this._defaultOptionGroup)}_initCommandGroup(Q){if(this._defaultCommandGroup&&!Q.helpGroup())Q.helpGroup(this._defaultCommandGroup)}nameFromFilename(Q){return this._name=L.basename(Q,L.extname(Q)),this}executableDir(Q){if(Q===void 0)return this._executableDir;return this._executableDir=Q,this}helpInformation(Q){let X=this.createHelp(),Y=this._getOutputContext(Q);X.prepareContext({error:Y.error,helpWidth:Y.helpWidth,outputHasColors:Y.hasColors});let Z=X.formatHelp(this,X);if(Y.hasColors)return Z;return this._outputConfiguration.stripColor(Z)}_getOutputContext(Q){Q=Q||{};let X=!!Q.error,Y,Z,$;if(X)Y=(B)=>this._outputConfiguration.writeErr(B),Z=this._outputConfiguration.getErrHasColors(),$=this._outputConfiguration.getErrHelpWidth();else Y=(B)=>this._outputConfiguration.writeOut(B),Z=this._outputConfiguration.getOutHasColors(),$=this._outputConfiguration.getOutHelpWidth();return{error:X,write:(B)=>{if(!Z)B=this._outputConfiguration.stripColor(B);return Y(B)},hasColors:Z,helpWidth:$}}outputHelp(Q){let X;if(typeof Q==="function")X=Q,Q=void 0;let Y=this._getOutputContext(Q),Z={error:Y.error,write:Y.write,command:this};this._getCommandAndAncestors().reverse().forEach((q)=>q.emit("beforeAllHelp",Z)),this.emit("beforeHelp",Z);let $=this.helpInformation({error:Y.error});if(X){if($=X($),typeof $!=="string"&&!Buffer.isBuffer($))throw Error("outputHelp callback must return a string or a Buffer")}if(Y.write($),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",Z),this._getCommandAndAncestors().forEach((q)=>q.emit("afterAllHelp",Z))}helpOption(Q,X){if(typeof Q==="boolean"){if(Q){if(this._helpOption===null)this._helpOption=void 0;if(this._defaultOptionGroup)this._initOptionGroup(this._getHelpOption())}else this._helpOption=null;return this}if(this._helpOption=this.createOption(Q??"-h, --help",X??"display help for command"),Q||X)this._initOptionGroup(this._helpOption);return this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(Q){return this._helpOption=Q,this._initOptionGroup(Q),this}help(Q){this.outputHelp(Q);let X=Number(H.exitCode??0);if(X===0&&Q&&typeof Q!=="function"&&Q.error)X=1;this._exit(X,"commander.help","(outputHelp)")}addHelpText(Q,X){let Y=["beforeAll","before","after","afterAll"];if(!Y.includes(Q))throw Error(`Unexpected value for position to addHelpText.
26
+ Expecting one of '${Y.join("', '")}'`);let Z=`${Q}Help`;return this.on(Z,($)=>{let q;if(typeof X==="function")q=X({error:$.error,command:$.command});else q=X;if(q)$.write(`${q}
27
+ `)}),this}_outputHelpIfRequested(Q){let X=this._getHelpOption();if(X&&Q.find((Z)=>X.is(Z)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function YQ(Q){return Q.map((X)=>{if(!X.startsWith("--inspect"))return X;let Y,Z="127.0.0.1",$="9229",q;if((q=X.match(/^(--inspect(-brk)?)$/))!==null)Y=q[1];else if((q=X.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(Y=q[1],/^\d+$/.test(q[3]))$=q[3];else Z=q[3];else if((q=X.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)Y=q[1],Z=q[3],$=q[4];if(Y&&$!=="0")return`${Y}=${Z}:${parseInt($)+1}`;return X})}function b(){if(H.env.NO_COLOR||H.env.FORCE_COLOR==="0"||H.env.FORCE_COLOR==="false")return!1;if(H.env.FORCE_COLOR||H.env.CLICOLOR_FORCE!==void 0)return!0;return}oQ.Command=f;oQ.useColor=b});var BQ=S((ZX)=>{var{Argument:$Q}=A(),{Command:v}=ZQ(),{CommanderError:XX,InvalidArgumentError:qQ}=D(),{Help:YX}=w(),{Option:JQ}=O();ZX.program=new v;ZX.createCommand=(Q)=>new v(Q);ZX.createOption=(Q,X)=>new JQ(Q,X);ZX.createArgument=(Q,X)=>new $Q(Q,X);ZX.Command=v;ZX.Option=JQ;ZX.Argument=$Q;ZX.Help=YX;ZX.CommanderError=XX;ZX.InvalidArgumentError=qQ;ZX.InvalidOptionArgumentError=qQ});import{readFileSync as xX}from"node:fs";import{dirname as CX,join as bX}from"node:path";import{fileURLToPath as fX}from"node:url";var _Q=EQ(BQ(),1),{program:tX,createCommand:oX,createArgument:eX,createOption:QY,CommanderError:XY,InvalidArgumentError:YY,InvalidOptionArgumentError:ZY,Command:zQ,Argument:$Y,Option:qY,Help:JY}=_Q.default;import{join as AX}from"node:path";import{existsSync as RQ}from"node:fs";import{readFile as KX}from"node:fs/promises";import{dirname as GQ,join as TQ,resolve as h}from"node:path";var WX=".gstatxrc.json";function g(Q){let Y=Q.replace(/\.git$/,"").split(/[/:]/);return Y[Y.length-1]||"repository"}function LX(Q){let X=h(Q),Y=20,Z=0;while(Z<Y){let $=TQ(X,WX);if(RQ($))return $;let q=GQ(X);if(q===X)break;X=q,Z++}return null}async function N(Q,X=process.cwd()){try{let Y;if(Q){let B=h(Q);if(!RQ(B))return console.error(`Error: Config file not found: ${B}`),null;Y=B}else if(Y=LX(X),!Y)return null;let Z=await KX(Y,"utf-8"),$=JSON.parse(Z),q=GQ(Y);if($.repositories)$.repositories=$.repositories.map((B)=>{if(!B.path&&B.url){let _=g(B.url);return{...B,path:TQ(q,_),name:B.name||_}}if(B.path)return{...B,path:h(q,B.path)};return B});return{config:$,configDir:q}}catch(Y){if(Q)console.error(`Error: Failed to load config file: ${Y}`);return null}}import{exec as SX,execSync as jX}from"node:child_process";import{access as HQ,readFile as IX}from"node:fs/promises";import{join as c}from"node:path";import{promisify as VX}from"node:util";var u=VX(SX);async function UQ(Q){try{return await HQ(c(Q,".mailmap")),!0}catch{return!1}}async function MX(Q){let X=new Map;try{let Y=c(Q,".mailmap"),$=(await IX(Y,"utf-8")).split(`
28
+ `);for(let q of $){let B=q.trim();if(!B||B.startsWith("#"))continue;let _=B.matchAll(/<([^>]+)>/g),R=Array.from(_).map((J)=>J[1]?.trim()).filter((J)=>J!==void 0);if(R.length>=2){let J=R[0];if(J){let z=J.toLowerCase();for(let G=1;G<R.length;G++){let T=R[G];if(T)X.set(T.toLowerCase(),z)}}}}}catch{}return X}async function V(Q){try{return await HQ(c(Q,".git")),!0}catch{return!1}}async function d(Q){try{let X=await UQ(Q),Y=new Map;if(X){let $=await MX(Q),{stdout:q}=await u("git log --all --format='%aN|%aE' --use-mailmap",{cwd:Q}),B=new Map,_=q.trim().split(`
29
+ `);for(let R of _){if(!R.trim())continue;let[J,z]=R.split("|");if(!J||!z)continue;let G=z.toLowerCase(),T=$.get(G);if(T)G=T;let U=Y.get(G);if(!B.has(G))B.set(G,new Map);let K=B.get(G);if(K)K.set(J,(K.get(J)||0)+1);if(U)Y.set(G,{...U,commits:U.commits+1});else{let W=T||z;Y.set(G,{name:J,email:W,commits:1,maxIndividualCommits:1})}}for(let[R,J]of B.entries()){let z=Y.get(R);if(z){let G=0,T=z.name;for(let[U,K]of J.entries())if(K>G)G=K,T=U;Y.set(R,{...z,name:T})}}}else{let{stdout:$}=await u("git shortlog -sn --all",{cwd:Q}),q=$.trim().split(`
30
+ `);for(let B of q){let _=B.match(/^\s*(\d+)\s+(.+)$/);if(_){let R=parseInt(_[1]||"0",10),J=_[2]||"",{stdout:z}=await u(`git log --format='%aE' --author="${J.replace(/"/g,"\\\"")}" -1`,{cwd:Q}),G=z.trim().split(`
31
+ `)[0]||"",T=G.toLowerCase(),U=Y.get(T);if(U){let K=U.commits+R;if(R>U.maxIndividualCommits)Y.set(T,{name:J,email:G,commits:K,maxIndividualCommits:R});else Y.set(T,{...U,commits:K})}else Y.set(T,{name:J,email:G,commits:R,maxIndividualCommits:R})}}}return Array.from(Y.values()).map(($)=>({name:$.name,email:$.email,commits:$.commits})).sort(($,q)=>q.commits-$.commits)}catch(X){throw Error(`Failed to get contributors from ${Q}: ${X}`)}}async function l(Q,X,Y){let q=`git log --format="%H|%an|%ae|%ad|%s" --date=iso-strict --numstat${await UQ(Q)?" --use-mailmap":""}`;if(X)q+=` --since="${X}"`;if(Y)q+=` --until="${Y}"`;let B=jX(q,{encoding:"utf-8",cwd:Q,maxBuffer:10485760}),_=[],R=B.split(`
32
+ `).filter((K)=>K.trim()),J=null,z=0,G=0,T=0,U=[];for(let K of R)if(K.includes("|")){if(J?.hash&&J?.author&&J?.email&&J?.date&&J?.message)_.push({hash:J.hash,author:J.author,email:J.email,date:J.date,message:J.message,filesChanged:z,insertions:G,deletions:T,files:U});let[W,j,I,M,...SQ]=K.split("|");if(W&&j&&I&&M)J={hash:W.trim(),author:j.trim(),email:I.trim(),date:M.trim(),message:SQ.join("|").trim()},z=0,G=0,T=0,U=[]}else{let W=K.trim().split(/\s+/);if(W.length>=2&&W[0]&&W[1]){let j=parseInt(W[0],10)||0,I=parseInt(W[1],10)||0,M=W.slice(2).join(" ");if(M&&!Number.isNaN(j)&&!Number.isNaN(I))z++,G+=j,T+=I,U.push({path:M,insertions:j,deletions:I})}}if(J?.hash&&J?.author&&J?.email&&J?.date&&J?.message)_.push({hash:J.hash,author:J.author,email:J.email,date:J.date,message:J.message,filesChanged:z,insertions:G,deletions:T,files:U});return _}import{exec as EX}from"node:child_process";import{existsSync as KQ}from"node:fs";import{mkdir as DX}from"node:fs/promises";import{dirname as NX}from"node:path";import{promisify as FX}from"node:util";var yX=FX(EX);async function m(Q){if(!Q.path)return console.error(`Error: Repository ${Q.name||"unknown"} has no path specified`),null;if(KQ(Q.path)&&await V(Q.path))return Q.path;if(KQ(Q.path))return console.error(`Error: Path exists but is not a git repository: ${Q.path}`),null;if(!Q.url)return console.error(`Error: Repository not found at ${Q.path} and no URL provided for cloning`),null;try{console.log(`Cloning repository from ${Q.url} to ${Q.path}...`);let X=NX(Q.path),Y=Q.path.split("/").pop()||"repository";try{await DX(X,{recursive:!0})}catch(Z){}return await yX(`git clone "${Q.url}" "${Q.path}"`),console.log(`✓ Successfully cloned ${Q.name||Y}`),Q.path}catch(X){return console.error(`Error: Failed to clone repository: ${X}`),null}}class F{config;loadedConfig=null;constructor(Q={}){this.config=Q}async initialize(){if(!this.config.repositories){if(this.loadedConfig=await N(this.config.configPath),this.loadedConfig?.config.repositories)this.config.repositories=this.loadedConfig.config.repositories;if(this.loadedConfig?.config)this.config={...this.loadedConfig.config,...this.config,repositories:this.config.repositories||this.loadedConfig.config.repositories}}if(this.config.repositories)this.config.repositories=this.config.repositories.map((Q)=>{if(!Q.path&&Q.url){let X=this.loadedConfig?.configDir||process.cwd(),Y=g(Q.url);return{...Q,path:AX(X,Y),name:Q.name||Y}}return Q});if(this.config.cloneIfNotExists&&this.config.repositories){let Q=[];for(let X of this.config.repositories){if(!X.path){console.error(`
33
+ \x1B[31mError:\x1B[0m \x1B[91mRepository ${X.name||"unknown"} has no path and no URL\x1B[0m`),Q.push("");continue}let Y=await m(X);if(Y)Q.push(Y);else Q.push(X.path)}this.config.repositories=this.config.repositories.map((X,Y)=>({...X,path:Q[Y]||X.path}))}}getRepoPaths(Q){if(Q&&Q.length>0)return Q;if(this.config.repositories)return this.config.repositories.map((X)=>X.path).filter((X)=>X!==void 0);return[]}async listContributors(Q){await this.initialize();let X=this.getRepoPaths(Q);if(X.length===0)throw Error("No repository paths specified");let Y=[];for(let Z of X){if(!await V(Z))throw Error(`${Z} is not a git repository`);try{let q=await d(Z);Y.push({path:Z,contributors:q})}catch(q){throw Error(`Failed to get contributors from ${Z}: ${q}`)}}return Y}async getHistory(Q,X,Y){await this.initialize();let Z=this.getRepoPaths(Q);if(Z.length===0)throw Error("No repository paths specified");let $=[];for(let q of Z){if(!await V(q))throw Error(`${q} is not a git repository`);try{let _=await l(q,X,Y);$.push({path:q,commits:_})}catch(_){throw Error(`Failed to get commit history from ${q}: ${_}`)}}return $}}async function WQ(Q,X=!0,Y,Z="text",$=!1){let q=new F({configPath:Y});try{let B=await q.listContributors(Q);if($){let _=new Map;for(let J of B)for(let z of J.contributors){let G=z.email.toLowerCase(),T=_.get(G);if(T){let U=T.commits+z.commits;if(z.commits>T.maxIndividualCommits)_.set(G,{name:z.name,email:z.email,commits:U,maxIndividualCommits:z.commits});else _.set(G,{...T,commits:U})}else _.set(G,{name:z.name,email:z.email,commits:z.commits,maxIndividualCommits:z.commits})}let R=Array.from(_.values()).sort((J,z)=>z.commits-J.commits);if(Z==="json"){let J=R.map((z)=>({name:z.name,email:z.email,...X&&{commits:z.commits}}));console.log(JSON.stringify(J,null,2));return}if(console.log(`
34
+ \uD83D\uDCE7 Unique email addresses:`),console.log("─".repeat(60)),R.length===0)console.log(" No contributors found");else for(let J of R)if(X)console.log(` ${J.name} <${J.email}> (${J.commits} commits)`);else console.log(` ${J.name} <${J.email}>`);return}if(Z==="json"){let _=B.map((R)=>({path:R.path,contributors:R.contributors.map((J)=>({name:J.name,email:J.email,...X&&{commits:J.commits}}))}));console.log(JSON.stringify(_,null,2));return}for(let _ of B)if(console.log(`
35
+ \uD83D\uDCCA Contributors for ${_.path}:`),console.log("─".repeat(60)),_.contributors.length===0)console.log(" No contributors found");else for(let R of _.contributors)if(X)console.log(` ${R.name} <${R.email}> (${R.commits} commits)`);else console.log(` ${R.name} <${R.email}>`)}catch(B){let _=B instanceof Error?B.message:String(B);console.error(`
36
+ ❌ \x1B[31mError processing repositories:\x1B[0m \x1B[91m${_}\x1B[0m`),process.exit(1)}}import{mkdirSync as kX,writeFileSync as PX}from"node:fs";import{dirname as wX,resolve as OX}from"node:path";async function LQ(Q,X={},Y){let Z=new F({configPath:Y});try{let $=await Z.getHistory(Q,X.since,X.until),q={generatedAt:new Date().toISOString(),period:{since:X.since,until:X.until},repositories:$.map((_)=>{let R=new Set(_.commits.flatMap((G)=>G.files.map((T)=>T.path))).size,J=_.commits.reduce((G,T)=>G+T.insertions,0),z=_.commits.reduce((G,T)=>G+T.deletions,0);return{path:_.path,commits:_.commits,summary:{totalCommits:_.commits.length,totalFilesChanged:R,totalInsertions:J,totalDeletions:z}}})},B=JSON.stringify(q,null,2);if(X.out){let _=OX(process.cwd(),X.out),R=wX(_);kX(R,{recursive:!0}),PX(_,B,"utf-8"),console.log(`✅ Report saved to: ${_}`),console.log(`
37
+ \uD83D\uDCCA Summary:`);for(let J of q.repositories)console.log(`
38
+ Repository: ${J.path}`),console.log(` Commits: ${J.summary.totalCommits}`),console.log(` Files Changed: ${J.summary.totalFilesChanged}`),console.log(` Lines Added: ${J.summary.totalInsertions.toLocaleString()}`),console.log(` Lines Removed: ${J.summary.totalDeletions.toLocaleString()}`)}else console.log(B)}catch($){let q=$ instanceof Error?$.message:String($);console.error(`
39
+ ❌ \x1B[31mError generating history report:\x1B[0m \x1B[91m${q}\x1B[0m`),process.exit(1)}}var vX=fX(import.meta.url),hX=CX(vX),gX=bX(hX,"..","package.json"),uX=JSON.parse(xX(gX,"utf-8")),cX=uX.version,y=new zQ;y.name("gstatx").description("A CLI tool to export statistics from git repositories").version(cX).option("-c, --config <path>","Specify custom config file path").configureHelp({helpWidth:100});y.command("contributors").description("List contributors for specified repositories").option("--no-commits","Hide commit counts in contributor list").option("-f, --format <format>","Output format: 'json' or 'text' (default: 'text')").option("-u, --unique-emails","List unique email addresses only (deduplicates by email)").argument("[repo-paths...]","Repository paths").action(async(Q,X,Y)=>{let Z=Y.parent?.opts().config,$=await N(Z),q=$?.config.contributors?.["no-commits"]??!1,B=!(X.noCommits||q),_=$?.config.contributors?.format||"text",R=X.format||_;if(R!=="json"&&R!=="text")console.error(`
40
+ ❌ \x1B[31mError:\x1B[0m \x1B[91mInvalid format '${R}'. Must be 'json' or 'text'\x1B[0m`),process.exit(1);let J=Q.length===0?void 0:Q,z=X.uniqueEmails||!1;await WQ(J,B,Z,R,z)}).addHelpText("after",`
34
41
  Examples:
35
42
  gstatx contributors ./my-repo
36
43
  gstatx contributors ./repo1 ./repo2
37
- gstatx contributors --no-commits ./my-repo`);N.command("hist").description("Generate commit history report").option("-s, --since <date>",'Start date for the report (e.g., "2024-01-01", "1 month ago")').option("-u, --until <date>",'End date for the report (e.g., "2024-12-31", "now")').option("-o, --out <file>","Output file path (defaults to stdout)").argument("[repo-paths...]","Repository paths").action(async($,q,z)=>{let J=z.parent?.opts().config,Q={since:q.since,until:q.until,out:q.out},X=$.length===0?void 0:$;await _1(X,Q,J)}).addHelpText("after",`
44
+ gstatx contributors --no-commits ./my-repo
45
+ gstatx contributors --format json ./my-repo
46
+ gstatx contributors --unique-emails ./my-repo`);y.command("hist").description("Generate commit history report").option("-s, --since <date>",'Start date for the report (e.g., "2024-01-01", "1 month ago")').option("-u, --until <date>",'End date for the report (e.g., "2024-12-31", "now")').option("-o, --out <file>","Output file path (defaults to stdout)").argument("[repo-paths...]","Repository paths").action(async(Q,X,Y)=>{let Z=Y.parent?.opts().config,$={since:X.since,until:X.until,out:X.out},q=Q.length===0?void 0:Q;await LQ(q,$,Z)}).addHelpText("after",`
38
47
  Examples:
39
48
  gstatx hist ./my-repo
40
49
  gstatx hist --since "1 month ago" ./my-repo
41
50
  gstatx hist --since "2024-01-01" --until "2024-12-31" ./my-repo
42
- gstatx hist --since "1 month ago" --out report.json ./my-repo`);N.addHelpText("after",`
51
+ gstatx hist --since "1 month ago" --out report.json ./my-repo`);y.addHelpText("after",`
43
52
  Configuration:
44
53
  You can create a .gstatxrc.json file to set default options
45
54
  and repository paths. CLI arguments override config values.
46
55
  Set 'cloneIfNotExists: true' to automatically clone repositories
47
56
  that don't exist locally (requires 'url' in repository config).
48
- `);N.parse();
57
+ `);y.parse();
package/dist/lib.js CHANGED
@@ -1,4 +1,7 @@
1
- import{join as m}from"node:path";import{existsSync as L}from"node:fs";import{readFile as N}from"node:fs/promises";import{dirname as I,join as R,resolve as U}from"node:path";var D=".gstatxrc.json";function E(q){let z=q.replace(/\.git$/,"").split(/[/:]/);return z[z.length-1]||"repository"}function F(q){let w=U(q),z=20,J=0;while(J<z){let Q=R(w,D);if(L(Q))return Q;let H=I(w);if(H===w)break;w=H,J++}return null}async function j(q,w=process.cwd()){try{let z;if(q){let K=U(q);if(!L(K))return console.error(`Error: Config file not found: ${K}`),null;z=K}else if(z=F(w),!z)return null;let J=await N(z,"utf-8"),Q=JSON.parse(J),H=I(z);if(Q.repositories)Q.repositories=Q.repositories.map((K)=>{if(!K.path&&K.url){let B=E(K.url);return{...K,path:R(H,B),name:K.name||B}}if(K.path)return{...K,path:U(H,K.path)};return K});return{config:Q,configDir:H}}catch(z){if(q)console.error(`Error: Failed to load config file: ${z}`);return null}}import{exec as y,execSync as x}from"node:child_process";import{access as C}from"node:fs/promises";import{join as f}from"node:path";import{promisify as g}from"node:util";var b=g(y);async function Z(q){try{return await C(f(q,".git")),!0}catch{return!1}}async function A(q){try{let{stdout:w}=await b("git shortlog -sn --all",{cwd:q}),z=[],J=w.trim().split(`
2
- `);for(let Q of J){let H=Q.match(/^\s*(\d+)\s+(.+)$/);if(H){let K=parseInt(H[1]||"0",10),B=H[2]||"",{stdout:V}=await b(`git log --format='%aE' --author="${B.replace(/"/g,"\\\"")}" -1`,{cwd:q}),W=V.trim().split(`
3
- `)[0]||"";z.push({name:B,email:W,commits:K})}}return z.sort((Q,H)=>H.commits-Q.commits)}catch(w){throw new Error(`Failed to get contributors from ${q}: ${w}`)}}function G(q,w,z){let J='git log --format="%H|%an|%ae|%ad|%s" --date=iso-strict --numstat';if(w)J+=` --since="${w}"`;if(z)J+=` --until="${z}"`;let Q=x(J,{encoding:"utf-8",cwd:q,maxBuffer:10485760}),H=[],K=Q.split(`
4
- `).filter(($)=>$.trim()),B=null,V=0,W=0,M=0,O=[];for(let $ of K)if($.includes("|")){if(B?.hash&&B?.author&&B?.email&&B?.date&&B?.message)H.push({hash:B.hash,author:B.author,email:B.email,date:B.date,message:B.message,filesChanged:V,insertions:W,deletions:M,files:O});let[T,X,Y,k,...v]=$.split("|");if(T&&X&&Y&&k)B={hash:T.trim(),author:X.trim(),email:Y.trim(),date:k.trim(),message:v.join("|").trim()},V=0,W=0,M=0,O=[]}else{let T=$.trim().split(/\s+/);if(T.length>=2&&T[0]&&T[1]){let X=parseInt(T[0],10)||0,Y=parseInt(T[1],10)||0,k=T.slice(2).join(" ");if(k&&!Number.isNaN(X)&&!Number.isNaN(Y))V++,W+=X,M+=Y,O.push({path:k,insertions:X,deletions:Y})}}if(B?.hash&&B?.author&&B?.email&&B?.date&&B?.message)H.push({hash:B.hash,author:B.author,email:B.email,date:B.date,message:B.message,filesChanged:V,insertions:W,deletions:M,files:O});return H}import{exec as d}from"node:child_process";import{existsSync as S}from"node:fs";import{mkdir as P}from"node:fs/promises";import{dirname as l}from"node:path";import{promisify as u}from"node:util";var h=u(d);async function _(q){if(!q.path)return console.error(`Error: Repository ${q.name||"unknown"} has no path specified`),null;if(S(q.path)&&await Z(q.path))return q.path;if(S(q.path))return console.error(`Error: Path exists but is not a git repository: ${q.path}`),null;if(!q.url)return console.error(`Error: Repository not found at ${q.path} and no URL provided for cloning`),null;try{console.log(`Cloning repository from ${q.url} to ${q.path}...`);let w=l(q.path),z=q.path.split("/").pop()||"repository";try{await P(w,{recursive:!0})}catch(J){}return await h(`git clone "${q.url}" "${q.path}"`),console.log(`✓ Successfully cloned ${q.name||z}`),q.path}catch(w){return console.error(`Error: Failed to clone repository: ${w}`),null}}class c{config;loadedConfig=null;constructor(q={}){this.config=q}async initialize(){if(!this.config.repositories){if(this.loadedConfig=await j(this.config.configPath),this.loadedConfig?.config.repositories)this.config.repositories=this.loadedConfig.config.repositories;if(this.loadedConfig?.config)this.config={...this.loadedConfig.config,...this.config,repositories:this.config.repositories||this.loadedConfig.config.repositories}}if(this.config.repositories)this.config.repositories=this.config.repositories.map((q)=>{if(!q.path&&q.url){let w=this.loadedConfig?.configDir||process.cwd(),z=E(q.url);return{...q,path:m(w,z),name:q.name||z}}return q});if(this.config.cloneIfNotExists&&this.config.repositories){let q=[];for(let w of this.config.repositories){if(!w.path){console.error(`Error: Repository ${w.name||"unknown"} has no path and no URL`),q.push("");continue}let z=await _(w);if(z)q.push(z);else q.push(w.path)}this.config.repositories=this.config.repositories.map((w,z)=>({...w,path:q[z]||w.path}))}}getRepoPaths(q){if(q&&q.length>0)return q;if(this.config.repositories)return this.config.repositories.map((w)=>w.path).filter((w)=>w!==void 0);return[]}async listContributors(q){await this.initialize();let w=this.getRepoPaths(q);if(w.length===0)throw new Error("No repository paths specified");let z=[];for(let J of w){if(!await Z(J))throw new Error(`${J} is not a git repository`);try{let H=await A(J);z.push({path:J,contributors:H})}catch(H){throw new Error(`Failed to get contributors from ${J}: ${H}`)}}return z}async getHistory(q,w,z){await this.initialize();let J=this.getRepoPaths(q);if(J.length===0)throw new Error("No repository paths specified");let Q=[];for(let H of J){if(!await Z(H))throw new Error(`${H} is not a git repository`);try{let B=G(H,w,z);Q.push({path:H,commits:B})}catch(B){throw new Error(`Failed to get commit history from ${H}: ${B}`)}}return Q}}export{j as loadConfig,Z as isGitRepo,A as getContributors,G as getCommits,_ as ensureRepository,c as Client};
1
+ import{join as a}from"node:path";import{existsSync as N}from"node:fs";import{readFile as f}from"node:fs/promises";import{dirname as b,join as F,resolve as I}from"node:path";var C=".gstatxrc.json";function R(q){let B=q.replace(/\.git$/,"").split(/[/:]/);return B[B.length-1]||"repository"}function g(q){let H=I(q),B=20,$=0;while($<B){let V=F(H,C);if(N(V))return V;let K=b(H);if(K===H)break;H=K,$++}return null}async function w(q,H=process.cwd()){try{let B;if(q){let Q=I(q);if(!N(Q))return console.error(`Error: Config file not found: ${Q}`),null;B=Q}else if(B=g(H),!B)return null;let $=await f(B,"utf-8"),V=JSON.parse($),K=b(B);if(V.repositories)V.repositories=V.repositories.map((Q)=>{if(!Q.path&&Q.url){let Y=R(Q.url);return{...Q,path:F(K,Y),name:Q.name||Y}}if(Q.path)return{...Q,path:I(K,Q.path)};return Q});return{config:V,configDir:K}}catch(B){if(q)console.error(`Error: Failed to load config file: ${B}`);return null}}import{exec as d,execSync as P}from"node:child_process";import{access as y,readFile as h}from"node:fs/promises";import{join as v}from"node:path";import{promisify as u}from"node:util";var S=u(d);async function E(q){try{return await y(v(q,".mailmap")),!0}catch{return!1}}async function l(q){let H=new Map;try{let B=v(q,".mailmap"),V=(await h(B,"utf-8")).split(`
2
+ `);for(let K of V){let Q=K.trim();if(!Q||Q.startsWith("#"))continue;let Y=Q.matchAll(/<([^>]+)>/g),Z=Array.from(Y).map((J)=>J[1]?.trim()).filter((J)=>J!==void 0);if(Z.length>=2){let J=Z[0];if(J){let k=J.toLowerCase();for(let W=1;W<Z.length;W++){let X=Z[W];if(X)H.set(X.toLowerCase(),k)}}}}}catch{}return H}async function A(q){try{return await y(v(q,".git")),!0}catch{return!1}}async function z(q){try{let H=await E(q),B=new Map;if(H){let V=await l(q),{stdout:K}=await S("git log --all --format='%aN|%aE' --use-mailmap",{cwd:q}),Q=new Map,Y=K.trim().split(`
3
+ `);for(let Z of Y){if(!Z.trim())continue;let[J,k]=Z.split("|");if(!J||!k)continue;let W=k.toLowerCase(),X=V.get(W);if(X)W=X;let T=B.get(W);if(!Q.has(W))Q.set(W,new Map);let U=Q.get(W);if(U)U.set(J,(U.get(J)||0)+1);if(T)B.set(W,{...T,commits:T.commits+1});else{let O=X||k;B.set(W,{name:J,email:O,commits:1,maxIndividualCommits:1})}}for(let[Z,J]of Q.entries()){let k=B.get(Z);if(k){let W=0,X=k.name;for(let[T,U]of J.entries())if(U>W)W=U,X=T;B.set(Z,{...k,name:X})}}}else{let{stdout:V}=await S("git shortlog -sn --all",{cwd:q}),K=V.trim().split(`
4
+ `);for(let Q of K){let Y=Q.match(/^\s*(\d+)\s+(.+)$/);if(Y){let Z=parseInt(Y[1]||"0",10),J=Y[2]||"",{stdout:k}=await S(`git log --format='%aE' --author="${J.replace(/"/g,"\\\"")}" -1`,{cwd:q}),W=k.trim().split(`
5
+ `)[0]||"",X=W.toLowerCase(),T=B.get(X);if(T){let U=T.commits+Z;if(Z>T.maxIndividualCommits)B.set(X,{name:J,email:W,commits:U,maxIndividualCommits:Z});else B.set(X,{...T,commits:U})}else B.set(X,{name:J,email:W,commits:Z,maxIndividualCommits:Z})}}}return Array.from(B.values()).map((V)=>({name:V.name,email:V.email,commits:V.commits})).sort((V,K)=>K.commits-V.commits)}catch(H){throw Error(`Failed to get contributors from ${q}: ${H}`)}}async function D(q,H,B){let K=`git log --format="%H|%an|%ae|%ad|%s" --date=iso-strict --numstat${await E(q)?" --use-mailmap":""}`;if(H)K+=` --since="${H}"`;if(B)K+=` --until="${B}"`;let Q=P(K,{encoding:"utf-8",cwd:q,maxBuffer:10485760}),Y=[],Z=Q.split(`
6
+ `).filter((U)=>U.trim()),J=null,k=0,W=0,X=0,T=[];for(let U of Z)if(U.includes("|")){if(J?.hash&&J?.author&&J?.email&&J?.date&&J?.message)Y.push({hash:J.hash,author:J.author,email:J.email,date:J.date,message:J.message,filesChanged:k,insertions:W,deletions:X,files:T});let[O,G,_,j,...x]=U.split("|");if(O&&G&&_&&j)J={hash:O.trim(),author:G.trim(),email:_.trim(),date:j.trim(),message:x.join("|").trim()},k=0,W=0,X=0,T=[]}else{let O=U.trim().split(/\s+/);if(O.length>=2&&O[0]&&O[1]){let G=parseInt(O[0],10)||0,_=parseInt(O[1],10)||0,j=O.slice(2).join(" ");if(j&&!Number.isNaN(G)&&!Number.isNaN(_))k++,W+=G,X+=_,T.push({path:j,insertions:G,deletions:_})}}if(J?.hash&&J?.author&&J?.email&&J?.date&&J?.message)Y.push({hash:J.hash,author:J.author,email:J.email,date:J.date,message:J.message,filesChanged:k,insertions:W,deletions:X,files:T});return Y}import{exec as c}from"node:child_process";import{existsSync as M}from"node:fs";import{mkdir as p}from"node:fs/promises";import{dirname as m}from"node:path";import{promisify as s}from"node:util";var n=s(c);async function L(q){if(!q.path)return console.error(`Error: Repository ${q.name||"unknown"} has no path specified`),null;if(M(q.path)&&await A(q.path))return q.path;if(M(q.path))return console.error(`Error: Path exists but is not a git repository: ${q.path}`),null;if(!q.url)return console.error(`Error: Repository not found at ${q.path} and no URL provided for cloning`),null;try{console.log(`Cloning repository from ${q.url} to ${q.path}...`);let H=m(q.path),B=q.path.split("/").pop()||"repository";try{await p(H,{recursive:!0})}catch($){}return await n(`git clone "${q.url}" "${q.path}"`),console.log(`✓ Successfully cloned ${q.name||B}`),q.path}catch(H){return console.error(`Error: Failed to clone repository: ${H}`),null}}class i{config;loadedConfig=null;constructor(q={}){this.config=q}async initialize(){if(!this.config.repositories){if(this.loadedConfig=await w(this.config.configPath),this.loadedConfig?.config.repositories)this.config.repositories=this.loadedConfig.config.repositories;if(this.loadedConfig?.config)this.config={...this.loadedConfig.config,...this.config,repositories:this.config.repositories||this.loadedConfig.config.repositories}}if(this.config.repositories)this.config.repositories=this.config.repositories.map((q)=>{if(!q.path&&q.url){let H=this.loadedConfig?.configDir||process.cwd(),B=R(q.url);return{...q,path:a(H,B),name:q.name||B}}return q});if(this.config.cloneIfNotExists&&this.config.repositories){let q=[];for(let H of this.config.repositories){if(!H.path){console.error(`
7
+ ❌ \x1B[31mError:\x1B[0m \x1B[91mRepository ${H.name||"unknown"} has no path and no URL\x1B[0m`),q.push("");continue}let B=await L(H);if(B)q.push(B);else q.push(H.path)}this.config.repositories=this.config.repositories.map((H,B)=>({...H,path:q[B]||H.path}))}}getRepoPaths(q){if(q&&q.length>0)return q;if(this.config.repositories)return this.config.repositories.map((H)=>H.path).filter((H)=>H!==void 0);return[]}async listContributors(q){await this.initialize();let H=this.getRepoPaths(q);if(H.length===0)throw Error("No repository paths specified");let B=[];for(let $ of H){if(!await A($))throw Error(`${$} is not a git repository`);try{let K=await z($);B.push({path:$,contributors:K})}catch(K){throw Error(`Failed to get contributors from ${$}: ${K}`)}}return B}async getHistory(q,H,B){await this.initialize();let $=this.getRepoPaths(q);if($.length===0)throw Error("No repository paths specified");let V=[];for(let K of $){if(!await A(K))throw Error(`${K} is not a git repository`);try{let Y=await D(K,H,B);V.push({path:K,commits:Y})}catch(Y){throw Error(`Failed to get commit history from ${K}: ${Y}`)}}return V}}export{w as loadConfig,A as isGitRepo,z as getContributors,D as getCommits,L as ensureRepository,i as Client};
@@ -5,6 +5,7 @@ export interface RepositoryConfig {
5
5
  }
6
6
  export interface ContributorsConfig {
7
7
  "no-commits"?: boolean;
8
+ format?: "json" | "text";
8
9
  }
9
10
  export interface GstatxConfig {
10
11
  contributors?: ContributorsConfig;
@@ -21,4 +21,4 @@ export interface Commit {
21
21
  files: CommitFile[];
22
22
  }
23
23
  export declare function getContributors(repoPath: string): Promise<RepoContributor[]>;
24
- export declare function getCommits(repoPath: string, since?: string, until?: string): Commit[];
24
+ export declare function getCommits(repoPath: string, since?: string, until?: string): Promise<Commit[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gstatx",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Export stats of a repo or list of repos",
5
5
  "type": "module",
6
6
  "engines": {