From 4c0db142d74d5371de0c9c1d51e12032e9a50497 Mon Sep 17 00:00:00 2001 From: ineedbots Date: Thu, 24 Jun 2021 15:04:42 -0600 Subject: [PATCH] Added deploy scripts --- deploy.bat | 3 +++ deploy.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ z_deploy.bat | 1 + 3 files changed, 55 insertions(+) create mode 100644 deploy.bat create mode 100644 deploy.js create mode 100644 z_deploy.bat diff --git a/deploy.bat b/deploy.bat new file mode 100644 index 0000000..9d97151 --- /dev/null +++ b/deploy.bat @@ -0,0 +1,3 @@ +xcopy pt6_bot_warfare\raw\maps raw\maps\ /Y /I /E /H /C +xcopy pt6_bot_warfare\raw\scripts raw\scripts\ /Y /I /E /H /C +xcopy pt6_bot_warfare\raw\bots.txt raw\ /Y /I /H /C diff --git a/deploy.js b/deploy.js new file mode 100644 index 0000000..b59ee34 --- /dev/null +++ b/deploy.js @@ -0,0 +1,51 @@ +// nodejs 14+ + +const exec = require('util').promisify(require('child_process').exec) + +const repo_name = 'pt6_bot_warfare' +const repo_url = `https://github.com/ineedbots/${repo_name}` +const deploy_check_rate = 60000 +const title = 'PT6 Bot Warfare Git Deployer' + +function printToConsole(what, error = false) +{ + log = error ? console.error : console.log + + log(`[${new Date().toISOString()}]:`, what) +} + +async function doDeploy() { + try { + const { stdout, stderr } = await exec(`cd ${repo_name} && git fetch`) + + if (stderr.length <= 0) + return + + if (stderr.startsWith('From ')) + { + printToConsole('git fetched! Pulling...') + await exec(`cd ${repo_name} && git pull && git submodule update --init --recursive`) + printToConsole('Deploying...') + await exec('deploy.bat') + printToConsole('Deployed!') + } + } catch (e) { + printToConsole(e, true) + + if (!e.stderr.startsWith('The system cannot find the path specified')) + return + + printToConsole('Cloning repo...') + try { + await exec(`git clone ${repo_url} && cd ${repo_name} && git submodule update --init --recursive`) + + printToConsole('Cloned!') + } catch (f) { + printToConsole(f, true) + } + } +} + +process.stdout.write(`${String.fromCharCode(27)}]0;${title}${String.fromCharCode(7)}`) +doDeploy() +setInterval(doDeploy, deploy_check_rate) diff --git a/z_deploy.bat b/z_deploy.bat new file mode 100644 index 0000000..05197ae --- /dev/null +++ b/z_deploy.bat @@ -0,0 +1 @@ +start "" "node" deploy.js \ No newline at end of file