-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (33 loc) · 1.18 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
#!/usr/bin/env node
import prompts from "prompts";
import fs from "fs-extra";
import path from "path";
import { execSync } from "child_process";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
(async () => {
const response = await prompts([
{
type: "text",
name: "projectName",
message: "Enter your project name:",
validate: name => (name ? true : "Project name cannot be empty."),
},
]);
const projectName = response.projectName;
const projectPath = path.join(process.cwd(), projectName);
try {
console.log(`\nCreating project directory: ${projectName}`);
fs.ensureDirSync(projectPath);
console.log("\nScaffolding project...");
const templatePath = path.join(__dirname, "template");
fs.copySync(templatePath, projectPath);
console.log("\nInstalling dependencies...");
execSync("npm install", { stdio: "inherit", cwd: projectPath });
console.log("\nProject setup complete!");
console.log(`\nTo get started:\n cd ${projectName}\n npm run dev`);
} catch (error) {
console.error("Error creating project:", error.message);
}
})();