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
|
@@ -1,20 +1,60 @@
|
|
|
1
1
|
import '../node-global.mjs';
|
|
2
2
|
/**
|
|
3
|
-
* Checks if TypeScript type checks should run based on the diff from
|
|
4
|
-
*
|
|
5
|
-
* spell check config, or other non-TypeScript files that don't affect type
|
|
6
|
-
* checking.
|
|
3
|
+
* Checks if TypeScript type checks should run based on the diff from a base
|
|
4
|
+
* branch. Skips type checks if all changed files match the ignored patterns.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
6
|
+
* This function is typically used in CI/CD pipelines to determine whether
|
|
7
|
+
* expensive type checking operations should be performed. If all changed files
|
|
8
|
+
* are documentation, configuration, or other non-TypeScript files, type checks
|
|
9
|
+
* can be safely skipped to improve build performance.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Use default settings (compare against origin/main, ignore docs/md/txt files)
|
|
14
|
+
* await checkShouldRunTypeChecks();
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* // Custom ignore patterns
|
|
17
|
+
* await checkShouldRunTypeChecks({
|
|
18
|
+
* pathsIgnore: ['.eslintrc.json', 'docs/', '**.md', 'scripts/'],
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Custom base branch
|
|
22
|
+
* await checkShouldRunTypeChecks({
|
|
23
|
+
* baseBranch: 'origin/develop',
|
|
24
|
+
* });
|
|
25
|
+
* ```;
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* GitHub Actions usage
|
|
29
|
+
* ```yaml
|
|
30
|
+
* - name: Check if type checks should run
|
|
31
|
+
* id: check_diff
|
|
32
|
+
* run: npx check-should-run-type-checks
|
|
33
|
+
*
|
|
34
|
+
* - name: Run type checks
|
|
35
|
+
* if: steps.check_diff.outputs.should_run == 'true'
|
|
36
|
+
* run: npm run type-check
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @param options - Configuration options
|
|
40
|
+
* @param options.pathsIgnore - Array of patterns to ignore when determining if
|
|
41
|
+
* type checks should run. Supports three pattern types:
|
|
42
|
+
*
|
|
43
|
+
* - **Exact file matches**: e.g., `.cspell.json` matches only that file
|
|
44
|
+
* - **Directory prefixes**: e.g., `docs/` matches any file in docs directory
|
|
45
|
+
* - **File extensions**: e.g., `**.md` matches any markdown file Defaults to:
|
|
46
|
+
* `['LICENSE', '.editorconfig', '.gitignore', '.cspell.json',
|
|
47
|
+
* '.markdownlint-cli2.mjs', '.npmignore', '.prettierignore',
|
|
48
|
+
* '.prettierrc', 'docs/', '**.md', '**.txt']`
|
|
49
|
+
*
|
|
50
|
+
* @param options.baseBranch - Base branch to compare against for determining
|
|
51
|
+
* changed files. Defaults to `'origin/main'`
|
|
52
|
+
* @returns A promise that resolves when the check is complete. The function
|
|
53
|
+
* will set the GITHUB_OUTPUT environment variable with `should_run=true` or
|
|
54
|
+
* `should_run=false` if running in GitHub Actions environment.
|
|
18
55
|
*/
|
|
19
|
-
export declare const checkShouldRunTypeChecks: (
|
|
56
|
+
export declare const checkShouldRunTypeChecks: (options?: Readonly<{
|
|
57
|
+
pathsIgnore?: readonly string[];
|
|
58
|
+
baseBranch?: string;
|
|
59
|
+
}>) => Promise<void>;
|
|
20
60
|
//# sourceMappingURL=should-run.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"should-run.d.mts","sourceRoot":"","sources":["../../src/functions/should-run.mts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,CAAC;AAG5B
|
|
1
|
+
{"version":3,"file":"should-run.d.mts","sourceRoot":"","sources":["../../src/functions/should-run.mts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,eAAO,MAAM,wBAAwB,GACnC,UAAU,QAAQ,CAAC;IACjB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC,KACD,OAAO,CAAC,IAAI,CAmDd,CAAC"}
|
|
@@ -1,39 +1,98 @@
|
|
|
1
|
-
import { Result
|
|
1
|
+
import { Result } from 'ts-data-forge';
|
|
2
2
|
import '../node-global.mjs';
|
|
3
3
|
import { getDiffFrom } from './diff.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Checks if TypeScript type checks should run based on the diff from
|
|
7
|
-
*
|
|
8
|
-
* spell check config, or other non-TypeScript files that don't affect type
|
|
9
|
-
* checking.
|
|
6
|
+
* Checks if TypeScript type checks should run based on the diff from a base
|
|
7
|
+
* branch. Skips type checks if all changed files match the ignored patterns.
|
|
10
8
|
*
|
|
11
|
-
*
|
|
9
|
+
* This function is typically used in CI/CD pipelines to determine whether
|
|
10
|
+
* expensive type checking operations should be performed. If all changed files
|
|
11
|
+
* are documentation, configuration, or other non-TypeScript files, type checks
|
|
12
|
+
* can be safely skipped to improve build performance.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Use default settings (compare against origin/main, ignore docs/md/txt files)
|
|
17
|
+
* await checkShouldRunTypeChecks();
|
|
17
18
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* // Custom ignore patterns
|
|
20
|
+
* await checkShouldRunTypeChecks({
|
|
21
|
+
* pathsIgnore: ['.eslintrc.json', 'docs/', '**.md', 'scripts/'],
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Custom base branch
|
|
25
|
+
* await checkShouldRunTypeChecks({
|
|
26
|
+
* baseBranch: 'origin/develop',
|
|
27
|
+
* });
|
|
28
|
+
* ```;
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* GitHub Actions usage
|
|
32
|
+
* ```yaml
|
|
33
|
+
* - name: Check if type checks should run
|
|
34
|
+
* id: check_diff
|
|
35
|
+
* run: npx check-should-run-type-checks
|
|
36
|
+
*
|
|
37
|
+
* - name: Run type checks
|
|
38
|
+
* if: steps.check_diff.outputs.should_run == 'true'
|
|
39
|
+
* run: npm run type-check
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param options - Configuration options
|
|
43
|
+
* @param options.pathsIgnore - Array of patterns to ignore when determining if
|
|
44
|
+
* type checks should run. Supports three pattern types:
|
|
45
|
+
*
|
|
46
|
+
* - **Exact file matches**: e.g., `.cspell.json` matches only that file
|
|
47
|
+
* - **Directory prefixes**: e.g., `docs/` matches any file in docs directory
|
|
48
|
+
* - **File extensions**: e.g., `**.md` matches any markdown file Defaults to:
|
|
49
|
+
* `['LICENSE', '.editorconfig', '.gitignore', '.cspell.json',
|
|
50
|
+
* '.markdownlint-cli2.mjs', '.npmignore', '.prettierignore',
|
|
51
|
+
* '.prettierrc', 'docs/', '**.md', '**.txt']`
|
|
52
|
+
*
|
|
53
|
+
* @param options.baseBranch - Base branch to compare against for determining
|
|
54
|
+
* changed files. Defaults to `'origin/main'`
|
|
55
|
+
* @returns A promise that resolves when the check is complete. The function
|
|
56
|
+
* will set the GITHUB_OUTPUT environment variable with `should_run=true` or
|
|
57
|
+
* `should_run=false` if running in GitHub Actions environment.
|
|
21
58
|
*/
|
|
22
|
-
const checkShouldRunTypeChecks = async () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
59
|
+
const checkShouldRunTypeChecks = async (options) => {
|
|
60
|
+
const pathsIgnore = options?.pathsIgnore ?? [
|
|
61
|
+
'LICENSE',
|
|
62
|
+
'.editorconfig',
|
|
63
|
+
'.gitignore',
|
|
64
|
+
'.cspell.json',
|
|
65
|
+
'.markdownlint-cli2.mjs',
|
|
66
|
+
'.npmignore',
|
|
67
|
+
'.prettierignore',
|
|
68
|
+
'.prettierrc',
|
|
69
|
+
'docs/',
|
|
70
|
+
'**.md',
|
|
71
|
+
'**.txt',
|
|
72
|
+
];
|
|
73
|
+
const baseBranch = options?.baseBranch ?? 'origin/main';
|
|
28
74
|
const GITHUB_OUTPUT = process.env['GITHUB_OUTPUT'];
|
|
29
|
-
const files = await getDiffFrom(
|
|
75
|
+
const files = await getDiffFrom(baseBranch);
|
|
30
76
|
if (Result.isErr(files)) {
|
|
31
77
|
console.error('Error getting diff:', files.value);
|
|
32
78
|
process.exit(1);
|
|
33
79
|
}
|
|
34
|
-
const shouldRunTsChecks = !files.value.every((file) =>
|
|
35
|
-
file
|
|
36
|
-
|
|
80
|
+
const shouldRunTsChecks = !files.value.every((file) => pathsIgnore.some((pattern) => {
|
|
81
|
+
// Exact file match
|
|
82
|
+
if (pattern === file) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
// Directory prefix match (pattern ends with '/')
|
|
86
|
+
if (pattern.endsWith('/') && file.startsWith(pattern)) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
// File extension pattern match (pattern starts with '**.')
|
|
90
|
+
if (pattern.startsWith('**.')) {
|
|
91
|
+
const extension = pattern.slice(2); // Remove '**'
|
|
92
|
+
return path.basename(file).endsWith(extension);
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}));
|
|
37
96
|
if (GITHUB_OUTPUT !== undefined) {
|
|
38
97
|
await fs.appendFile(GITHUB_OUTPUT, `should_run=${shouldRunTsChecks}\n`);
|
|
39
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"should-run.mjs","sources":["../../src/functions/should-run.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA
|
|
1
|
+
{"version":3,"file":"should-run.mjs","sources":["../../src/functions/should-run.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDG;MACU,wBAAwB,GAAG,OACtC,OAGE,KACe;AACjB,IAAA,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI;QAC1C,SAAS;QACT,eAAe;QACf,YAAY;QACZ,cAAc;QACd,wBAAwB;QACxB,YAAY;QACZ,iBAAiB;QACjB,aAAa;QACb,OAAO;QACP,OAAO;QACP,QAAQ;KACT;AAED,IAAA,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,aAAa;IAEvD,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;AAElD,IAAA,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,UAAU,CAAC;AAE3C,IAAA,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,KAAK,CAAC;AACjD,QAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACjB;IAEA,MAAM,iBAAiB,GAAY,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,KACzD,WAAW,CAAC,IAAI,CAAC,CAAC,OAAO,KAAI;;AAE3B,QAAA,IAAI,OAAO,KAAK,IAAI,EAAE;AACpB,YAAA,OAAO,IAAI;QACb;;AAGA,QAAA,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;AACrD,YAAA,OAAO,IAAI;QACb;;AAGA,QAAA,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC7B,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACnC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;QAChD;AAEA,QAAA,OAAO,KAAK;IACd,CAAC,CAAC,CACH;AAED,IAAA,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,MAAM,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,CAAA,WAAA,EAAc,iBAAiB,CAAA,EAAA,CAAI,CAAC;IACzE;AACF;;;;"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-repo-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript"
|
|
@@ -23,6 +23,13 @@
|
|
|
23
23
|
},
|
|
24
24
|
"module": "./dist/index.mjs",
|
|
25
25
|
"types": "./dist/type.d.mts",
|
|
26
|
+
"bin": {
|
|
27
|
+
"assert-repo-is-clean": "./src/cmd/assert-repo-is-clean.mts",
|
|
28
|
+
"check-should-run-type-checks": "./src/cmd/check-should-run-type-checks.mts",
|
|
29
|
+
"format-diff-from": "./src/cmd/format-diff-from.mts",
|
|
30
|
+
"format-untracked": "./src/cmd/format-untracked.mts",
|
|
31
|
+
"gen-index-ts": "./src/cmd/gen-index-ts.mts"
|
|
32
|
+
},
|
|
26
33
|
"files": [
|
|
27
34
|
"src",
|
|
28
35
|
"dist",
|
|
@@ -35,12 +42,14 @@
|
|
|
35
42
|
"check:ext": "tsx ./scripts/cmd/check-ext.mjs",
|
|
36
43
|
"cspell": "cspell \"**\" --gitignore --gitignore-root ./ --no-progress",
|
|
37
44
|
"doc": "tsx ./scripts/cmd/gen-docs.mjs",
|
|
38
|
-
"fmt": "
|
|
45
|
+
"fmt": "npm exec -- format-diff-from origin/main",
|
|
39
46
|
"fmt:full": "prettier --write .",
|
|
40
|
-
"gi": "
|
|
47
|
+
"gi": "npm exec -- gen-index-ts ./src/functions --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --fmt 'npm run fmt'",
|
|
41
48
|
"lint": "eslint .",
|
|
42
49
|
"lint:fix": "eslint . --fix",
|
|
43
50
|
"md": "markdownlint-cli2",
|
|
51
|
+
"prepare-release": "run-s sync-cli-versions fmt build doc",
|
|
52
|
+
"sync-cli-versions": "tsx scripts/cmd/sync-cli-versions.mts",
|
|
44
53
|
"test": "npm run z:vitest -- run",
|
|
45
54
|
"test:cov": "npm run z:vitest -- run --coverage",
|
|
46
55
|
"test:cov:ui": "vite preview --outDir ./coverage",
|
|
@@ -54,10 +63,12 @@
|
|
|
54
63
|
},
|
|
55
64
|
"dependencies": {
|
|
56
65
|
"@types/micromatch": "^4.0.9",
|
|
66
|
+
"cmd-ts": "^0.13.0",
|
|
57
67
|
"fast-glob": "^3.3.3",
|
|
58
68
|
"micromatch": "^4.0.8",
|
|
59
69
|
"prettier": "^3.6.2",
|
|
60
|
-
"ts-data-forge": "^3.0.5"
|
|
70
|
+
"ts-data-forge": "^3.0.5",
|
|
71
|
+
"tsx": "^4.20.3"
|
|
61
72
|
},
|
|
62
73
|
"devDependencies": {
|
|
63
74
|
"@eslint/js": "^9.31.0",
|
|
@@ -88,6 +99,7 @@
|
|
|
88
99
|
"eslint-plugin-unicorn": "60.0.0",
|
|
89
100
|
"eslint-plugin-vitest": "0.5.4",
|
|
90
101
|
"markdownlint-cli2": "^0.18.1",
|
|
102
|
+
"npm-run-all2": "^8.0.4",
|
|
91
103
|
"prettier-plugin-jsdoc": "^1.3.3",
|
|
92
104
|
"prettier-plugin-organize-imports": "^4.2.0",
|
|
93
105
|
"prettier-plugin-packagejson": "^2.5.19",
|
|
@@ -95,7 +107,6 @@
|
|
|
95
107
|
"semantic-release": "^24.2.7",
|
|
96
108
|
"ts-type-forge": "^2.1.1",
|
|
97
109
|
"tslib": "^2.8.1",
|
|
98
|
-
"tsx": "^4.20.3",
|
|
99
110
|
"typedoc": "^0.28.7",
|
|
100
111
|
"typedoc-plugin-markdown": "^4.8.0",
|
|
101
112
|
"typescript": "^5.8.3",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
|
|
3
|
+
import * as cmd from 'cmd-ts';
|
|
4
|
+
import { assertRepoIsClean } from '../functions/index.mjs';
|
|
5
|
+
|
|
6
|
+
const cmdDef = cmd.command({
|
|
7
|
+
name: 'assert-repo-is-clean-cli',
|
|
8
|
+
version: '6.0.0',
|
|
9
|
+
args: {
|
|
10
|
+
silent: cmd.flag({
|
|
11
|
+
long: 'silent',
|
|
12
|
+
type: cmd.optional(cmd.boolean),
|
|
13
|
+
description: 'If true, suppresses output messages (default: false)',
|
|
14
|
+
}),
|
|
15
|
+
},
|
|
16
|
+
handler: (args) => {
|
|
17
|
+
main(args).catch((error) => {
|
|
18
|
+
console.error('An error occurred:', error);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const main = async (args: Readonly<{ silent?: boolean }>): Promise<void> => {
|
|
25
|
+
await assertRepoIsClean({ silent: args.silent });
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
await cmd.run(cmdDef, process.argv.slice(2));
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
|
|
3
|
+
import * as cmd from 'cmd-ts';
|
|
4
|
+
import { checkShouldRunTypeChecks } from '../functions/index.mjs';
|
|
5
|
+
|
|
6
|
+
const cmdDef = cmd.command({
|
|
7
|
+
name: 'check-should-run-type-checks-cli',
|
|
8
|
+
version: '6.0.0',
|
|
9
|
+
args: {
|
|
10
|
+
pathsIgnore: cmd.multioption({
|
|
11
|
+
long: 'paths-ignore',
|
|
12
|
+
type: cmd.optional(cmd.array(cmd.string)),
|
|
13
|
+
description:
|
|
14
|
+
'Patterns to ignore when checking if type checks should run. Supports exact file matches, directory prefixes (ending with "/"), and file extensions (starting with "**.")',
|
|
15
|
+
}),
|
|
16
|
+
baseBranch: cmd.option({
|
|
17
|
+
long: 'base-branch',
|
|
18
|
+
type: cmd.optional(cmd.string),
|
|
19
|
+
description:
|
|
20
|
+
'Base branch to compare against for determining changed files. Defaults to "origin/main"',
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
handler: (args) => {
|
|
24
|
+
main(args).catch((error) => {
|
|
25
|
+
console.error('An error occurred:', error);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const main = async (
|
|
32
|
+
args: Readonly<{
|
|
33
|
+
pathsIgnore?: readonly string[];
|
|
34
|
+
baseBranch?: string;
|
|
35
|
+
}>,
|
|
36
|
+
): Promise<void> => {
|
|
37
|
+
await checkShouldRunTypeChecks({
|
|
38
|
+
pathsIgnore: args.pathsIgnore,
|
|
39
|
+
baseBranch: args.baseBranch,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
await cmd.run(cmdDef, process.argv.slice(2));
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
|
|
3
|
+
import * as cmd from 'cmd-ts';
|
|
4
|
+
import { formatDiffFrom } from '../functions/index.mjs';
|
|
5
|
+
|
|
6
|
+
const cmdDef = cmd.command({
|
|
7
|
+
name: 'format-diff-from-cli',
|
|
8
|
+
version: '6.0.0',
|
|
9
|
+
args: {
|
|
10
|
+
base: cmd.positional({
|
|
11
|
+
type: cmd.string,
|
|
12
|
+
displayName: 'base',
|
|
13
|
+
description: 'Base branch name or commit hash to compare against',
|
|
14
|
+
}),
|
|
15
|
+
includeUntracked: cmd.flag({
|
|
16
|
+
long: 'include-untracked',
|
|
17
|
+
type: cmd.optional(cmd.boolean),
|
|
18
|
+
description:
|
|
19
|
+
'Include untracked files in addition to diff files (default: true)',
|
|
20
|
+
}),
|
|
21
|
+
silent: cmd.flag({
|
|
22
|
+
long: 'silent',
|
|
23
|
+
type: cmd.optional(cmd.boolean),
|
|
24
|
+
description: 'If true, suppresses output messages (default: false)',
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
handler: (args) => {
|
|
28
|
+
main(args).catch((error) => {
|
|
29
|
+
console.error('An error occurred:', error);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const main = async (
|
|
36
|
+
args: Readonly<{
|
|
37
|
+
base: string;
|
|
38
|
+
includeUntracked?: boolean;
|
|
39
|
+
silent?: boolean;
|
|
40
|
+
}>,
|
|
41
|
+
): Promise<void> => {
|
|
42
|
+
const result = await formatDiffFrom(args.base, args);
|
|
43
|
+
|
|
44
|
+
if (result === 'err') {
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
await cmd.run(cmdDef, process.argv.slice(2));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
|
|
3
|
+
import * as cmd from 'cmd-ts';
|
|
4
|
+
import { formatUntracked } from '../functions/index.mjs';
|
|
5
|
+
|
|
6
|
+
const cmdDef = cmd.command({
|
|
7
|
+
name: 'format-untracked-cli',
|
|
8
|
+
version: '6.0.0',
|
|
9
|
+
args: {
|
|
10
|
+
silent: cmd.flag({
|
|
11
|
+
long: 'silent',
|
|
12
|
+
type: cmd.optional(cmd.boolean),
|
|
13
|
+
description: 'If true, suppresses output messages (default: false)',
|
|
14
|
+
}),
|
|
15
|
+
},
|
|
16
|
+
handler: (args) => {
|
|
17
|
+
main(args).catch((error) => {
|
|
18
|
+
console.error('An error occurred:', error);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const main = async (args: Readonly<{ silent?: boolean }>): Promise<void> => {
|
|
25
|
+
const result = await formatUntracked({ silent: args.silent });
|
|
26
|
+
if (result === 'err') {
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
await cmd.run(cmdDef, process.argv.slice(2));
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
|
|
3
|
+
import * as cmd from 'cmd-ts';
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line import/no-internal-modules
|
|
6
|
+
import { type InputOf, type OutputOf } from 'cmd-ts/dist/esm/from.js';
|
|
7
|
+
import { expectType } from 'ts-data-forge';
|
|
8
|
+
import { genIndex } from '../functions/index.mjs';
|
|
9
|
+
|
|
10
|
+
type Ext = `.${string}`;
|
|
11
|
+
|
|
12
|
+
const extensionType = cmd.extendType(cmd.string, {
|
|
13
|
+
from: (s) => {
|
|
14
|
+
if (!s.startsWith('.')) {
|
|
15
|
+
throw new Error(`ext should start with '.'`);
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
18
|
+
return Promise.resolve(s as Ext);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
const nonEmptyArray = <T extends cmd.Type<any, any>>(
|
|
24
|
+
t: T,
|
|
25
|
+
commandName: string,
|
|
26
|
+
): cmd.Type<InputOf<T>[], NonEmptyArray<OutputOf<T>>> =>
|
|
27
|
+
cmd.extendType(cmd.array(t), {
|
|
28
|
+
from: (arr) => {
|
|
29
|
+
if (arr.length === 0) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`No value provided for --${commandName}. At least one value is required.`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
35
|
+
return Promise.resolve(arr as unknown as NonEmptyArray<OutputOf<T>>);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const cmdDef = cmd.command({
|
|
40
|
+
name: 'gen-index-ts-cli',
|
|
41
|
+
version: '6.0.0',
|
|
42
|
+
args: {
|
|
43
|
+
// required args
|
|
44
|
+
targetDirectory: cmd.positional({
|
|
45
|
+
type: cmd.string,
|
|
46
|
+
displayName: 'target-directory',
|
|
47
|
+
description:
|
|
48
|
+
'Directory where the index file will be generated (Comma-separated list can be used)',
|
|
49
|
+
}),
|
|
50
|
+
|
|
51
|
+
targetExtensions: cmd.multioption({
|
|
52
|
+
long: 'target-ext',
|
|
53
|
+
type: nonEmptyArray(extensionType, 'target-ext'),
|
|
54
|
+
description: 'File extensions to include in the index file',
|
|
55
|
+
}),
|
|
56
|
+
indexFileExtension: cmd.option({
|
|
57
|
+
long: 'index-ext',
|
|
58
|
+
type: extensionType,
|
|
59
|
+
description: 'Extension of the index file to be generated',
|
|
60
|
+
}),
|
|
61
|
+
exportStatementExtension: cmd.option({
|
|
62
|
+
long: 'export-ext',
|
|
63
|
+
type: cmd.union([
|
|
64
|
+
extensionType,
|
|
65
|
+
cmd.extendType(cmd.string, {
|
|
66
|
+
from: (s) => {
|
|
67
|
+
if (s !== 'none') {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`export-ext should be 'none' or a valid extension`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return Promise.resolve('none' as const);
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
]),
|
|
76
|
+
description: 'Extension of the export statements in the index file',
|
|
77
|
+
}),
|
|
78
|
+
|
|
79
|
+
// optional args
|
|
80
|
+
exclude: cmd.multioption({
|
|
81
|
+
long: 'exclude',
|
|
82
|
+
type: cmd.optional(cmd.array(cmd.string)),
|
|
83
|
+
description:
|
|
84
|
+
'Glob patterns of files to exclude from the index file (e.g., "*.d.mts", "*.test.mts")',
|
|
85
|
+
}),
|
|
86
|
+
formatCommand: cmd.option({
|
|
87
|
+
long: 'fmt',
|
|
88
|
+
type: cmd.optional(cmd.string),
|
|
89
|
+
description:
|
|
90
|
+
'Command to format after generating the index file (e.g., "npm run fmt")',
|
|
91
|
+
}),
|
|
92
|
+
silent: cmd.flag({
|
|
93
|
+
long: 'silent',
|
|
94
|
+
type: cmd.optional(cmd.boolean),
|
|
95
|
+
description: 'If true, suppresses output messages (default: false)',
|
|
96
|
+
}),
|
|
97
|
+
},
|
|
98
|
+
handler: (args) => {
|
|
99
|
+
console.log(args);
|
|
100
|
+
|
|
101
|
+
expectType<typeof args.targetDirectory, string>('=');
|
|
102
|
+
expectType<typeof args.targetExtensions, NonEmptyArray<Ext>>('=');
|
|
103
|
+
expectType<typeof args.exportStatementExtension, Ext | 'none'>('=');
|
|
104
|
+
expectType<typeof args.indexFileExtension, Ext>('=');
|
|
105
|
+
|
|
106
|
+
expectType<typeof args.exclude, string[] | undefined>('=');
|
|
107
|
+
expectType<typeof args.formatCommand, string | undefined>('=');
|
|
108
|
+
expectType<typeof args.silent, boolean | undefined>('=');
|
|
109
|
+
|
|
110
|
+
main(args).catch((error) => {
|
|
111
|
+
console.error('An error occurred:', error);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const main = async ({
|
|
118
|
+
targetDirectory,
|
|
119
|
+
targetExtensions,
|
|
120
|
+
exportStatementExtension,
|
|
121
|
+
indexFileExtension,
|
|
122
|
+
exclude,
|
|
123
|
+
formatCommand,
|
|
124
|
+
silent,
|
|
125
|
+
}: Readonly<{
|
|
126
|
+
targetDirectory: string;
|
|
127
|
+
targetExtensions: readonly Ext[];
|
|
128
|
+
exportStatementExtension: Ext | 'none';
|
|
129
|
+
indexFileExtension: Ext;
|
|
130
|
+
exclude?: readonly string[] | undefined;
|
|
131
|
+
formatCommand?: string | undefined;
|
|
132
|
+
silent?: boolean | undefined;
|
|
133
|
+
}>): Promise<void> => {
|
|
134
|
+
await genIndex({
|
|
135
|
+
targetDirectory: targetDirectory.includes(',')
|
|
136
|
+
? targetDirectory.split(',').map((dir) => dir.trim())
|
|
137
|
+
: targetDirectory,
|
|
138
|
+
exportStatementExtension,
|
|
139
|
+
targetExtensions,
|
|
140
|
+
exclude,
|
|
141
|
+
indexFileExtension,
|
|
142
|
+
formatCommand,
|
|
143
|
+
silent,
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
await cmd.run(cmdDef, process.argv.slice(2));
|