|
1 | | -import path from 'path'; |
2 | 1 | import { scanCodebase } from '../services/codeBaseScanner.js'; |
3 | 2 | import type { |
4 | 3 | ScanUsageOptions, |
5 | 4 | EnvUsage, |
6 | | - Filtered, |
7 | 5 | ScanResult, |
8 | 6 | } from '../config/types.js'; |
9 | 7 | import { determineComparisonFile } from '../core/determineComparisonFile.js'; |
10 | 8 | import { outputToConsole } from '../services/scanOutputToConsole.js'; |
11 | 9 | import { createJsonOutput } from '../core/scanJsonOutput.js'; |
12 | | -import { isEnvIgnoredByGit } from '../services/git.js'; |
13 | | -import { printFixTips } from '../ui/shared/printFixTips.js'; |
14 | 10 | import { printMissingExample } from '../ui/scan/printMissingExample.js'; |
15 | 11 | import { processComparisonFile } from '../core/processComparisonFile.js'; |
16 | | -import { printAutoFix } from '../ui/compare/printAutoFix.js'; |
17 | 12 | import { printComparisonError } from '../ui/scan/printComparisonError.js'; |
18 | 13 |
|
19 | 14 | /** |
@@ -94,6 +89,8 @@ export async function scanUsage( |
94 | 89 | let removedDuplicates: string[] = []; |
95 | 90 | let gitignoreUpdated = false; |
96 | 91 |
|
| 92 | + // If comparing against a file, process it |
| 93 | + // fx: if the scan is comparing against .env.example, it will check for missing keys there |
97 | 94 | if (compareFile) { |
98 | 95 | const result = processComparisonFile(scanResult, compareFile, opts); |
99 | 96 |
|
@@ -141,45 +138,13 @@ export async function scanUsage( |
141 | 138 | }; |
142 | 139 | } |
143 | 140 |
|
144 | | - const filtered: Filtered = { |
145 | | - missing: scanResult.missing ?? [], |
146 | | - duplicatesEnv: dupsEnv, |
147 | | - duplicatesEx: dupsExample, |
148 | | - gitignoreIssue: |
149 | | - isEnvIgnoredByGit({ cwd: opts.cwd, envFile: '.env' }) === false || |
150 | | - isEnvIgnoredByGit({ cwd: opts.cwd, envFile: '.env' }) === null |
151 | | - ? { reason: 'not-ignored' } |
152 | | - : null, |
153 | | - }; |
154 | | - |
155 | 141 | // Console output |
156 | | - const result = outputToConsole(scanResult, opts, comparedAgainst); |
157 | | - |
158 | | - // Consolidated fix message |
159 | | - if (opts.fix) { |
160 | | - printAutoFix( |
161 | | - fixApplied, |
162 | | - { |
163 | | - removedDuplicates, |
164 | | - addedEnv: fixedKeys, |
165 | | - addedExample: opts.examplePath ? fixedKeys : [], |
166 | | - }, |
167 | | - comparedAgainst || '.env', |
168 | | - opts.examplePath ? path.basename(opts.examplePath) : 'example file', |
169 | | - opts.json ?? false, |
170 | | - gitignoreUpdated, |
171 | | - ); |
172 | | - } |
173 | | - |
174 | | - const ignored = isEnvIgnoredByGit({ cwd: opts.cwd, envFile: '.env' }); |
175 | | - const envNotIgnored = ignored === false || ignored === null; |
176 | | - |
177 | | - printFixTips( |
178 | | - filtered, |
179 | | - envNotIgnored, |
180 | | - opts.json ?? false, |
181 | | - opts.fix ?? false, |
182 | | - ); |
| 142 | + const result = outputToConsole(scanResult, opts, comparedAgainst, { |
| 143 | + fixApplied, |
| 144 | + removedDuplicates, |
| 145 | + addedEnv: fixedKeys, |
| 146 | + gitignoreUpdated, |
| 147 | + }); |
183 | 148 |
|
184 | 149 | return { exitWithError: result.exitWithError || duplicatesFound }; |
185 | 150 | } |
0 commit comments