-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
96 lines (69 loc) · 2.91 KB
/
gulpfile.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const { series, parallel } = require("gulp");
const spawn = require("child_process").spawn;
const copyFile = require("node:fs/promises").copyFile;
const rimraf = require("rimraf");
const path = require("path");
const clientsSources = ["workspace-platform/", "react-client/"];
const builtClients = ["intents-resolver-ui/"];
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
process.stdout.write = (chunk, encoding, callback) => {
if (chunk === '\x1B[2J\x1B[0f' || chunk === '\x1B[2J\x1B[3J\x1B[H') {
return;
}
return originalStdoutWrite(chunk, encoding, callback);
};
const installAllDeps = (client) => async () => {
return new Promise((resolve, reject) => {
console.log(`Installing dependencies in ${client}`);
spawn("npm", ["install"], { cwd: `${client}`, stdio: "inherit", shell: true }).on("close", resolve).on("error", reject);
});
};
const clearNodeModules = (client) => () => {
return new Promise((resolve, reject) => {
const node_modulesPath = path.join(__dirname, client, "node_modules", "*");
console.log(`Deleting: ${node_modulesPath}`);
rimraf(node_modulesPath, (err) => {
if (err) {
return reject(err);
}
console.log(`Deleted: ${node_modulesPath}`);
resolve()
});
});
};
const copyPlatformConfig = async () => {
await copyFile(path.join(__dirname, "config.json"), path.join(__dirname, "workspace-platform", "src", "config.json"));
};
const buildProdApp = (client) => async () => {
return new Promise((resolve, reject) => {
console.log(`Building prod bundle of ${client}`);
const child = spawn("npm", ["run", "build"], { cwd: `${client}`, shell: true }).on("close", resolve).on("error", reject);
child.stdout.on('data', process.stdout.write);
});
};
const startApp = (client) => async () => {
return new Promise((resolve, reject) => {
console.log(`Starting ${client}`);
const child = spawn("npm", ["start"], { cwd: `${client}`, shell: true }).on("close", resolve).on("error", reject);
child.stdout.on('data', process.stdout.write);
});
};
const startBuildClient = (client) => async () => {
return new Promise((resolve, reject) => {
console.log(`Starting ${client}`);
spawn("http-server", [`${client}`, "-p", "4221"], { stdio: "inherit", shell: true }).on("close", resolve).on("error", reject);
});
};
exports.bootstrap = series(
parallel(clientsSources.map((client) => clearNodeModules(client))),
parallel(clientsSources.map((client) => installAllDeps(client))),
copyPlatformConfig
);
exports.build = parallel(clientsSources.map((client) => buildProdApp(client)));
exports.start = parallel(
...clientsSources.map((client) => startApp(client)),
...builtClients.map((client) => startBuildClient(client))
);
exports.updateConfig = series(
copyPlatformConfig
);