create-laju-app 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 +74 -0
  2. package/package.json +7 -0
package/bin/cli.js ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { program } = require('commander');
4
+ const prompts = require('prompts');
5
+ const degit = require('degit');
6
+ const path = require('path');
7
+ const fs = require('fs');
8
+
9
+ program
10
+ .name('create-my-app')
11
+ .description('CLI untuk membuat proyek baru dari template')
12
+ .version('1.0.0');
13
+
14
+ program
15
+ .argument('[project-directory]', 'Nama direktori proyek')
16
+ .action(async (projectDirectory) => {
17
+ try {
18
+ // Jika tidak ada nama proyek, tanya user
19
+ if (!projectDirectory) {
20
+ const response = await prompts({
21
+ type: 'text',
22
+ name: 'projectDirectory',
23
+ message: 'Masukkan nama proyek:'
24
+ });
25
+ projectDirectory = response.projectDirectory;
26
+ }
27
+
28
+ if (!projectDirectory) {
29
+ console.log('Nama proyek diperlukan untuk melanjutkan.');
30
+ process.exit(1);
31
+ }
32
+
33
+ const targetPath = path.resolve(projectDirectory);
34
+
35
+ // Cek apakah direktori sudah ada
36
+ if (fs.existsSync(targetPath)) {
37
+ console.log(`Direktori ${projectDirectory} sudah ada. Pilih nama lain.`);
38
+ process.exit(1);
39
+ }
40
+
41
+ console.log(`Creating a new project in ${targetPath}...`);
42
+
43
+ // Clone template dari GitHub
44
+ const emitter = degit('maulanashalihin/laju');
45
+
46
+ await emitter.clone(targetPath);
47
+
48
+ // Baca package.json dari template
49
+ const packageJsonPath = path.join(targetPath, 'package.json');
50
+ const packageJson = require(packageJsonPath);
51
+
52
+ // Update nama proyek di package.json
53
+ packageJson.name = projectDirectory;
54
+
55
+ // Tulis kembali package.json
56
+ fs.writeFileSync(
57
+ packageJsonPath,
58
+ JSON.stringify(packageJson, null, 2)
59
+ );
60
+
61
+ console.log('✅ Project berhasil dibuat!');
62
+ console.log('');
63
+ console.log('Untuk memulai:');
64
+ console.log(` cd ${projectDirectory}`);
65
+ console.log(' npm install');
66
+ console.log(' npm run dev');
67
+
68
+ } catch (error) {
69
+ console.error('Error:', error.message);
70
+ process.exit(1);
71
+ }
72
+ });
73
+
74
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "create-laju-app",
3
+ "version": "1.0.0",
4
+ "bin": {
5
+ "create-laju-app": "./bin/cli.js"
6
+ }
7
+ }