create-jinmankn-app 1.0.1 → 1.0.2

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 +54 -27
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const fs = require('fs-extra');
4
4
  const path = require('path');
@@ -9,54 +9,80 @@ async function createProject() {
9
9
  const projectName = process.argv[2];
10
10
 
11
11
  if (!projectName) {
12
+ console.log('');
12
13
  console.log('Please provide a project name.');
13
- console.log('Example: npx create-jinmama-app my-app');
14
+ console.log('');
15
+ console.log('Example:');
16
+ console.log('npx create-jinmankn-app my-app');
14
17
  process.exit(1);
15
18
  }
16
19
 
20
+ const templatesDir = path.join(__dirname, '../templates');
21
+
22
+ // Automatically read all template folders
23
+ const templates = fs
24
+ .readdirSync(templatesDir)
25
+ .filter((file) =>
26
+ fs.statSync(path.join(templatesDir, file)).isDirectory()
27
+ );
28
+
29
+ if (templates.length === 0) {
30
+ console.log('No templates found.');
31
+ process.exit(1);
32
+ }
33
+
34
+ // Ask user to choose template
17
35
  const answers = await inquirer.prompt([
18
36
  {
19
37
  type: 'list',
20
38
  name: 'template',
21
- message: 'Select a project template:',
22
- choices: [
23
- 'blueprint',
24
- 'chom',
25
- 'hospital-faisal'
26
- ]
27
- }
39
+ message: 'Select a template:',
40
+ choices: templates,
41
+ },
28
42
  ]);
29
43
 
30
44
  const selectedTemplate = answers.template;
31
45
 
32
46
  const currentDir = process.cwd();
47
+
33
48
  const projectPath = path.join(currentDir, projectName);
34
49
 
35
50
  const templatePath = path.join(
36
- __dirname,
37
- `../templates/${selectedTemplate}`
51
+ templatesDir,
52
+ selectedTemplate
38
53
  );
39
54
 
40
55
  console.log('');
41
56
  console.log(`Creating ${selectedTemplate} project...`);
57
+ console.log('');
42
58
 
59
+ // Copy template files
43
60
  fs.copySync(templatePath, projectPath);
44
61
 
45
- console.log('');
46
- console.log('Installing frontend dependencies...');
62
+ // Install frontend dependencies
63
+ const frontendPath = path.join(projectPath, 'frontend');
47
64
 
48
- execSync('npm install', {
49
- cwd: path.join(projectPath, 'frontend'),
50
- stdio: 'inherit',
51
- });
65
+ if (fs.existsSync(frontendPath)) {
66
+ console.log('Installing frontend dependencies...');
52
67
 
53
- console.log('');
54
- console.log('Installing backend dependencies...');
68
+ execSync('npm install', {
69
+ cwd: frontendPath,
70
+ stdio: 'inherit',
71
+ });
72
+ }
73
+
74
+ // Install backend dependencies
75
+ const backendPath = path.join(projectPath, 'backend');
55
76
 
56
- execSync('npm install', {
57
- cwd: path.join(projectPath, 'backend'),
58
- stdio: 'inherit',
59
- });
77
+ if (fs.existsSync(backendPath)) {
78
+ console.log('');
79
+ console.log('Installing backend dependencies...');
80
+
81
+ execSync('npm install', {
82
+ cwd: backendPath,
83
+ stdio: 'inherit',
84
+ });
85
+ }
60
86
 
61
87
  console.log('');
62
88
  console.log('Project created successfully!');
@@ -64,13 +90,14 @@ async function createProject() {
64
90
 
65
91
  console.log(`cd ${projectName}`);
66
92
 
67
- console.log('');
68
- console.log('Run backend:');
69
- console.log('cd backend && npm run dev');
70
-
71
93
  console.log('');
72
94
  console.log('Run frontend:');
73
95
  console.log('cd frontend && npm run dev');
96
+
97
+ console.log('');
98
+
99
+ console.log('Run backend:');
100
+ console.log('cd backend && npm run dev');
74
101
  }
75
102
 
76
103
  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.2",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "create-jinmankn-app": "./bin/index.js"