-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
43 lines (34 loc) · 1.44 KB
/
setup.js
File metadata and controls
43 lines (34 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const { execSync, spawn } = require('child_process');
const path = require('path');
function runSyncCommand(command, directory = '.') {
try {
const fullPath = path.join(__dirname, directory);
console.log(`\n👉 Đang chạy: "${command}" trong thư mục: ${fullPath}`);
execSync(command, { cwd: fullPath, stdio: 'inherit' });
} catch (error) {
console.error(`❌ Lỗi khi chạy lệnh "${command}" trong thư mục ${directory}:`, error.message);
process.exit(1);
}
}
function runDevCommand(command, directory = '.', label = 'PROCESS') {
const fullPath = path.join(__dirname, directory);
const child = spawn(command, { cwd: fullPath, shell: true });
child.stdout.on('data', (data) => {
process.stdout.write(`[${label}] ${data}`);
});
child.stderr.on('data', (data) => {
process.stderr.write(`[${label} ERROR] ${data}`);
});
child.on('close', (code) => {
console.log(`\n🔚 [${label}] kết thúc với mã: ${code}`);
});
}
// ====== CÀI ĐẶT ======
console.log('\n🚀 Bắt đầu cài đặt...');
runSyncCommand('npm install');
runSyncCommand('npm install', 'FE');
// ====== KHỞI CHẠY ======
console.log('\n⚡ Đang khởi chạy cả hai server...');
runDevCommand('npm run dev', '.', 'MAIN');
runDevCommand('npm run dev', 'FE', 'FE');
console.log('\n🎉 Tất cả đã được khởi động. Hãy theo dõi log ở phía trên!');