gstatx 0.1.2 → 0.1.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 +129 -5
- package/dist/index.js +25 -25
- package/dist/lib.js +4 -4
- package/dist/utils/config.d.ts +9 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
📊 Export statistics from git repositories
|
|
4
4
|
|
|
5
|
-
A CLI tool to analyze and export statistics from one or multiple git repositories.
|
|
5
|
+
A CLI tool and library to analyze and export statistics from one or multiple git repositories.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -10,10 +10,10 @@ A CLI tool to analyze and export statistics from one or multiple git repositorie
|
|
|
10
10
|
npm install -g gstatx
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Or
|
|
13
|
+
Or install as a library:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
npm install
|
|
16
|
+
npm install gstatx
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Quick Start
|
|
@@ -27,6 +27,12 @@ gstatx contributors ./repo1 ./repo2 ./repo3
|
|
|
27
27
|
|
|
28
28
|
# Hide commit counts
|
|
29
29
|
gstatx contributors --no-commits ./my-repo
|
|
30
|
+
|
|
31
|
+
# Generate commit history report
|
|
32
|
+
gstatx hist ./my-repo
|
|
33
|
+
|
|
34
|
+
# Generate history report for last month and save to file
|
|
35
|
+
gstatx hist --since "1 month ago" --out report.json ./my-repo
|
|
30
36
|
```
|
|
31
37
|
|
|
32
38
|
## User Guide
|
|
@@ -39,7 +45,7 @@ List contributors for specified git repositories.
|
|
|
39
45
|
|
|
40
46
|
**Usage:**
|
|
41
47
|
```bash
|
|
42
|
-
gstatx contributors [options]
|
|
48
|
+
gstatx contributors [options] [repo-paths...]
|
|
43
49
|
```
|
|
44
50
|
|
|
45
51
|
**Options:**
|
|
@@ -56,8 +62,49 @@ gstatx contributors --no-commits ./my-repo
|
|
|
56
62
|
|
|
57
63
|
# List contributors for multiple repositories
|
|
58
64
|
gstatx contributors ./repo1 ./repo2 ./repo3
|
|
65
|
+
|
|
66
|
+
# Use repositories from config file
|
|
67
|
+
gstatx contributors
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### `hist`
|
|
71
|
+
|
|
72
|
+
Generate commit history report with detailed statistics.
|
|
73
|
+
|
|
74
|
+
**Usage:**
|
|
75
|
+
```bash
|
|
76
|
+
gstatx hist [options] [repo-paths...]
|
|
59
77
|
```
|
|
60
78
|
|
|
79
|
+
**Options:**
|
|
80
|
+
- `-s, --since <date>` - Start date for the report (e.g., "2024-01-01", "1 month ago")
|
|
81
|
+
- `-u, --until <date>` - End date for the report (e.g., "2024-12-31", "now")
|
|
82
|
+
- `-o, --out <file>` - Output file path (defaults to stdout)
|
|
83
|
+
- `--help, -h` - Show help message
|
|
84
|
+
|
|
85
|
+
**Examples:**
|
|
86
|
+
```bash
|
|
87
|
+
# Generate history for a repository
|
|
88
|
+
gstatx hist ./my-repo
|
|
89
|
+
|
|
90
|
+
# Generate history for last month
|
|
91
|
+
gstatx hist --since "1 month ago" ./my-repo
|
|
92
|
+
|
|
93
|
+
# Generate history for specific period
|
|
94
|
+
gstatx hist --since "2024-01-01" --until "2024-12-31" ./my-repo
|
|
95
|
+
|
|
96
|
+
# Save to file
|
|
97
|
+
gstatx hist --since "1 month ago" --out report.json ./my-repo
|
|
98
|
+
|
|
99
|
+
# Use repositories from config file
|
|
100
|
+
gstatx hist --since "1 month ago" --out report.json
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The report includes:
|
|
104
|
+
- Commit details (hash, author, date, message)
|
|
105
|
+
- File-level statistics (files changed, insertions, deletions)
|
|
106
|
+
- Summary statistics per repository
|
|
107
|
+
|
|
61
108
|
### Configuration File
|
|
62
109
|
|
|
63
110
|
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.
|
|
@@ -85,7 +132,6 @@ You can create a `.gstatxrc.json` file to set default options and repository pat
|
|
|
85
132
|
```
|
|
86
133
|
|
|
87
134
|
**Configuration Fields:**
|
|
88
|
-
|
|
89
135
|
- `contributors.no-commits` (boolean, optional): Hide commit counts by default
|
|
90
136
|
- `cloneIfNotExists` (boolean, optional): Automatically clone repositories that don't exist locally
|
|
91
137
|
- `repositories` (array, optional): List of repositories to process
|
|
@@ -97,6 +143,7 @@ You can create a `.gstatxrc.json` file to set default options and repository pat
|
|
|
97
143
|
- Repository paths in the config file are resolved relative to the `.gstatxrc.json` file location, not the current working directory
|
|
98
144
|
- If `cloneIfNotExists: true` and a repository doesn't exist, it will be cloned from the `url`
|
|
99
145
|
- CLI arguments always override config file values
|
|
146
|
+
- Both `contributors` and `hist` commands can use repositories from the config file
|
|
100
147
|
|
|
101
148
|
**Example Config File:**
|
|
102
149
|
|
|
@@ -125,6 +172,7 @@ You can create a `.gstatxrc.json` file to set default options and repository pat
|
|
|
125
172
|
|
|
126
173
|
- `--help, -h` - Show help message
|
|
127
174
|
- `--config, -c <path>` - Specify custom config file path
|
|
175
|
+
- `--version, -V` - Show version number
|
|
128
176
|
|
|
129
177
|
**Examples:**
|
|
130
178
|
```bash
|
|
@@ -133,6 +181,9 @@ gstatx --config ./custom-config.json contributors
|
|
|
133
181
|
|
|
134
182
|
# Short form
|
|
135
183
|
gstatx -c ./custom-config.json contributors
|
|
184
|
+
|
|
185
|
+
# Show version
|
|
186
|
+
gstatx --version
|
|
136
187
|
```
|
|
137
188
|
|
|
138
189
|
### Using Config File Repositories
|
|
@@ -142,6 +193,9 @@ If you have repositories defined in your config file, you can run commands witho
|
|
|
142
193
|
```bash
|
|
143
194
|
# Uses repositories from .gstatxrc.json
|
|
144
195
|
gstatx contributors
|
|
196
|
+
|
|
197
|
+
# Generate history for all config repositories
|
|
198
|
+
gstatx hist --since "1 month ago" --out report.json
|
|
145
199
|
```
|
|
146
200
|
|
|
147
201
|
The tool will automatically use the repositories listed in your config file.
|
|
@@ -171,6 +225,76 @@ When `cloneIfNotExists: true` is set in your config:
|
|
|
171
225
|
|
|
172
226
|
Running `gstatx contributors` will automatically clone the repository if it doesn't exist.
|
|
173
227
|
|
|
228
|
+
## Library Usage
|
|
229
|
+
|
|
230
|
+
gstatx can also be used as a library in your TypeScript/JavaScript projects.
|
|
231
|
+
|
|
232
|
+
### Installation
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
npm install gstatx
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Basic Usage
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import { Client } from "gstatx";
|
|
242
|
+
|
|
243
|
+
const client = new Client({
|
|
244
|
+
cloneIfNotExists: true,
|
|
245
|
+
repositories: [
|
|
246
|
+
{
|
|
247
|
+
path: "/path/to/repository",
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
contributors: {
|
|
251
|
+
"no-commits": false
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// List contributors
|
|
256
|
+
const contributors = await client.listContributors();
|
|
257
|
+
// Returns: Array<{ path: string; contributors: RepoContributor[] }>
|
|
258
|
+
|
|
259
|
+
// Get commit history
|
|
260
|
+
const history = await client.getHistory(
|
|
261
|
+
undefined, // use config repositories
|
|
262
|
+
"1 month ago", // since
|
|
263
|
+
"now" // until
|
|
264
|
+
);
|
|
265
|
+
// Returns: Array<{ path: string; commits: Commit[] }>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Available Exports
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import {
|
|
272
|
+
Client,
|
|
273
|
+
getContributors,
|
|
274
|
+
getCommits,
|
|
275
|
+
isGitRepo,
|
|
276
|
+
ensureRepository,
|
|
277
|
+
loadConfig,
|
|
278
|
+
type RepoContributor,
|
|
279
|
+
type Commit,
|
|
280
|
+
type GstatxConfig,
|
|
281
|
+
type RepositoryConfig,
|
|
282
|
+
} from "gstatx";
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Client Options
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
interface ClientOptions {
|
|
289
|
+
cloneIfNotExists?: boolean;
|
|
290
|
+
repositories?: RepositoryConfig[];
|
|
291
|
+
configPath?: string;
|
|
292
|
+
contributors?: {
|
|
293
|
+
"no-commits"?: boolean;
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
174
298
|
## Development
|
|
175
299
|
|
|
176
300
|
### Prerequisites
|
package/dist/index.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as
|
|
3
|
-
`)}displayWidth($){return
|
|
4
|
-
`+" ".repeat(q+
|
|
5
|
-
${X}`)}boxWrap($,q){if(q<this.minWidthToWrap)return $;let J=$.split(/\r\n|\n/),z=/[\s]*[^\s]+/g,Q=[];return J.forEach((X)=>{let
|
|
6
|
-
`)}}function
|
|
2
|
+
import{createRequire as W1}from"node:module";var L1=Object.create;var{getPrototypeOf:M1,defineProperty:l,getOwnPropertyNames:U1}=Object;var S1=Object.prototype.hasOwnProperty;var K1=($,q,J)=>{J=$!=null?L1(M1($)):{};let z=q||!$||!$.__esModule?l(J,"default",{value:$,enumerable:!0}):J;for(let Q of U1($))if(!S1.call(z,Q))l(z,Q,{get:()=>$[Q],enumerable:!0});return z};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,J){super(J);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,J)=>{if(!this.argChoices.includes(q))throw new V1(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(q,J);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((z)=>!z._hidden),J=$._getHelpCommand();if(J&&!J._hidden)q.push(J);if(this.sortSubcommands)q.sort((z,Q)=>{return z.name().localeCompare(Q.name())});return q}compareOptions($,q){let J=(z)=>{return z.short?z.short.replace(/^-/,""):z.long.replace(/^--/,"")};return J($).localeCompare(J(q))}visibleOptions($){let q=$.options.filter((z)=>!z.hidden),J=$._getHelpOption();if(J&&!J.hidden){let z=J.short&&$._findOption(J.short),Q=J.long&&$._findOption(J.long);if(!z&&!Q)q.push(J);else if(J.long&&!Q)q.push($.createOption(J.long,J.description));else if(J.short&&!z)q.push($.createOption(J.short,J.description))}if(this.sortOptions)q.sort(this.compareOptions);return q}visibleGlobalOptions($){if(!this.showGlobalOptions)return[];let q=[];for(let J=$.parent;J;J=J.parent){let z=J.options.filter((Q)=>!Q.hidden);q.push(...z)}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((J)=>w1(J)).join(" ");return $._name+($._aliases[0]?"|"+$._aliases[0]:"")+($.options.length?" [options]":"")+(q?" "+q:"")}optionTerm($){return $.flags}argumentTerm($){return $.name()}longestSubcommandTermLength($,q){return q.visibleCommands($).reduce((J,z)=>{return Math.max(J,this.displayWidth(q.styleSubcommandTerm(q.subcommandTerm(z))))},0)}longestOptionTermLength($,q){return q.visibleOptions($).reduce((J,z)=>{return Math.max(J,this.displayWidth(q.styleOptionTerm(q.optionTerm(z))))},0)}longestGlobalOptionTermLength($,q){return q.visibleGlobalOptions($).reduce((J,z)=>{return Math.max(J,this.displayWidth(q.styleOptionTerm(q.optionTerm(z))))},0)}longestArgumentTermLength($,q){return q.visibleArguments($).reduce((J,z)=>{return Math.max(J,this.displayWidth(q.styleArgumentTerm(q.argumentTerm(z))))},0)}commandUsage($){let q=$._name;if($._aliases[0])q=q+"|"+$._aliases[0];let J="";for(let z=$.parent;z;z=z.parent)J=z.name()+" "+J;return J+q+" "+$.usage()}commandDescription($){return $.description()}subcommandDescription($){return $.summary()||$.description()}optionDescription($){let q=[];if($.argChoices)q.push(`choices: ${$.argChoices.map((J)=>JSON.stringify(J)).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 J=`(${q.join(", ")})`;if($.description)return`${$.description} ${J}`;return J}return $.description}argumentDescription($){let q=[];if($.argChoices)q.push(`choices: ${$.argChoices.map((J)=>JSON.stringify(J)).join(", ")}`);if($.defaultValue!==void 0)q.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`);if(q.length>0){let J=`(${q.join(", ")})`;if($.description)return`${$.description} ${J}`;return J}return $.description}formatItemList($,q,J){if(q.length===0)return[];return[J.styleTitle($),...q,""]}groupItems($,q,J){let z=new Map;return $.forEach((Q)=>{let X=J(Q);if(!z.has(X))z.set(X,[])}),q.forEach((Q)=>{let X=J(Q);if(!z.has(X))z.set(X,[]);z.get(X).push(Q)}),z}formatHelp($,q){let J=q.padWidth($,q),z=q.helpWidth??80;function Q(H,T){return q.formatItem(H,J,T,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),z),""]);let Z=q.visibleArguments($).map((H)=>{return Q(q.styleArgumentTerm(q.argumentTerm(H)),q.styleArgumentDescription(q.argumentDescription(H)))});if(X=X.concat(this.formatItemList("Arguments:",Z,q)),this.groupItems($.options,q.visibleOptions($),(H)=>H.helpGroupHeading??"Options:").forEach((H,T)=>{let G=H.map((L)=>{return Q(q.styleOptionTerm(q.optionTerm(L)),q.styleOptionDescription(q.optionDescription(L)))});X=X.concat(this.formatItemList(T,G,q))}),q.showGlobalOptions){let H=q.visibleGlobalOptions($).map((T)=>{return Q(q.styleOptionTerm(q.optionTerm(T)),q.styleOptionDescription(q.optionDescription(T)))});X=X.concat(this.formatItemList("Global Options:",H,q))}return this.groupItems($.commands,q.visibleCommands($),(H)=>H.helpGroup()||"Commands:").forEach((H,T)=>{let G=H.map((L)=>{return Q(q.styleSubcommandTerm(q.subcommandTerm(L)),q.styleSubcommandDescription(q.subcommandDescription(L)))});X=X.concat(this.formatItemList(T,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,J,z){let X=" ".repeat(2);if(!J)return X+$;let Y=$.padEnd(q+$.length-z.displayWidth($)),Z=2,R=(this.helpWidth??80)-q-Z-2,H;if(R<this.minWidthToWrap||z.preformatted(J))H=J;else H=z.boxWrap(J,R).replace(/\n/g,`
|
|
4
|
+
`+" ".repeat(q+Z));return X+Y+" ".repeat(Z)+H.replace(/\n/g,`
|
|
5
|
+
${X}`)}boxWrap($,q){if(q<this.minWidthToWrap)return $;let J=$.split(/\r\n|\n/),z=/[\s]*[^\s]+/g,Q=[];return J.forEach((X)=>{let Y=X.match(z);if(Y===null){Q.push("");return}let Z=[Y.shift()],_=this.displayWidth(Z[0]);Y.forEach((R)=>{let H=this.displayWidth(R);if(_+H<=q){Z.push(R),_+=H;return}Q.push(Z.join(""));let T=R.trimStart();Z=[T],_=this.displayWidth(T)}),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 J=x1($);if(this.short=J.shortFlag,this.long=J.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,J)=>{if(!this.argChoices.includes(q))throw new O1(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(q,J);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,J)=>{if(this.positiveOptions.has(J))this.dualOptions.add(J)})}valueFromOption($,q){let J=q.attributeName();if(!this.dualOptions.has(J))return!0;let z=this.negativeOptions.get(J).presetArg,Q=z!==void 0?z:!1;return q.negate===(Q===$)}}function s($){return $.split("-").reduce((q,J)=>{return q+J[0].toUpperCase()+J.slice(1)})}function x1($){let q,J,z=/^-[^-]$/,Q=/^--[^-]/,X=$.split(/[ |,]+/).concat("guard");if(z.test(X[0]))q=X.shift();if(Q.test(X[0]))J=X.shift();if(!q&&z.test(X[0]))q=X.shift();if(!q&&Q.test(X[0]))q=J,J=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}
|
|
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(z.test(
|
|
10
|
-
- too many short flags`);if(Q.test(
|
|
11
|
-
- too many long flags`);throw new Error(`${
|
|
12
|
-
- unrecognised flag format`)}if(q===void 0&&J===void 0)throw new Error(`option creation failed due to no flags found in '${$}'.`);return{shortFlag:q,longFlag:J}}
|
|
9
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(z.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&&J===void 0)throw new Error(`option creation failed due to no flags found in '${$}'.`);return{shortFlag:q,longFlag:J}}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 J=[];for(let z=0;z<=$.length;z++)J[z]=[z];for(let z=0;z<=q.length;z++)J[0][z]=z;for(let z=1;z<=q.length;z++)for(let Q=1;Q<=$.length;Q++){let X=1;if($[Q-1]===q[z-1])X=0;else X=1;if(J[Q][z]=Math.min(J[Q-1][z]+1,J[Q][z-1]+1,J[Q-1][z-1]+X),Q>1&&z>1&&$[Q-1]===q[z-2]&&$[Q-2]===q[z-1])J[Q][z]=Math.min(J[Q][z],J[Q-2][z-2]+1)}return J[$.length][q.length]}function h1($,q){if(!q||q.length===0)return"";q=Array.from(new Set(q));let J=$.startsWith("--");if(J)$=$.slice(2),q=q.map((Y)=>Y.slice(2));let z=[],Q=3,X=0.4;if(q.forEach((Y)=>{if(Y.length<=1)return;let Z=v1($,Y),_=Math.max($.length,Y.length);if((_-Z)/_>X){if(Z<Q)Q=Z,z=[Y];else if(Z===Q)z.push(Y)}}),z.sort((Y,Z)=>Y.localeCompare(Z)),J)z=z.map((Y)=>`--${Y}`);if(z.length>1)return`
|
|
13
13
|
(Did you mean one of ${z.join(", ")}?)`;if(z.length===1)return`
|
|
14
|
-
(Did you mean ${z[0]}?)`;return""}
|
|
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
|
|
16
|
-
Expecting one of '${J.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,J){if(this._exitCallback)this._exitCallback(new O($,q,J));B.exit($)}action($){let q=(J)=>{let z=this.registeredArguments.length,Q=J.slice(0,z);if(this._storeOptionsAsProperties)Q[z]=this;else Q[z]=this.opts();return Q.push(this),$.apply(this,Q)};return this._actionHandler=q,this}createOption($,q){return new
|
|
17
|
-
- already used by option '${q.flags}'`)}this._initOptionGroup($),this.options.push($)}_registerCommand($){let q=(z)=>{return[z.name()].concat(z.aliases())},J=q($).find((z)=>this._findCommand(z));if(J){let z=q(this._findCommand(J)).join("|"),Q=q($).join("|");throw new Error(`cannot add command '${Q}' as already have command '${z}'`)}this._initCommandGroup($),this.commands.push($)}addOption($){this._registerOption($);let q=$.name(),J=$.attributeName();if($.negate){let Q=$.long.replace(/^--no-/,"--");if(!this._findOption(Q))this.setOptionValueWithSource(J,$.defaultValue===void 0?!0:$.defaultValue,"default")}else if($.defaultValue!==void 0)this.setOptionValueWithSource(J,$.defaultValue,"default");let z=(Q,X,
|
|
14
|
+
(Did you mean ${z[0]}?)`;return""}u1.suggestSimilar=h1});var e=U((i1)=>{var l1=I("node:events").EventEmitter,k=I("node:child_process"),M=I("node:path"),F=I("node:fs"),B=I("node:process"),{Argument:c1,humanReadableArgName:m1}=y(),{CommanderError:O}=E(),{Help:d1,stripColor:p1}=A(),{Option:a,DualOptions:s1}=P(),{suggestSimilar:r}=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)=>B.stdout.write(q),writeErr:(q)=>B.stderr.write(q),outputError:(q,J)=>J(q),getOutHelpWidth:()=>B.stdout.isTTY?B.stdout.columns:void 0,getErrHelpWidth:()=>B.stderr.isTTY?B.stderr.columns:void 0,getOutHasColors:()=>x()??(B.stdout.isTTY&&B.stdout.hasColors?.()),getErrHasColors:()=>x()??(B.stderr.isTTY&&B.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,J){let z=q,Q=J;if(typeof z==="object"&&z!==null)Q=z,z=null;Q=Q||{};let[,X,Y]=$.match(/([^ ]+) *(.*)/),Z=this.createCommand(X);if(z)Z.description(z),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),z)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,J,z){let Q=this.createArgument($,q);if(typeof J==="function")Q.default(z).argParser(J);else Q.default(J);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 J=$??"help [command]",[,z,Q]=J.match(/([^ ]+) *(.*)/),X=q??"display help for command",Y=this.createCommand(z);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 J=["preSubcommand","preAction","postAction"];if(!J.includes($))throw new Error(`Unexpected value for event passed to hook : '${$}'.
|
|
16
|
+
Expecting one of '${J.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,J){if(this._exitCallback)this._exitCallback(new O($,q,J));B.exit($)}action($){let q=(J)=>{let z=this.registeredArguments.length,Q=J.slice(0,z);if(this._storeOptionsAsProperties)Q[z]=this;else Q[z]=this.opts();return Q.push(this),$.apply(this,Q)};return this._actionHandler=q,this}createOption($,q){return new a($,q)}_callParseArg($,q,J,z){try{return $.parseArg(q,J)}catch(Q){if(Q.code==="commander.invalidArgument"){let X=`${z} ${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 J=$.long&&this._findOption($.long)?$.long:$.short;throw new Error(`Cannot add option '${$.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${J}'
|
|
17
|
+
- already used by option '${q.flags}'`)}this._initOptionGroup($),this.options.push($)}_registerCommand($){let q=(z)=>{return[z.name()].concat(z.aliases())},J=q($).find((z)=>this._findCommand(z));if(J){let z=q(this._findCommand(J)).join("|"),Q=q($).join("|");throw new Error(`cannot add command '${Q}' as already have command '${z}'`)}this._initCommandGroup($),this.commands.push($)}addOption($){this._registerOption($);let q=$.name(),J=$.attributeName();if($.negate){let Q=$.long.replace(/^--no-/,"--");if(!this._findOption(Q))this.setOptionValueWithSource(J,$.defaultValue===void 0?!0:$.defaultValue,"default")}else if($.defaultValue!==void 0)this.setOptionValueWithSource(J,$.defaultValue,"default");let z=(Q,X,Y)=>{if(Q==null&&$.presetArg!==void 0)Q=$.presetArg;let Z=this.getOptionValue(J);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(J,Q,Y)};if(this.on("option:"+q,(Q)=>{let X=`error: option '${$.flags}' argument '${Q}' is invalid.`;z(Q,X,"cli")}),$.envVar)this.on("optionEnv:"+q,(Q)=>{let X=`error: option '${$.flags}' value '${Q}' from env '${$.envVar}' is invalid.`;z(Q,X,"env")});return this}_optionEx($,q,J,z,Q){if(typeof q==="object"&&q instanceof a)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let X=this.createOption(q,J);if(X.makeOptionMandatory(!!$.mandatory),typeof z==="function")X.default(Q).argParser(z);else if(z instanceof RegExp){let Y=z;z=(Z,_)=>{let R=Y.exec(Z);return R?R[0]:_},X.default(Q).argParser(z)}else X.default(z);return this.addOption(X)}option($,q,J,z){return this._optionEx({},$,q,J,z)}requiredOption($,q,J,z){return this._optionEx({mandatory:!0},$,q,J,z)}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,J){if(this._storeOptionsAsProperties)this[$]=q;else this._optionValues[$]=q;return this._optionValueSources[$]=J,this}getOptionValueSource($){return this._optionValueSources[$]}getOptionValueSourceWithGlobals($){let q;return this._getCommandAndAncestors().forEach((J)=>{if(J.getOptionValueSource($)!==void 0)q=J.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(B.versions?.electron)q.from="electron";let z=B.execArgv??[];if(z.includes("-e")||z.includes("--eval")||z.includes("-p")||z.includes("--print"))q.from="eval"}if($===void 0)$=B.argv;this.rawArgs=$.slice();let J;switch(q.from){case void 0:case"node":this._scriptPath=$[1],J=$.slice(2);break;case"electron":if(B.defaultApp)this._scriptPath=$[1],J=$.slice(2);else J=$.slice(1);break;case"user":J=$.slice(0);break;case"eval":J=$.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",J}parse($,q){this._prepareForParse();let J=this._prepareUserArgs($,q);return this._parseCommand([],J),this}async parseAsync($,q){this._prepareForParse();let J=this._prepareUserArgs($,q);return await this._parseCommand([],J),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
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,J){if(F.existsSync($))return;let z=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
19
|
- if '${J}' 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
|
-
- ${z}`;throw new Error(Q)}_executeSubCommand($,q){q=q.slice();let J=!1,z=[".js",".ts",".tsx",".mjs",".cjs"];function Q(R,H){let T=
|
|
21
|
+
- ${z}`;throw new Error(Q)}_executeSubCommand($,q){q=q.slice();let J=!1,z=[".js",".ts",".tsx",".mjs",".cjs"];function Q(R,H){let T=M.resolve(R,H);if(F.existsSync(T))return T;if(z.includes(M.extname(H)))return;let G=z.find((L)=>F.existsSync(`${T}${L}`));if(G)return`${T}${G}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let X=$._executableFile||`${this._name}-${$._name}`,Y=this._executableDir||"";if(this._scriptPath){let R;try{R=F.realpathSync(this._scriptPath)}catch{R=this._scriptPath}Y=M.resolve(M.dirname(R),Y)}if(Y){let R=Q(Y,X);if(!R&&!$._executableFile&&this._scriptPath){let H=M.basename(this._scriptPath,M.extname(this._scriptPath));if(H!==this._name)R=Q(Y,`${H}-${$._name}`)}X=R||X}J=z.includes(M.extname(X));let Z;if(B.platform!=="win32")if(J)q.unshift(X),q=o(B.execArgv).concat(q),Z=k.spawn(B.argv[0],q,{stdio:"inherit"});else Z=k.spawn(X,q,{stdio:"inherit"});else this._checkForMissingExecutable(X,Y,$._name),q.unshift(X),q=o(B.execArgv).concat(q),Z=k.spawn(B.execPath,q,{stdio:"inherit"});if(!Z.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((H)=>{B.on(H,()=>{if(Z.killed===!1&&Z.exitCode===null)Z.kill(H)})});let _=this._exitCallback;Z.on("close",(R)=>{if(R=R??1,!_)B.exit(R);else _(new O(R,"commander.executeSubCommandAsync","(close)"))}),Z.on("error",(R)=>{if(R.code==="ENOENT")this._checkForMissingExecutable(X,Y,$._name);else if(R.code==="EACCES")throw new Error(`'${X}' not executable`);if(!_)B.exit(1);else{let H=new O(1,"commander.executeSubCommandAsync","(error)");H.nestedError=R,_(H)}}),this.runningCommand=Z}_dispatchSubcommand($,q,J){let z=this._findCommand($);if(!z)this.help({error:!0});z._prepareForParse();let Q;return Q=this._chainOrCallSubCommandHook(Q,z,"preSubcommand"),Q=this._chainOrCall(Q,()=>{if(z._executableHandler)this._executeSubCommand(z,q.concat(J));else return z._parseCommand(q,J)}),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 $=(J,z,Q)=>{let X=z;if(z!==null&&J.parseArg){let Y=`error: command-argument value '${z}' is invalid for argument '${J.name()}'.`;X=this._callParseArg(J,z,Q,Y)}return X};this._checkNumberOfArguments();let q=[];this.registeredArguments.forEach((J,z)=>{let Q=J.defaultValue;if(J.variadic){if(z<this.args.length){if(Q=this.args.slice(z),J.parseArg)Q=Q.reduce((X,Y)=>{return $(J,Y,X)},J.defaultValue)}else if(Q===void 0)Q=[]}else if(z<this.args.length){if(Q=this.args[z],J.parseArg)Q=$(J,Q,J.defaultValue)}q[z]=Q}),this.processedArgs=q}_chainOrCall($,q){if($?.then&&typeof $.then==="function")return $.then(()=>q());return q()}_chainOrCallHooks($,q){let J=$,z=[];if(this._getCommandAndAncestors().reverse().filter((Q)=>Q._lifeCycleHooks[q]!==void 0).forEach((Q)=>{Q._lifeCycleHooks[q].forEach((X)=>{z.push({hookedCommand:Q,callback:X})})}),q==="postAction")z.reverse();return z.forEach((Q)=>{J=this._chainOrCall(J,()=>{return Q.callback(Q.hookedCommand,this)})}),J}_chainOrCallSubCommandHook($,q,J){let z=$;if(this._lifeCycleHooks[J]!==void 0)this._lifeCycleHooks[J].forEach((Q)=>{z=this._chainOrCall(z,()=>{return Q(this,q)})});return z}_parseCommand($,q){let J=this.parseOptions(q);if(this._parseOptionsEnv(),this._parseOptionsImplied(),$=$.concat(J.operands),q=J.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(J.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let z=()=>{if(J.unknown.length>0)this.unknownOption(J.unknown[0])},Q=`command:${this.name()}`;if(this._actionHandler){z(),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))z(),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 z(),this._processArguments()}else if(this.commands.length)z(),this.help({error:!0});else z(),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((J)=>{let z=J.attributeName();if(this.getOptionValue(z)===void 0)return!1;return this.getOptionValueSource(z)!=="default"});$.filter((J)=>J.conflictsWith.length>0).forEach((J)=>{let z=$.find((Q)=>J.conflictsWith.includes(Q.attributeName()));if(z)this._conflictingOption(J,z)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(($)=>{$._checkForConflictingLocalOptions()})}parseOptions($){let q=[],J=[],z=q;function Q(R){return R.length>1&&R[0]==="-"}let X=(R)=>{if(!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(R))return!1;return!this._getCommandAndAncestors().some((H)=>H.options.map((T)=>T.short).some((T)=>/^-\d$/.test(T)))},Y=null,Z=null,_=0;while(_<$.length||Z){let R=Z??$[_++];if(Z=null,R==="--"){if(z===J)z.push(R);z.push(...$.slice(_));break}if(Y&&(!Q(R)||X(R))){this.emit(`option:${Y.name()}`,R);continue}if(Y=null,Q(R)){let H=this._findOption(R);if(H){if(H.required){let T=$[_++];if(T===void 0)this.optionMissingArgument(H);this.emit(`option:${H.name()}`,T)}else if(H.optional){let T=null;if(_<$.length&&(!Q($[_])||X($[_])))T=$[_++];this.emit(`option:${H.name()}`,T)}else this.emit(`option:${H.name()}`);Y=H.variadic?H:null;continue}}if(R.length>2&&R[0]==="-"&&R[1]!=="-"){let H=this._findOption(`-${R[1]}`);if(H){if(H.required||H.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${H.name()}`,R.slice(2));else this.emit(`option:${H.name()}`),Z=`-${R.slice(2)}`;continue}}if(/^--[^=]+=/.test(R)){let H=R.indexOf("="),T=this._findOption(R.slice(0,H));if(T&&(T.required||T.optional)){this.emit(`option:${T.name()}`,R.slice(H+1));continue}}if(z===q&&Q(R)&&!(this.commands.length===0&&X(R)))z=J;if((this._enablePositionalOptions||this._passThroughOptions)&&q.length===0&&J.length===0){if(this._findCommand(R)){q.push(R),J.push(...$.slice(_));break}else if(this._getHelpCommand()&&R===this._getHelpCommand().name()){q.push(R,...$.slice(_));break}else if(this._defaultCommandName){J.push(R,...$.slice(_));break}}if(this._passThroughOptions){z.push(R,...$.slice(_));break}z.push(R)}return{operands:q,unknown:J}}opts(){if(this._storeOptionsAsProperties){let $={},q=this.options.length;for(let J=0;J<q;J++){let z=this.options[J].attributeName();$[z]=z===this._versionOptionName?this._version:this[z]}return $}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce(($,q)=>Object.assign($,q.opts()),{})}error($,q){if(this._outputConfiguration.outputError(`${$}
|
|
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 J=q||{},z=J.exitCode||1,Q=J.code||"commander.error";this._exit(z,Q,$)}_parseOptionsEnv(){this.options.forEach(($)=>{if($.envVar&&$.envVar in B.env){let q=$.attributeName();if(this.getOptionValue(q)===void 0||["default","config","env"].includes(this.getOptionValueSource(q)))if($.required||$.optional)this.emit(`optionEnv:${$.name()}`,B.env[$.envVar]);else this.emit(`optionEnv:${$.name()}`)}})}_parseOptionsImplied(){let $=new
|
|
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 J=this.parent?._findCommand($);if(J){let z=[J.name()].concat(J.aliases()).join("|");throw new Error(`cannot add alias '${$}' to command '${this.name()}' as already have command '${z}'`)}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((J)=>{return
|
|
24
|
+
`),this.outputHelp({error:!0});let J=q||{},z=J.exitCode||1,Q=J.code||"commander.error";this._exit(z,Q,$)}_parseOptionsEnv(){this.options.forEach(($)=>{if($.envVar&&$.envVar in B.env){let q=$.attributeName();if(this.getOptionValue(q)===void 0||["default","config","env"].includes(this.getOptionValueSource(q)))if($.required||$.optional)this.emit(`optionEnv:${$.name()}`,B.env[$.envVar]);else this.emit(`optionEnv:${$.name()}`)}})}_parseOptionsImplied(){let $=new s1(this.options),q=(J)=>{return this.getOptionValue(J)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(J))};this.options.filter((J)=>J.implied!==void 0&&q(J.attributeName())&&$.valueFromOption(this.getOptionValue(J.attributeName()),J)).forEach((J)=>{Object.keys(J.implied).filter((z)=>!q(z)).forEach((z)=>{this.setOptionValueWithSource(z,J.implied[z],"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 J=(X)=>{let Y=X.attributeName(),Z=this.getOptionValue(Y),_=this.options.find((H)=>H.negate&&Y===H.attributeName()),R=this.options.find((H)=>!H.negate&&Y===H.attributeName());if(_&&(_.presetArg===void 0&&Z===!1||_.presetArg!==void 0&&Z===_.presetArg))return _;return R||X},z=(X)=>{let Y=J(X),Z=Y.attributeName();if(this.getOptionValueSource(Z)==="env")return`environment variable '${Y.envVar}'`;return`option '${Y.flags}'`},Q=`error: ${z($)} cannot be used with ${z(q)}`;this.error(Q,{code:"commander.conflictingOption"})}unknownOption($){if(this._allowUnknownOption)return;let q="";if($.startsWith("--")&&this._showSuggestionAfterError){let z=[],Q=this;do{let X=Q.createHelp().visibleOptions(Q).filter((Y)=>Y.long).map((Y)=>Y.long);z=z.concat(X),Q=Q.parent}while(Q&&!Q._enablePositionalOptions);q=r($,z)}let J=`error: unknown option '${$}'${q}`;this.error(J,{code:"commander.unknownOption"})}_excessArguments($){if(this._allowExcessArguments)return;let q=this.registeredArguments.length,J=q===1?"":"s",Q=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${q} argument${J} but got ${$.length}.`;this.error(Q,{code:"commander.excessArguments"})}unknownCommand(){let $=this.args[0],q="";if(this._showSuggestionAfterError){let z=[];this.createHelp().visibleCommands(this).forEach((Q)=>{if(z.push(Q.name()),Q.alias())z.push(Q.alias())}),q=r($,z)}let J=`error: unknown command '${$}'${q}`;this.error(J,{code:"commander.unknownCommand"})}version($,q,J){if($===void 0)return this._version;this._version=$,q=q||"-V, --version",J=J||"output the version number";let z=this.createOption(q,J);return this._versionOptionName=z.attributeName(),this._registerOption(z),this.on("option:"+z.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 J=this.parent?._findCommand($);if(J){let z=[J.name()].concat(J.aliases()).join("|");throw new Error(`cannot add alias '${$}' to command '${this.name()}' as already have command '${z}'`)}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((J)=>{return m1(J)});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=M.basename($,M.extname($)),this}executableDir($){if($===void 0)return this._executableDir;return this._executableDir=$,this}helpInformation($){let q=this.createHelp(),J=this._getOutputContext($);q.prepareContext({error:J.error,helpWidth:J.helpWidth,outputHasColors:J.hasColors});let z=q.formatHelp(this,q);if(J.hasColors)return z;return this._outputConfiguration.stripColor(z)}_getOutputContext($){$=$||{};let q=!!$.error,J,z,Q;if(q)J=(Y)=>this._outputConfiguration.writeErr(Y),z=this._outputConfiguration.getErrHasColors(),Q=this._outputConfiguration.getErrHelpWidth();else J=(Y)=>this._outputConfiguration.writeOut(Y),z=this._outputConfiguration.getOutHasColors(),Q=this._outputConfiguration.getOutHelpWidth();return{error:q,write:(Y)=>{if(!z)Y=this._outputConfiguration.stripColor(Y);return J(Y)},hasColors:z,helpWidth:Q}}outputHelp($){let q;if(typeof $==="function")q=$,$=void 0;let J=this._getOutputContext($),z={error:J.error,write:J.write,command:this};this._getCommandAndAncestors().reverse().forEach((X)=>X.emit("beforeAllHelp",z)),this.emit("beforeHelp",z);let Q=this.helpInformation({error:J.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(J.write(Q),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",z),this._getCommandAndAncestors().forEach((X)=>X.emit("afterAllHelp",z))}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(B.exitCode??0);if(q===0&&$&&typeof $!=="function"&&$.error)q=1;this._exit(q,"commander.help","(outputHelp)")}addHelpText($,q){let J=["beforeAll","before","after","afterAll"];if(!J.includes($))throw new Error(`Unexpected value for position to addHelpText.
|
|
26
26
|
Expecting one of '${J.join("', '")}'`);let z=`${$}Help`;return this.on(z,(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((z)=>q.is(z)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function
|
|
28
|
-
`);for(let Q of z){let X=Q.match(/^\s*(\d+)\s+(.+)$/);if(X){let
|
|
29
|
-
`)[0]||"";J.push({name:
|
|
30
|
-
`).filter((
|
|
31
|
-
\uD83D\uDCCA Contributors for ${X.path}:`),console.log("─".repeat(60)),X.contributors.length===0)console.log(" No contributors found");else for(let
|
|
27
|
+
`)}),this}_outputHelpIfRequested($){let q=this._getHelpOption();if(q&&$.find((z)=>q.is(z)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function o($){return $.map((q)=>{if(!q.startsWith("--inspect"))return q;let J,z="127.0.0.1",Q="9229",X;if((X=q.match(/^(--inspect(-brk)?)$/))!==null)J=X[1];else if((X=q.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(J=X[1],/^\d+$/.test(X[3]))Q=X[3];else z=X[3];else if((X=q.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)J=X[1],z=X[3],Q=X[4];if(J&&Q!=="0")return`${J}=${z}:${parseInt(Q)+1}`;return q})}function x(){if(B.env.NO_COLOR||B.env.FORCE_COLOR==="0"||B.env.FORCE_COLOR==="false")return!1;if(B.env.FORCE_COLOR||B.env.CLICOLOR_FORCE!==void 0)return!0;return}i1.Command=b;i1.useColor=x});var z1=U((o1)=>{var{Argument:$1}=y(),{Command:C}=e(),{CommanderError:a1,InvalidArgumentError:q1}=E(),{Help:r1}=A(),{Option:J1}=P();o1.program=new C;o1.createCommand=($)=>new C($);o1.createOption=($,q)=>new J1($,q);o1.createArgument=($,q)=>new $1($,q);o1.Command=C;o1.Option=J1;o1.Argument=$1;o1.Help=r1;o1.CommanderError=a1;o1.InvalidArgumentError=q1;o1.InvalidOptionArgumentError=q1});var Q1=K1(z1(),1),{program:C2,createCommand:f2,createArgument:v2,createOption:h2,CommanderError:u2,InvalidArgumentError:g2,InvalidOptionArgumentError:l2,Command:X1,Argument:c2,Option:m2,Help:d2}=Q1.default;import{join as V2}from"node:path";import{existsSync as Y1}from"node:fs";import{readFile as _2}from"node:fs/promises";import{dirname as Z1,join as R1,resolve as f}from"node:path";var T2=".gstatxrc.json";function v($){let J=$.replace(/\.git$/,"").split(/[/:]/);return J[J.length-1]||"repository"}function B2($){let q=f($),J=20,z=0;while(z<J){let Q=R1(q,T2);if(Y1(Q))return Q;let X=Z1(q);if(X===q)break;q=X,z++}return null}async function V($,q=process.cwd()){try{let J;if($){let Y=f($);if(!Y1(Y))return console.error(`Error: Config file not found: ${Y}`),null;J=Y}else if(J=B2(q),!J)return null;let z=await _2(J,"utf-8"),Q=JSON.parse(z),X=Z1(J);if(Q.repositories)Q.repositories=Q.repositories.map((Y)=>{if(!Y.path&&Y.url){let Z=v(Y.url);return{...Y,path:R1(X,Z),name:Y.name||Z}}if(Y.path)return{...Y,path:f(X,Y.path)};return Y});return{config:Q,configDir:X}}catch(J){if($)console.error(`Error: Failed to load config file: ${J}`);return null}}import{exec as G2,execSync as L2}from"node:child_process";import{access as M2}from"node:fs/promises";import{join as U2}from"node:path";import{promisify as S2}from"node:util";var H1=S2(G2);async function W($){try{return await M2(U2($,".git")),!0}catch{return!1}}async function h($){try{let{stdout:q}=await H1("git shortlog -sn --all",{cwd:$}),J=[],z=q.trim().split(`
|
|
28
|
+
`);for(let Q of z){let X=Q.match(/^\s*(\d+)\s+(.+)$/);if(X){let Y=parseInt(X[1]||"0",10),Z=X[2]||"",{stdout:_}=await H1(`git log --format='%aE' --author="${Z.replace(/"/g,"\\\"")}" -1`,{cwd:$}),R=_.trim().split(`
|
|
29
|
+
`)[0]||"";J.push({name:Z,email:R,commits:Y})}}return J.sort((Q,X)=>X.commits-Q.commits)}catch(q){throw new Error(`Failed to get contributors from ${$}: ${q}`)}}function u($,q,J){let z='git log --format="%H|%an|%ae|%ad|%s" --date=iso-strict --numstat';if(q)z+=` --since="${q}"`;if(J)z+=` --until="${J}"`;let Q=L2(z,{encoding:"utf-8",cwd:$,maxBuffer:10485760}),X=[],Y=Q.split(`
|
|
30
|
+
`).filter((G)=>G.trim()),Z=null,_=0,R=0,H=0,T=[];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:_,insertions:R,deletions:H,files:T});let[L,S,K,j,...G1]=G.split("|");if(L&&S&&K&&j)Z={hash:L.trim(),author:S.trim(),email:K.trim(),date:j.trim(),message:G1.join("|").trim()},_=0,R=0,H=0,T=[]}else{let L=G.trim().split(/\s+/);if(L.length>=2&&L[0]&&L[1]){let S=parseInt(L[0],10)||0,K=parseInt(L[1],10)||0,j=L.slice(2).join(" ");if(j&&!Number.isNaN(S)&&!Number.isNaN(K))_++,R+=S,H+=K,T.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:_,insertions:R,deletions:H,files:T});return X}import{exec as K2}from"node:child_process";import{existsSync as _1}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(_1($.path)&&await W($.path))return $.path;if(_1($.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),J=$.path.split("/").pop()||"repository";try{await W2(q,{recursive:!0})}catch(z){}return await E2(`git clone "${$.url}" "${$.path}"`),console.log(`✓ Successfully cloned ${$.name||J}`),$.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(),J=v($.url);return{...$,path:V2(q,J),name:$.name||J}}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 J=await g(q);if(J)$.push(J);else $.push(q.path)}this.config.repositories=this.config.repositories.map((q,J)=>({...q,path:$[J]||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 J=[];for(let z of q){if(!await W(z))throw new Error(`${z} is not a git repository`);try{let X=await h(z);J.push({path:z,contributors:X})}catch(X){throw new Error(`Failed to get contributors from ${z}: ${X}`)}}return J}async getHistory($,q,J){await this.initialize();let z=this.getRepoPaths($);if(z.length===0)throw new Error("No repository paths specified");let Q=[];for(let X of z){if(!await W(X))throw new Error(`${X} is not a git repository`);try{let Z=u(X,q,J);Q.push({path:X,commits:Z})}catch(Z){throw new Error(`Failed to get commit history from ${X}: ${Z}`)}}return Q}}async function T1($,q=!0,J){let z=new D({configPath:J});try{let Q=await z.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 B1($,q={},J){let z=new D({configPath:J});try{let Q=await z.getHistory($,q.since,q.until),X={generatedAt:new Date().toISOString(),period:{since:q.since,until:q.until},repositories:Q.map((Z)=>{let _=new Set(Z.commits.flatMap((T)=>T.files.map((G)=>G.path))).size,R=Z.commits.reduce((T,G)=>T+G.insertions,0),H=Z.commits.reduce((T,G)=>T+G.deletions,0);return{path:Z.path,commits:Z.commits,summary:{totalCommits:Z.commits.length,totalFilesChanged:_,totalInsertions:R,totalDeletions:H}}})},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
32
|
\uD83D\uDCCA Summary:`);for(let _ of X.repositories)console.log(`
|
|
33
|
-
Repository: ${_.path}`),console.log(` Commits: ${_.summary.totalCommits}`),console.log(` Files Changed: ${_.summary.totalFilesChanged}`),console.log(` Lines Added: ${_.summary.totalInsertions.toLocaleString()}`),console.log(` Lines Removed: ${_.summary.totalDeletions.toLocaleString()}`)}else console.log(
|
|
33
|
+
Repository: ${_.path}`),console.log(` Commits: ${_.summary.totalCommits}`),console.log(` Files Changed: ${_.summary.totalFilesChanged}`),console.log(` Lines Added: ${_.summary.totalInsertions.toLocaleString()}`),console.log(` Lines Removed: ${_.summary.totalDeletions.toLocaleString()}`)}else console.log(Y)}catch(Q){throw console.error("Error generating history report:",Q),Q}}var N=new X1;N.name("gstatx").description("A CLI tool to export statistics from git repositories").version("0.1.1").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,J)=>{let z=J.parent?.opts().config,X=(await V(z))?.config.contributors?.["no-commits"]??!1,Y=!(q.noCommits||X),Z=$.length===0?void 0:$;await T1(Z,Y,z)}).addHelpText("after",`
|
|
34
34
|
Examples:
|
|
35
35
|
gstatx contributors ./my-repo
|
|
36
36
|
gstatx contributors ./repo1 ./repo2
|
|
37
|
-
gstatx contributors --no-commits ./my-repo`);
|
|
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,J)=>{let z=J.parent?.opts().config,Q={since:q.since,until:q.until,out:q.out},X=$.length===0?void 0:$;await B1(X,Q,z)}).addHelpText("after",`
|
|
38
38
|
Examples:
|
|
39
39
|
gstatx hist ./my-repo
|
|
40
40
|
gstatx hist --since "1 month ago" ./my-repo
|
|
41
41
|
gstatx hist --since "2024-01-01" --until "2024-12-31" ./my-repo
|
|
42
|
-
gstatx hist --since "1 month ago" --out report.json ./my-repo`);
|
|
42
|
+
gstatx hist --since "1 month ago" --out report.json ./my-repo`);N.addHelpText("after",`
|
|
43
43
|
Configuration:
|
|
44
44
|
You can create a .gstatxrc.json file to set default options
|
|
45
45
|
and repository paths. CLI arguments override config values.
|
|
46
46
|
Set 'cloneIfNotExists: true' to automatically clone repositories
|
|
47
47
|
that don't exist locally (requires 'url' in repository config).
|
|
48
|
-
`);
|
|
48
|
+
`);N.parse();
|
package/dist/lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync as
|
|
2
|
-
`);for(let
|
|
3
|
-
`)[0]||"";
|
|
4
|
-
`).filter((
|
|
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};
|
package/dist/utils/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export interface RepositoryConfig {
|
|
2
|
-
path
|
|
2
|
+
path?: string;
|
|
3
3
|
name?: string;
|
|
4
4
|
url?: string;
|
|
5
5
|
}
|
|
@@ -11,6 +11,14 @@ export interface GstatxConfig {
|
|
|
11
11
|
repositories?: RepositoryConfig[];
|
|
12
12
|
cloneIfNotExists?: boolean;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Extract repository name from a Git URL
|
|
16
|
+
* Examples:
|
|
17
|
+
* - git@git.4d-ps.com:4d/web-studio/qodly-workspace.git -> qodly-workspace
|
|
18
|
+
* - https://github.com/user/repo.git -> repo
|
|
19
|
+
* - git@github.com:user/repo.git -> repo
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractRepoNameFromUrl(url: string): string;
|
|
14
22
|
export interface LoadedConfig {
|
|
15
23
|
config: GstatxConfig;
|
|
16
24
|
configDir: string;
|