@kuldi/create-nestjs 1.1.5 ā 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.
- package/package.json +1 -1
- package/src/cli.js +46 -7
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -18,18 +18,22 @@ 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
24
|
// 1. Tanya Project Name
|
|
23
25
|
const { projectName } = await inquirer.prompt([
|
|
24
26
|
{
|
|
25
27
|
type: 'input',
|
|
26
28
|
name: 'projectName',
|
|
27
|
-
message: 'Project Name
|
|
28
|
-
default:
|
|
29
|
+
message: 'Project Name:',
|
|
30
|
+
default: defaultName,
|
|
29
31
|
}
|
|
30
32
|
]);
|
|
31
33
|
|
|
32
|
-
const
|
|
34
|
+
const isCurrentDir = isCurrentDirArg || projectName === '.';
|
|
35
|
+
const projectPath = isCurrentDir ? currentPath : path.join(currentPath, projectName);
|
|
36
|
+
const finalProjectName = projectName === '.' ? path.basename(currentPath) : projectName;
|
|
33
37
|
|
|
34
38
|
// 2. Cek apakah folder kosong (Overwrite Check)
|
|
35
39
|
if (fs.existsSync(projectPath)) {
|
|
@@ -57,7 +61,7 @@ async function run() {
|
|
|
57
61
|
type: 'input',
|
|
58
62
|
name: 'database',
|
|
59
63
|
message: 'PostgreSQL Database Name:',
|
|
60
|
-
default:
|
|
64
|
+
default: `${finalProjectName}_db`,
|
|
61
65
|
},
|
|
62
66
|
{
|
|
63
67
|
type: 'confirm',
|
|
@@ -112,14 +116,49 @@ async function run() {
|
|
|
112
116
|
envSpinner.fail('Failed to configure .env file.');
|
|
113
117
|
}
|
|
114
118
|
|
|
115
|
-
// 4.
|
|
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
|
|
116
155
|
try {
|
|
117
156
|
execSync('git init', { stdio: 'ignore' });
|
|
118
157
|
} catch (e) {
|
|
119
158
|
// Ignore if git is not installed
|
|
120
159
|
}
|
|
121
160
|
|
|
122
|
-
//
|
|
161
|
+
// 6. Install Dependencies
|
|
123
162
|
if (!answers.skipInstall) {
|
|
124
163
|
const installSpinner = ora(`Installing dependencies using npm... (this may take a few minutes)`).start();
|
|
125
164
|
try {
|
|
@@ -131,7 +170,7 @@ async function run() {
|
|
|
131
170
|
}
|
|
132
171
|
}
|
|
133
172
|
|
|
134
|
-
//
|
|
173
|
+
// 7. Success Message
|
|
135
174
|
console.log(chalk.green.bold('\nā
Project successfully created!\n'));
|
|
136
175
|
console.log(chalk.white('Next steps:'));
|
|
137
176
|
|