-
Notifications
You must be signed in to change notification settings - Fork 23
/
postbuild.js
49 lines (43 loc) · 1.55 KB
/
postbuild.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
// Copy the client into the server
// Copying everything into a build folder in the root would require having @monopoly-money/game-state as a dependency in the root.
// This would create a circular dependency and cause issues. Instead we just use the server package build as our build that we run.
const fs = require("fs");
const path = require("path");
const clientSource = "packages/client/build";
const serverDestination = "packages/server/build/client";
function deleteFolderRecursive(folderPath) {
// src: https://stackoverflow.com/a/20920795
if (fs.existsSync(folderPath)) {
fs.readdirSync(folderPath).forEach(function (file) {
var curPath = folderPath + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) {
// recurse
deleteFolderRecursive(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(folderPath);
}
}
function copyRecursiveSync(src, dest) {
// src: https://stackoverflow.com/a/22185855
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest);
fs.readdirSync(src).forEach(function (childItemName) {
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest);
}
}
// Make sure destination is empty
if (fs.existsSync(serverDestination)) {
deleteFolderRecursive(serverDestination);
}
// Copy the built client
copyRecursiveSync(clientSource, serverDestination);