gstatx 0.2.2 → 0.2.5
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 +54 -3
- package/dist/index.js +41 -30
- package/dist/lib.d.ts +1 -0
- package/dist/lib.js +7 -4
- package/dist/utils/config.d.ts +2 -0
- package/dist/utils/git.d.ts +1 -1
- package/dist/utils/repo.d.ts +1 -1
- package/package.json +1 -1
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.
|
|
@@ -121,6 +166,7 @@ You can create a `.gstatxrc.json` file to set default options and repository pat
|
|
|
121
166
|
"no-commits": false
|
|
122
167
|
},
|
|
123
168
|
"cloneIfNotExists": false,
|
|
169
|
+
"pullIfExists": true,
|
|
124
170
|
"repositories": [
|
|
125
171
|
{
|
|
126
172
|
"path": "../my-repo",
|
|
@@ -134,6 +180,7 @@ You can create a `.gstatxrc.json` file to set default options and repository pat
|
|
|
134
180
|
**Configuration Fields:**
|
|
135
181
|
- `contributors.no-commits` (boolean, optional): Hide commit counts by default
|
|
136
182
|
- `cloneIfNotExists` (boolean, optional): Automatically clone repositories that don't exist locally
|
|
183
|
+
- `pullIfExists` (boolean, optional): Pull latest changes if repository already exists (default: `true`)
|
|
137
184
|
- `repositories` (array, optional): List of repositories to process
|
|
138
185
|
- `path` (string, required): Repository path (relative to config file location)
|
|
139
186
|
- `name` (string, optional): Display name for the repository
|
|
@@ -142,6 +189,7 @@ You can create a `.gstatxrc.json` file to set default options and repository pat
|
|
|
142
189
|
**Important Notes:**
|
|
143
190
|
- Repository paths in the config file are resolved relative to the `.gstatxrc.json` file location, not the current working directory
|
|
144
191
|
- If `cloneIfNotExists: true` and a repository doesn't exist, it will be cloned from the `url`
|
|
192
|
+
- If `pullIfExists: true` (default) and a repository already exists, it will pull the latest changes before processing
|
|
145
193
|
- CLI arguments always override config file values
|
|
146
194
|
- Both `contributors` and `hist` commands can use repositories from the config file
|
|
147
195
|
|
|
@@ -200,13 +248,15 @@ gstatx hist --since "1 month ago" --out report.json
|
|
|
200
248
|
|
|
201
249
|
The tool will automatically use the repositories listed in your config file.
|
|
202
250
|
|
|
203
|
-
### Auto-Cloning Repositories
|
|
251
|
+
### Auto-Cloning and Auto-Updating Repositories
|
|
204
252
|
|
|
205
253
|
When `cloneIfNotExists: true` is set in your config:
|
|
206
254
|
|
|
207
255
|
1. The tool checks if each repository exists at the specified path
|
|
208
256
|
2. If the repository doesn't exist and a `url` is provided, it will be cloned automatically
|
|
209
|
-
3. If the repository already exists
|
|
257
|
+
3. If the repository already exists:
|
|
258
|
+
- If `pullIfExists: true` (default), it will pull the latest changes before processing
|
|
259
|
+
- If `pullIfExists: false`, it will be used as-is without updating
|
|
210
260
|
4. If the path exists but isn't a git repository, an error is shown
|
|
211
261
|
|
|
212
262
|
**Example:**
|
|
@@ -287,6 +337,7 @@ import {
|
|
|
287
337
|
```typescript
|
|
288
338
|
interface ClientOptions {
|
|
289
339
|
cloneIfNotExists?: boolean;
|
|
340
|
+
pullIfExists?: boolean;
|
|
290
341
|
repositories?: RepositoryConfig[];
|
|
291
342
|
configPath?: string;
|
|
292
343
|
contributors?: {
|
package/dist/index.js
CHANGED
|
@@ -1,48 +1,59 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as
|
|
3
|
-
`)}displayWidth(
|
|
4
|
-
`+" ".repeat(
|
|
5
|
-
${
|
|
6
|
-
`)}}function
|
|
2
|
+
import{createRequire as NQ}from"node:module";var IQ=Object.create;var{getPrototypeOf:VQ,defineProperty:p,getOwnPropertyNames:MQ}=Object;var EQ=Object.prototype.hasOwnProperty;var DQ=(Q,X,Y)=>{Y=Q!=null?IQ(VQ(Q)):{};let Z=X||!Q||!Q.__esModule?p(Y,"default",{value:Q,enumerable:!0}):Y;for(let $ of MQ(Q))if(!EQ.call(Z,$))p(Z,$,{get:()=>Q[$],enumerable:!0});return Z};var S=(Q,X)=>()=>(X||Q((X={exports:{}}).exports,X),X.exports);var E=NQ(import.meta.url);var D=S((FQ)=>{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}}FQ.CommanderError=P;FQ.InvalidArgumentError=s});var A=S((wQ)=>{var{InvalidArgumentError:kQ}=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 kQ(`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 PQ(Q){let X=Q.name()+(Q.variadic===!0?"...":"");return Q.required?"<"+X+">":"["+X+"]"}wQ.Argument=i;wQ.humanReadableArgName=PQ});var w=S((bQ)=>{var{humanReadableArgName:CQ}=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)=>CQ(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,"")}bQ.Help=n;bQ.stripColor=a});var O=S((uQ)=>{var{InvalidArgumentError:hQ}=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=gQ(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 hQ(`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 gQ(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(
|
|
10
|
-
- too many short flags`);if(
|
|
11
|
-
- too many long flags`);throw
|
|
12
|
-
- unrecognised flag format`)}if(
|
|
13
|
-
(Did you mean one of ${
|
|
14
|
-
(Did you mean ${
|
|
15
|
-
- specify the name in Command constructor or using .name()`);if(
|
|
16
|
-
Expecting one of '${
|
|
17
|
-
- already used by option '${
|
|
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(
|
|
19
|
-
- if '${
|
|
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}}uQ.Option=t;uQ.DualOptions=o});var e=S((pQ)=>{function lQ(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 mQ(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 _=lQ(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""}pQ.suggestSimilar=mQ});var ZQ=S((eQ)=>{var iQ=E("node:events").EventEmitter,x=E("node:child_process"),L=E("node:path"),k=E("node:fs"),H=E("node:process"),{Argument:nQ,humanReadableArgName:aQ}=A(),{CommanderError:C}=D(),{Help:rQ,stripColor:tQ}=w(),{Option:QQ,DualOptions:oQ}=O(),{suggestSimilar:XQ}=e();class f extends iQ{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)=>tQ(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 rQ,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 nQ(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
|
-
- ${
|
|
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
|
|
25
|
-
`),this._exit(0,"commander.version"
|
|
26
|
-
Expecting one of '${
|
|
27
|
-
`)}),this}_outputHelpIfRequested(
|
|
28
|
-
`);for(let
|
|
29
|
-
`)[
|
|
30
|
-
`)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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 oQ(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 aQ(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}eQ.Command=f;eQ.useColor=b});var BQ=S(($X)=>{var{Argument:$Q}=A(),{Command:v}=ZQ(),{CommanderError:YX,InvalidArgumentError:qQ}=D(),{Help:ZX}=w(),{Option:JQ}=O();$X.program=new v;$X.createCommand=(Q)=>new v(Q);$X.createOption=(Q,X)=>new JQ(Q,X);$X.createArgument=(Q,X)=>new $Q(Q,X);$X.Command=v;$X.Option=JQ;$X.Argument=$Q;$X.Help=ZX;$X.CommanderError=YX;$X.InvalidArgumentError=qQ;$X.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=DQ(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 WX}from"node:fs/promises";import{dirname as GQ,join as TQ,resolve as h}from"node:path";var LX=".gstatxrc.json";function g(Q){let Y=Q.replace(/\.git$/,"").split(/[/:]/);return Y[Y.length-1]||"repository"}function SX(Q){let X=h(Q),Y=20,Z=0;while(Z<Y){let $=TQ(X,LX);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=SX(X),!Y)return null;let Z=await WX(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 jX,execSync as IX}from"node:child_process";import{access as HQ,readFile as VX}from"node:fs/promises";import{join as c}from"node:path";import{promisify as MX}from"node:util";var u=MX(jX);async function UQ(Q){try{return await HQ(c(Q,".mailmap")),!0}catch{return!1}}async function EX(Q){let X=new Map;try{let Y=c(Q,".mailmap"),$=(await VX(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 EX(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=IX(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,...jQ]=K.split("|");if(W&&j&&I&&M)J={hash:W.trim(),author:j.trim(),email:I.trim(),date:M.trim(),message:jQ.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 DX}from"node:child_process";import{existsSync as KQ}from"node:fs";import{mkdir as NX}from"node:fs/promises";import{dirname as FX}from"node:path";import{promisify as yX}from"node:util";var WQ=yX(DX);async function m(Q,X=!0){if(!Q.path)return console.error(`Error: Repository ${Q.name||"unknown"} has no path specified`),null;if(KQ(Q.path)&&await V(Q.path)){if(X)try{console.log(`Pulling latest changes for ${Q.name||Q.path}...`),await WQ("git pull",{cwd:Q.path}),console.log(`✓ Successfully updated ${Q.name||Q.path}`)}catch(Y){console.warn(`Warning: Failed to pull latest changes for ${Q.path}: ${Y}. Continuing with existing code.`)}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 Y=FX(Q.path),Z=Q.path.split("/").pop()||"repository";try{await NX(Y,{recursive:!0})}catch($){}return await WQ(`git clone "${Q.url}" "${Q.path}"`),console.log(`✓ Successfully cloned ${Q.name||Z}`),Q.path}catch(Y){return console.error(`Error: Failed to clone repository: ${Y}`),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=this.config.pullIfExists??!0,X=[];for(let Y of this.config.repositories){if(!Y.path){console.error(`
|
|
33
|
+
❌ \x1B[31mError:\x1B[0m \x1B[91mRepository ${Y.name||"unknown"} has no path and no URL\x1B[0m`),X.push("");continue}let Z=await m(Y,Q);if(Z)X.push(Z);else X.push(Y.path)}this.config.repositories=this.config.repositories.map((Y,Z)=>({...Y,path:X[Z]||Y.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 LQ(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 SQ(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??".gstatxrc.json",$=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 LQ(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
|
|
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??".gstatxrc.json",$={since:X.since,until:X.until,out:X.out},q=Q.length===0?void 0:Q;await SQ(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`);
|
|
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
|
-
|
|
57
|
+
Set 'pullIfExists: true' (default) to pull latest changes for
|
|
58
|
+
existing repositories, or 'pullIfExists: false' to skip updating.
|
|
59
|
+
`);y.parse();
|
package/dist/lib.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { type Commit, type RepoContributor } from "./utils/git";
|
|
|
7
7
|
export type * from "./types";
|
|
8
8
|
export interface ClientOptions extends GstatxConfig {
|
|
9
9
|
cloneIfNotExists?: boolean;
|
|
10
|
+
pullIfExists?: boolean;
|
|
10
11
|
repositories?: RepositoryConfig[];
|
|
11
12
|
configPath?: string;
|
|
12
13
|
}
|
package/dist/lib.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import{join as
|
|
2
|
-
`);for(let
|
|
3
|
-
`)[
|
|
4
|
-
`)
|
|
1
|
+
import{join as a}from"node:path";import{existsSync as N}from"node:fs";import{readFile as C}from"node:fs/promises";import{dirname as b,join as F,resolve as R}from"node:path";var g=".gstatxrc.json";function w(q){let B=q.replace(/\.git$/,"").split(/[/:]/);return B[B.length-1]||"repository"}function d(q){let J=R(q),B=20,X=0;while(X<B){let V=F(J,g);if(N(V))return V;let K=b(J);if(K===J)break;J=K,X++}return null}async function S(q,J=process.cwd()){try{let B;if(q){let Q=R(q);if(!N(Q))return console.error(`Error: Config file not found: ${Q}`),null;B=Q}else if(B=d(J),!B)return null;let X=await C(B,"utf-8"),V=JSON.parse(X),K=b(B);if(V.repositories)V.repositories=V.repositories.map((Q)=>{if(!Q.path&&Q.url){let Z=w(Q.url);return{...Q,path:F(K,Z),name:Q.name||Z}}if(Q.path)return{...Q,path:R(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 P,execSync as h}from"node:child_process";import{access as y,readFile as u}from"node:fs/promises";import{join as I}from"node:path";import{promisify as l}from"node:util";var v=l(P);async function E(q){try{return await y(I(q,".mailmap")),!0}catch{return!1}}async function c(q){let J=new Map;try{let B=I(q,".mailmap"),V=(await u(B,"utf-8")).split(`
|
|
2
|
+
`);for(let K of V){let Q=K.trim();if(!Q||Q.startsWith("#"))continue;let Z=Q.matchAll(/<([^>]+)>/g),$=Array.from(Z).map((H)=>H[1]?.trim()).filter((H)=>H!==void 0);if($.length>=2){let H=$[0];if(H){let k=H.toLowerCase();for(let W=1;W<$.length;W++){let Y=$[W];if(Y)J.set(Y.toLowerCase(),k)}}}}}catch{}return J}async function j(q){try{return await y(I(q,".git")),!0}catch{return!1}}async function z(q){try{let J=await E(q),B=new Map;if(J){let V=await c(q),{stdout:K}=await v("git log --all --format='%aN|%aE' --use-mailmap",{cwd:q}),Q=new Map,Z=K.trim().split(`
|
|
3
|
+
`);for(let $ of Z){if(!$.trim())continue;let[H,k]=$.split("|");if(!H||!k)continue;let W=k.toLowerCase(),Y=V.get(W);if(Y)W=Y;let T=B.get(W);if(!Q.has(W))Q.set(W,new Map);let U=Q.get(W);if(U)U.set(H,(U.get(H)||0)+1);if(T)B.set(W,{...T,commits:T.commits+1});else{let O=Y||k;B.set(W,{name:H,email:O,commits:1,maxIndividualCommits:1})}}for(let[$,H]of Q.entries()){let k=B.get($);if(k){let W=0,Y=k.name;for(let[T,U]of H.entries())if(U>W)W=U,Y=T;B.set($,{...k,name:Y})}}}else{let{stdout:V}=await v("git shortlog -sn --all",{cwd:q}),K=V.trim().split(`
|
|
4
|
+
`);for(let Q of K){let Z=Q.match(/^\s*(\d+)\s+(.+)$/);if(Z){let $=parseInt(Z[1]||"0",10),H=Z[2]||"",{stdout:k}=await v(`git log --format='%aE' --author="${H.replace(/"/g,"\\\"")}" -1`,{cwd:q}),W=k.trim().split(`
|
|
5
|
+
`)[0]||"",Y=W.toLowerCase(),T=B.get(Y);if(T){let U=T.commits+$;if($>T.maxIndividualCommits)B.set(Y,{name:H,email:W,commits:U,maxIndividualCommits:$});else B.set(Y,{...T,commits:U})}else B.set(Y,{name:H,email:W,commits:$,maxIndividualCommits:$})}}}return Array.from(B.values()).map((V)=>({name:V.name,email:V.email,commits:V.commits})).sort((V,K)=>K.commits-V.commits)}catch(J){throw Error(`Failed to get contributors from ${q}: ${J}`)}}async function D(q,J,B){let K=`git log --format="%H|%an|%ae|%ad|%s" --date=iso-strict --numstat${await E(q)?" --use-mailmap":""}`;if(J)K+=` --since="${J}"`;if(B)K+=` --until="${B}"`;let Q=h(K,{encoding:"utf-8",cwd:q,maxBuffer:10485760}),Z=[],$=Q.split(`
|
|
6
|
+
`).filter((U)=>U.trim()),H=null,k=0,W=0,Y=0,T=[];for(let U of $)if(U.includes("|")){if(H?.hash&&H?.author&&H?.email&&H?.date&&H?.message)Z.push({hash:H.hash,author:H.author,email:H.email,date:H.date,message:H.message,filesChanged:k,insertions:W,deletions:Y,files:T});let[O,G,_,A,...f]=U.split("|");if(O&&G&&_&&A)H={hash:O.trim(),author:G.trim(),email:_.trim(),date:A.trim(),message:f.join("|").trim()},k=0,W=0,Y=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,A=O.slice(2).join(" ");if(A&&!Number.isNaN(G)&&!Number.isNaN(_))k++,W+=G,Y+=_,T.push({path:A,insertions:G,deletions:_})}}if(H?.hash&&H?.author&&H?.email&&H?.date&&H?.message)Z.push({hash:H.hash,author:H.author,email:H.email,date:H.date,message:H.message,filesChanged:k,insertions:W,deletions:Y,files:T});return Z}import{exec as m}from"node:child_process";import{existsSync as M}from"node:fs";import{mkdir as p}from"node:fs/promises";import{dirname as s}from"node:path";import{promisify as n}from"node:util";var x=n(m);async function L(q,J=!0){if(!q.path)return console.error(`Error: Repository ${q.name||"unknown"} has no path specified`),null;if(M(q.path)&&await j(q.path)){if(J)try{console.log(`Pulling latest changes for ${q.name||q.path}...`),await x("git pull",{cwd:q.path}),console.log(`✓ Successfully updated ${q.name||q.path}`)}catch(B){console.warn(`Warning: Failed to pull latest changes for ${q.path}: ${B}. Continuing with existing code.`)}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 B=s(q.path),X=q.path.split("/").pop()||"repository";try{await p(B,{recursive:!0})}catch(V){}return await x(`git clone "${q.url}" "${q.path}"`),console.log(`✓ Successfully cloned ${q.name||X}`),q.path}catch(B){return console.error(`Error: Failed to clone repository: ${B}`),null}}class i{config;loadedConfig=null;constructor(q={}){this.config=q}async initialize(){if(!this.config.repositories){if(this.loadedConfig=await S(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 J=this.loadedConfig?.configDir||process.cwd(),B=w(q.url);return{...q,path:a(J,B),name:q.name||B}}return q});if(this.config.cloneIfNotExists&&this.config.repositories){let q=this.config.pullIfExists??!0,J=[];for(let B of this.config.repositories){if(!B.path){console.error(`
|
|
7
|
+
❌ \x1B[31mError:\x1B[0m \x1B[91mRepository ${B.name||"unknown"} has no path and no URL\x1B[0m`),J.push("");continue}let X=await L(B,q);if(X)J.push(X);else J.push(B.path)}this.config.repositories=this.config.repositories.map((B,X)=>({...B,path:J[X]||B.path}))}}getRepoPaths(q){if(q&&q.length>0)return q;if(this.config.repositories)return this.config.repositories.map((J)=>J.path).filter((J)=>J!==void 0);return[]}async listContributors(q){await this.initialize();let J=this.getRepoPaths(q);if(J.length===0)throw Error("No repository paths specified");let B=[];for(let X of J){if(!await j(X))throw Error(`${X} is not a git repository`);try{let K=await z(X);B.push({path:X,contributors:K})}catch(K){throw Error(`Failed to get contributors from ${X}: ${K}`)}}return B}async getHistory(q,J,B){await this.initialize();let X=this.getRepoPaths(q);if(X.length===0)throw Error("No repository paths specified");let V=[];for(let K of X){if(!await j(K))throw Error(`${K} is not a git repository`);try{let Z=await D(K,J,B);V.push({path:K,commits:Z})}catch(Z){throw Error(`Failed to get commit history from ${K}: ${Z}`)}}return V}}export{S as loadConfig,j as isGitRepo,z as getContributors,D as getCommits,L as ensureRepository,i as Client};
|
package/dist/utils/config.d.ts
CHANGED
|
@@ -5,11 +5,13 @@ 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;
|
|
11
12
|
repositories?: RepositoryConfig[];
|
|
12
13
|
cloneIfNotExists?: boolean;
|
|
14
|
+
pullIfExists?: boolean;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Extract repository name from a Git URL
|
package/dist/utils/git.d.ts
CHANGED
|
@@ -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/dist/utils/repo.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RepositoryConfig } from "./config";
|
|
2
|
-
export declare function ensureRepository(repo: RepositoryConfig): Promise<string | null>;
|
|
2
|
+
export declare function ensureRepository(repo: RepositoryConfig, pullIfExists?: boolean): Promise<string | null>;
|