diff options
Diffstat (limited to 'bundle/scripts/build.js')
-rw-r--r-- | bundle/scripts/build.js | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/bundle/scripts/build.js b/bundle/scripts/build.js index 88d76d34..4f56694c 100644 --- a/bundle/scripts/build.js +++ b/bundle/scripts/build.js @@ -1,6 +1,7 @@ const { execSync } = require("child_process"); const path = require("path"); const fse = require("fs-extra"); +const fs = require("fs"); const { getSystemErrorMap } = require("util"); const { argv } = require("process"); @@ -8,21 +9,41 @@ const dirs = ["api", "util", "cdn", "gateway", "bundle"]; const verbose = argv.includes("verbose") || argv.includes("v"); +var copyRecursiveSync = function(src, dest) { + if(verbose) console.log(`cpsync: ${src} -> ${dest}`); + var exists = fs.existsSync(src); + if(!exists){ + console.log(src + " doesn't exist, not copying!"); + return; + } + var stats = exists && fs.statSync(src); + var isDirectory = exists && stats.isDirectory(); + if (isDirectory) { + fs.mkdirSync(dest, {recursive: true}); + fs.readdirSync(src).forEach(function(childItemName) { + copyRecursiveSync(path.join(src, childItemName), + path.join(dest, childItemName)); + }); + } else { + fs.copyFileSync(src, dest); + } + }; + if (argv.includes("clean")) { dirs.forEach((a) => { var d = "../" + a + "/dist"; - if (fse.existsSync(d)) { - fse.rmSync(d, { recursive: true }); + if (fs.existsSync(d)) { + fs.rmSync(d, { recursive: true }); if (verbose) console.log(`Deleted ${d}!`); } }); } -fse.copySync(path.join(__dirname, "..", "..", "api", "assets"), path.join(__dirname, "..", "dist", "api", "assets")); -fse.copySync(path.join(__dirname, "..", "..", "api", "client_test"), path.join(__dirname, "..", "dist", "api", "client_test")); -fse.copySync(path.join(__dirname, "..", "..", "api", "locales"), path.join(__dirname, "..", "dist", "api", "locales")); +copyRecursiveSync(path.join(__dirname, "..", "..", "api", "assets"), path.join(__dirname, "..", "dist", "api", "assets")); +copyRecursiveSync(path.join(__dirname, "..", "..", "api", "client_test"), path.join(__dirname, "..", "dist", "api", "client_test")); +copyRecursiveSync(path.join(__dirname, "..", "..", "api", "locales"), path.join(__dirname, "..", "dist", "api", "locales")); dirs.forEach((a) => { - fse.copySync("../" + a + "/src", "dist/" + a + "/src"); + copyRecursiveSync("../" + a + "/src", "dist/" + a + "/src"); if (verbose) console.log(`Copied ${"../" + a + "/dist"} -> ${"dist/" + a + "/src"}!`); }); @@ -46,3 +67,4 @@ if (!argv.includes("copyonly")) { ) ); } + |