11import fs from 'fs' ;
22import path from 'path' ;
3- import chalk from 'chalk' ;
43import { confirmYesNo } from '../ui/prompts.js' ;
54import { warnIfEnvNotIgnored } from './git.js' ;
5+ import { printPrompt } from '../ui/compare/printPrompt.js' ;
66
77/**
88 * Ensures that the necessary .env files exist or prompts the user to create them.
@@ -26,6 +26,7 @@ export async function ensureFilesOrPrompt(args: {
2626 isYesMode,
2727 isCiMode,
2828 } = args ;
29+
2930 const envPath = path . resolve ( cwd , primaryEnv ) ;
3031 const examplePath = path . resolve ( cwd , primaryExample ) ;
3132 const envExists = fs . existsSync ( envPath ) ;
@@ -35,60 +36,53 @@ export async function ensureFilesOrPrompt(args: {
3536 if ( ! envExists && ! exampleExists ) {
3637 const hasAnyEnv = fs . readdirSync ( cwd ) . some ( ( f ) => f . startsWith ( '.env' ) ) ;
3738 if ( ! hasAnyEnv ) {
38- console . log (
39- chalk . yellow (
40- '⚠️ No .env* or .env.example file found. Skipping comparison.' ,
41- ) ,
42- ) ;
39+ printPrompt . noEnvFound ( ) ;
4340 return { didCreate : false , shouldExit : true , exitCode : 0 } ;
4441 }
4542 }
4643
4744 // Case 2: missing .env but has .env.example
4845 if ( ! envExists && exampleExists ) {
4946 if ( ! alreadyWarnedMissingEnv ) {
50- console . log ( ) ;
51- console . log ( chalk . yellow ( `📄 ${ path . basename ( envPath ) } file not found.` ) ) ;
47+ printPrompt . missingEnv ( envPath ) ;
5248 }
53- let createEnv = isYesMode
49+
50+ const createEnv = isYesMode
5451 ? true
5552 : isCiMode
56- ? false
57- : await confirmYesNo (
58- `❓ Do you want to create a new ${ path . basename ( envPath ) } file from ${ path . basename ( examplePath ) } ?` ,
59- { isCiMode, isYesMode } ,
60- ) ;
53+ ? false
54+ : await confirmYesNo (
55+ `❓ Do you want to create a new ${ path . basename ( envPath ) } file from ${ path . basename ( examplePath ) } ?` ,
56+ { isCiMode, isYesMode } ,
57+ ) ;
6158
6259 if ( ! createEnv ) {
63- console . log ( chalk . gray ( '🚫 Skipping .env creation.' ) ) ;
60+ printPrompt . skipCreation ( ' .env' ) ;
6461 return { didCreate : false , shouldExit : true , exitCode : 0 } ;
6562 }
63+
6664 const exampleContent = fs . readFileSync ( examplePath , 'utf-8' ) ;
6765 fs . writeFileSync ( envPath , exampleContent ) ;
68- console . log (
69- chalk . green (
70- `✅ ${ path . basename ( envPath ) } file created successfully from ${ path . basename ( examplePath ) } .` ,
71- ) ,
72- ) ;
66+ printPrompt . envCreated ( envPath , examplePath ) ;
67+
7368 warnIfEnvNotIgnored ( { envFile : path . basename ( envPath ) } ) ;
7469 }
7570
7671 // Case 3: has .env but is missing .env.example
7772 if ( envExists && ! exampleExists ) {
78- console . log (
79- chalk . yellow ( `📄 ${ path . basename ( examplePath ) } file not found.` ) ,
80- ) ;
81- let createExample = isYesMode
73+ printPrompt . missingEnv ( examplePath ) ;
74+
75+ const createExample = isYesMode
8276 ? true
8377 : isCiMode
84- ? false
85- : await confirmYesNo (
86- `❓ Do you want to create a new ${ path . basename ( examplePath ) } file from ${ path . basename ( envPath ) } ?` ,
87- { isCiMode, isYesMode } ,
88- ) ;
78+ ? false
79+ : await confirmYesNo (
80+ `❓ Do you want to create a new ${ path . basename ( examplePath ) } file from ${ path . basename ( envPath ) } ?` ,
81+ { isCiMode, isYesMode } ,
82+ ) ;
8983
9084 if ( ! createExample ) {
91- console . log ( chalk . gray ( '🚫 Skipping .env.example creation.' ) ) ;
85+ printPrompt . skipCreation ( ' .env.example' ) ;
9286 return { didCreate : false , shouldExit : true , exitCode : 0 } ;
9387 }
9488
@@ -104,11 +98,7 @@ export async function ensureFilesOrPrompt(args: {
10498 . join ( '\n' ) ;
10599
106100 fs . writeFileSync ( examplePath , envContent ) ;
107- console . log (
108- chalk . green (
109- `✅ ${ path . basename ( examplePath ) } file created successfully from ${ path . basename ( envPath ) } .` ,
110- ) ,
111- ) ;
101+ printPrompt . exampleCreated ( examplePath , envPath ) ;
112102 }
113103
114104 return { didCreate : true , shouldExit : false , exitCode : 0 } ;
0 commit comments