@kuldi/create-nestjs 1.1.4 → 1.1.8

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/package.json +1 -1
  2. package/src/cli.js +65 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuldi/create-nestjs",
3
- "version": "1.1.4",
3
+ "version": "1.1.8",
4
4
  "type": "module",
5
5
  "description": "Scaffolding tool for Kuli Digital NestJS Boilerplate",
6
6
  "main": "src/cli.js",
package/src/cli.js CHANGED
@@ -18,34 +18,24 @@ async function run() {
18
18
  console.log(chalk.cyan.bold('\nšŸš€ Kuli Digital NestJS Boilerplate Generator\n'));
19
19
 
20
20
  const argProjectName = process.argv[2];
21
+ const isCurrentDirArg = argProjectName === '.';
22
+ const defaultName = isCurrentDirArg ? path.basename(currentPath) : (argProjectName || 'my-nestjs-app');
21
23
 
22
- // 1. Tanya-tanya
23
- const answers = await inquirer.prompt([
24
+ // 1. Tanya Project Name
25
+ const { projectName } = await inquirer.prompt([
24
26
  {
25
27
  type: 'input',
26
28
  name: 'projectName',
27
- message: 'Project Name (or . for current directory):',
28
- default: argProjectName || 'my-nestjs-app',
29
- when: !argProjectName,
30
- },
31
- {
32
- type: 'input',
33
- name: 'database',
34
- message: 'PostgreSQL Database Name:',
35
- default: 'kulidigital_db',
36
- },
37
- {
38
- type: 'confirm',
39
- name: 'skipInstall',
40
- message: 'Skip package installation (npm install)?',
41
- default: false,
42
- },
29
+ message: 'Project Name:',
30
+ default: defaultName,
31
+ }
43
32
  ]);
44
33
 
45
- const projectName = argProjectName || answers.projectName;
46
- const projectPath = projectName === '.' ? currentPath : path.join(currentPath, projectName);
34
+ const isCurrentDir = isCurrentDirArg || projectName === '.';
35
+ const projectPath = isCurrentDir ? currentPath : path.join(currentPath, projectName);
36
+ const finalProjectName = projectName === '.' ? path.basename(currentPath) : projectName;
47
37
 
48
- // Check if target directory is empty
38
+ // 2. Cek apakah folder kosong (Overwrite Check)
49
39
  if (fs.existsSync(projectPath)) {
50
40
  const files = fs.readdirSync(projectPath).filter(f => !f.startsWith('.git'));
51
41
  if (files.length > 0) {
@@ -65,6 +55,22 @@ async function run() {
65
55
  }
66
56
  }
67
57
 
58
+ // 3. Tanya Database & Setup
59
+ const answers = await inquirer.prompt([
60
+ {
61
+ type: 'input',
62
+ name: 'database',
63
+ message: 'PostgreSQL Database Name:',
64
+ default: `${finalProjectName}_db`,
65
+ },
66
+ {
67
+ type: 'confirm',
68
+ name: 'skipInstall',
69
+ message: 'Skip package installation (npm install)?',
70
+ default: false,
71
+ },
72
+ ]);
73
+
68
74
  // 2. Salin Template
69
75
  const copySpinner = ora('Generating project structure...').start();
70
76
  try {
@@ -110,14 +116,49 @@ async function run() {
110
116
  envSpinner.fail('Failed to configure .env file.');
111
117
  }
112
118
 
113
- // 4. Initialize Git
119
+ // 4. Update package.json & README.md
120
+ const configSpinner = ora('Configuring project details...').start();
121
+ try {
122
+ // Update package.json
123
+ const pkgPath = path.join(projectPath, 'package.json');
124
+ if (fs.existsSync(pkgPath)) {
125
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
126
+ pkg.name = finalProjectName;
127
+ pkg.description = `${finalProjectName} Application`;
128
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
129
+ }
130
+
131
+ // Update README.md
132
+ const readmePath = path.join(projectPath, 'README.md');
133
+ if (fs.existsSync(readmePath)) {
134
+ let readmeContent = fs.readFileSync(readmePath, 'utf-8');
135
+ readmeContent = readmeContent.replace(/<h1>šŸ— Kuli Digital NestJS Backend<\/h1>/g, `<h1>šŸ— ${finalProjectName} Backend</h1>`);
136
+ readmeContent = readmeContent.replace(/<p>The standard backend application architecture built with NestJS following the <b>Kuli Digital Standardization Manual<\/b>\.<\/p>/g, `<p>Backend application for ${finalProjectName}.</p>`);
137
+ fs.writeFileSync(readmePath, readmeContent);
138
+ }
139
+
140
+ // Update Swagger config in main.ts
141
+ const mainTsPath = path.join(projectPath, 'src', 'main.ts');
142
+ if (fs.existsSync(mainTsPath)) {
143
+ let mainTsContent = fs.readFileSync(mainTsPath, 'utf-8');
144
+ mainTsContent = mainTsContent.replace(/\.setTitle\('Kuli Digital Standard API'\)/g, `.setTitle('${finalProjectName} API')`);
145
+ mainTsContent = mainTsContent.replace(/\.setDescription\('Kuli Digital NestJS Backend API Documentation'\)/g, `.setDescription('${finalProjectName} Backend API Documentation')`);
146
+ fs.writeFileSync(mainTsPath, mainTsContent);
147
+ }
148
+
149
+ configSpinner.succeed('Project details configured successfully.');
150
+ } catch (error) {
151
+ configSpinner.fail('Failed to configure project details.');
152
+ }
153
+
154
+ // 5. Initialize Git
114
155
  try {
115
156
  execSync('git init', { stdio: 'ignore' });
116
157
  } catch (e) {
117
158
  // Ignore if git is not installed
118
159
  }
119
160
 
120
- // 5. Install Dependencies
161
+ // 6. Install Dependencies
121
162
  if (!answers.skipInstall) {
122
163
  const installSpinner = ora(`Installing dependencies using npm... (this may take a few minutes)`).start();
123
164
  try {
@@ -129,7 +170,7 @@ async function run() {
129
170
  }
130
171
  }
131
172
 
132
- // 6. Success Message
173
+ // 7. Success Message
133
174
  console.log(chalk.green.bold('\nāœ… Project successfully created!\n'));
134
175
  console.log(chalk.white('Next steps:'));
135
176