ts-repo-utils 2.1.0 → 2.2.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/dist/functions/assert-ext.d.mts +2 -2
- package/dist/functions/assert-ext.d.mts.map +1 -1
- package/dist/functions/assert-ext.mjs +10 -7
- package/dist/functions/assert-ext.mjs.map +1 -1
- package/dist/functions/diff.d.mts +8 -2
- package/dist/functions/diff.d.mts.map +1 -1
- package/dist/functions/diff.mjs +7 -4
- package/dist/functions/diff.mjs.map +1 -1
- package/dist/functions/format.d.mts +11 -1
- package/dist/functions/format.d.mts.map +1 -1
- package/dist/functions/format.mjs +84 -110
- package/dist/functions/format.mjs.map +1 -1
- package/dist/functions/index.d.mts +1 -0
- package/dist/functions/index.d.mts.map +1 -1
- package/dist/functions/index.mjs +2 -1
- package/dist/functions/index.mjs.map +1 -1
- package/dist/functions/should-run.d.mts +3 -0
- package/dist/functions/should-run.d.mts.map +1 -0
- package/dist/functions/should-run.mjs +26 -0
- package/dist/functions/should-run.mjs.map +1 -0
- package/dist/globals.d.mjs +2 -0
- package/dist/globals.d.mjs.map +1 -0
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/functions/assert-ext.mts +16 -9
- package/src/functions/diff.mts +17 -3
- package/src/functions/format.mts +112 -130
- package/src/functions/format.test.mts +225 -16
- package/src/functions/index.mts +1 -0
- package/src/functions/should-run.mts +33 -0
|
@@ -7,8 +7,8 @@ export type CheckExtConfig = DeepReadonly<{
|
|
|
7
7
|
directories: {
|
|
8
8
|
/** Directory path to check */
|
|
9
9
|
path: string;
|
|
10
|
-
/** Expected file extension (including the dot) */
|
|
11
|
-
extension: string;
|
|
10
|
+
/** Expected file extension(s) (including the dot). Can be a single extension or an array of valid extensions */
|
|
11
|
+
extension: `.${string}` | `.${string}`[];
|
|
12
12
|
/** Optional glob patterns to ignore (defaults to ['tsconfig.json', 'globals.d.*']) */
|
|
13
13
|
ignorePatterns?: string[];
|
|
14
14
|
}[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert-ext.d.mts","sourceRoot":"","sources":["../../src/functions/assert-ext.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assert-ext.d.mts","sourceRoot":"","sources":["../../src/functions/assert-ext.mts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,CAAC;AAG5B;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC;IACxC,6DAA6D;IAC7D,WAAW,EAAE;QACX,8BAA8B;QAC9B,IAAI,EAAE,MAAM,CAAC;QAEb,gHAAgH;QAChH,SAAS,EAAE,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,EAAE,CAAC;QAEzC,sFAAsF;QACtF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;KAC3B,EAAE,CAAC;CACL,CAAC,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAU,QAAQ,cAAc,KAAG,OAAO,CAAC,IAAI,CA0DpE,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isString } from 'ts-data-forge';
|
|
1
2
|
import '../node-global.mjs';
|
|
2
3
|
import { assertPathExists } from './assert-path-exists.mjs';
|
|
3
4
|
|
|
@@ -10,7 +11,7 @@ const assertExt = async (config) => {
|
|
|
10
11
|
// Check all directories in parallel
|
|
11
12
|
const results = await Promise.all(config.directories.map(async ({ path: dir, extension, ignorePatterns }) => {
|
|
12
13
|
try {
|
|
13
|
-
return await getFilesWithIncorrectExtension(dir, extension, ignorePatterns);
|
|
14
|
+
return await getFilesWithIncorrectExtension(dir, isString(extension) ? [extension] : extension, ignorePatterns);
|
|
14
15
|
}
|
|
15
16
|
catch (error) {
|
|
16
17
|
console.error(`Failed to check directory ${dir}: ${String(error)}`);
|
|
@@ -25,10 +26,11 @@ const assertExt = async (config) => {
|
|
|
25
26
|
const extensionGroups = new Map();
|
|
26
27
|
for (const { path: dirPath, extension } of config.directories) {
|
|
27
28
|
const relativePath = path.relative(process.cwd(), dirPath);
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
const extKey = isString(extension) ? extension : extension.join(' or ');
|
|
30
|
+
if (!extensionGroups.has(extKey)) {
|
|
31
|
+
extensionGroups.set(extKey, []);
|
|
30
32
|
}
|
|
31
|
-
extensionGroups.get(
|
|
33
|
+
extensionGroups.get(extKey)?.push(relativePath);
|
|
32
34
|
}
|
|
33
35
|
// Generate message parts for each extension
|
|
34
36
|
const messageParts = Array.from(extensionGroups.entries(), ([ext, dirs]) => {
|
|
@@ -51,11 +53,11 @@ const assertExt = async (config) => {
|
|
|
51
53
|
/**
|
|
52
54
|
* Checks if all files in a directory have the expected extension.
|
|
53
55
|
* @param dir - The directory to check.
|
|
54
|
-
* @param
|
|
56
|
+
* @param expectedExtensions - The expected file extensions.
|
|
55
57
|
* @param ignorePatterns - Optional glob patterns to ignore.
|
|
56
58
|
* @returns Array of files with incorrect extensions.
|
|
57
59
|
*/
|
|
58
|
-
const getFilesWithIncorrectExtension = async (dir,
|
|
60
|
+
const getFilesWithIncorrectExtension = async (dir, expectedExtensions, ignorePatterns) => {
|
|
59
61
|
await assertPathExists(dir, 'Directory');
|
|
60
62
|
const defaultIgnorePatterns = ['tsconfig.json', 'globals.d.*'];
|
|
61
63
|
const finalIgnorePatterns = ignorePatterns ?? defaultIgnorePatterns;
|
|
@@ -64,7 +66,8 @@ const getFilesWithIncorrectExtension = async (dir, expectedExtension, ignorePatt
|
|
|
64
66
|
const files = await glob(`${dir}/**/*`, {
|
|
65
67
|
ignore: absoluteIgnorePatterns,
|
|
66
68
|
});
|
|
67
|
-
|
|
69
|
+
// Type assertion: glob always returns string[] for this use case
|
|
70
|
+
return files.filter((file) => !expectedExtensions.some((ext) => file.endsWith(ext)));
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
export { assertExt };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert-ext.mjs","sources":["../../src/functions/assert-ext.mts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assert-ext.mjs","sources":["../../src/functions/assert-ext.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAqBA;;;;AAIG;MACU,SAAS,GAAG,OAAO,MAAsB,KAAmB;;IAEvE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,cAAc,EAAE,KAAI;AACxE,QAAA,IAAI;YACF,OAAO,MAAM,8BAA8B,CACzC,GAAG,EACH,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,SAAS,EAC7C,cAAc,CACf;;QACD,OAAO,KAAK,EAAE;AACd,YAAA,OAAO,CAAC,KAAK,CAAC,CAAA,0BAAA,EAA6B,GAAG,CAAA,EAAA,EAAK,MAAM,CAAC,KAAK,CAAC,CAAA,CAAE,CAAC;AACnE,YAAA,OAAO,EAAE;;KAEZ,CAAC,CACH;;AAGD,IAAA,MAAM,iBAAiB,GAAsB,OAAO,CAAC,IAAI,EAAE;AAE3D,IAAA,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;QAChC,MAAM,oBAAoB,GAAG,MAAa;;AAExC,YAAA,MAAM,eAAe,GAAG,IAAI,GAAG,EAAoB;AAEnD,YAAA,KAAK,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,MAAM,CAAC,WAAW,EAAE;AAC7D,gBAAA,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC;AAC1D,gBAAA,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;gBACvE,IAAI,CAAC,eAAe,CAAC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AsB,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,KAC7D,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,CAAA,EAAG,GAAG,CAAA,CAAA,EAAI,OAAO,CAAA,CAAE,CACzD;IAED,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,CAAA,EAAG,GAAG,OAAO,EAAE;AACtC,QAAA,MAAM,EAAE,sBAAsB;AAC/B,KAAA,CAAC;;IAGF,OAAO,KAAK,CAAC,MAAM,CACjB,CAAC,IAAI,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAChE;AACH,CAAC;;;;"}
|
|
@@ -4,13 +4,19 @@ import '../node-global.mjs';
|
|
|
4
4
|
/**
|
|
5
5
|
* Get files that have been changed (git status).
|
|
6
6
|
*/
|
|
7
|
-
export declare const getUntrackedFiles: (
|
|
7
|
+
export declare const getUntrackedFiles: (options?: Readonly<{
|
|
8
|
+
/** @default true */
|
|
9
|
+
excludeDeleted?: boolean;
|
|
10
|
+
}>) => Promise<Result<readonly string[], ExecException | Readonly<{
|
|
8
11
|
message: string;
|
|
9
12
|
}>>>;
|
|
10
13
|
/**
|
|
11
14
|
* Get files that differ from the specified base branch or commit
|
|
12
15
|
*/
|
|
13
|
-
export declare const getDiffFrom: (base: string
|
|
16
|
+
export declare const getDiffFrom: (base: string, options?: Readonly<{
|
|
17
|
+
/** @default true */
|
|
18
|
+
excludeDeleted?: boolean;
|
|
19
|
+
}>) => Promise<Result<readonly string[], ExecException | Readonly<{
|
|
14
20
|
message: string;
|
|
15
21
|
}>>>;
|
|
16
22
|
//# sourceMappingURL=diff.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.mts","sourceRoot":"","sources":["../../src/functions/diff.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,oBAAoB,CAAC;AAE5B;;GAEG;AACH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"diff.d.mts","sourceRoot":"","sources":["../../src/functions/diff.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,oBAAoB,CAAC;AAE5B;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,QAAQ,CAAC;IACjB,oBAAoB;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC,KACD,OAAO,CACR,MAAM,CAAC,SAAS,MAAM,EAAE,EAAE,aAAa,GAAG,QAAQ,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CA8BzE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,MAAM,MAAM,EACZ,UAAU,QAAQ,CAAC;IACjB,oBAAoB;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC,KACD,OAAO,CACR,MAAM,CAAC,SAAS,MAAM,EAAE,EAAE,aAAa,GAAG,QAAQ,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAoBzE,CAAC"}
|
package/dist/functions/diff.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import '../node-global.mjs';
|
|
|
4
4
|
/**
|
|
5
5
|
* Get files that have been changed (git status).
|
|
6
6
|
*/
|
|
7
|
-
const getUntrackedFiles = async () => {
|
|
7
|
+
const getUntrackedFiles = async (options) => {
|
|
8
8
|
// Get changed files from git status
|
|
9
9
|
const result = await $('git status --porcelain');
|
|
10
10
|
if (Result.isErr(result)) {
|
|
@@ -22,15 +22,18 @@ const getUntrackedFiles = async () => {
|
|
|
22
22
|
})
|
|
23
23
|
.filter((file) =>
|
|
24
24
|
// Filter out deleted files (status starts with 'D')
|
|
25
|
-
file !== undefined &&
|
|
25
|
+
file !== undefined &&
|
|
26
|
+
((options?.excludeDeleted ?? true)
|
|
27
|
+
? !stdout.includes(`D ${file}`)
|
|
28
|
+
: true));
|
|
26
29
|
return Result.ok(files);
|
|
27
30
|
};
|
|
28
31
|
/**
|
|
29
32
|
* Get files that differ from the specified base branch or commit
|
|
30
33
|
*/
|
|
31
|
-
const getDiffFrom = async (base) => {
|
|
34
|
+
const getDiffFrom = async (base, options) => {
|
|
32
35
|
// Get files that differ from base branch/commit (excluding deleted files)
|
|
33
|
-
const result = await $(`git diff --name-only ${base} --diff-filter=d`);
|
|
36
|
+
const result = await $(`git diff --name-only ${base} ${(options?.excludeDeleted ?? true) ? '--diff-filter=d' : ''}`);
|
|
34
37
|
if (Result.isErr(result)) {
|
|
35
38
|
return result;
|
|
36
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.mjs","sources":["../../src/functions/diff.mts"],"sourcesContent":[null],"names":[],"mappings":";;;AAIA;;AAEG;
|
|
1
|
+
{"version":3,"file":"diff.mjs","sources":["../../src/functions/diff.mts"],"sourcesContent":[null],"names":[],"mappings":";;;AAIA;;AAEG;MACU,iBAAiB,GAAG,OAC/B,OAGE,KAGA;;AAEF,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,wBAAwB,CAAC;AAEhD,IAAA,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;AACxB,QAAA,OAAO,MAAM;;AAGf,IAAA,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK;;IAG/B,MAAM,KAAK,GAAG;SACX,KAAK,CAAC,IAAI;AACV,SAAA,MAAM,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;AACnC,SAAA,GAAG,CAAC,CAAC,IAAI,KAAI;;QAEZ,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;AACvC,QAAA,OAAO,KAAK,GAAG,CAAC,CAAC;AACnB,KAAC;AACA,SAAA,MAAM,CACL,CAAC,IAAI;;AAEH,IAAA,IAAI,KAAK,SAAS;AAClB,SAAC,CAAC,OAAO,EAAE,cAAc,IAAI,IAAI;cAC7B,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA,GAAA,EAAM,IAAI,CAAA,CAAE;AAC/B,cAAE,IAAI,CAAC,CACZ;AAEH,IAAA,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;AACzB;AAEA;;AAEG;AACI,MAAM,WAAW,GAAG,OACzB,IAAY,EACZ,OAGE,KAGA;;IAEF,MAAM,MAAM,GAAG,MAAM,CAAC,CACpB,wBAAwB,IAAI,CAAA,CAAA,EAAI,CAAC,OAAO,EAAE,cAAc,IAAI,IAAI,IAAI,iBAAiB,GAAG,EAAE,CAAA,CAAE,CAC7F;AAED,IAAA,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;AACxB,QAAA,OAAO,MAAM;;AAGf,IAAA,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK;;IAG/B,MAAM,KAAK,GAAG;SACX,KAAK,CAAC,IAAI;SACV,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;SACzB,MAAM,CAAC,CAAC,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC;AAEhC,IAAA,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;AACzB;;;;"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import '../node-global.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Format a list of files using Prettier
|
|
4
|
+
* @param files - Array of file paths to format
|
|
5
|
+
* @returns 'ok' if successful, 'err' if any errors occurred
|
|
6
|
+
*/
|
|
7
|
+
export declare const formatFilesList: (files: readonly string[]) => Promise<"ok" | "err">;
|
|
2
8
|
/**
|
|
3
9
|
* Format files matching the given glob pattern using Prettier
|
|
4
10
|
* @param pathGlob - Glob pattern to match files
|
|
@@ -13,7 +19,11 @@ export declare const formatUntracked: () => Promise<"ok" | "err">;
|
|
|
13
19
|
/**
|
|
14
20
|
* Format only files that differ from the specified base branch or commit
|
|
15
21
|
* @param base - Base branch name or commit hash to compare against (defaults to 'main')
|
|
22
|
+
* @param options - Options for formatting
|
|
23
|
+
* @param options.includeUntracked - Include untracked files in addition to diff files (default is true)
|
|
16
24
|
* @returns 'ok' if successful, 'err' if any errors occurred
|
|
17
25
|
*/
|
|
18
|
-
export declare const formatDiffFrom: (base: string
|
|
26
|
+
export declare const formatDiffFrom: (base: string, options?: Readonly<{
|
|
27
|
+
includeUntracked?: boolean;
|
|
28
|
+
}>) => Promise<"ok" | "err">;
|
|
19
29
|
//# sourceMappingURL=format.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.mts","sourceRoot":"","sources":["../../src/functions/format.mts"],"names":[],"mappings":"AAIA,OAAO,oBAAoB,CAAC;AAG5B;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAU,UAAU,MAAM,KAAG,OAAO,CAAC,IAAI,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"format.d.mts","sourceRoot":"","sources":["../../src/functions/format.mts"],"names":[],"mappings":"AAIA,OAAO,oBAAoB,CAAC;AAG5B;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,SAAS,MAAM,EAAE,KACvB,OAAO,CAAC,IAAI,GAAG,KAAK,CAiDtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAU,UAAU,MAAM,KAAG,OAAO,CAAC,IAAI,GAAG,KAAK,CAmBxE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAa,OAAO,CAAC,IAAI,GAAG,KAAK,CA2C5D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GACzB,MAAM,MAAM,EACZ,UAAU,QAAQ,CAAC;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,KACjD,OAAO,CAAC,IAAI,GAAG,KAAK,CAiDtB,CAAC"}
|
|
@@ -5,6 +5,52 @@ import { Result } from 'ts-data-forge';
|
|
|
5
5
|
import '../node-global.mjs';
|
|
6
6
|
import { getUntrackedFiles, getDiffFrom } from './diff.mjs';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Format a list of files using Prettier
|
|
10
|
+
* @param files - Array of file paths to format
|
|
11
|
+
* @returns 'ok' if successful, 'err' if any errors occurred
|
|
12
|
+
*/
|
|
13
|
+
const formatFilesList = async (files) => {
|
|
14
|
+
if (files.length === 0) {
|
|
15
|
+
echo('No files to format');
|
|
16
|
+
return 'ok';
|
|
17
|
+
}
|
|
18
|
+
echo(`Formatting ${files.length} files...`);
|
|
19
|
+
// Format each file
|
|
20
|
+
const results = await Promise.allSettled(files.map(async (filePath) => {
|
|
21
|
+
try {
|
|
22
|
+
// Read file content
|
|
23
|
+
const content = await readFile(filePath, 'utf8');
|
|
24
|
+
// Resolve prettier config for this file
|
|
25
|
+
const options = await prettier.resolveConfig(filePath);
|
|
26
|
+
// Check if file is ignored by prettier
|
|
27
|
+
const fileInfo = await prettier.getFileInfo(filePath, {
|
|
28
|
+
ignorePath: '.prettierignore',
|
|
29
|
+
});
|
|
30
|
+
if (fileInfo.ignored) {
|
|
31
|
+
echo(`Skipping ignored file: ${filePath}`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Format the content
|
|
35
|
+
const formatted = await prettier.format(content, {
|
|
36
|
+
...options,
|
|
37
|
+
filepath: filePath,
|
|
38
|
+
});
|
|
39
|
+
// Only write if content changed
|
|
40
|
+
if (formatted !== content) {
|
|
41
|
+
await writeFile(filePath, formatted, 'utf8');
|
|
42
|
+
echo(`Formatted: ${filePath}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error(`Error formatting ${filePath}:`, error);
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
// Check if any formatting failed
|
|
51
|
+
const hasErrors = results.some((result) => result.status === 'rejected');
|
|
52
|
+
return hasErrors ? 'err' : 'ok';
|
|
53
|
+
};
|
|
8
54
|
/**
|
|
9
55
|
* Format files matching the given glob pattern using Prettier
|
|
10
56
|
* @param pathGlob - Glob pattern to match files
|
|
@@ -22,41 +68,7 @@ const formatFiles = async (pathGlob) => {
|
|
|
22
68
|
echo('No files found matching pattern:', pathGlob);
|
|
23
69
|
return 'ok';
|
|
24
70
|
}
|
|
25
|
-
|
|
26
|
-
// Format each file
|
|
27
|
-
const results = await Promise.allSettled(files.map(async (filePath) => {
|
|
28
|
-
try {
|
|
29
|
-
// Read file content
|
|
30
|
-
const content = await readFile(filePath, 'utf8');
|
|
31
|
-
// Resolve prettier config for this file
|
|
32
|
-
const options = await prettier.resolveConfig(filePath);
|
|
33
|
-
// Check if file is ignored by prettier
|
|
34
|
-
const fileInfo = await prettier.getFileInfo(filePath, {
|
|
35
|
-
ignorePath: '.prettierignore',
|
|
36
|
-
});
|
|
37
|
-
if (fileInfo.ignored) {
|
|
38
|
-
echo(`Skipping ignored file: ${filePath}`);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
// Format the content
|
|
42
|
-
const formatted = await prettier.format(content, {
|
|
43
|
-
...options,
|
|
44
|
-
filepath: filePath,
|
|
45
|
-
});
|
|
46
|
-
// Only write if content changed
|
|
47
|
-
if (formatted !== content) {
|
|
48
|
-
await writeFile(filePath, formatted, 'utf8');
|
|
49
|
-
echo(`Formatted: ${filePath}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
console.error(`Error formatting ${filePath}:`, error);
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
}));
|
|
57
|
-
// Check if any formatting failed
|
|
58
|
-
const hasErrors = results.some((result) => result.status === 'rejected');
|
|
59
|
-
return hasErrors ? 'err' : 'ok';
|
|
71
|
+
return await formatFilesList(files);
|
|
60
72
|
}
|
|
61
73
|
catch (error) {
|
|
62
74
|
console.error('Error in formatFiles:', error);
|
|
@@ -80,56 +92,35 @@ const formatUntracked = async () => {
|
|
|
80
92
|
return 'ok';
|
|
81
93
|
}
|
|
82
94
|
echo('Formatting changed files:', files);
|
|
83
|
-
//
|
|
84
|
-
const
|
|
95
|
+
// Filter out non-existent files before formatting
|
|
96
|
+
const fileExistenceChecks = await Promise.allSettled(files.map(async (filePath) => {
|
|
85
97
|
try {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (content === null) {
|
|
89
|
-
echo(`Skipping non-existent file: ${filePath}`);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
// Resolve prettier config for this file
|
|
93
|
-
const options = await prettier.resolveConfig(filePath);
|
|
94
|
-
// Check if file is ignored by prettier
|
|
95
|
-
const fileInfo = await prettier.getFileInfo(filePath, {
|
|
96
|
-
ignorePath: '.prettierignore',
|
|
97
|
-
});
|
|
98
|
-
if (fileInfo.ignored) {
|
|
99
|
-
echo(`Skipping ignored file: ${filePath}`);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
// Format the content
|
|
103
|
-
const formatted = await prettier.format(content, {
|
|
104
|
-
...options,
|
|
105
|
-
filepath: filePath,
|
|
106
|
-
});
|
|
107
|
-
// Only write if content changed
|
|
108
|
-
if (formatted !== content) {
|
|
109
|
-
await writeFile(filePath, formatted, 'utf8');
|
|
110
|
-
echo(`Formatted: ${filePath}`);
|
|
111
|
-
}
|
|
98
|
+
await readFile(filePath, 'utf8');
|
|
99
|
+
return filePath;
|
|
112
100
|
}
|
|
113
|
-
catch
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
catch {
|
|
102
|
+
echo(`Skipping non-existent file: ${filePath}`);
|
|
103
|
+
return undefined;
|
|
116
104
|
}
|
|
117
105
|
}));
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
const existingFiles = fileExistenceChecks
|
|
107
|
+
.filter((result) => result.status === 'fulfilled' && result.value !== undefined)
|
|
108
|
+
.map((result) => result.value);
|
|
109
|
+
return await formatFilesList(existingFiles);
|
|
121
110
|
}
|
|
122
111
|
catch (error) {
|
|
123
|
-
console.error('Error in
|
|
112
|
+
console.error('Error in formatUntracked:', error);
|
|
124
113
|
return 'err';
|
|
125
114
|
}
|
|
126
115
|
};
|
|
127
116
|
/**
|
|
128
117
|
* Format only files that differ from the specified base branch or commit
|
|
129
118
|
* @param base - Base branch name or commit hash to compare against (defaults to 'main')
|
|
119
|
+
* @param options - Options for formatting
|
|
120
|
+
* @param options.includeUntracked - Include untracked files in addition to diff files (default is true)
|
|
130
121
|
* @returns 'ok' if successful, 'err' if any errors occurred
|
|
131
122
|
*/
|
|
132
|
-
const formatDiffFrom = async (base) => {
|
|
123
|
+
const formatDiffFrom = async (base, options) => {
|
|
133
124
|
try {
|
|
134
125
|
// Get files that differ from base branch/commit (excluding deleted files)
|
|
135
126
|
const diffFromBaseResult = await getDiffFrom(base);
|
|
@@ -137,46 +128,29 @@ const formatDiffFrom = async (base) => {
|
|
|
137
128
|
console.error('Error getting changed files:', diffFromBaseResult.value);
|
|
138
129
|
return 'err';
|
|
139
130
|
}
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
131
|
+
const diffFiles = diffFromBaseResult.value;
|
|
132
|
+
let allFiles = diffFiles;
|
|
133
|
+
// If includeUntracked is true, also get untracked files
|
|
134
|
+
if (options?.includeUntracked ?? true) {
|
|
135
|
+
const untrackedFilesResult = await getUntrackedFiles();
|
|
136
|
+
if (Result.isErr(untrackedFilesResult)) {
|
|
137
|
+
console.error('Error getting untracked files:', untrackedFilesResult.value);
|
|
138
|
+
return 'err';
|
|
139
|
+
}
|
|
140
|
+
const untrackedFiles = untrackedFilesResult.value;
|
|
141
|
+
// Combine and deduplicate files
|
|
142
|
+
const uniqueFiles = new Set([...diffFiles, ...untrackedFiles]);
|
|
143
|
+
allFiles = Array.from(uniqueFiles);
|
|
144
|
+
echo(`Formatting files that differ from ${base} and untracked files:`, allFiles);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
echo(`Formatting files that differ from ${base}:`, allFiles);
|
|
148
|
+
}
|
|
149
|
+
if (allFiles.length === 0) {
|
|
150
|
+
echo(`No files to format`);
|
|
143
151
|
return 'ok';
|
|
144
152
|
}
|
|
145
|
-
|
|
146
|
-
// Format each file
|
|
147
|
-
const results = await Promise.allSettled(files.map(async (filePath) => {
|
|
148
|
-
try {
|
|
149
|
-
// Read file content
|
|
150
|
-
const content = await readFile(filePath, 'utf8');
|
|
151
|
-
// Resolve prettier config for this file
|
|
152
|
-
const options = await prettier.resolveConfig(filePath);
|
|
153
|
-
// Check if file is ignored by prettier
|
|
154
|
-
const fileInfo = await prettier.getFileInfo(filePath, {
|
|
155
|
-
ignorePath: '.prettierignore',
|
|
156
|
-
});
|
|
157
|
-
if (fileInfo.ignored) {
|
|
158
|
-
echo(`Skipping ignored file: ${filePath}`);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
// Format the content
|
|
162
|
-
const formatted = await prettier.format(content, {
|
|
163
|
-
...options,
|
|
164
|
-
filepath: filePath,
|
|
165
|
-
});
|
|
166
|
-
// Only write if content changed
|
|
167
|
-
if (formatted !== content) {
|
|
168
|
-
await writeFile(filePath, formatted, 'utf8');
|
|
169
|
-
echo(`Formatted: ${filePath}`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
catch (error) {
|
|
173
|
-
console.error(`Error formatting ${filePath}:`, error);
|
|
174
|
-
throw error;
|
|
175
|
-
}
|
|
176
|
-
}));
|
|
177
|
-
// Check if any formatting failed
|
|
178
|
-
const hasErrors = results.some((result) => result.status === 'rejected');
|
|
179
|
-
return hasErrors ? 'err' : 'ok';
|
|
153
|
+
return await formatFilesList(allFiles);
|
|
180
154
|
}
|
|
181
155
|
catch (error) {
|
|
182
156
|
console.error('Error in formatDiffFrom:', error);
|
|
@@ -184,5 +158,5 @@ const formatDiffFrom = async (base) => {
|
|
|
184
158
|
}
|
|
185
159
|
};
|
|
186
160
|
|
|
187
|
-
export { formatDiffFrom, formatFiles, formatUntracked };
|
|
161
|
+
export { formatDiffFrom, formatFiles, formatFilesList, formatUntracked };
|
|
188
162
|
//# sourceMappingURL=format.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.mjs","sources":["../../src/functions/format.mts"],"sourcesContent":[null],"names":["glob"],"mappings":";;;;;;;AAOA;;;;AAIG;MACU,
|
|
1
|
+
{"version":3,"file":"format.mjs","sources":["../../src/functions/format.mts"],"sourcesContent":[null],"names":["glob"],"mappings":";;;;;;;AAOA;;;;AAIG;MACU,eAAe,GAAG,OAC7B,KAAwB,KACC;AACzB,IAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,IAAI,CAAC,oBAAoB,CAAC;AAC1B,QAAA,OAAO,IAAI;;AAGb,IAAA,IAAI,CAAC,CAAA,WAAA,EAAc,KAAK,CAAC,MAAM,CAAA,SAAA,CAAW,CAAC;;AAG3C,IAAA,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CACtC,KAAK,CAAC,GAAG,CAAC,OAAO,QAAQ,KAAI;AAC3B,QAAA,IAAI;;YAEF,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;;YAGhD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;;YAGtD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE;AACpD,gBAAA,UAAU,EAAE,iBAAiB;AAC9B,aAAA,CAAC;AAEF,YAAA,IAAI,QAAQ,CAAC,OAAO,EAAE;AACpB,gBAAA,IAAI,CAAC,CAAA,uBAAA,EAA0B,QAAQ,CAAA,CAAE,CA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AA0B,EAAE,KAAK,CAAC;AAChD,QAAA,OAAO,KAAK;;AAEhB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/functions/index.mts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/functions/index.mts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
package/dist/functions/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ export { assertPathExists, pathExists } from './assert-path-exists.mjs';
|
|
|
3
3
|
export { assertRepoIsDirty, repoIsDirty } from './assert-repo-is-dirty.mjs';
|
|
4
4
|
export { getDiffFrom, getUntrackedFiles } from './diff.mjs';
|
|
5
5
|
export { $ } from './exec-async.mjs';
|
|
6
|
-
export { formatDiffFrom, formatFiles, formatUntracked } from './format.mjs';
|
|
6
|
+
export { formatDiffFrom, formatFiles, formatFilesList, formatUntracked } from './format.mjs';
|
|
7
7
|
export { genIndex } from './gen-index.mjs';
|
|
8
|
+
export { checkShouldRunTypeChecks } from './should-run.mjs';
|
|
8
9
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"should-run.d.mts","sourceRoot":"","sources":["../../src/functions/should-run.mts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,CAAC;AAG5B,eAAO,MAAM,wBAAwB,QAAa,OAAO,CAAC,IAAI,CA4B7D,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Result, pipe } from 'ts-data-forge';
|
|
2
|
+
import '../node-global.mjs';
|
|
3
|
+
import { getDiffFrom } from './diff.mjs';
|
|
4
|
+
|
|
5
|
+
const checkShouldRunTypeChecks = async () => {
|
|
6
|
+
// paths-ignore:
|
|
7
|
+
// - '.cspell.json'
|
|
8
|
+
// - '**.md'
|
|
9
|
+
// - '**.txt'
|
|
10
|
+
// - 'docs/**'
|
|
11
|
+
const GITHUB_OUTPUT = process.env['GITHUB_OUTPUT'];
|
|
12
|
+
const files = await getDiffFrom('origin/main');
|
|
13
|
+
if (Result.isErr(files)) {
|
|
14
|
+
console.error('Error getting diff:', files.value);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
const shouldRunTsChecks = !files.value.every((file) => file === '.cspell.json' ||
|
|
18
|
+
file.startsWith('docs/') ||
|
|
19
|
+
pipe(path.basename(file)).map((filename) => filename.endsWith('.md') || filename.endsWith('.txt')).value);
|
|
20
|
+
if (GITHUB_OUTPUT !== undefined) {
|
|
21
|
+
await fs.appendFile(GITHUB_OUTPUT, `should_run=${shouldRunTsChecks}\n`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { checkShouldRunTypeChecks };
|
|
26
|
+
//# sourceMappingURL=should-run.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"should-run.mjs","sources":["../../src/functions/should-run.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIO,MAAM,wBAAwB,GAAG,YAA0B;;;;;;IAOhE,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;AAElD,IAAA,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,aAAa,CAAC;AAE9C,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;;AAGjB,IAAA,MAAM,iBAAiB,GAAY,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CACnD,CAAC,IAAI,KACH,IAAI,KAAK,cAAc;AACvB,QAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;AACxB,QAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAC3B,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CACpE,CAAC,KAAK,CACV;AAED,IAAA,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,MAAM,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,CAAA,WAAA,EAAc,iBAAiB,CAAA,EAAA,CAAI,CAAC;;AAE3E;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globals.d.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ export { assertPathExists, pathExists } from './functions/assert-path-exists.mjs
|
|
|
3
3
|
export { assertRepoIsDirty, repoIsDirty } from './functions/assert-repo-is-dirty.mjs';
|
|
4
4
|
export { getDiffFrom, getUntrackedFiles } from './functions/diff.mjs';
|
|
5
5
|
export { $ } from './functions/exec-async.mjs';
|
|
6
|
-
export { formatDiffFrom, formatFiles, formatUntracked } from './functions/format.mjs';
|
|
6
|
+
export { formatDiffFrom, formatFiles, formatFilesList, formatUntracked } from './functions/format.mjs';
|
|
7
7
|
export { genIndex } from './functions/gen-index.mjs';
|
|
8
|
+
export { checkShouldRunTypeChecks } from './functions/should-run.mjs';
|
|
8
9
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isString } from 'ts-data-forge';
|
|
1
2
|
import '../node-global.mjs';
|
|
2
3
|
import { assertPathExists } from './assert-path-exists.mjs';
|
|
3
4
|
|
|
@@ -9,8 +10,10 @@ export type CheckExtConfig = DeepReadonly<{
|
|
|
9
10
|
directories: {
|
|
10
11
|
/** Directory path to check */
|
|
11
12
|
path: string;
|
|
12
|
-
|
|
13
|
-
extension
|
|
13
|
+
|
|
14
|
+
/** Expected file extension(s) (including the dot). Can be a single extension or an array of valid extensions */
|
|
15
|
+
extension: `.${string}` | `.${string}`[];
|
|
16
|
+
|
|
14
17
|
/** Optional glob patterns to ignore (defaults to ['tsconfig.json', 'globals.d.*']) */
|
|
15
18
|
ignorePatterns?: string[];
|
|
16
19
|
}[];
|
|
@@ -28,7 +31,7 @@ export const assertExt = async (config: CheckExtConfig): Promise<void> => {
|
|
|
28
31
|
try {
|
|
29
32
|
return await getFilesWithIncorrectExtension(
|
|
30
33
|
dir,
|
|
31
|
-
extension,
|
|
34
|
+
isString(extension) ? [extension] : extension,
|
|
32
35
|
ignorePatterns,
|
|
33
36
|
);
|
|
34
37
|
} catch (error) {
|
|
@@ -48,10 +51,11 @@ export const assertExt = async (config: CheckExtConfig): Promise<void> => {
|
|
|
48
51
|
|
|
49
52
|
for (const { path: dirPath, extension } of config.directories) {
|
|
50
53
|
const relativePath = path.relative(process.cwd(), dirPath);
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
const extKey = isString(extension) ? extension : extension.join(' or ');
|
|
55
|
+
if (!extensionGroups.has(extKey)) {
|
|
56
|
+
extensionGroups.set(extKey, []);
|
|
53
57
|
}
|
|
54
|
-
extensionGroups.get(
|
|
58
|
+
extensionGroups.get(extKey)?.push(relativePath);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
// Generate message parts for each extension
|
|
@@ -83,13 +87,13 @@ export const assertExt = async (config: CheckExtConfig): Promise<void> => {
|
|
|
83
87
|
/**
|
|
84
88
|
* Checks if all files in a directory have the expected extension.
|
|
85
89
|
* @param dir - The directory to check.
|
|
86
|
-
* @param
|
|
90
|
+
* @param expectedExtensions - The expected file extensions.
|
|
87
91
|
* @param ignorePatterns - Optional glob patterns to ignore.
|
|
88
92
|
* @returns Array of files with incorrect extensions.
|
|
89
93
|
*/
|
|
90
94
|
const getFilesWithIncorrectExtension = async (
|
|
91
95
|
dir: string,
|
|
92
|
-
|
|
96
|
+
expectedExtensions: readonly string[],
|
|
93
97
|
ignorePatterns?: readonly string[],
|
|
94
98
|
): Promise<readonly string[]> => {
|
|
95
99
|
await assertPathExists(dir, 'Directory');
|
|
@@ -106,5 +110,8 @@ const getFilesWithIncorrectExtension = async (
|
|
|
106
110
|
ignore: absoluteIgnorePatterns,
|
|
107
111
|
});
|
|
108
112
|
|
|
109
|
-
|
|
113
|
+
// Type assertion: glob always returns string[] for this use case
|
|
114
|
+
return files.filter(
|
|
115
|
+
(file) => !expectedExtensions.some((ext) => file.endsWith(ext)),
|
|
116
|
+
);
|
|
110
117
|
};
|