@kuldi/create-nestjs 1.0.0

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/cli.js +71 -0
  2. package/package.json +29 -0
package/bin/cli.js ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ const projectName = process.argv[2];
8
+
9
+ if (!projectName) {
10
+ console.error('\n❌ Tolong masukkan nama project!');
11
+ console.error('Contoh: npm create @kuldi/nestjs my-app');
12
+ console.error('Atau gunakan "." untuk install di folder saat ini: npm create @kuldi/nestjs .\n');
13
+ process.exit(1);
14
+ }
15
+
16
+ // Menangani jika user menggunakan titik (.) untuk current directory
17
+ const currentPath = process.cwd();
18
+ const projectPath = projectName === '.' ? currentPath : path.join(currentPath, projectName);
19
+ const gitRepo = 'https://github.com/bhagaskuro/boilerplate-nestJs.git';
20
+
21
+ try {
22
+ // Mengecek apakah target directory kosong (jika menggunakan .)
23
+ if (projectName === '.') {
24
+ const files = fs.readdirSync(currentPath);
25
+ if (files.length > 0) {
26
+ console.error('\n❌ Folder saat ini tidak kosong! Harap jalankan di folder kosong agar tidak menimpa file yang ada.\n');
27
+ process.exit(1);
28
+ }
29
+ }
30
+
31
+ console.log(`\n🚀 Mengunduh Kuli Digital NestJS Boilerplate ke ${projectPath}...`);
32
+
33
+ // 1. Clone repository
34
+ // Gunakan git clone ke folder sementara jika current dir agar tidak tabrakan,
35
+ // tapi berhubung git clone butuh folder kosong, aman.
36
+ execSync(`git clone --depth 1 ${gitRepo} "${projectPath}"`, { stdio: 'inherit' });
37
+
38
+ // 2. Masuk ke folder project
39
+ process.chdir(projectPath);
40
+
41
+ // 3. Hapus folder .git bawaan boilerplate
42
+ fs.rmSync(path.join(projectPath, '.git'), { recursive: true, force: true });
43
+
44
+ // Hapus juga folder create-nestjs agar tidak mengotori project user akhir
45
+ const cliFolder = path.join(projectPath, 'create-nestjs');
46
+ if (fs.existsSync(cliFolder)) {
47
+ fs.rmSync(cliFolder, { recursive: true, force: true });
48
+ }
49
+
50
+ // Inisialisasi ulang git baru
51
+ execSync('git init', { stdio: 'ignore' });
52
+
53
+ // 4. Install dependencies
54
+ console.log('\n📦 Meng-install dependencies (ini butuh waktu beberapa menit)...');
55
+ execSync('npm install', { stdio: 'inherit' });
56
+
57
+ console.log('\n✅ Project berhasil dibuat!');
58
+
59
+ if (projectName !== '.') {
60
+ console.log(`\nLangkah selanjutnya:`);
61
+ console.log(` cd ${projectName}`);
62
+ console.log(` npm run start:dev\n`);
63
+ } else {
64
+ console.log(`\nLangkah selanjutnya:`);
65
+ console.log(` npm run start:dev\n`);
66
+ }
67
+
68
+ } catch (error) {
69
+ console.error('\n❌ Gagal membuat project:', error.message);
70
+ process.exit(1);
71
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@kuldi/create-nestjs",
3
+ "version": "1.0.0",
4
+ "description": "Scaffolding tool for Kuli Digital NestJS Boilerplate",
5
+ "main": "bin/cli.js",
6
+ "bin": {
7
+ "create-nestjs": "./bin/cli.js",
8
+ "@kuldi/create-nestjs": "./bin/cli.js"
9
+ },
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/bhagaskuro/boilerplate-nestJs.git"
16
+ },
17
+ "keywords": [
18
+ "nestjs",
19
+ "boilerplate",
20
+ "kuli-digital",
21
+ "cli",
22
+ "create-nestjs"
23
+ ],
24
+ "author": "Kuli Digital",
25
+ "license": "MIT",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }