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