ts-repo-utils 6.1.0 → 7.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 +153 -33
- 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 +29 -8
- package/dist/cmd/format-diff-from.mjs.map +1 -1
- package/dist/cmd/format-uncommitted.d.mts +3 -0
- package/dist/cmd/format-uncommitted.d.mts.map +1 -0
- package/dist/cmd/format-uncommitted.mjs +59 -0
- package/dist/cmd/format-uncommitted.mjs.map +1 -0
- 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 +32 -2
- package/dist/functions/diff.d.mts.map +1 -1
- package/dist/functions/diff.mjs +47 -29
- package/dist/functions/diff.mjs.map +1 -1
- package/dist/functions/exec-async.d.mts +4 -4
- 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 +20 -11
- package/dist/functions/format.d.mts.map +1 -1
- package/dist/functions/format.mjs +136 -110
- 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/dist/functions/index.mjs +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
- 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 +35 -9
- package/src/cmd/format-uncommitted.mts +67 -0
- package/src/cmd/gen-index-ts.mts +1 -1
- package/src/functions/assert-repo-is-clean.mts +43 -34
- package/src/functions/diff.mts +85 -32
- package/src/functions/diff.test.mts +569 -102
- package/src/functions/exec-async.mts +21 -29
- package/src/functions/exec-async.test.mts +77 -47
- package/src/functions/format.mts +222 -150
- package/src/functions/format.test.mts +625 -20
- package/src/functions/gen-index.mts +16 -10
- package/src/functions/workspace-utils/run-cmd-in-stages.test.mts +266 -0
- package/dist/cmd/format-untracked.d.mts +0 -3
- package/dist/cmd/format-untracked.d.mts.map +0 -1
- package/dist/cmd/format-untracked.mjs +0 -34
- package/dist/cmd/format-untracked.mjs.map +0 -1
- package/src/cmd/format-untracked.mts +0 -31
|
@@ -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,EAAE,KAAK;AAC/B,IAAA,MAAM,EAAE,KAAK;CAGd;AAkBD;;;;;AAKG;MACU,QAAQ,GAAG,
|
|
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,EAAE,KAAK;AAC/B,IAAA,MAAM,EAAE,KAAK;CAGd;AAkBD;;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A,IAAA,IACE,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC;MACzB;AACA,QAAA,OAAO,KAAK;IACd;;IAGA,IACE,MAAM,CAAC,OAAO,CAAC;QACb,YAAY;AACZ,QAAA,YAAY,EAAE,QAAQ;QACtB,QAAQ;AACT,KAAA,CAAC,EACF;AACA,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,OAAO,IAAI;AACb,CAAC;AAqBD;;;;;;;AAOG;AACH,MAAM,oBAAoB,GAAG,CAC3B,cAAiC,EACjC,aAAgC,EAChC,MAA8B,KACpB;AACV,IAAA,MAAM,gBAAgB,GAAG;AACvB,QAAA,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,KAC3B,MAAM,CAAC,wBAAwB,KAAK;cAChC,CAAA,iBAAA,EAAoB,MAAM,CAAA,EAAA;cAC1B,oBAAoB,MAAM,CAAA,MAAA,EAAS,MAAM,CAAC,wBAAwB,IAAI,CAC3E;AACD,QAAA,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,KAAI;AAC5B,YAAA,MAAM,kBAAkB,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAElE,YAAA,OAAO,MAAM,CAAC,wBAAwB,KAAK;kBACvC,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/dist/functions/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { assertExt } from './assert-ext.mjs';
|
|
2
2
|
export { assertPathExists, pathExists } from './assert-path-exists.mjs';
|
|
3
3
|
export { assertRepoIsClean, repoIsDirty } from './assert-repo-is-clean.mjs';
|
|
4
|
-
export { getDiffFrom, getUntrackedFiles } from './diff.mjs';
|
|
4
|
+
export { getDiffFrom, getModifiedFiles, getStagedFiles, getUntrackedFiles } from './diff.mjs';
|
|
5
5
|
export { $ } from './exec-async.mjs';
|
|
6
|
-
export { formatDiffFrom, formatFiles,
|
|
6
|
+
export { formatDiffFrom, formatFiles, formatFilesGlob, formatUncommittedFiles } from './format.mjs';
|
|
7
7
|
export { genIndex } from './gen-index.mjs';
|
|
8
8
|
export { checkShouldRunTypeChecks } from './should-run.mjs';
|
|
9
9
|
export { executeParallel, executeStages } from './workspace-utils/execute-parallel.mjs';
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { assertExt } from './functions/assert-ext.mjs';
|
|
2
2
|
export { assertPathExists, pathExists } from './functions/assert-path-exists.mjs';
|
|
3
3
|
export { assertRepoIsClean, repoIsDirty } from './functions/assert-repo-is-clean.mjs';
|
|
4
|
-
export { getDiffFrom, getUntrackedFiles } from './functions/diff.mjs';
|
|
4
|
+
export { getDiffFrom, getModifiedFiles, getStagedFiles, getUntrackedFiles } from './functions/diff.mjs';
|
|
5
5
|
export { $ } from './functions/exec-async.mjs';
|
|
6
|
-
export { formatDiffFrom, formatFiles,
|
|
6
|
+
export { formatDiffFrom, formatFiles, formatFilesGlob, formatUncommittedFiles } from './functions/format.mjs';
|
|
7
7
|
export { genIndex } from './functions/gen-index.mjs';
|
|
8
8
|
export { checkShouldRunTypeChecks } from './functions/should-run.mjs';
|
|
9
9
|
export { executeParallel, executeStages } from './functions/workspace-utils/execute-parallel.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-repo-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"assert-repo-is-clean": "./src/cmd/assert-repo-is-clean.mts",
|
|
28
28
|
"check-should-run-type-checks": "./src/cmd/check-should-run-type-checks.mts",
|
|
29
29
|
"format-diff-from": "./src/cmd/format-diff-from.mts",
|
|
30
|
-
"format-
|
|
30
|
+
"format-uncommitted": "./src/cmd/format-uncommitted.mts",
|
|
31
31
|
"gen-index-ts": "./src/cmd/gen-index-ts.mts"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env -S npx tsx
|
|
2
2
|
|
|
3
3
|
import * as cmd from 'cmd-ts';
|
|
4
|
+
import { Result } from 'ts-data-forge';
|
|
4
5
|
import { formatDiffFrom } from '../functions/index.mjs';
|
|
5
6
|
|
|
6
7
|
const cmdDef = cmd.command({
|
|
7
8
|
name: 'format-diff-from-cli',
|
|
8
|
-
version: '
|
|
9
|
+
version: '7.0.0',
|
|
9
10
|
args: {
|
|
10
11
|
base: cmd.positional({
|
|
11
12
|
type: cmd.string,
|
|
12
13
|
displayName: 'base',
|
|
13
14
|
description: 'Base branch name or commit hash to compare against',
|
|
14
15
|
}),
|
|
15
|
-
|
|
16
|
-
long: '
|
|
16
|
+
excludeUntracked: cmd.flag({
|
|
17
|
+
long: 'exclude-untracked',
|
|
17
18
|
type: cmd.optional(cmd.boolean),
|
|
18
19
|
description:
|
|
19
|
-
'
|
|
20
|
+
'Exclude untracked files in addition to diff files (default: false)',
|
|
21
|
+
}),
|
|
22
|
+
excludeModified: cmd.flag({
|
|
23
|
+
long: 'exclude-modified',
|
|
24
|
+
type: cmd.optional(cmd.boolean),
|
|
25
|
+
description:
|
|
26
|
+
'Exclude modified files in addition to diff files (default: false)',
|
|
27
|
+
}),
|
|
28
|
+
excludeStaged: cmd.flag({
|
|
29
|
+
long: 'exclude-staged',
|
|
30
|
+
type: cmd.optional(cmd.boolean),
|
|
31
|
+
description:
|
|
32
|
+
'Exclude staged files in addition to diff files (default: false)',
|
|
20
33
|
}),
|
|
21
34
|
silent: cmd.flag({
|
|
22
35
|
long: 'silent',
|
|
@@ -25,7 +38,13 @@ const cmdDef = cmd.command({
|
|
|
25
38
|
}),
|
|
26
39
|
},
|
|
27
40
|
handler: (args) => {
|
|
28
|
-
main(
|
|
41
|
+
main({
|
|
42
|
+
base: args.base,
|
|
43
|
+
excludeUntracked: args.excludeUntracked ?? false,
|
|
44
|
+
excludeModified: args.excludeModified ?? false,
|
|
45
|
+
excludeStaged: args.excludeStaged ?? false,
|
|
46
|
+
silent: args.silent ?? false,
|
|
47
|
+
}).catch((error) => {
|
|
29
48
|
console.error('An error occurred:', error);
|
|
30
49
|
process.exit(1);
|
|
31
50
|
});
|
|
@@ -35,13 +54,20 @@ const cmdDef = cmd.command({
|
|
|
35
54
|
const main = async (
|
|
36
55
|
args: Readonly<{
|
|
37
56
|
base: string;
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
excludeUntracked: boolean;
|
|
58
|
+
excludeModified: boolean;
|
|
59
|
+
excludeStaged: boolean;
|
|
60
|
+
silent: boolean;
|
|
40
61
|
}>,
|
|
41
62
|
): Promise<void> => {
|
|
42
|
-
const result = await formatDiffFrom(args.base,
|
|
63
|
+
const result = await formatDiffFrom(args.base, {
|
|
64
|
+
includeUntracked: !args.excludeUntracked,
|
|
65
|
+
includeModified: !args.excludeModified,
|
|
66
|
+
includeStaged: !args.excludeStaged,
|
|
67
|
+
silent: args.silent,
|
|
68
|
+
});
|
|
43
69
|
|
|
44
|
-
if (result
|
|
70
|
+
if (Result.isErr(result)) {
|
|
45
71
|
process.exit(1);
|
|
46
72
|
}
|
|
47
73
|
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env -S npx tsx
|
|
2
|
+
|
|
3
|
+
import * as cmd from 'cmd-ts';
|
|
4
|
+
import { Result } from 'ts-data-forge';
|
|
5
|
+
import { formatUncommittedFiles } from '../functions/index.mjs';
|
|
6
|
+
|
|
7
|
+
const cmdDef = cmd.command({
|
|
8
|
+
name: 'format-uncommitted-cli',
|
|
9
|
+
version: '7.0.0',
|
|
10
|
+
args: {
|
|
11
|
+
excludeUntracked: cmd.flag({
|
|
12
|
+
long: 'exclude-untracked',
|
|
13
|
+
type: cmd.optional(cmd.boolean),
|
|
14
|
+
description:
|
|
15
|
+
'Exclude untracked files in addition to diff files (default: false)',
|
|
16
|
+
}),
|
|
17
|
+
excludeModified: cmd.flag({
|
|
18
|
+
long: 'exclude-modified',
|
|
19
|
+
type: cmd.optional(cmd.boolean),
|
|
20
|
+
description:
|
|
21
|
+
'Exclude modified files in addition to diff files (default: false)',
|
|
22
|
+
}),
|
|
23
|
+
excludeStaged: cmd.flag({
|
|
24
|
+
long: 'exclude-staged',
|
|
25
|
+
type: cmd.optional(cmd.boolean),
|
|
26
|
+
description:
|
|
27
|
+
'Exclude staged files in addition to diff files (default: false)',
|
|
28
|
+
}),
|
|
29
|
+
silent: cmd.flag({
|
|
30
|
+
long: 'silent',
|
|
31
|
+
type: cmd.optional(cmd.boolean),
|
|
32
|
+
description: 'If true, suppresses output messages (default: false)',
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
handler: (args) => {
|
|
36
|
+
main({
|
|
37
|
+
excludeUntracked: args.excludeUntracked ?? false,
|
|
38
|
+
excludeModified: args.excludeModified ?? false,
|
|
39
|
+
excludeStaged: args.excludeStaged ?? false,
|
|
40
|
+
silent: args.silent ?? false,
|
|
41
|
+
}).catch((error) => {
|
|
42
|
+
console.error('An error occurred:', error);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const main = async (
|
|
49
|
+
args: Readonly<{
|
|
50
|
+
excludeUntracked: boolean;
|
|
51
|
+
excludeModified: boolean;
|
|
52
|
+
excludeStaged: boolean;
|
|
53
|
+
silent: boolean;
|
|
54
|
+
}>,
|
|
55
|
+
): Promise<void> => {
|
|
56
|
+
const result = await formatUncommittedFiles({
|
|
57
|
+
untracked: !args.excludeUntracked,
|
|
58
|
+
modified: !args.excludeModified,
|
|
59
|
+
staged: !args.excludeStaged,
|
|
60
|
+
silent: args.silent,
|
|
61
|
+
});
|
|
62
|
+
if (Result.isErr(result)) {
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
await cmd.run(cmdDef, process.argv.slice(2));
|
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
|
@@ -2,7 +2,10 @@ import { type ExecException } from 'node:child_process';
|
|
|
2
2
|
import { Result } from 'ts-data-forge';
|
|
3
3
|
import '../node-global.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Get untracked files from the working tree (files not added to git). Runs `git
|
|
7
|
+
* ls-files --others --exclude-standard [--deleted]`
|
|
8
|
+
*/
|
|
6
9
|
export const getUntrackedFiles = async (
|
|
7
10
|
options?: Readonly<{
|
|
8
11
|
/** @default true */
|
|
@@ -12,35 +15,60 @@ export const getUntrackedFiles = async (
|
|
|
12
15
|
}>,
|
|
13
16
|
): Promise<
|
|
14
17
|
Result<readonly string[], ExecException | Readonly<{ message: string }>>
|
|
15
|
-
> =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
]
|
|
23
|
-
.filter((s) => s !== '')
|
|
24
|
-
.join(' '),
|
|
25
|
-
{ silent: options?.silent ?? false },
|
|
26
|
-
);
|
|
18
|
+
> =>
|
|
19
|
+
cmdResultToFiles({
|
|
20
|
+
cmd: `git ls-files --others --exclude-standard`,
|
|
21
|
+
cmdOptionToExcludeDeleted: '',
|
|
22
|
+
cmdOptionToIncludeDeleted: '--deleted',
|
|
23
|
+
options,
|
|
24
|
+
});
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
/**
|
|
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
|
+
*/
|
|
30
|
+
export const getModifiedFiles = async (
|
|
31
|
+
options?: Readonly<{
|
|
32
|
+
/** @default true */
|
|
33
|
+
excludeDeleted?: boolean;
|
|
34
|
+
/** @default false */
|
|
35
|
+
silent?: boolean;
|
|
36
|
+
}>,
|
|
37
|
+
): Promise<
|
|
38
|
+
Result<readonly string[], ExecException | Readonly<{ message: string }>>
|
|
39
|
+
> =>
|
|
40
|
+
cmdResultToFiles({
|
|
41
|
+
cmd: `git diff --name-only`,
|
|
42
|
+
cmdOptionToExcludeDeleted: '--diff-filter=d', // lower case 'd' means exclude deleted files
|
|
43
|
+
cmdOptionToIncludeDeleted: '',
|
|
44
|
+
options,
|
|
45
|
+
});
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Get files that are staged for commit (files added with git add). Runs `git
|
|
49
|
+
* diff --staged --name-only [--diff-filter=d]`
|
|
50
|
+
*/
|
|
51
|
+
export const getStagedFiles = async (
|
|
52
|
+
options?: Readonly<{
|
|
53
|
+
/** @default true */
|
|
54
|
+
excludeDeleted?: boolean;
|
|
55
|
+
/** @default false */
|
|
56
|
+
silent?: boolean;
|
|
57
|
+
}>,
|
|
58
|
+
): Promise<
|
|
59
|
+
Result<readonly string[], ExecException | Readonly<{ message: string }>>
|
|
60
|
+
> =>
|
|
61
|
+
cmdResultToFiles({
|
|
62
|
+
cmd: `git diff --staged --name-only`,
|
|
63
|
+
cmdOptionToExcludeDeleted: '--diff-filter=d', // lower case 'd' means exclude deleted files
|
|
64
|
+
cmdOptionToIncludeDeleted: '',
|
|
65
|
+
options,
|
|
66
|
+
});
|
|
42
67
|
|
|
43
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Get files that differ from the specified base branch or commit. Runs `git
|
|
70
|
+
* diff --name-only <base> [--diff-filter=d]`
|
|
71
|
+
*/
|
|
44
72
|
export const getDiffFrom = async (
|
|
45
73
|
base: string,
|
|
46
74
|
options?: Readonly<{
|
|
@@ -51,13 +79,38 @@ export const getDiffFrom = async (
|
|
|
51
79
|
}>,
|
|
52
80
|
): Promise<
|
|
53
81
|
Result<readonly string[], ExecException | Readonly<{ message: string }>>
|
|
82
|
+
> =>
|
|
83
|
+
cmdResultToFiles({
|
|
84
|
+
cmd: `git diff --name-only ${base}`,
|
|
85
|
+
cmdOptionToExcludeDeleted: '--diff-filter=d',
|
|
86
|
+
cmdOptionToIncludeDeleted: '',
|
|
87
|
+
options,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const cmdResultToFiles = async ({
|
|
91
|
+
cmd,
|
|
92
|
+
cmdOptionToExcludeDeleted,
|
|
93
|
+
cmdOptionToIncludeDeleted,
|
|
94
|
+
options,
|
|
95
|
+
}: Readonly<{
|
|
96
|
+
cmd: string;
|
|
97
|
+
cmdOptionToExcludeDeleted: string;
|
|
98
|
+
cmdOptionToIncludeDeleted: string;
|
|
99
|
+
options?: Readonly<{
|
|
100
|
+
/** @default true */
|
|
101
|
+
excludeDeleted?: boolean;
|
|
102
|
+
/** @default false */
|
|
103
|
+
silent?: boolean;
|
|
104
|
+
}>;
|
|
105
|
+
}>): Promise<
|
|
106
|
+
Result<readonly string[], ExecException | Readonly<{ message: string }>>
|
|
54
107
|
> => {
|
|
55
|
-
// Get files that differ from base branch/commit (excluding deleted files)
|
|
56
108
|
const result = await $(
|
|
57
109
|
[
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
110
|
+
cmd,
|
|
111
|
+
(options?.excludeDeleted ?? true)
|
|
112
|
+
? cmdOptionToExcludeDeleted
|
|
113
|
+
: cmdOptionToIncludeDeleted,
|
|
61
114
|
]
|
|
62
115
|
.filter((s) => s !== '')
|
|
63
116
|
.join(' '),
|
|
@@ -70,7 +123,7 @@ export const getDiffFrom = async (
|
|
|
70
123
|
|
|
71
124
|
const { stdout } = result.value;
|
|
72
125
|
|
|
73
|
-
// Parse git
|
|
126
|
+
// Parse git output
|
|
74
127
|
const files = stdout
|
|
75
128
|
.split('\n')
|
|
76
129
|
.map((line) => line.trim())
|