diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2022-08-06 15:32:28 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2022-08-06 15:32:28 +0200 |
commit | 11227bb2b3810432f77ea94c9eac26b4875397f2 (patch) | |
tree | c9887bf994ebc575369de2f00a4bedffadfd1563 | |
parent | Add silent mode (diff) | |
download | server-11227bb2b3810432f77ea94c9eac26b4875397f2.tar.xz |
Update gitignore, push correct version of build script
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | bundle/scripts/build.js | 42 |
2 files changed, 34 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore index 607b4f5a..0f1d9332 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ api/assets/plugins/*.js .idea/ *.code-workspace + +*.log +*.log.ansi \ No newline at end of file diff --git a/bundle/scripts/build.js b/bundle/scripts/build.js index 99454be6..1a12ae73 100644 --- a/bundle/scripts/build.js +++ b/bundle/scripts/build.js @@ -3,33 +3,35 @@ const path = require("path"); const fs = require("fs"); const { getSystemErrorMap } = require("util"); const { argv, stdout, exit } = require("process"); -const { copyRecursiveSync, execIn, parts} = require('./utils'); +const {copyRecursiveSync,execIn} = require('./utils'); if(argv.includes("help")) { console.log(`Fosscord build script help: - Arguments: clean Cleans up previous builds copyonly Only copy source files, don't build (useful for updating assets) verbose Enable verbose logging logerrors Log build errors to console pretty-errors Pretty-print build errors - silent No output, no build log`); + silent No output to console or files.`); exit(0); } let steps = 3, i = 0; if (argv.includes("clean")) steps++; if (argv.includes("copyonly")) steps--; +const dirs = ["api", "util", "cdn", "gateway", "bundle"]; const verbose = argv.includes("verbose") || argv.includes("v"); +const logerr = argv.includes("logerrors"); +const pretty = argv.includes("pretty-errors"); const silent = argv.includes("silent"); -if(silent) console.log = function() {} +if(silent) console.error = console.log = function(){} if (argv.includes("clean")) { console.log(`[${++i}/${steps}] Cleaning...`); - parts.forEach((a) => { + dirs.forEach((a) => { let d = "../" + a + "/dist"; if (fs.existsSync(d)) { fs.rmSync(d, { recursive: true }); @@ -47,7 +49,7 @@ console.log(`[${++i}/${steps}] Copying src files...`); 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")); -parts.forEach((a) => { +dirs.forEach((a) => { copyRecursiveSync("../" + a + "/src", "dist/" + a + "/src"); if (verbose) console.log(`Copied ${"../" + a + "/dist"} -> ${"dist/" + a + "/src"}!`); }); @@ -55,13 +57,16 @@ parts.forEach((a) => { if (!argv.includes("copyonly")) { console.log(`[${++i}/${steps}] Compiling src files ...`); - console.log( + let buildFlags = '' + if(pretty) buildFlags += '--pretty ' + + try { execSync( 'node "' + path.join(__dirname, "..", "node_modules", "typescript", "lib", "tsc.js") + '" -p "' + path.join(__dirname, "..") + - '"', + '" ' + buildFlags, { cwd: path.join(__dirname, ".."), shell: true, @@ -69,6 +74,21 @@ if (!argv.includes("copyonly")) { encoding: "utf8" } ) - ); -} - + } catch (error) { + if(verbose || logerr) { + error.stdout.split(/\r?\n/).forEach((line) => { + let _line = line.replace('dist/','',1); + if(!pretty && _line.includes('.ts(')) { + //reformat file path for easy jumping + _line = _line.replace('(',':',1).replace(',',':',1).replace(')','',1) + } + console.error(_line); + }) + } + console.error(`Build failed! Please check build.log for info!`); + if(!silent){ + if(pretty) fs.writeFileSync("build.log.ansi", error.stdout); + fs.writeFileSync("build.log", error.stdout.replaceAll(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')); + } + } +} \ No newline at end of file |