create-cedro-app 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/index.js +92 -13
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -1,46 +1,125 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const inquirer = require("inquirer");
4
4
  const fs = require("fs-extra");
5
5
  const path = require("path");
6
6
  const ora = require("ora");
7
7
  const chalk = require("chalk");
8
+ const { execSync } = require("child_process");
8
9
 
9
10
  async function run() {
10
11
  const answers = await inquirer.prompt([
12
+ {
13
+ type: "list",
14
+ name: "template",
15
+ message: "Choose a project template:",
16
+ choices: [
17
+ {
18
+ name: "1. Employee Management System",
19
+ value: "employee-management-system",
20
+ },
21
+ {
22
+ name: "2. Stock Management System",
23
+ value: "stock-management-system",
24
+ },
25
+ {
26
+ name: "3. Library Management System",
27
+ value: "library-management-system",
28
+ },
29
+ ],
30
+ },
31
+
11
32
  {
12
33
  type: "input",
13
34
  name: "projectName",
14
- message: "Enter project folder name:"
15
- }
35
+ message: "Enter project folder name:",
36
+ validate: (input) => {
37
+ if (!input) {
38
+ return "Project name is required";
39
+ }
40
+ return true;
41
+ },
42
+ },
16
43
  ]);
17
44
 
18
45
  const targetPath = path.join(process.cwd(), answers.projectName);
19
46
 
20
- // FIX: check if folder exists
47
+ // CHECK IF FOLDER EXISTS
21
48
  if (fs.existsSync(targetPath)) {
22
49
  console.log(chalk.red("❌ Folder already exists!"));
23
50
  process.exit(1);
24
51
  }
25
52
 
26
- const spinner = ora("Creating project from local template...").start();
53
+ const spinner = ora("Creating project...").start();
27
54
 
28
55
  try {
29
- // SOURCE TEMPLATE PATH (IMPORTANT)
56
+ // TEMPLATE PATH
30
57
  const templatePath = path.join(
31
58
  __dirname,
32
- "../templates/employee-management-system"
59
+ `../templates/${answers.template}`
33
60
  );
34
61
 
35
- // COPY TEMPLATE → NEW PROJECT
62
+ // CHECK TEMPLATE EXISTS
63
+ if (!fs.existsSync(templatePath)) {
64
+ spinner.fail("❌ Template not found!");
65
+ process.exit(1);
66
+ }
67
+
68
+ // COPY TEMPLATE
36
69
  await fs.copy(templatePath, targetPath);
37
70
 
38
- spinner.succeed("Template copied successfully!");
71
+ spinner.text = "Installing dependencies...";
72
+
73
+ // =========================
74
+ // INSTALL CLIENT
75
+ // =========================
76
+
77
+ const clientPath = path.join(targetPath, "client");
78
+
79
+ if (fs.existsSync(clientPath)) {
80
+ console.log(chalk.cyan("\nInstalling client dependencies...\n"));
81
+
82
+ execSync("npm install", {
83
+ cwd: clientPath,
84
+ stdio: "inherit",
85
+ });
86
+ }
87
+
88
+ // =========================
89
+ // INSTALL SERVER
90
+ // =========================
39
91
 
40
- console.log(chalk.green("\n✅ Project created successfully!"));
41
- console.log(chalk.blue(`\ncd ${answers.projectName}`));
42
- console.log(chalk.blue("npm install"));
43
- console.log(chalk.blue("npm run dev"));
92
+ const serverPath = path.join(targetPath, "server");
93
+
94
+ if (fs.existsSync(serverPath)) {
95
+ console.log(chalk.cyan("\nInstalling server dependencies...\n"));
96
+
97
+ execSync("npm install", {
98
+ cwd: serverPath,
99
+ stdio: "inherit",
100
+ });
101
+ }
102
+
103
+ spinner.succeed("✅ Project created successfully!");
104
+
105
+ // =========================
106
+ // START CLIENT
107
+ // =========================
108
+
109
+ const clientPackageJson = path.join(clientPath, "package.json");
110
+
111
+ if (fs.existsSync(clientPackageJson)) {
112
+ const clientPkg = fs.readJsonSync(clientPackageJson);
113
+
114
+ if (clientPkg.scripts && clientPkg.scripts.dev) {
115
+ console.log(chalk.green("\n🚀 Starting client...\n"));
116
+
117
+ execSync("npm run dev", {
118
+ cwd: clientPath,
119
+ stdio: "inherit",
120
+ });
121
+ }
122
+ }
44
123
 
45
124
  } catch (err) {
46
125
  spinner.fail("❌ Failed to create project");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cedro-app",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "bin": {
5
5
  "create-cedro-app": "./bin/index.js"
6
6
  },