create-synapse-mfe 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.
- package/bin/index.js +78 -0
- package/package.json +27 -0
package/bin/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const readline = require('readline');
|
|
7
|
+
|
|
8
|
+
// TODO: Anda perlu membuat repository kosong di GitHub bernama "synapse-template"
|
|
9
|
+
// dan memindahkan (push) versi polos dari Arsitektur MFE kita ke sana.
|
|
10
|
+
const GIT_REPO = 'https://github.com/rfkokt/synapse-template.git';
|
|
11
|
+
|
|
12
|
+
const runCommand = (command, options = {}) => {
|
|
13
|
+
try {
|
|
14
|
+
execSync(command, { stdio: 'inherit', ...options });
|
|
15
|
+
return true;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error(`\x1b[31mGagal mengeksekusi:\x1b[0m ${command}`, error.message);
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const rl = readline.createInterface({
|
|
23
|
+
input: process.stdin,
|
|
24
|
+
output: process.stdout,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log('\x1b[36m%s\x1b[0m', '🚀 Welcome to create-synapse-mfe CLI!');
|
|
28
|
+
console.log('Scaffolding a Vite-powered Micro-Frontend Architecture...');
|
|
29
|
+
|
|
30
|
+
const getProjectName = () => {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
if (process.argv[2]) {
|
|
33
|
+
resolve(process.argv[2]);
|
|
34
|
+
} else {
|
|
35
|
+
rl.question('\n\x1b[33m? Nama direktori proyek Anda:\x1b[0m (nashta-mfe-app) ', (answer) => {
|
|
36
|
+
resolve(answer.trim() || 'nashta-mfe-app');
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
(async () => {
|
|
43
|
+
const projectName = await getProjectName();
|
|
44
|
+
const currentDir = process.cwd();
|
|
45
|
+
const projectPath = path.join(currentDir, projectName);
|
|
46
|
+
|
|
47
|
+
if (fs.existsSync(projectPath)) {
|
|
48
|
+
console.error(`\n\x1b[31m❌ Error: Folder "${projectName}" sudah ada! Harap pilih nama lain.\x1b[0m`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
console.log(`\n\x1b[32m📦 Mengkloning blueprint MFE ke dalam \x1b[1m${projectName}\x1b[0m...\x1b[0m`);
|
|
53
|
+
|
|
54
|
+
const cloneCmd = `git clone --depth 1 ${GIT_REPO} "${projectName}"`;
|
|
55
|
+
if (!runCommand(cloneCmd)) {
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
console.log(`\n\x1b[32m🧹 Membersihkan jejak git lama (Re-initializing)...\x1b[0m`);
|
|
60
|
+
const gitFolder = path.join(projectPath, '.git');
|
|
61
|
+
if (fs.existsSync(gitFolder)) {
|
|
62
|
+
fs.rmSync(gitFolder, { recursive: true, force: true });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.log(`\x1b[32m🌱 Memulai repositori Git baru...\x1b[0m`);
|
|
66
|
+
runCommand(`git init`, { cwd: projectPath });
|
|
67
|
+
|
|
68
|
+
console.log(`\n\x1b[36m✨ Berhasil! Proyek "\x1b[1m${projectName}\x1b[0m\x1b[36m" telah siap.\n`);
|
|
69
|
+
console.log('Langkah selanjutnya yang harus Anda lakukan:');
|
|
70
|
+
console.log(`\x1b[33m cd ${projectName}\x1b[0m`);
|
|
71
|
+
console.log('\x1b[33m pnpm install\x1b[0m');
|
|
72
|
+
console.log('\x1b[33m pnpm run dev:new\n\x1b[0m');
|
|
73
|
+
|
|
74
|
+
console.log('\x1b[35mSelamat Mengoding Micro-Frontend! ⚛️\x1b[0m\n');
|
|
75
|
+
|
|
76
|
+
rl.close();
|
|
77
|
+
process.exit(0);
|
|
78
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-synapse-mfe",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Scaffolding tool to create a new Synapse Micro-Frontend workspace",
|
|
5
|
+
"main": "bin/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-synapse-mfe": "bin/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node bin/index.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"micro-frontend",
|
|
14
|
+
"mfe",
|
|
15
|
+
"synapse",
|
|
16
|
+
"vite",
|
|
17
|
+
"react"
|
|
18
|
+
],
|
|
19
|
+
"author": "Synapse",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18.0.0"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
}
|
|
27
|
+
}
|