Skip to content

Commit

Permalink
Merge pull request #46 from expressots/45-rename-envexample-to-env-du…
Browse files Browse the repository at this point in the history
…ring-project-creation

fix: add coverage folder to eslint ignore pattern
  • Loading branch information
rsaz committed Apr 29, 2024
2 parents 416595f + 93f9c83 commit 0413d03
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
"commitlint.config.ts",
"vitest.config.ts",
".eslintrc.cjs",
"coverage/*",
],
rules: {
"@typescript-eslint/interface-name-prefix": "off",
Expand Down
38 changes: 34 additions & 4 deletions src/new/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,21 @@ async function packageManagerInstall({
});

installProcess.stdout.on("data", (data: Buffer) => {
progressBar.increment(5, {
doing: `${data.toString().trim()}`,
});
const output = data.toString().trim();

const npmProgressMatch = output.match(
/\[(\d+)\/(\d+)\] (?:npm )?([\w\s]+)\.{3}/,
);

if (npmProgressMatch) {
const [, current, total, task] = npmProgressMatch;
const progress = Math.round(
(parseInt(current) / parseInt(total)) * 100,
);
progressBar.update(progress, { doing: task });
} else {
progressBar.increment(5, { doing: output });
}
});

installProcess.on("close", (code) => {
Expand Down Expand Up @@ -79,6 +91,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 @@ -195,7 +223,7 @@ const projectForm = async (projectName: string, args: any[]): Promise<void> => {
"| {percentage}% || {doing}",
hideCursor: true,
},
Presets.shades_classic,
Presets.rect,
);

progressBar.start(100, 0, {
Expand Down Expand Up @@ -236,6 +264,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 0413d03

Please sign in to comment.