-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (58 loc) · 1.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /usr/bin/env node
import { input, select } from "@inquirer/prompts";
import chalk from "chalk";
import banner from "./banner.js";
import createExpressProject from "./projects/createExpressProject.js";
import createReactProject from "./projects/createReactApp.js";
// Improved error handling
process.on("unhandledRejection", (err) => {
console.error(chalk.red("Error creating project:"), err);
process.exit(1);
});
process.on("SIGINT", () => {
console.log(chalk.yellow("\nProcess terminated by user."));
process.exit(0);
});
async function main() {
console.log(chalk.yellowBright(banner));
console.log(chalk.bgRedBright(`Welcome to the make-project CLI`));
const projectName = await input({
message: chalk.blue("Enter the project name ❓: "),
validate: (input) => input.trim() !== "" || "Project name cannot be empty",
});
const projectType = await select({
message: "Select project type ⚙️",
choices: [
{
name: "React",
value: "react",
description: "React is a JavaScript library for building user interfaces",
},
{
name: "Express",
value: "express",
description: "Express is a minimal and flexible Node.js web application framework",
},
],
});
try {
switch (projectType) {
case "react":
await createReactProject(projectName);
break;
case "express":
await createExpressProject(projectName);
break;
default:
throw new Error(`Unsupported project type: ${projectType}`);
}
console.log(chalk.green(`✅ Project "${projectName}" created successfully!`));
} catch (error) {
console.error(chalk.red(`Error creating project: ${error.message}`));
process.exit(1);
}
}
main().catch((err) => {
console.error(chalk.red("Unexpected error:"), err);
process.exit(1);
});