ts-repo-utils 5.3.0 → 6.0.1

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.
Files changed (40) hide show
  1. package/README.md +176 -0
  2. package/dist/cmd/assert-repo-is-clean.d.mts +3 -0
  3. package/dist/cmd/assert-repo-is-clean.d.mts.map +1 -0
  4. package/dist/cmd/assert-repo-is-clean.mjs +32 -0
  5. package/dist/cmd/assert-repo-is-clean.mjs.map +1 -0
  6. package/dist/cmd/check-should-run-type-checks.d.mts +3 -0
  7. package/dist/cmd/check-should-run-type-checks.d.mts.map +1 -0
  8. package/dist/cmd/check-should-run-type-checks.mjs +42 -0
  9. package/dist/cmd/check-should-run-type-checks.mjs.map +1 -0
  10. package/dist/cmd/format-diff-from.d.mts +3 -0
  11. package/dist/cmd/format-diff-from.d.mts.map +1 -0
  12. package/dist/cmd/format-diff-from.mjs +45 -0
  13. package/dist/cmd/format-diff-from.mjs.map +1 -0
  14. package/dist/cmd/format-untracked.d.mts +3 -0
  15. package/dist/cmd/format-untracked.d.mts.map +1 -0
  16. package/dist/cmd/format-untracked.mjs +34 -0
  17. package/dist/cmd/format-untracked.mjs.map +1 -0
  18. package/dist/cmd/gen-index-ts.d.mts +3 -0
  19. package/dist/cmd/gen-index-ts.d.mts.map +1 -0
  20. package/dist/cmd/gen-index-ts.mjs +119 -0
  21. package/dist/cmd/gen-index-ts.mjs.map +1 -0
  22. package/dist/functions/format.mjs +1 -1
  23. package/dist/functions/gen-index.d.mts +5 -11
  24. package/dist/functions/gen-index.d.mts.map +1 -1
  25. package/dist/functions/gen-index.mjs +21 -15
  26. package/dist/functions/gen-index.mjs.map +1 -1
  27. package/dist/functions/should-run.d.mts +53 -13
  28. package/dist/functions/should-run.d.mts.map +1 -1
  29. package/dist/functions/should-run.mjs +82 -23
  30. package/dist/functions/should-run.mjs.map +1 -1
  31. package/dist/index.d.mts.map +1 -1
  32. package/package.json +23 -12
  33. package/src/cmd/assert-repo-is-clean.mts +28 -0
  34. package/src/cmd/check-should-run-type-checks.mts +43 -0
  35. package/src/cmd/format-diff-from.mts +49 -0
  36. package/src/cmd/format-untracked.mts +31 -0
  37. package/src/cmd/gen-index-ts.mts +147 -0
  38. package/src/functions/gen-index.mts +36 -30
  39. package/src/functions/should-run.mts +92 -27
  40. package/src/index.mts +0 -2
package/README.md CHANGED
@@ -15,6 +15,182 @@ A comprehensive toolkit for managing TypeScript projects with strict ESM support
15
15
  npm install ts-repo-utils
16
16
  ```
17
17
 
18
+ ## CLI Commands
19
+
20
+ `ts-repo-utils` provides several CLI commands that can be used directly or through npm scripts.
21
+
22
+ ### `gen-index-ts`
23
+
24
+ Generates index.ts files recursively in target directories with automatic barrel exports.
25
+
26
+ ```bash
27
+ # Basic usage with required options
28
+ npm exec -- gen-index-ts ./src --target-ext .mts --index-ext .mts --export-ext .mjs
29
+
30
+ # With formatting command
31
+ npm exec -- gen-index-ts ./src --target-ext .mts --index-ext .mts --export-ext .mjs --fmt 'npm run fmt'
32
+
33
+ # Multiple target extensions
34
+ npm exec -- gen-index-ts ./src --target-ext .mts --target-ext .tsx --index-ext .mts --export-ext .mjs
35
+
36
+ # With exclude patterns
37
+ npm exec -- gen-index-ts ./src --target-ext .ts --index-ext .ts --export-ext .js --exclude '*.test.ts' --exclude '*.spec.ts'
38
+
39
+ # Example in npm scripts
40
+ "gi": "gen-index-ts ./src --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --fmt 'npm run fmt'"
41
+ ```
42
+
43
+ **Options:**
44
+
45
+ - `<target-directory>` - Directory where the index file will be generated (comma-separated list can be used)
46
+ - `--target-ext` - File extensions to include in the index file (required, can be specified multiple times)
47
+ - `--index-ext` - Extension of the index file to be generated (required)
48
+ - `--export-ext` - Extension of the export statements in the index file (required, or 'none')
49
+ - `--exclude` - Glob patterns of files to exclude (optional, can be specified multiple times)
50
+ - `--fmt` - Command to format after generating the index file (optional)
51
+ - `--silent` - Suppress output messages (optional)
52
+
53
+ ### `assert-repo-is-clean`
54
+
55
+ Checks if repository is clean and exits with code 1 if it has uncommitted changes.
56
+
57
+ ```bash
58
+ # Basic usage
59
+ npm exec -- assert-repo-is-clean
60
+
61
+ # Silent mode
62
+ npm exec -- assert-repo-is-clean --silent
63
+ ```
64
+
65
+ ```yaml
66
+ # Example in GitHub Actions
67
+ - name: Check if there is no file diff
68
+ run: npm exec -- assert-repo-is-clean
69
+ ```
70
+
71
+ **Options:**
72
+
73
+ - `--silent` - Suppress output messages (optional)
74
+
75
+ ### `format-untracked`
76
+
77
+ Formats only untracked/modified files using Prettier.
78
+
79
+ ```bash
80
+ # Basic usage
81
+ npm exec -- format-untracked
82
+
83
+ # Silent mode
84
+ npm exec -- format-untracked --silent
85
+ ```
86
+
87
+ **Options:**
88
+
89
+ - `--silent` - Suppress output messages (optional)
90
+
91
+ ### `format-diff-from`
92
+
93
+ Formats only files that differ from the specified base branch or commit.
94
+
95
+ ```bash
96
+ # Format files different from main branch
97
+ npm exec -- format-diff-from main
98
+
99
+ # Format files different from origin/main
100
+ npm exec -- format-diff-from origin/main
101
+
102
+ # Exclude untracked files
103
+ npm exec -- format-diff-from main --exclude-untracked
104
+
105
+ # Silent mode
106
+ npm exec -- format-diff-from main --silent
107
+
108
+ # Example in npm scripts
109
+ "fmt": "format-diff-from origin/main"
110
+ ```
111
+
112
+ **Options:**
113
+
114
+ - `<base>` - Base branch name or commit hash to compare against (required)
115
+ - `--include-untracked` - Include untracked files in addition to diff files (default: true)
116
+ - `--exclude-untracked` - Exclude untracked files, only format diff files (optional)
117
+ - `--silent` - Suppress output messages (optional)
118
+
119
+ ### `check-should-run-type-checks`
120
+
121
+ Checks if TypeScript type checks should run based on the diff from a base branch. Optimizes CI/CD pipelines by skipping type checks when only non-TypeScript files are changed.
122
+
123
+ ```bash
124
+ # Basic usage (compares against origin/main)
125
+ npm exec -- check-should-run-type-checks
126
+
127
+ # Custom base branch
128
+ npm exec -- check-should-run-type-checks --base-branch origin/develop
129
+
130
+ # Custom ignore patterns
131
+ npm exec -- check-should-run-type-checks \
132
+ --paths-ignore '.github/' \
133
+ --paths-ignore 'docs/' \
134
+ --paths-ignore '**.md' \
135
+ --paths-ignore '**.yml'
136
+ ```
137
+
138
+ ```yaml
139
+ # Example in GitHub Actions
140
+ - name: Check if type checks should run
141
+ id: check_diff
142
+ run: npm exec -- check-should-run-type-checks
143
+
144
+ - name: Run type checks
145
+ if: steps.check_diff.outputs.should_run == 'true'
146
+ run: npm run type-check
147
+ ```
148
+
149
+ **Options:**
150
+
151
+ - `--paths-ignore` - Patterns to ignore when checking if type checks should run (optional, can be specified multiple times)
152
+ - Supports exact file matches: `.cspell.json`
153
+ - Directory prefixes: `docs/` (matches any file in docs directory)
154
+ - File extensions: `**.md` (matches any markdown file)
155
+ - Default: `['LICENSE', '.editorconfig', '.gitignore', '.cspell.json', '.markdownlint-cli2.mjs', '.npmignore', '.prettierignore', '.prettierrc', 'docs/', '**.md', '**.txt']`
156
+ - `--base-branch` - Base branch to compare against for determining changed files (default: `origin/main`)
157
+
158
+ **GitHub Actions Integration:**
159
+
160
+ When running in GitHub Actions, the command sets the `GITHUB_OUTPUT` environment variable with `should_run=true` or `should_run=false`, which can be used in subsequent steps.
161
+
162
+ ### Usage in npm scripts
163
+
164
+ The CLI commands are commonly used in npm scripts for automation:
165
+
166
+ ```json
167
+ {
168
+ "scripts": {
169
+ "fmt": "format-diff-from origin/main",
170
+ "gi": "gen-index-ts ./src --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --fmt 'npm run fmt'",
171
+ "check:clean": "assert-repo-is-clean"
172
+ }
173
+ }
174
+ ```
175
+
176
+ ### Usage in CI/CD
177
+
178
+ These commands are particularly useful in CI/CD pipelines:
179
+
180
+ ```yaml
181
+ # GitHub Actions example
182
+ - name: Format check
183
+ run: |
184
+ npm run fmt
185
+ npm exec -- assert-repo-is-clean
186
+
187
+ # Check for uncommitted changes after build
188
+ - name: Build
189
+ run: npm run build
190
+ - name: Check if there is no file diff
191
+ run: npm exec -- assert-repo-is-clean
192
+ ```
193
+
18
194
  ## API Reference
19
195
 
20
196
  ### Path and File System Utilities
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ export {};
3
+ //# sourceMappingURL=assert-repo-is-clean.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-repo-is-clean.d.mts","sourceRoot":"","sources":["../../src/cmd/assert-repo-is-clean.mts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ import 'child_process';
3
+ import * as cmd from 'cmd-ts';
4
+ import 'micromatch';
5
+ import 'node:child_process';
6
+ import 'prettier';
7
+ import 'ts-data-forge';
8
+ import { assertRepoIsClean } from '../functions/assert-repo-is-clean.mjs';
9
+ import '../node-global.mjs';
10
+
11
+ const cmdDef = cmd.command({
12
+ name: 'assert-repo-is-clean-cli',
13
+ version: '6.0.1',
14
+ args: {
15
+ silent: cmd.flag({
16
+ long: 'silent',
17
+ type: cmd.optional(cmd.boolean),
18
+ description: 'If true, suppresses output messages (default: false)',
19
+ }),
20
+ },
21
+ handler: (args) => {
22
+ main(args).catch((error) => {
23
+ console.error('An error occurred:', error);
24
+ process.exit(1);
25
+ });
26
+ },
27
+ });
28
+ const main = async (args) => {
29
+ await assertRepoIsClean({ silent: args.silent });
30
+ };
31
+ await cmd.run(cmdDef, process.argv.slice(2));
32
+ //# sourceMappingURL=assert-repo-is-clean.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-repo-is-clean.mjs","sources":["../../src/cmd/assert-repo-is-clean.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;AAKA,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;AACzB,IAAA,IAAI,EAAE,0BAA0B;AAChC,IAAA,OAAO,EAAE,OAAO;AAChB,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC;AACf,YAAA,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;AAC/B,YAAA,WAAW,EAAE,sDAAsD;SACpE,CAAC;AACH,KAAA;AACD,IAAA,OAAO,EAAE,CAAC,IAAI,KAAI;QAChB,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,KAAI;AACzB,YAAA,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC;AAC1C,YAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB,QAAA,CAAC,CAAC;IACJ,CAAC;AACF,CAAA,CAAC;AAEF,MAAM,IAAI,GAAG,OAAO,IAAoC,KAAmB;IACzE,MAAM,iBAAiB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AAClD,CAAC;AAED,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ export {};
3
+ //# sourceMappingURL=check-should-run-type-checks.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-should-run-type-checks.d.mts","sourceRoot":"","sources":["../../src/cmd/check-should-run-type-checks.mts"],"names":[],"mappings":""}
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ import 'child_process';
3
+ import * as cmd from 'cmd-ts';
4
+ import 'micromatch';
5
+ import 'node:child_process';
6
+ import 'prettier';
7
+ import 'ts-data-forge';
8
+ import { checkShouldRunTypeChecks } from '../functions/should-run.mjs';
9
+ import '../node-global.mjs';
10
+
11
+ const cmdDef = cmd.command({
12
+ name: 'check-should-run-type-checks-cli',
13
+ version: '6.0.1',
14
+ args: {
15
+ pathsIgnore: cmd.multioption({
16
+ long: 'paths-ignore',
17
+ type: cmd.optional(cmd.array(cmd.string)),
18
+ description:
19
+ 'Patterns to ignore when checking if type checks should run. Supports exact file matches, directory prefixes (ending with "/"), and file extensions (starting with "**.")',
20
+ }),
21
+ baseBranch: cmd.option({
22
+ long: 'base-branch',
23
+ type: cmd.optional(cmd.string),
24
+ description:
25
+ 'Base branch to compare against for determining changed files. Defaults to "origin/main"',
26
+ }),
27
+ },
28
+ handler: (args) => {
29
+ main(args).catch((error) => {
30
+ console.error('An error occurred:', error);
31
+ process.exit(1);
32
+ });
33
+ },
34
+ });
35
+ const main = async (args) => {
36
+ await checkShouldRunTypeChecks({
37
+ pathsIgnore: args.pathsIgnore,
38
+ baseBranch: args.baseBranch,
39
+ });
40
+ };
41
+ await cmd.run(cmdDef, process.argv.slice(2));
42
+ //# sourceMappingURL=check-should-run-type-checks.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-should-run-type-checks.mjs","sources":["../../src/cmd/check-should-run-type-checks.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;AAKA,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;AACzB,IAAA,IAAI,EAAE,kCAAkC;AACxC,IAAA,OAAO,EAAE,OAAO;AAChB,IAAA,IAAI,EAAE;AACJ,QAAA,WAAW,EAAE,GAAG,CAAC,WAAW,CAAC;AAC3B,YAAA,IAAI,EAAE,cAAc;AACpB,YAAA,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACzC,YAAA,WAAW,EACT,0KAA0K;SAC7K,CAAC;AACF,QAAA,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC;AACrB,YAAA,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;AAC9B,YAAA,WAAW,EACT,yFAAyF;SAC5F,CAAC;AACH,KAAA;AACD,IAAA,OAAO,EAAE,CAAC,IAAI,KAAI;QAChB,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,KAAI;AACzB,YAAA,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC;AAC1C,YAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB,QAAA,CAAC,CAAC;IACJ,CAAC;AACF,CAAA,CAAC;AAEF,MAAM,IAAI,GAAG,OACX,IAGE,KACe;AACjB,IAAA,MAAM,wBAAwB,CAAC;QAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;AAC5B,KAAA,CAAC;AACJ,CAAC;AAED,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ export {};
3
+ //# sourceMappingURL=format-diff-from.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-diff-from.d.mts","sourceRoot":"","sources":["../../src/cmd/format-diff-from.mts"],"names":[],"mappings":""}
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ import 'child_process';
3
+ import * as cmd from 'cmd-ts';
4
+ import 'micromatch';
5
+ import 'node:child_process';
6
+ import 'ts-data-forge';
7
+ import { formatDiffFrom } from '../functions/format.mjs';
8
+ import '../node-global.mjs';
9
+
10
+ const cmdDef = cmd.command({
11
+ name: 'format-diff-from-cli',
12
+ version: '6.0.1',
13
+ args: {
14
+ base: cmd.positional({
15
+ type: cmd.string,
16
+ displayName: 'base',
17
+ description: 'Base branch name or commit hash to compare against',
18
+ }),
19
+ includeUntracked: cmd.flag({
20
+ long: 'include-untracked',
21
+ type: cmd.optional(cmd.boolean),
22
+ description:
23
+ 'Include untracked files in addition to diff files (default: true)',
24
+ }),
25
+ silent: cmd.flag({
26
+ long: 'silent',
27
+ type: cmd.optional(cmd.boolean),
28
+ description: 'If true, suppresses output messages (default: false)',
29
+ }),
30
+ },
31
+ handler: (args) => {
32
+ main(args).catch((error) => {
33
+ console.error('An error occurred:', error);
34
+ process.exit(1);
35
+ });
36
+ },
37
+ });
38
+ const main = async (args) => {
39
+ const result = await formatDiffFrom(args.base, args);
40
+ if (result === 'err') {
41
+ process.exit(1);
42
+ }
43
+ };
44
+ await cmd.run(cmdDef, process.argv.slice(2));
45
+ //# sourceMappingURL=format-diff-from.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-diff-from.mjs","sources":["../../src/cmd/format-diff-from.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAKA,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;AACzB,IAAA,IAAI,EAAE,sBAAsB;AAC5B,IAAA,OAAO,EAAE,OAAO;AAChB,IAAA,IAAI,EAAE;AACJ,QAAA,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC;YACnB,IAAI,EAAE,GAAG,CAAC,MAAM;AAChB,YAAA,WAAW,EAAE,MAAM;AACnB,YAAA,WAAW,EAAE,oDAAoD;SAClE,CAAC;AACF,QAAA,gBAAgB,EAAE,GAAG,CAAC,IAAI,CAAC;AACzB,YAAA,IAAI,EAAE,mBAAmB;YACzB,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;AAC/B,YAAA,WAAW,EACT,mEAAmE;SACtE,CAAC;AACF,QAAA,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC;AACf,YAAA,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;AAC/B,YAAA,WAAW,EAAE,sDAAsD;SACpE,CAAC;AACH,KAAA;AACD,IAAA,OAAO,EAAE,CAAC,IAAI,KAAI;QAChB,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,KAAI;AACzB,YAAA,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC;AAC1C,YAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB,QAAA,CAAC,CAAC;IACJ,CAAC;AACF,CAAA,CAAC;AAEF,MAAM,IAAI,GAAG,OACX,IAIE,KACe;IACjB,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC;AAEpD,IAAA,IAAI,MAAM,KAAK,KAAK,EAAE;AACpB,QAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACjB;AACF,CAAC;AAED,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ export {};
3
+ //# sourceMappingURL=format-untracked.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-untracked.d.mts","sourceRoot":"","sources":["../../src/cmd/format-untracked.mts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ import 'child_process';
3
+ import * as cmd from 'cmd-ts';
4
+ import 'micromatch';
5
+ import 'node:child_process';
6
+ import 'ts-data-forge';
7
+ import { formatUntracked } from '../functions/format.mjs';
8
+ import '../node-global.mjs';
9
+
10
+ const cmdDef = cmd.command({
11
+ name: 'format-untracked-cli',
12
+ version: '6.0.1',
13
+ args: {
14
+ silent: cmd.flag({
15
+ long: 'silent',
16
+ type: cmd.optional(cmd.boolean),
17
+ description: 'If true, suppresses output messages (default: false)',
18
+ }),
19
+ },
20
+ handler: (args) => {
21
+ main(args).catch((error) => {
22
+ console.error('An error occurred:', error);
23
+ process.exit(1);
24
+ });
25
+ },
26
+ });
27
+ const main = async (args) => {
28
+ const result = await formatUntracked({ silent: args.silent });
29
+ if (result === 'err') {
30
+ process.exit(1);
31
+ }
32
+ };
33
+ await cmd.run(cmdDef, process.argv.slice(2));
34
+ //# sourceMappingURL=format-untracked.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-untracked.mjs","sources":["../../src/cmd/format-untracked.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAKA,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;AACzB,IAAA,IAAI,EAAE,sBAAsB;AAC5B,IAAA,OAAO,EAAE,OAAO;AAChB,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC;AACf,YAAA,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;AAC/B,YAAA,WAAW,EAAE,sDAAsD;SACpE,CAAC;AACH,KAAA;AACD,IAAA,OAAO,EAAE,CAAC,IAAI,KAAI;QAChB,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,KAAI;AACzB,YAAA,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC;AAC1C,YAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB,QAAA,CAAC,CAAC;IACJ,CAAC;AACF,CAAA,CAAC;AAEF,MAAM,IAAI,GAAG,OAAO,IAAoC,KAAmB;AACzE,IAAA,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AAC7D,IAAA,IAAI,MAAM,KAAK,KAAK,EAAE;AACpB,QAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACjB;AACF,CAAC;AAED,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ export {};
3
+ //# sourceMappingURL=gen-index-ts.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gen-index-ts.d.mts","sourceRoot":"","sources":["../../src/cmd/gen-index-ts.mts"],"names":[],"mappings":""}
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ import 'child_process';
3
+ import * as cmd from 'cmd-ts';
4
+ import 'node:child_process';
5
+ import 'prettier';
6
+ import 'ts-data-forge';
7
+ import { genIndex } from '../functions/gen-index.mjs';
8
+ import '../node-global.mjs';
9
+
10
+ const extensionType = cmd.extendType(cmd.string, {
11
+ from: (s) => {
12
+ if (!s.startsWith('.')) {
13
+ throw new Error(`ext should start with '.'`);
14
+ }
15
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
16
+ return Promise.resolve(s);
17
+ },
18
+ });
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ const nonEmptyArray = (t, commandName) =>
21
+ cmd.extendType(cmd.array(t), {
22
+ from: (arr) => {
23
+ if (arr.length === 0) {
24
+ throw new Error(
25
+ `No value provided for --${commandName}. At least one value is required.`,
26
+ );
27
+ }
28
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
29
+ return Promise.resolve(arr);
30
+ },
31
+ });
32
+ const cmdDef = cmd.command({
33
+ name: 'gen-index-ts-cli',
34
+ version: '6.0.1',
35
+ args: {
36
+ // required args
37
+ targetDirectory: cmd.positional({
38
+ type: cmd.string,
39
+ displayName: 'target-directory',
40
+ description:
41
+ 'Directory where the index file will be generated (Comma-separated list can be used)',
42
+ }),
43
+ targetExtensions: cmd.multioption({
44
+ long: 'target-ext',
45
+ type: nonEmptyArray(extensionType, 'target-ext'),
46
+ description: 'File extensions to include in the index file',
47
+ }),
48
+ indexFileExtension: cmd.option({
49
+ long: 'index-ext',
50
+ type: extensionType,
51
+ description: 'Extension of the index file to be generated',
52
+ }),
53
+ exportStatementExtension: cmd.option({
54
+ long: 'export-ext',
55
+ type: cmd.union([
56
+ extensionType,
57
+ cmd.extendType(cmd.string, {
58
+ from: (s) => {
59
+ if (s !== 'none') {
60
+ throw new Error(
61
+ `export-ext should be 'none' or a valid extension`,
62
+ );
63
+ }
64
+ return Promise.resolve('none');
65
+ },
66
+ }),
67
+ ]),
68
+ description: 'Extension of the export statements in the index file',
69
+ }),
70
+ // optional args
71
+ exclude: cmd.multioption({
72
+ long: 'exclude',
73
+ type: cmd.optional(cmd.array(cmd.string)),
74
+ description:
75
+ 'Glob patterns of files to exclude from the index file (e.g., "*.d.mts", "*.test.mts")',
76
+ }),
77
+ formatCommand: cmd.option({
78
+ long: 'fmt',
79
+ type: cmd.optional(cmd.string),
80
+ description:
81
+ 'Command to format after generating the index file (e.g., "npm run fmt")',
82
+ }),
83
+ silent: cmd.flag({
84
+ long: 'silent',
85
+ type: cmd.optional(cmd.boolean),
86
+ description: 'If true, suppresses output messages (default: false)',
87
+ }),
88
+ },
89
+ handler: (args) => {
90
+ console.log(args);
91
+ main(args).catch((error) => {
92
+ console.error('An error occurred:', error);
93
+ process.exit(1);
94
+ });
95
+ },
96
+ });
97
+ const main = async ({
98
+ targetDirectory,
99
+ targetExtensions,
100
+ exportStatementExtension,
101
+ indexFileExtension,
102
+ exclude,
103
+ formatCommand,
104
+ silent,
105
+ }) => {
106
+ await genIndex({
107
+ targetDirectory: targetDirectory.includes(',')
108
+ ? targetDirectory.split(',').map((dir) => dir.trim())
109
+ : targetDirectory,
110
+ exportStatementExtension,
111
+ targetExtensions,
112
+ exclude,
113
+ indexFileExtension,
114
+ formatCommand,
115
+ silent,
116
+ });
117
+ };
118
+ await cmd.run(cmdDef, process.argv.slice(2));
119
+ //# sourceMappingURL=gen-index-ts.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gen-index-ts.mjs","sources":["../../src/cmd/gen-index-ts.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAWA,MAAM,aAAa,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE;AAC/C,IAAA,IAAI,EAAE,CAAC,CAAC,KAAI;QACV,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAA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CAAC,oBAAoB,EAAE,KAAK,CAAC;AAC1C,YAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB,QAAA,CAAC,CAAC;KACH;AACF,CAAA,CAAC;AAEF,MAAM,IAAI,GAAG,OAAO,EAClB,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,MAAM,GASN,KAAmB;AACnB,IAAA,MAAM,QAAQ,CAAC;AACb,QAAA,eAAe,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG;AAC3C,cAAE,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,EAAE;AACpD,cAAE,eAAe;QACnB,wBAAwB;QACxB,gBAAgB;QAChB,OAAO;QACP,kBAAkB;QAClB,aAAa;QACb,MAAM;AACP,KAAA,CAAC;AACJ,CAAC;AAED,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import * as prettier from 'prettier';
2
2
  import { Result, Arr } from 'ts-data-forge';
3
3
  import '../node-global.mjs';
4
- import { getUntrackedFiles, getDiffFrom } from './diff.mjs';
4
+ import { getDiffFrom, getUntrackedFiles } from './diff.mjs';
5
5
 
6
6
  /**
7
7
  * Format a list of files using Prettier
@@ -5,26 +5,20 @@ export type GenIndexConfig = DeepReadonly<{
5
5
  targetDirectory: string | readonly string[];
6
6
  /**
7
7
  * Glob patterns of files or predicate function to exclude from exports
8
- * (default: excludes `'**\/*.{test,spec}.?(c|m)[jt]s?(x)'`)
8
+ * (default: excludes `'**\/*.{test,spec}.?(c|m)[jt]s?(x)'` and
9
+ * `'**\/*.d.?(c|m)ts'`)
9
10
  */
10
11
  exclude?: readonly string[] | ((args: Readonly<{
11
12
  absolutePath: string;
12
13
  relativePath: string;
13
14
  fileName: string;
14
15
  }>) => boolean);
15
- /**
16
- * Glob patterns of files or predicate function to exclude from exports
17
- * (default: excludes `'**\/*.{test,spec}.?(c|m)[jt]s?(x)'`)
18
- *
19
- * @deprecated Use `exclude` instead.
20
- */
21
- excludePatterns?: readonly string[];
22
16
  /** File extensions of source files to export (default: ['.ts', '.tsx']) */
23
- sourceExtensions?: readonly `.${string}`[];
17
+ targetExtensions?: readonly `.${string}`[];
24
18
  /** File extension of index files to generate (default: '.ts') */
25
- indexExtension?: `.${string}`;
19
+ indexFileExtension?: `.${string}`;
26
20
  /** File extension to use in export statements (default: '.js') */
27
- exportExtension?: `.${string}` | 'none';
21
+ exportStatementExtension?: `.${string}` | 'none';
28
22
  /** Command to run for formatting generated files (optional) */
29
23
  formatCommand?: string;
30
24
  /** Whether to suppress output during execution (default: false) */
@@ -1 +1 @@
1
- {"version":3,"file":"gen-index.d.mts","sourceRoot":"","sources":["../../src/functions/gen-index.mts"],"names":[],"mappings":"AAEA,OAAO,oBAAoB,CAAC;AAG5B,+CAA+C;AAC/C,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC;IACxC,kFAAkF;IAClF,eAAe,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IAE5C;;;OAGG;IACH,OAAO,CAAC,EACJ,SAAS,MAAM,EAAE,GACjB,CAAC,CACC,IAAI,EAAE,QAAQ,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC,KACC,OAAO,CAAC,CAAC;IAElB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAEpC,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,SAAS,IAAI,MAAM,EAAE,EAAE,CAAC;IAE3C,iEAAiE;IACjE,cAAc,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;IAE9B,kEAAkE;IAClE,eAAe,CAAC,EAAE,IAAI,MAAM,EA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