Skip to content

Commit 8f839ff

Browse files
committed
moved ui to ui folder frem gitignore
1 parent fc35c6e commit 8f839ff

2 files changed

Lines changed: 42 additions & 12 deletions

File tree

src/services/git.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import chalk from 'chalk';
3+
import { printGitignoreWarning } from '../ui/shared/printGitignore.js';
44

55
export type GitignoreCheckOptions = {
66
/** Project root directory (default: process.cwd()) */
@@ -86,27 +86,26 @@ export function warnIfEnvNotIgnored(options: GitignoreCheckOptions = {}): void {
8686

8787
const envPath = path.resolve(cwd, envFile);
8888
if (!fs.existsSync(envPath)) return; // No .env file → nothing to warn about
89-
9089
if (!isGitRepo(cwd)) return; // Not a git repo → skip
9190

9291
const gitignorePath = path.resolve(cwd, '.gitignore');
9392

9493
if (!fs.existsSync(gitignorePath)) {
95-
log(
96-
chalk.yellow(
97-
`⚠️ No .gitignore found – your ${envFile} may be committed.\n Add:\n ${envFile}\n ${envFile}.*\n`,
98-
),
99-
);
94+
printGitignoreWarning({
95+
envFile,
96+
reason: 'no-gitignore',
97+
log,
98+
});
10099
return;
101100
}
102101

103102
const ignored = isEnvIgnoredByGit({ cwd, envFile });
104103
if (ignored === false || ignored === null) {
105-
log(
106-
chalk.yellow(
107-
`⚠️ ${envFile} is not ignored by Git (.gitignore).\n Consider adding:\n ${envFile}\n ${envFile}.*\n`,
108-
),
109-
);
104+
printGitignoreWarning({
105+
envFile,
106+
reason: 'not-ignored',
107+
log,
108+
});
110109
}
111110
}
112111

src/ui/shared/printGitignore.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import chalk from 'chalk';
2+
3+
type GitignoreWarningOptions = {
4+
envFile: string;
5+
reason: 'no-gitignore' | 'not-ignored';
6+
log?: (msg: string) => void;
7+
};
8+
9+
export function printGitignoreWarning(options: GitignoreWarningOptions): void {
10+
const { envFile, reason, log = console.log } = options;
11+
12+
if (reason === 'no-gitignore') {
13+
log(
14+
chalk.yellow(
15+
`⚠️ No .gitignore found – your ${envFile} may be committed.\n` +
16+
` Add:\n` +
17+
` ${envFile}\n` +
18+
` ${envFile}.*\n`
19+
)
20+
);
21+
} else {
22+
log(
23+
chalk.yellow(
24+
`⚠️ ${envFile} is not ignored by Git (.gitignore).\n` +
25+
` Consider adding:\n` +
26+
` ${envFile}\n` +
27+
` ${envFile}.*\n`
28+
)
29+
);
30+
}
31+
}

0 commit comments

Comments
 (0)