From 5717fc8cfef1248c9d2853d38b66ea71910c6048 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Fri, 22 Mar 2019 19:50:46 -0400 Subject: [PATCH] Add a build script to build cli with pkg. --- cli/scripts/build.js | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 cli/scripts/build.js diff --git a/cli/scripts/build.js b/cli/scripts/build.js new file mode 100644 index 0000000..64203a5 --- /dev/null +++ b/cli/scripts/build.js @@ -0,0 +1,51 @@ +'use strict' + +const { exec } = require('pkg') +const execRaw = require('child_process').exec +const os = require('os') +const fs = require('fs-extra') +const packageJson = require('./package.json') + +const platform = os.platform() +const arch = os.arch() +const name = packageJson.name; + +/** + * Shells out to execute a command with async/await. + * Async wrapper to exec module. + * + * @param {string} cmd Command to execute + * + * @returns {Promise} Promise containing the complete stdio + **/ +async function shell_out (cmd) { + return new Promise((resolve, reject) => { + return execRaw(cmd, (err, stdio, stderr) => { + if (err) return reject(err) + return resolve(stdio) + }) + }) +} + +//exec(args) takes an array of command line arguments and returns a promise. For example: + +if (!fs.existsSync(`./dist/${platform}_${arch}`)) { + fs.mkdirSync(`./dist/${platform}_${arch}`) +} + +console.log(`Building frameloom and saving in dist/${platform}_${arch}...`) +console.time('frameloom') +exec([ 'frameloom', '--target', 'host', '--output', `./dist/${platform}_${arch}/frameloom` ]).then(async (res) => { + try { + await shell_out(`zip -r ./dist/frameloom_${platform}_${arch}_${packageJson.version}.zip ./dist/${platform}_${arch}/frameloom`) + console.log(`Compressed binary to dist/frameloom_${platform}_${arch}_${packageJson.version}.zip`) + } catch (err) { + console.error(err) + process.exit(err) + } + + console.timeEnd('frameloom') + console.log('built') +}).catch(err => { + console.error(err) +}) \ No newline at end of file