ts-repo-utils 5.3.0 → 6.0.0
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 +133 -0
- package/dist/cmd/assert-repo-is-clean.d.mts +3 -0
- package/dist/cmd/assert-repo-is-clean.d.mts.map +1 -0
- package/dist/cmd/assert-repo-is-clean.mjs +32 -0
- package/dist/cmd/assert-repo-is-clean.mjs.map +1 -0
- package/dist/cmd/check-should-run-type-checks.d.mts +3 -0
- package/dist/cmd/check-should-run-type-checks.d.mts.map +1 -0
- package/dist/cmd/check-should-run-type-checks.mjs +40 -0
- package/dist/cmd/check-should-run-type-checks.mjs.map +1 -0
- package/dist/cmd/format-diff-from.d.mts +3 -0
- package/dist/cmd/format-diff-from.d.mts.map +1 -0
- package/dist/cmd/format-diff-from.mjs +44 -0
- package/dist/cmd/format-diff-from.mjs.map +1 -0
- package/dist/cmd/format-untracked.d.mts +3 -0
- package/dist/cmd/format-untracked.d.mts.map +1 -0
- package/dist/cmd/format-untracked.mjs +34 -0
- package/dist/cmd/format-untracked.mjs.map +1 -0
- package/dist/cmd/gen-index-ts.d.mts +3 -0
- package/dist/cmd/gen-index-ts.d.mts.map +1 -0
- package/dist/cmd/gen-index-ts.mjs +103 -0
- package/dist/cmd/gen-index-ts.mjs.map +1 -0
- package/dist/functions/format.mjs +1 -1
- package/dist/functions/gen-index.d.mts +5 -11
- package/dist/functions/gen-index.d.mts.map +1 -1
- package/dist/functions/gen-index.mjs +21 -15
- package/dist/functions/gen-index.mjs.map +1 -1
- package/dist/functions/should-run.d.mts +53 -13
- package/dist/functions/should-run.d.mts.map +1 -1
- package/dist/functions/should-run.mjs +82 -23
- package/dist/functions/should-run.mjs.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/package.json +16 -5
- package/src/cmd/assert-repo-is-clean.mts +28 -0
- package/src/cmd/check-should-run-type-checks.mts +43 -0
- package/src/cmd/format-diff-from.mts +49 -0
- package/src/cmd/format-untracked.mts +31 -0
- package/src/cmd/gen-index-ts.mts +147 -0
- package/src/functions/gen-index.mts +36 -30
- package/src/functions/should-run.mts +92 -27
- package/src/index.mts +0 -2
package/README.md
CHANGED
|
@@ -15,6 +15,139 @@ 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
|
+
npx gen-index-ts ./src --target-ext .mts --index-ext .mts --export-ext .mjs
|
|
29
|
+
|
|
30
|
+
# With formatting command
|
|
31
|
+
npx gen-index-ts ./src --target-ext .mts --index-ext .mts --export-ext .mjs --fmt 'npm run fmt'
|
|
32
|
+
|
|
33
|
+
# Multiple target extensions
|
|
34
|
+
npx gen-index-ts ./src --target-ext .mts --target-ext .tsx --index-ext .mts --export-ext .mjs
|
|
35
|
+
|
|
36
|
+
# With exclude patterns
|
|
37
|
+
npx 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/functions --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
|
+
npx assert-repo-is-clean
|
|
60
|
+
|
|
61
|
+
# Silent mode
|
|
62
|
+
npx 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: npx tsx ./src/cmd/assert-repo-is-clean.mts
|
|
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
|
+
npx format-untracked
|
|
82
|
+
|
|
83
|
+
# Silent mode
|
|
84
|
+
npx 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
|
+
npx format-diff-from main
|
|
98
|
+
|
|
99
|
+
# Format files different from origin/main
|
|
100
|
+
npx format-diff-from origin/main
|
|
101
|
+
|
|
102
|
+
# Exclude untracked files
|
|
103
|
+
npx format-diff-from main --exclude-untracked
|
|
104
|
+
|
|
105
|
+
# Silent mode
|
|
106
|
+
npx 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
|
+
### Usage in npm scripts
|
|
120
|
+
|
|
121
|
+
The CLI commands are commonly used in npm scripts for automation:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"scripts": {
|
|
126
|
+
"fmt": "format-diff-from origin/main",
|
|
127
|
+
"gi": "gen-index-ts ./src/functions --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --fmt 'npm run fmt'",
|
|
128
|
+
"check:clean": "assert-repo-is-clean"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Usage in CI/CD
|
|
134
|
+
|
|
135
|
+
These commands are particularly useful in CI/CD pipelines:
|
|
136
|
+
|
|
137
|
+
```yaml
|
|
138
|
+
# GitHub Actions example
|
|
139
|
+
- name: Format check
|
|
140
|
+
run: |
|
|
141
|
+
npm run fmt
|
|
142
|
+
npx assert-repo-is-clean
|
|
143
|
+
|
|
144
|
+
# Check for uncommitted changes after build
|
|
145
|
+
- name: Build
|
|
146
|
+
run: npm run build
|
|
147
|
+
- name: Check if there is no file diff
|
|
148
|
+
run: npx tsx ./src/cmd/assert-repo-is-clean.mts
|
|
149
|
+
```
|
|
150
|
+
|
|
18
151
|
## API Reference
|
|
19
152
|
|
|
20
153
|
### Path and File System Utilities
|
|
@@ -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 * as cmd from 'cmd-ts';
|
|
3
|
+
import 'ts-data-forge';
|
|
4
|
+
import '../node-global.mjs';
|
|
5
|
+
import { assertRepoIsClean } from '../functions/assert-repo-is-clean.mjs';
|
|
6
|
+
import 'node:child_process';
|
|
7
|
+
import 'prettier';
|
|
8
|
+
import 'micromatch';
|
|
9
|
+
import 'child_process';
|
|
10
|
+
|
|
11
|
+
const cmdDef = cmd.command({
|
|
12
|
+
name: 'assert-repo-is-clean-cli',
|
|
13
|
+
version: '6.0.0',
|
|
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 @@
|
|
|
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,40 @@
|
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
import * as cmd from 'cmd-ts';
|
|
3
|
+
import 'ts-data-forge';
|
|
4
|
+
import '../node-global.mjs';
|
|
5
|
+
import 'node:child_process';
|
|
6
|
+
import 'prettier';
|
|
7
|
+
import 'micromatch';
|
|
8
|
+
import { checkShouldRunTypeChecks } from '../functions/should-run.mjs';
|
|
9
|
+
import 'child_process';
|
|
10
|
+
|
|
11
|
+
const cmdDef = cmd.command({
|
|
12
|
+
name: 'check-should-run-type-checks-cli',
|
|
13
|
+
version: '6.0.0',
|
|
14
|
+
args: {
|
|
15
|
+
pathsIgnore: cmd.multioption({
|
|
16
|
+
long: 'paths-ignore',
|
|
17
|
+
type: cmd.optional(cmd.array(cmd.string)),
|
|
18
|
+
description: 'Patterns to ignore when checking if type checks should run. Supports exact file matches, directory prefixes (ending with "/"), and file extensions (starting with "**.")',
|
|
19
|
+
}),
|
|
20
|
+
baseBranch: cmd.option({
|
|
21
|
+
long: 'base-branch',
|
|
22
|
+
type: cmd.optional(cmd.string),
|
|
23
|
+
description: 'Base branch to compare against for determining changed files. Defaults to "origin/main"',
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
handler: (args) => {
|
|
27
|
+
main(args).catch((error) => {
|
|
28
|
+
console.error('An error occurred:', error);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
const main = async (args) => {
|
|
34
|
+
await checkShouldRunTypeChecks({
|
|
35
|
+
pathsIgnore: args.pathsIgnore,
|
|
36
|
+
baseBranch: args.baseBranch,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
await cmd.run(cmdDef, process.argv.slice(2));
|
|
40
|
+
//# 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 @@
|
|
|
1
|
+
{"version":3,"file":"format-diff-from.d.mts","sourceRoot":"","sources":["../../src/cmd/format-diff-from.mts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
import * as cmd from 'cmd-ts';
|
|
3
|
+
import 'ts-data-forge';
|
|
4
|
+
import '../node-global.mjs';
|
|
5
|
+
import 'node:child_process';
|
|
6
|
+
import { formatDiffFrom } from '../functions/format.mjs';
|
|
7
|
+
import 'micromatch';
|
|
8
|
+
import 'child_process';
|
|
9
|
+
|
|
10
|
+
const cmdDef = cmd.command({
|
|
11
|
+
name: 'format-diff-from-cli',
|
|
12
|
+
version: '6.0.0',
|
|
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: 'Include untracked files in addition to diff files (default: true)',
|
|
23
|
+
}),
|
|
24
|
+
silent: cmd.flag({
|
|
25
|
+
long: 'silent',
|
|
26
|
+
type: cmd.optional(cmd.boolean),
|
|
27
|
+
description: 'If true, suppresses output messages (default: false)',
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
handler: (args) => {
|
|
31
|
+
main(args).catch((error) => {
|
|
32
|
+
console.error('An error occurred:', error);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const main = async (args) => {
|
|
38
|
+
const result = await formatDiffFrom(args.base, args);
|
|
39
|
+
if (result === 'err') {
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
await cmd.run(cmdDef, process.argv.slice(2));
|
|
44
|
+
//# 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 @@
|
|
|
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 * as cmd from 'cmd-ts';
|
|
3
|
+
import 'ts-data-forge';
|
|
4
|
+
import '../node-global.mjs';
|
|
5
|
+
import 'node:child_process';
|
|
6
|
+
import { formatUntracked } from '../functions/format.mjs';
|
|
7
|
+
import 'micromatch';
|
|
8
|
+
import 'child_process';
|
|
9
|
+
|
|
10
|
+
const cmdDef = cmd.command({
|
|
11
|
+
name: 'format-untracked-cli',
|
|
12
|
+
version: '6.0.0',
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"gen-index-ts.d.mts","sourceRoot":"","sources":["../../src/cmd/gen-index-ts.mts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
import * as cmd from 'cmd-ts';
|
|
3
|
+
import 'ts-data-forge';
|
|
4
|
+
import '../node-global.mjs';
|
|
5
|
+
import 'node:child_process';
|
|
6
|
+
import 'prettier';
|
|
7
|
+
import { genIndex } from '../functions/gen-index.mjs';
|
|
8
|
+
import 'child_process';
|
|
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) => cmd.extendType(cmd.array(t), {
|
|
21
|
+
from: (arr) => {
|
|
22
|
+
if (arr.length === 0) {
|
|
23
|
+
throw new Error(`No value provided for --${commandName}. At least one value is required.`);
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
26
|
+
return Promise.resolve(arr);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const cmdDef = cmd.command({
|
|
30
|
+
name: 'gen-index-ts-cli',
|
|
31
|
+
version: '6.0.0',
|
|
32
|
+
args: {
|
|
33
|
+
// required args
|
|
34
|
+
targetDirectory: cmd.positional({
|
|
35
|
+
type: cmd.string,
|
|
36
|
+
displayName: 'target-directory',
|
|
37
|
+
description: 'Directory where the index file will be generated (Comma-separated list can be used)',
|
|
38
|
+
}),
|
|
39
|
+
targetExtensions: cmd.multioption({
|
|
40
|
+
long: 'target-ext',
|
|
41
|
+
type: nonEmptyArray(extensionType, 'target-ext'),
|
|
42
|
+
description: 'File extensions to include in the index file',
|
|
43
|
+
}),
|
|
44
|
+
indexFileExtension: cmd.option({
|
|
45
|
+
long: 'index-ext',
|
|
46
|
+
type: extensionType,
|
|
47
|
+
description: 'Extension of the index file to be generated',
|
|
48
|
+
}),
|
|
49
|
+
exportStatementExtension: cmd.option({
|
|
50
|
+
long: 'export-ext',
|
|
51
|
+
type: cmd.union([
|
|
52
|
+
extensionType,
|
|
53
|
+
cmd.extendType(cmd.string, {
|
|
54
|
+
from: (s) => {
|
|
55
|
+
if (s !== 'none') {
|
|
56
|
+
throw new Error(`export-ext should be 'none' or a valid extension`);
|
|
57
|
+
}
|
|
58
|
+
return Promise.resolve('none');
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
]),
|
|
62
|
+
description: 'Extension of the export statements in the index file',
|
|
63
|
+
}),
|
|
64
|
+
// optional args
|
|
65
|
+
exclude: cmd.multioption({
|
|
66
|
+
long: 'exclude',
|
|
67
|
+
type: cmd.optional(cmd.array(cmd.string)),
|
|
68
|
+
description: 'Glob patterns of files to exclude from the index file (e.g., "*.d.mts", "*.test.mts")',
|
|
69
|
+
}),
|
|
70
|
+
formatCommand: cmd.option({
|
|
71
|
+
long: 'fmt',
|
|
72
|
+
type: cmd.optional(cmd.string),
|
|
73
|
+
description: 'Command to format after generating the index file (e.g., "npm run fmt")',
|
|
74
|
+
}),
|
|
75
|
+
silent: cmd.flag({
|
|
76
|
+
long: 'silent',
|
|
77
|
+
type: cmd.optional(cmd.boolean),
|
|
78
|
+
description: 'If true, suppresses output messages (default: false)',
|
|
79
|
+
}),
|
|
80
|
+
},
|
|
81
|
+
handler: (args) => {
|
|
82
|
+
console.log(args);
|
|
83
|
+
main(args).catch((error) => {
|
|
84
|
+
console.error('An error occurred:', error);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
const main = async ({ targetDirectory, targetExtensions, exportStatementExtension, indexFileExtension, exclude, formatCommand, silent, }) => {
|
|
90
|
+
await genIndex({
|
|
91
|
+
targetDirectory: targetDirectory.includes(',')
|
|
92
|
+
? targetDirectory.split(',').map((dir) => dir.trim())
|
|
93
|
+
: targetDirectory,
|
|
94
|
+
exportStatementExtension,
|
|
95
|
+
targetExtensions,
|
|
96
|
+
exclude,
|
|
97
|
+
indexFileExtension,
|
|
98
|
+
formatCommand,
|
|
99
|
+
silent,
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
await cmd.run(cmdDef, process.argv.slice(2));
|
|
103
|
+
//# 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,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zB,YAAA,OAAO,CAAC,KAAK,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 {
|
|
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
|
-
|
|
17
|
+
targetExtensions?: readonly `.${string}`[];
|
|
24
18
|
/** File extension of index files to generate (default: '.ts') */
|
|
25
|
-
|
|
19
|
+
indexFileExtension?: `.${string}`;
|
|
26
20
|
/** File extension to use in export statements (default: '.js') */
|
|
27
|
-
|
|
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
|
|
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;;;;OAIG;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,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,SAAS,IAAI,MAAM,EAAE,EAAE,CAAC;IAE3C,iEAAiE;IACjE,kBAAkB,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;IAElC,kEAAkE;IAClE,wBAAwB,CAAC,EAAE,IAAI,MAAM,EAAE,GAAG,MAAM,CAAC;IAEjD,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,mEAAmE;IACnE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC,CAAC;AA4BH;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAU,QAAQ,cAAc,KAAG,OAAO,CAAC,IAAI,CA8CnE,CAAC"}
|
|
@@ -3,6 +3,13 @@ import { Result, ISet, pipe, Arr, isString } from 'ts-data-forge';
|
|
|
3
3
|
import '../node-global.mjs';
|
|
4
4
|
import { assertPathExists } from './assert-path-exists.mjs';
|
|
5
5
|
|
|
6
|
+
const defaultConfig = {
|
|
7
|
+
exclude: ['**/*.{test,spec}.?(c|m)[jt]s?(x)', '**/*.d.?(c|m)ts'],
|
|
8
|
+
targetExtensions: ['.ts', '.tsx'],
|
|
9
|
+
indexFileExtension: '.ts',
|
|
10
|
+
exportStatementExtension: '.js', // For ESM imports, .mts resolves to .mjs
|
|
11
|
+
silent: false,
|
|
12
|
+
};
|
|
6
13
|
/**
|
|
7
14
|
* Generates index.ts files recursively in `config.targetDirectory`.
|
|
8
15
|
*
|
|
@@ -51,21 +58,20 @@ const genIndex = async (config) => {
|
|
|
51
58
|
}
|
|
52
59
|
};
|
|
53
60
|
const fillConfig = (config) => {
|
|
54
|
-
const
|
|
55
|
-
const exportExtension = config.
|
|
61
|
+
const targetExtensions = config.targetExtensions ?? defaultConfig.targetExtensions;
|
|
62
|
+
const exportExtension = config.exportStatementExtension ?? defaultConfig.exportStatementExtension;
|
|
56
63
|
return {
|
|
57
64
|
formatCommand: config.formatCommand,
|
|
58
65
|
targetDirectory: ISet.create(isString(config.targetDirectory)
|
|
59
66
|
? [config.targetDirectory]
|
|
60
67
|
: config.targetDirectory),
|
|
61
|
-
|
|
62
|
-
exclude: pipe(config.exclude ?? config.excludePatterns).map((exclude) => typeof exclude === 'function'
|
|
68
|
+
exclude: pipe(config.exclude).map((exclude) => typeof exclude === 'function'
|
|
63
69
|
? exclude
|
|
64
70
|
: pipe(ISet.create(Arr.generate(function* () {
|
|
65
71
|
if (exclude !== undefined && Array.isArray(exclude)) {
|
|
66
72
|
yield* exclude;
|
|
67
73
|
}
|
|
68
|
-
yield
|
|
74
|
+
yield* defaultConfig.exclude;
|
|
69
75
|
}))).map((set) => ({ relativePath, fileName, }) => {
|
|
70
76
|
for (const pattern of set.values()) {
|
|
71
77
|
if (micromatch.isMatch(relativePath, pattern) ||
|
|
@@ -75,10 +81,10 @@ const fillConfig = (config) => {
|
|
|
75
81
|
}
|
|
76
82
|
return false;
|
|
77
83
|
}).value).value,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
exportExtension,
|
|
81
|
-
silent: config.silent ??
|
|
84
|
+
targetExtensions: ISet.create(targetExtensions),
|
|
85
|
+
indexFileExtension: config.indexFileExtension ?? defaultConfig.indexFileExtension,
|
|
86
|
+
exportStatementExtension: exportExtension,
|
|
87
|
+
silent: config.silent ?? defaultConfig.silent,
|
|
82
88
|
};
|
|
83
89
|
};
|
|
84
90
|
/**
|
|
@@ -124,7 +130,7 @@ const generateIndexFileForDir = async (dirPath, config, baseDir) => {
|
|
|
124
130
|
}
|
|
125
131
|
}
|
|
126
132
|
const indexContent = generateIndexContent(mut_subDirectories, mut_filesToExport, config);
|
|
127
|
-
const indexPath = path.join(dirPath, `index${config.
|
|
133
|
+
const indexPath = path.join(dirPath, `index${config.indexFileExtension}`);
|
|
128
134
|
await fs.writeFile(indexPath, indexContent);
|
|
129
135
|
echo(`Generated: ${path.relative(process.cwd(), indexPath)}`);
|
|
130
136
|
}
|
|
@@ -150,7 +156,7 @@ const shouldExportFile = ({ absolutePath, filePath, config, }) => {
|
|
|
150
156
|
const fileName = path.basename(filePath);
|
|
151
157
|
const ext = path.extname(fileName);
|
|
152
158
|
// Must have the correct source extension
|
|
153
|
-
if (!config.
|
|
159
|
+
if (!config.targetExtensions.has(ext)) {
|
|
154
160
|
return false;
|
|
155
161
|
}
|
|
156
162
|
// Don't export the index file itself
|
|
@@ -178,14 +184,14 @@ const shouldExportFile = ({ absolutePath, filePath, config, }) => {
|
|
|
178
184
|
*/
|
|
179
185
|
const generateIndexContent = (subDirectories, filesToExport, config) => {
|
|
180
186
|
const exportStatements = [
|
|
181
|
-
...subDirectories.map((subDir) => config.
|
|
187
|
+
...subDirectories.map((subDir) => config.exportStatementExtension === 'none'
|
|
182
188
|
? `export * from "./${subDir}";`
|
|
183
|
-
: `export * from "./${subDir}/index${config.
|
|
189
|
+
: `export * from "./${subDir}/index${config.exportStatementExtension}";`),
|
|
184
190
|
...filesToExport.map((file) => {
|
|
185
191
|
const fileNameWithoutExt = path.basename(file, path.extname(file));
|
|
186
|
-
return config.
|
|
192
|
+
return config.exportStatementExtension === 'none'
|
|
187
193
|
? `export * from "./${fileNameWithoutExt}";`
|
|
188
|
-
: `export * from "./${fileNameWithoutExt}${config.
|
|
194
|
+
: `export * from "./${fileNameWithoutExt}${config.exportStatementExtension}";`;
|
|
189
195
|
}),
|
|
190
196
|
];
|
|
191
197
|
return exportStatements.length === 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gen-index.mjs","sources":["../../src/functions/gen-index.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"gen-index.mjs","sources":["../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