Skip to content

Commit b9de5ea

Browse files
committed
added autofix to ui folder
1 parent 1fd3eac commit b9de5ea

2 files changed

Lines changed: 54 additions & 36 deletions

File tree

src/commands/compare.ts

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { printFixTips } from '../ui/compare/printFixTips.js';
1818
import { printStats } from '../ui/compare/printStats.js';
1919
import { printDuplicates } from '../ui/compare/printDuplicates.js';
2020
import { printHeader } from '../ui/compare/printHeader.js';
21+
import { printAutoFix } from '../ui/compare/printAutoFix.js';
2122

2223
/**
2324
* Compares multiple pairs of .env and .env.example files.
@@ -258,43 +259,15 @@ export async function compareMany(
258259
}
259260

260261
if (opts.fix) {
261-
const { changed, result } = applyFixes({
262-
envPath,
263-
examplePath,
264-
missingKeys: filtered.missing,
265-
duplicateKeys: dupsEnv.map((d) => d.key),
266-
});
262+
const { changed, result } = applyFixes({
263+
envPath,
264+
examplePath,
265+
missingKeys: filtered.missing,
266+
duplicateKeys: dupsEnv.map((d) => d.key),
267+
});
267268

268-
if (!opts.json) {
269-
if (changed) {
270-
console.log(chalk.green('✅ Auto-fix applied:'));
271-
if (result.removedDuplicates.length) {
272-
console.log(
273-
chalk.green(
274-
` - Removed ${result.removedDuplicates.length} duplicate keys from ${envName}: ${result.removedDuplicates.join(', ')}`,
275-
),
276-
);
277-
}
278-
if (result.addedEnv.length) {
279-
console.log(
280-
chalk.green(
281-
` - Added ${result.addedEnv.length} missing keys to ${envName}: ${result.addedEnv.join(', ')}`,
282-
),
283-
);
284-
}
285-
if (result.addedExample.length) {
286-
console.log(
287-
chalk.green(
288-
` - Synced ${result.addedExample.length} keys to ${exampleName}: ${result.addedExample.join(', ')}`,
289-
),
290-
);
291-
}
292-
} else {
293-
console.log(chalk.green('✅ Auto-fix applied: no changes needed.'));
294-
}
295-
console.log();
296-
}
297-
}
269+
printAutoFix(changed, result, envName, exampleName, opts.json);
270+
}
298271

299272
opts.collect?.(entry);
300273
const warningsExist =

src/ui/compare/printAutoFix.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import chalk from 'chalk';
2+
3+
export interface AutoFixResult {
4+
removedDuplicates: string[];
5+
addedEnv: string[];
6+
addedExample: string[];
7+
}
8+
9+
export function printAutoFix(
10+
changed: boolean,
11+
result: AutoFixResult,
12+
envName: string,
13+
exampleName: string,
14+
json: boolean | undefined,
15+
): void {
16+
if (json) return;
17+
18+
if (changed) {
19+
console.log(chalk.green('✅ Auto-fix applied:'));
20+
if (result.removedDuplicates.length) {
21+
console.log(
22+
chalk.green(
23+
` - Removed ${result.removedDuplicates.length} duplicate keys from ${envName}: ${result.removedDuplicates.join(', ')}`,
24+
),
25+
);
26+
}
27+
if (result.addedEnv.length) {
28+
console.log(
29+
chalk.green(
30+
` - Added ${result.addedEnv.length} missing keys to ${envName}: ${result.addedEnv.join(', ')}`,
31+
),
32+
);
33+
}
34+
if (result.addedExample.length) {
35+
console.log(
36+
chalk.green(
37+
` - Synced ${result.addedExample.length} keys to ${exampleName}: ${result.addedExample.join(', ')}`,
38+
),
39+
);
40+
}
41+
} else {
42+
console.log(chalk.green('✅ Auto-fix applied: no changes needed.'));
43+
}
44+
console.log();
45+
}

0 commit comments

Comments
 (0)