ts-repo-utils 6.2.0 → 7.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.
- package/README.md +148 -32
- package/dist/cmd/assert-repo-is-clean.mjs +1 -1
- package/dist/cmd/check-should-run-type-checks.mjs +1 -1
- package/dist/cmd/format-diff-from.mjs +1 -1
- package/dist/cmd/format-uncommitted.mjs +1 -1
- package/dist/cmd/gen-index-ts.mjs +1 -1
- package/dist/functions/assert-repo-is-clean.d.mts.map +1 -1
- package/dist/functions/assert-repo-is-clean.mjs +30 -30
- package/dist/functions/assert-repo-is-clean.mjs.map +1 -1
- package/dist/functions/diff.d.mts +2 -2
- package/dist/functions/diff.mjs +4 -4
- package/dist/functions/diff.mjs.map +1 -1
- package/dist/functions/exec-async.d.mts +7 -8
- package/dist/functions/exec-async.d.mts.map +1 -1
- package/dist/functions/exec-async.mjs +5 -5
- package/dist/functions/exec-async.mjs.map +1 -1
- package/dist/functions/format.d.mts.map +1 -1
- package/dist/functions/format.mjs +12 -25
- package/dist/functions/format.mjs.map +1 -1
- package/dist/functions/gen-index.d.mts +2 -1
- package/dist/functions/gen-index.d.mts.map +1 -1
- package/dist/functions/gen-index.mjs +10 -8
- package/dist/functions/gen-index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/cmd/assert-repo-is-clean.mts +1 -1
- package/src/cmd/check-should-run-type-checks.mts +1 -1
- package/src/cmd/format-diff-from.mts +1 -1
- package/src/cmd/format-uncommitted.mts +1 -1
- package/src/cmd/gen-index-ts.mts +1 -1
- package/src/functions/assert-repo-is-clean.mts +43 -34
- package/src/functions/diff.mts +4 -4
- package/src/functions/exec-async.mts +25 -35
- package/src/functions/format.mts +14 -25
- package/src/functions/gen-index.mts +16 -10
|
@@ -10,15 +10,12 @@ import { getDiffFrom, getUntrackedFiles, getModifiedFiles, getStagedFiles } from
|
|
|
10
10
|
*/
|
|
11
11
|
const formatFiles = async (files, options) => {
|
|
12
12
|
const silent = options?.silent ?? false;
|
|
13
|
+
const conditionalEcho = silent ? () => { } : echo;
|
|
13
14
|
if (files.length === 0) {
|
|
14
|
-
|
|
15
|
-
echo('No files to format');
|
|
16
|
-
}
|
|
15
|
+
conditionalEcho('No files to format');
|
|
17
16
|
return Result.ok(undefined);
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
echo(`Formatting ${files.length} files...`);
|
|
21
|
-
}
|
|
18
|
+
conditionalEcho(`Formatting ${files.length} files...`);
|
|
22
19
|
// Format each file
|
|
23
20
|
const results =
|
|
24
21
|
// NOTE: Using Promise.allSettled to ensure all files are processed even if some fail
|
|
@@ -30,9 +27,7 @@ const formatFiles = async (files, options) => {
|
|
|
30
27
|
}
|
|
31
28
|
catch {
|
|
32
29
|
// File doesn't exist, skip it
|
|
33
|
-
|
|
34
|
-
echo(`Skipping non-existent file: ${filePath}`);
|
|
35
|
-
}
|
|
30
|
+
conditionalEcho(`Skipping non-existent file: ${filePath}`);
|
|
36
31
|
return Result.ok(undefined);
|
|
37
32
|
}
|
|
38
33
|
// Read file content
|
|
@@ -44,9 +39,7 @@ const formatFiles = async (files, options) => {
|
|
|
44
39
|
ignorePath: '.prettierignore',
|
|
45
40
|
});
|
|
46
41
|
if (fileInfo.ignored) {
|
|
47
|
-
|
|
48
|
-
echo(`Skipping ignored file: ${filePath}`);
|
|
49
|
-
}
|
|
42
|
+
conditionalEcho(`Skipping ignored file: ${filePath}`);
|
|
50
43
|
return Result.ok(undefined);
|
|
51
44
|
}
|
|
52
45
|
// Format the content
|
|
@@ -56,15 +49,11 @@ const formatFiles = async (files, options) => {
|
|
|
56
49
|
});
|
|
57
50
|
// Only write if content changed
|
|
58
51
|
if (formatted === content) {
|
|
59
|
-
|
|
60
|
-
echo(`Unchanged: ${filePath}`);
|
|
61
|
-
}
|
|
52
|
+
conditionalEcho(`Unchanged: ${filePath}`);
|
|
62
53
|
}
|
|
63
54
|
else {
|
|
64
55
|
await fs.writeFile(filePath, formatted, 'utf8');
|
|
65
|
-
|
|
66
|
-
echo(`Formatted: ${filePath}`);
|
|
67
|
-
}
|
|
56
|
+
conditionalEcho(`Formatted: ${filePath}`);
|
|
68
57
|
}
|
|
69
58
|
return Result.ok(undefined);
|
|
70
59
|
}
|
|
@@ -101,6 +90,7 @@ const formatFiles = async (files, options) => {
|
|
|
101
90
|
*/
|
|
102
91
|
const formatFilesGlob = async (pathGlob, options) => {
|
|
103
92
|
const silent = options?.silent ?? false;
|
|
93
|
+
const conditionalEcho = silent ? () => { } : echo;
|
|
104
94
|
try {
|
|
105
95
|
// Find all files matching the glob
|
|
106
96
|
const files = await glob(pathGlob, {
|
|
@@ -109,9 +99,7 @@ const formatFilesGlob = async (pathGlob, options) => {
|
|
|
109
99
|
dot: true,
|
|
110
100
|
});
|
|
111
101
|
if (files.length === 0) {
|
|
112
|
-
|
|
113
|
-
echo('No files found matching pattern:', pathGlob);
|
|
114
|
-
}
|
|
102
|
+
conditionalEcho('No files found matching pattern:', pathGlob);
|
|
115
103
|
return Result.ok(undefined);
|
|
116
104
|
}
|
|
117
105
|
return await formatFiles(files, { silent });
|
|
@@ -179,6 +167,7 @@ const formatUncommittedFiles = async (options) => {
|
|
|
179
167
|
const formatDiffFrom = async (base, options) => {
|
|
180
168
|
// const silent = options?.silent ?? false;
|
|
181
169
|
const { silent = false, includeUntracked = true, includeModified = true, includeStaged = true, } = options ?? {};
|
|
170
|
+
const conditionalEcho = silent ? () => { } : echo;
|
|
182
171
|
// Get files that differ from base branch/commit (excluding deleted files)
|
|
183
172
|
const diffFromBaseResult = await getDiffFrom(base, {
|
|
184
173
|
silent,
|
|
@@ -224,12 +213,10 @@ const formatDiffFrom = async (base, options) => {
|
|
|
224
213
|
.map((s, i) => i !== includedFileTypes.length - 1 ? `, ${s}` : ` and ${s}`)
|
|
225
214
|
.join(''),
|
|
226
215
|
].join('');
|
|
227
|
-
|
|
216
|
+
conditionalEcho(`${message}:`, allFiles);
|
|
228
217
|
}
|
|
229
218
|
if (allFiles.length === 0) {
|
|
230
|
-
|
|
231
|
-
echo('No files to format');
|
|
232
|
-
}
|
|
219
|
+
conditionalEcho('No files to format');
|
|
233
220
|
return Result.ok(undefined);
|
|
234
221
|
}
|
|
235
222
|
return formatFiles(allFiles, { silent });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.mjs","sources":["../../src/functions/format.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAWA;;;;AAIG;AACI,MAAM,WAAW,GAAG,OACzB,KAAwB,EACxB,OAAwC,KACU;AAClD,IAAA,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,KAAK;AAEvC,IAAA,
|
|
1
|
+
{"version":3,"file":"format.mjs","sources":["../../src/functions/format.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAWA;;;;AAIG;AACI,MAAM,WAAW,GAAG,OACzB,KAAwB,EACxB,OAAwC,KACU;AAClD,IAAA,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,KAAK;AAEvC,IAAA,MAAM,eAAe,GAAG,MAAM,GAAG,MAAK,EAAE,CAAC,GAAG,IAAI;AAEhD,IAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,eAAe,CAAC,oBAAoB,CAAC;AACrC,QAAA,OAAO,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC;IAC7B;AAEA,IAAA,eAAe,CAAC,CAAA,WAAA,EAAc,KAAK,CAAC,MAAM,CAAA,SAAA,CAAW,CAAC;;AAGtD,IAAA,MAAM,OAAO;;AAEX,IAAA,MAAM,OAAO,CAAC,UAAU,CACtB,KAAK,CAAC,GAAG,CAAC,OAAO,QAAQ,KAAI;AAC3B,QAAA,IAAI;;AAEF,YAAA,IAAI;AACF,gBAAA,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC;YAC3B;AAAE,YAAA,MAAM;;AAEN,gBAAA,eAAe,CAAC,CAAA,4BAAA,EAA+B,QAAQ,CAAA,CAAE,CAAC;A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C,KACR,CAAC,KAAK,iBAAiB,CAAC,MAAM,GAAG,CAAC,GAAG,CAAA,EAAA,EAAK,CAAC,CAAA,CAAE,GAAG,CAAA,KAAA,EAAQ,CAAC,CAAA,CAAE;iBAE5D,IAAI,CAAC,EAAE,CAAC;AACZ,SAAA,CAAC,IAAI,CAAC,EAAE,CAAC;AAEV,QAAA,eAAe,CAAC,CAAA,EAAG,OAAO,GAAG,EAAE,QAAQ,CAAC;IAC1C;AAEA,IAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QACzB,eAAe,CAAC,oBAAoB,CAAC;AACrC,QAAA,OAAO,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC;IAC7B;IAEA,OAAO,WAAW,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC;AAC1C;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Result } from 'ts-data-forge';
|
|
1
2
|
import '../node-global.mjs';
|
|
2
3
|
/** Configuration for index file generation. */
|
|
3
4
|
export type GenIndexConfig = DeepReadonly<{
|
|
@@ -30,5 +31,5 @@ export type GenIndexConfig = DeepReadonly<{
|
|
|
30
31
|
* @param config - Configuration for index file generation
|
|
31
32
|
* @throws Error if any step fails.
|
|
32
33
|
*/
|
|
33
|
-
export declare const genIndex: (config: GenIndexConfig) => Promise<
|
|
34
|
+
export declare const genIndex: (config: GenIndexConfig) => Promise<Result<undefined, unknown>>;
|
|
34
35
|
//# sourceMappingURL=gen-index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gen-index.d.mts","sourceRoot":"","sources":["../../src/functions/gen-index.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gen-index.d.mts","sourceRoot":"","sources":["../../src/functions/gen-index.mts"],"names":[],"mappings":"AACA,OAAO,EAA6B,MAAM,EAAE,MAAM,eAAe,CAAC;AAClE,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,GACnB,QAAQ,cAAc,KACrB,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAkDpC,CAAC"}
|
|
@@ -17,9 +17,10 @@ const defaultConfig = {
|
|
|
17
17
|
* @throws Error if any step fails.
|
|
18
18
|
*/
|
|
19
19
|
const genIndex = async (config) => {
|
|
20
|
-
echo('Starting index file generation...\n');
|
|
21
20
|
// Merge config with defaults
|
|
22
21
|
const filledConfig = fillConfig(config);
|
|
22
|
+
const conditionalEcho = filledConfig.silent ? () => { } : echo;
|
|
23
|
+
conditionalEcho('Starting index file generation...\n');
|
|
23
24
|
// Normalize target directories to array
|
|
24
25
|
const targetDirs = typeof config.targetDirectory === 'string'
|
|
25
26
|
? [config.targetDirectory]
|
|
@@ -32,29 +33,30 @@ const genIndex = async (config) => {
|
|
|
32
33
|
await assertPathExists(resolvedDir, `Target directory: ${dir}`);
|
|
33
34
|
}
|
|
34
35
|
// Step 2: Generate index files
|
|
35
|
-
|
|
36
|
+
conditionalEcho('Generating index files...');
|
|
36
37
|
for (const dir of targetDirs) {
|
|
37
38
|
const resolvedDir = path.resolve(dir);
|
|
38
39
|
// eslint-disable-next-line no-await-in-loop
|
|
39
40
|
await generateIndexFileForDir(resolvedDir, filledConfig);
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
conditionalEcho('✓ Index files generated\n');
|
|
42
43
|
// Step 3: Format generated files
|
|
43
44
|
if (filledConfig.formatCommand !== undefined) {
|
|
44
|
-
|
|
45
|
+
conditionalEcho('Formatting generated files...');
|
|
45
46
|
const fmtResult = await $(filledConfig.formatCommand, {
|
|
46
47
|
silent: filledConfig.silent,
|
|
47
48
|
});
|
|
48
49
|
if (Result.isErr(fmtResult)) {
|
|
49
50
|
throw new Error(`Formatting failed: ${fmtResult.value.message}`);
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
+
conditionalEcho('✓ Formatting completed\n');
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
conditionalEcho('✅ Index file generation completed successfully!\n');
|
|
55
|
+
return Result.ok(undefined);
|
|
54
56
|
}
|
|
55
57
|
catch (error) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
conditionalEcho(`❌ Index generation failed: ${String(error)}\n`);
|
|
59
|
+
return Result.err(error);
|
|
58
60
|
}
|
|
59
61
|
};
|
|
60
62
|
const fillConfig = (config) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gen-index.mjs","sources":["../../src/functions/gen-index.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAyCA,MAAM,aAAa,GAAG;AACpB,IAAA,OAAO,EAAE,CAAC,kCAAkC,EAAE,iBAAiB,CAAC;AAChE,IAAA,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;AACjC,IAAA,kBAAkB,EAAE,KAAK;IACzB,wBAAwB,E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C,CAAA,iBAAA,EAAoB,kBAAkB,CAAA,EAAA;kBACtC,oBAAoB,kBAAkB,CAAA,EAAG,MAAM,CAAC,wBAAwB,IAAI;AAClF,QAAA,CAAC,CAAC;KACH;AAED,IAAA,OAAO,gBAAgB,CAAC,MAAM,KAAK;AACjC,UAAE;AACF,UAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC;;;;"}
|
package/package.json
CHANGED
package/src/cmd/gen-index-ts.mts
CHANGED
|
@@ -11,7 +11,10 @@ export const repoIsDirty = async (
|
|
|
11
11
|
options?: Readonly<{ silent?: boolean }>,
|
|
12
12
|
): Promise<boolean> => {
|
|
13
13
|
const status = await getGitStatus({ silent: options?.silent ?? false });
|
|
14
|
-
|
|
14
|
+
if (Result.isErr(status)) {
|
|
15
|
+
throw new Error(`Failed to get git status: ${status.value}`);
|
|
16
|
+
}
|
|
17
|
+
return status.value.isDirty;
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
/**
|
|
@@ -21,38 +24,39 @@ export const repoIsDirty = async (
|
|
|
21
24
|
export const assertRepoIsClean = async (
|
|
22
25
|
options?: Readonly<{ silent?: boolean }>,
|
|
23
26
|
): Promise<void> => {
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
const silent = options?.silent ?? false;
|
|
28
|
+
const conditionalEcho = silent ? () => {} : echo;
|
|
29
|
+
|
|
30
|
+
const gitStatusResult = await getGitStatus({ silent });
|
|
31
|
+
|
|
32
|
+
if (Result.isErr(gitStatusResult)) {
|
|
33
|
+
conditionalEcho(gitStatusResult.value);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
echo('Repo is clean\n');
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
37
|
+
const gitStatus = gitStatusResult.value;
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
if (!gitStatus.isDirty) {
|
|
40
|
+
conditionalEcho('Repo is clean\n');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
if (Result.isErr(addResult)) {
|
|
41
|
-
echo('Warning: Failed to add untracked files for diff\n');
|
|
42
|
-
}
|
|
44
|
+
conditionalEcho('Repo is dirty\n');
|
|
45
|
+
conditionalEcho('Changed files:\n');
|
|
46
|
+
conditionalEcho(gitStatus.stdout);
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
48
|
+
// Show files not tracked by git and unstaged changes
|
|
49
|
+
const addResult = await $('git add -N .', { silent });
|
|
50
|
+
if (Result.isErr(addResult)) {
|
|
51
|
+
conditionalEcho('Warning: Failed to add untracked files for diff\n');
|
|
52
|
+
}
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
process.exit(1);
|
|
54
|
+
const diffResult = await $('git diff', { silent });
|
|
55
|
+
if (Result.isErr(diffResult)) {
|
|
56
|
+
conditionalEcho('Warning: Failed to show diff\n');
|
|
55
57
|
}
|
|
58
|
+
|
|
59
|
+
process.exit(1);
|
|
56
60
|
};
|
|
57
61
|
|
|
58
62
|
/**
|
|
@@ -62,22 +66,27 @@ export const assertRepoIsClean = async (
|
|
|
62
66
|
*/
|
|
63
67
|
const getGitStatus = async (
|
|
64
68
|
options?: Readonly<{ silent?: boolean }>,
|
|
65
|
-
): Promise<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
): Promise<
|
|
70
|
+
Result<
|
|
71
|
+
Readonly<{
|
|
72
|
+
isDirty: boolean;
|
|
73
|
+
stdout: string;
|
|
74
|
+
}>,
|
|
75
|
+
string
|
|
76
|
+
>
|
|
77
|
+
> => {
|
|
69
78
|
const res = await $('git status --porcelain', {
|
|
70
79
|
silent: options?.silent ?? false,
|
|
71
80
|
});
|
|
72
81
|
|
|
73
82
|
if (Result.isErr(res)) {
|
|
74
|
-
|
|
83
|
+
return Result.err(`Failed to get git status: ${res.value.message}`);
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
const { stdout } = res.value;
|
|
78
87
|
|
|
79
|
-
return {
|
|
88
|
+
return Result.ok({
|
|
80
89
|
isDirty: stdout.trim() !== '',
|
|
81
90
|
stdout,
|
|
82
|
-
};
|
|
91
|
+
});
|
|
83
92
|
};
|
package/src/functions/diff.mts
CHANGED
|
@@ -24,8 +24,8 @@ export const getUntrackedFiles = async (
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* Get
|
|
28
|
-
* git diff --
|
|
27
|
+
* Get modified files from the working tree (files that have been changed but
|
|
28
|
+
* not staged). Runs `git diff --name-only [--diff-filter=d]`
|
|
29
29
|
*/
|
|
30
30
|
export const getModifiedFiles = async (
|
|
31
31
|
options?: Readonly<{
|
|
@@ -39,7 +39,7 @@ export const getModifiedFiles = async (
|
|
|
39
39
|
> =>
|
|
40
40
|
cmdResultToFiles({
|
|
41
41
|
cmd: `git diff --name-only`,
|
|
42
|
-
cmdOptionToExcludeDeleted: '--diff-filter=d',
|
|
42
|
+
cmdOptionToExcludeDeleted: '--diff-filter=d', // lower case 'd' means exclude deleted files
|
|
43
43
|
cmdOptionToIncludeDeleted: '',
|
|
44
44
|
options,
|
|
45
45
|
});
|
|
@@ -60,7 +60,7 @@ export const getStagedFiles = async (
|
|
|
60
60
|
> =>
|
|
61
61
|
cmdResultToFiles({
|
|
62
62
|
cmd: `git diff --staged --name-only`,
|
|
63
|
-
cmdOptionToExcludeDeleted: '--diff-filter=d',
|
|
63
|
+
cmdOptionToExcludeDeleted: '--diff-filter=d', // lower case 'd' means exclude deleted files
|
|
64
64
|
cmdOptionToIncludeDeleted: '',
|
|
65
65
|
options,
|
|
66
66
|
});
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
exec,
|
|
3
|
-
type ExecException,
|
|
4
|
-
type ExecOptions as ExecOptions_,
|
|
5
|
-
} from 'node:child_process';
|
|
1
|
+
import * as childProcess from 'node:child_process';
|
|
6
2
|
import { Result } from 'ts-data-forge';
|
|
7
3
|
|
|
8
4
|
type ExecOptionsCustom = Readonly<{
|
|
9
5
|
silent?: boolean;
|
|
10
6
|
}>;
|
|
11
7
|
|
|
12
|
-
export type ExecOptions =
|
|
8
|
+
export type ExecOptions = childProcess.ExecOptions & ExecOptionsCustom;
|
|
13
9
|
|
|
14
10
|
export type ExecResult<T extends string | Buffer> = Result<
|
|
15
11
|
Readonly<{ stdout: T; stderr: T }>,
|
|
16
|
-
ExecException
|
|
12
|
+
childProcess.ExecException
|
|
17
13
|
>;
|
|
18
14
|
|
|
19
15
|
/**
|
|
@@ -23,23 +19,24 @@ export type ExecResult<T extends string | Buffer> = Result<
|
|
|
23
19
|
* @param options - Optional configuration for command execution.
|
|
24
20
|
* @returns A promise that resolves with the command result.
|
|
25
21
|
*/
|
|
22
|
+
|
|
26
23
|
export function $(
|
|
27
24
|
command: string,
|
|
28
|
-
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
26
|
+
options?:
|
|
27
|
+
| ExecOptionsCustom
|
|
28
|
+
| Readonly<{ encoding: BufferEncoding } & ExecOptions>,
|
|
29
29
|
): Promise<ExecResult<string>>;
|
|
30
30
|
|
|
31
31
|
export function $(
|
|
32
32
|
command: string,
|
|
33
|
-
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
34
|
+
options?: Readonly<{ encoding: 'buffer' | null } & ExecOptions>,
|
|
34
35
|
): Promise<ExecResult<Buffer>>;
|
|
35
36
|
|
|
36
37
|
export function $(
|
|
37
38
|
command: string,
|
|
38
|
-
|
|
39
|
-
): Promise<ExecResult<string>>;
|
|
40
|
-
|
|
41
|
-
export function $(
|
|
42
|
-
command: string,
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
43
40
|
options?: Readonly<
|
|
44
41
|
{ encoding?: BufferEncoding | 'buffer' | null } & ExecOptions
|
|
45
42
|
>,
|
|
@@ -52,28 +49,21 @@ export function $(
|
|
|
52
49
|
|
|
53
50
|
return new Promise((resolve) => {
|
|
54
51
|
// eslint-disable-next-line security/detect-child-process
|
|
55
|
-
exec(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
encoding?: 'buffer' | null | BufferEncoding;
|
|
60
|
-
} & ExecOptions_,
|
|
61
|
-
(error, stdout, stderr) => {
|
|
62
|
-
if (!silent) {
|
|
63
|
-
if (stdout !== '') {
|
|
64
|
-
echo(stdout);
|
|
65
|
-
}
|
|
66
|
-
if (stderr !== '') {
|
|
67
|
-
console.error(stderr);
|
|
68
|
-
}
|
|
52
|
+
childProcess.exec(command, restOptions, (error, stdout, stderr) => {
|
|
53
|
+
if (!silent) {
|
|
54
|
+
if (stdout !== '') {
|
|
55
|
+
echo(stdout);
|
|
69
56
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
resolve(Result.err(error));
|
|
73
|
-
} else {
|
|
74
|
-
resolve(Result.ok({ stdout, stderr }));
|
|
57
|
+
if (stderr !== '') {
|
|
58
|
+
console.error(stderr);
|
|
75
59
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (error !== null) {
|
|
63
|
+
resolve(Result.err(error));
|
|
64
|
+
} else {
|
|
65
|
+
resolve(Result.ok({ stdout, stderr }));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
78
68
|
});
|
|
79
69
|
}
|
package/src/functions/format.mts
CHANGED
|
@@ -20,16 +20,14 @@ export const formatFiles = async (
|
|
|
20
20
|
): Promise<Result<undefined, readonly unknown[]>> => {
|
|
21
21
|
const silent = options?.silent ?? false;
|
|
22
22
|
|
|
23
|
+
const conditionalEcho = silent ? () => {} : echo;
|
|
24
|
+
|
|
23
25
|
if (files.length === 0) {
|
|
24
|
-
|
|
25
|
-
echo('No files to format');
|
|
26
|
-
}
|
|
26
|
+
conditionalEcho('No files to format');
|
|
27
27
|
return Result.ok(undefined);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
echo(`Formatting ${files.length} files...`);
|
|
32
|
-
}
|
|
30
|
+
conditionalEcho(`Formatting ${files.length} files...`);
|
|
33
31
|
|
|
34
32
|
// Format each file
|
|
35
33
|
const results: readonly PromiseSettledResult<Result<undefined, unknown>>[] =
|
|
@@ -42,9 +40,7 @@ export const formatFiles = async (
|
|
|
42
40
|
await fs.access(filePath);
|
|
43
41
|
} catch {
|
|
44
42
|
// File doesn't exist, skip it
|
|
45
|
-
|
|
46
|
-
echo(`Skipping non-existent file: ${filePath}`);
|
|
47
|
-
}
|
|
43
|
+
conditionalEcho(`Skipping non-existent file: ${filePath}`);
|
|
48
44
|
return Result.ok(undefined);
|
|
49
45
|
}
|
|
50
46
|
|
|
@@ -60,9 +56,7 @@ export const formatFiles = async (
|
|
|
60
56
|
});
|
|
61
57
|
|
|
62
58
|
if (fileInfo.ignored) {
|
|
63
|
-
|
|
64
|
-
echo(`Skipping ignored file: ${filePath}`);
|
|
65
|
-
}
|
|
59
|
+
conditionalEcho(`Skipping ignored file: ${filePath}`);
|
|
66
60
|
return Result.ok(undefined);
|
|
67
61
|
}
|
|
68
62
|
|
|
@@ -74,14 +68,10 @@ export const formatFiles = async (
|
|
|
74
68
|
|
|
75
69
|
// Only write if content changed
|
|
76
70
|
if (formatted === content) {
|
|
77
|
-
|
|
78
|
-
echo(`Unchanged: ${filePath}`);
|
|
79
|
-
}
|
|
71
|
+
conditionalEcho(`Unchanged: ${filePath}`);
|
|
80
72
|
} else {
|
|
81
73
|
await fs.writeFile(filePath, formatted, 'utf8');
|
|
82
|
-
|
|
83
|
-
echo(`Formatted: ${filePath}`);
|
|
84
|
-
}
|
|
74
|
+
conditionalEcho(`Formatted: ${filePath}`);
|
|
85
75
|
}
|
|
86
76
|
|
|
87
77
|
return Result.ok(undefined);
|
|
@@ -124,6 +114,7 @@ export const formatFilesGlob = async (
|
|
|
124
114
|
options?: Readonly<{ silent?: boolean }>,
|
|
125
115
|
): Promise<Result<undefined, unknown>> => {
|
|
126
116
|
const silent = options?.silent ?? false;
|
|
117
|
+
const conditionalEcho = silent ? () => {} : echo;
|
|
127
118
|
|
|
128
119
|
try {
|
|
129
120
|
// Find all files matching the glob
|
|
@@ -134,9 +125,7 @@ export const formatFilesGlob = async (
|
|
|
134
125
|
});
|
|
135
126
|
|
|
136
127
|
if (files.length === 0) {
|
|
137
|
-
|
|
138
|
-
echo('No files found matching pattern:', pathGlob);
|
|
139
|
-
}
|
|
128
|
+
conditionalEcho('No files found matching pattern:', pathGlob);
|
|
140
129
|
return Result.ok(undefined);
|
|
141
130
|
}
|
|
142
131
|
|
|
@@ -260,6 +249,8 @@ export const formatDiffFrom = async (
|
|
|
260
249
|
includeStaged = true,
|
|
261
250
|
} = options ?? {};
|
|
262
251
|
|
|
252
|
+
const conditionalEcho = silent ? () => {} : echo;
|
|
253
|
+
|
|
263
254
|
// Get files that differ from base branch/commit (excluding deleted files)
|
|
264
255
|
const diffFromBaseResult = await getDiffFrom(base, {
|
|
265
256
|
silent,
|
|
@@ -317,13 +308,11 @@ export const formatDiffFrom = async (
|
|
|
317
308
|
.join(''),
|
|
318
309
|
].join('');
|
|
319
310
|
|
|
320
|
-
|
|
311
|
+
conditionalEcho(`${message}:`, allFiles);
|
|
321
312
|
}
|
|
322
313
|
|
|
323
314
|
if (allFiles.length === 0) {
|
|
324
|
-
|
|
325
|
-
echo('No files to format');
|
|
326
|
-
}
|
|
315
|
+
conditionalEcho('No files to format');
|
|
327
316
|
return Result.ok(undefined);
|
|
328
317
|
}
|
|
329
318
|
|