summary refs log tree commit diff
path: root/scripts/utils.js
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-22 22:08:22 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-22 22:08:22 +1000
commit975c414434ee08622126bdeb4060532029413c18 (patch)
treea46b7f33a150963f6b8d3515225574610325713f /scripts/utils.js
parentMerge branch 'master' into fix/claim_accounts (diff)
parentMerge remote-tracking branch 'Puyodead1/patch/prettier-config' into staging (diff)
downloadserver-975c414434ee08622126bdeb4060532029413c18.tar.xz
Merge remote-tracking branch 'upstream/staging' into fix/claim_accounts
Diffstat (limited to 'scripts/utils.js')
-rw-r--r--scripts/utils.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/scripts/utils.js b/scripts/utils.js
new file mode 100644

index 00000000..84aaeed6 --- /dev/null +++ b/scripts/utils.js
@@ -0,0 +1,51 @@ +const path = require("path"); +const fs = require("fs"); +const { env } = require("process"); +const { execSync } = require("child_process"); +const { argv, stdout, exit } = require("process"); + +function copyRecursiveSync(src, dest) { + //if (verbose) console.log(`cpsync: ${src} -> ${dest}`); + let exists = fs.existsSync(src); + if (!exists) { + console.log(src + " doesn't exist, not copying!"); + return; + } + let stats = exists && fs.statSync(src); + let 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); + } +} + +function execIn(cmd, workdir, opts) { + try { + return execSync(cmd, { + cwd: workdir, + shell: true, + env: process.env, + encoding: "utf-8", + ...opts + }); + } catch (error) { + return error.stdout; + } +} + +function getLines(output) { + return output.split("\n").length; +} + +module.exports = { + //consts + //functions + copyRecursiveSync, execIn, getLines +};