Skip to content

Commit

Permalink
feat: rename .env.example to .env during project creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Apr 29, 2024
1 parent 61c4df1 commit 94bc93d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/new/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ function changePackageName({
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
}

function renameEnvFile(directory: string): void {
try {
const envExamplePath = path.join(directory, ".env.example");
const envPath = path.join(directory, ".env");

if (!fs.existsSync(envExamplePath)) {
throw new Error(`File not found: ${envExamplePath}`);
}

fs.renameSync(envExamplePath, envPath);
} catch (error: any) {
printError("Error renaming .env.example file", ".env.example to .env");
process.exit(1);
}
}

enum Template {
"non-opinionated" = "Non-Opinionated :: Allows users to choose where to scaffold resources, offering flexible project organization.",
opinionated = "Opinionated :: Automatically scaffolds resources into a preset project structure. (Recommended)",
Expand Down Expand Up @@ -236,6 +252,8 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {
name: projName,
});

renameEnvFile(answer.name);

progressBar.update(100);

progressBar.stop();
Expand Down

0 comments on commit 94bc93d

Please sign in to comment.