-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (57 loc) · 1.84 KB
/
index.js
File metadata and controls
68 lines (57 loc) · 1.84 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const util = require("util");
const { exec } = require("child_process");
const path = require("path");
const runCommand = util.promisify(exec);
// Function to run npm install and npm build in a directory
const runNpmInstall = async (directory) => {
console.log(`Start npm install for ${directory}`);
try {
const { stdout, stderr } = await runCommand("npm install", {
cwd: directory,
});
} catch (err) {
console.error(`Error in ${directory}: ${err.message}`);
}
};
const runNpmBuild = async (directory) => {
console.log(`Start npm run build for ${directory}`);
try {
const { stdout, stderr } = await runCommand("npm run build", {
cwd: directory,
});
} catch (err) {
console.error(`Error in ${directory}: ${err.message}`);
}
};
// Function to run npm run start in a directory
const runNpmStart = async (directory) => {
console.log(`Start npm run start for ${directory}`);
try {
const { stdout, stderr } = await runCommand("npm run start &", {
cwd: directory,
});
} catch (err) {
console.error(`Error in ${directory}: ${err.message}`);
}
};
// Function to run npm commands in child directories
const runNpmCommands = async () => {
// Specify the paths to the child directories
const front = path.join(__dirname, "client");
const back = path.join(__dirname, "server");
// Run front
runNpmInstall(front).then(async () => {
await runNpmBuild(front);
console.log("\x1b[34mServer Front started with default port 3000\x1b[0m");
await runNpmStart(front);
});
// Run back
runNpmInstall(back).then(async () => {
console.log("\x1b[34mServer Back started with default port 3030\x1b[0m");
await runNpmStart(back);
});
};
// Call the function to run npm commands in child directories
runNpmCommands().catch((err) => {
console.error(`An error occurred: ${err.message}`);
});