File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import fs from 'fs' ;
22import path from 'path' ;
3- import chalk from 'chalk ' ;
3+ import { printGitignoreWarning } from '../ui/shared/printGitignore.js ' ;
44
55export 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments