create-jinmankn-app 1.0.1 → 1.0.3

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 +101 -51
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -1,76 +1,126 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
- const fs = require('fs-extra');
4
- const path = require('path');
5
- const { execSync } = require('child_process');
6
- const inquirer = require('inquirer').default;
3
+ const inquirer = require("inquirer").default;
4
+ const fs = require("fs-extra");
5
+ const path = require("path");
6
+ const ora = require("ora").default;
7
+ const chalk = require("chalk");
8
+ const { execSync } = require("child_process");
7
9
 
8
- async function createProject() {
9
- const projectName = process.argv[2];
10
+ const templatesDir = path.join(__dirname, "../templates");
10
11
 
11
- if (!projectName) {
12
- console.log('Please provide a project name.');
13
- console.log('Example: npx create-jinmama-app my-app');
14
- process.exit(1);
15
- }
12
+ // Check templates folder exists
13
+ if (!fs.existsSync(templatesDir)) {
14
+ console.log(chalk.red("Templates folder not found!"));
15
+ process.exit(1);
16
+ }
17
+
18
+ // Get templates automatically
19
+ const templates = fs
20
+ .readdirSync(templatesDir)
21
+ .filter((dir) =>
22
+ fs.lstatSync(path.join(templatesDir, dir)).isDirectory()
23
+ );
16
24
 
25
+ // No templates check
26
+ if (templates.length === 0) {
27
+ console.log(chalk.red("No templates found!"));
28
+ process.exit(1);
29
+ }
30
+
31
+ async function createProject() {
32
+ // Prompt user
17
33
  const answers = await inquirer.prompt([
18
34
  {
19
- type: 'list',
20
- name: 'template',
21
- message: 'Select a project template:',
22
- choices: [
23
- 'blueprint',
24
- 'chom',
25
- 'hospital-faisal'
26
- ]
35
+ type: "input",
36
+ name: "projectName",
37
+ message: "Project name:"
38
+ },
39
+ {
40
+ type: "list",
41
+ name: "template",
42
+ message: "Choose a template:",
43
+ choices: templates.map((t) => ({
44
+ name: t,
45
+ value: t
46
+ }))
27
47
  }
28
48
  ]);
29
49
 
30
- const selectedTemplate = answers.template;
31
-
32
- const currentDir = process.cwd();
33
- const projectPath = path.join(currentDir, projectName);
50
+ const projectPath = path.join(
51
+ process.cwd(),
52
+ answers.projectName
53
+ );
34
54
 
35
55
  const templatePath = path.join(
36
- __dirname,
37
- `../templates/${selectedTemplate}`
56
+ templatesDir,
57
+ answers.template
38
58
  );
39
59
 
40
- console.log('');
41
- console.log(`Creating ${selectedTemplate} project...`);
60
+ // Prevent overwrite
61
+ if (fs.existsSync(projectPath)) {
62
+ console.log(chalk.red("Folder already exists!"));
63
+ process.exit(1);
64
+ }
65
+
66
+ // Spinner
67
+ const spinner = ora("Creating project...").start();
68
+
69
+ try {
70
+ // Copy template
71
+ await fs.copy(templatePath, projectPath);
72
+
73
+ // Install frontend dependencies
74
+ const frontendPath = path.join(projectPath, "frontend");
75
+
76
+ if (fs.existsSync(frontendPath)) {
77
+ spinner.text = "Installing frontend dependencies...";
42
78
 
43
- fs.copySync(templatePath, projectPath);
79
+ execSync("npm install", {
80
+ cwd: frontendPath,
81
+ stdio: "inherit"
82
+ });
83
+ }
84
+
85
+ // Install backend dependencies
86
+ const backendPath = path.join(projectPath, "backend");
87
+
88
+ if (fs.existsSync(backendPath)) {
89
+ spinner.text = "Installing backend dependencies...";
44
90
 
45
- console.log('');
46
- console.log('Installing frontend dependencies...');
91
+ execSync("npm install", {
92
+ cwd: backendPath,
93
+ stdio: "inherit"
94
+ });
95
+ }
96
+
97
+ spinner.succeed(
98
+ chalk.green("Project created successfully!")
99
+ );
47
100
 
48
- execSync('npm install', {
49
- cwd: path.join(projectPath, 'frontend'),
50
- stdio: 'inherit',
51
- });
101
+ console.log("\n");
52
102
 
53
- console.log('');
54
- console.log('Installing backend dependencies...');
103
+ console.log(chalk.cyan("Next steps:"));
55
104
 
56
- execSync('npm install', {
57
- cwd: path.join(projectPath, 'backend'),
58
- stdio: 'inherit',
59
- });
105
+ console.log(
106
+ chalk.white(`cd ${answers.projectName}`)
107
+ );
60
108
 
61
- console.log('');
62
- console.log('Project created successfully!');
63
- console.log('');
109
+ console.log(
110
+ chalk.white("cd frontend && npm run dev")
111
+ );
64
112
 
65
- console.log(`cd ${projectName}`);
113
+ console.log(
114
+ chalk.white("cd backend && npm run dev")
115
+ );
66
116
 
67
- console.log('');
68
- console.log('Run backend:');
69
- console.log('cd backend && npm run dev');
117
+ } catch (err) {
118
+ spinner.fail(
119
+ chalk.red("Failed to create project")
120
+ );
70
121
 
71
- console.log('');
72
- console.log('Run frontend:');
73
- console.log('cd frontend && npm run dev');
122
+ console.log(err);
123
+ }
74
124
  }
75
125
 
76
126
  createProject();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-jinmankn-app",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "create-jinmankn-app": "./bin/index.js"