Build and create zip of binary

This commit is contained in:
mmcw-dev 2019-01-03 22:28:12 -05:00
parent 4aef3459ba
commit 23d7930e38
1 changed files with 31 additions and 1 deletions

View File

@ -1,19 +1,49 @@
'use strict' 'use strict'
const { exec } = require('pkg') const { exec } = require('pkg')
const execRaw = require('child_process').exec
const os = require('os') const os = require('os')
const fs = require('fs-extra') const fs = require('fs-extra')
const packageJson = require('./package.json')
const platform = os.platform() const platform = os.platform()
const arch = os.arch() const arch = os.arch()
/**
* 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: //exec(args) takes an array of command line arguments and returns a promise. For example:
if (!fs.existsSync(`./dist/${platform}_${arch}`)) { if (!fs.existsSync(`./dist/${platform}_${arch}`)) {
fs.mkdirSync(`./dist/${platform}_${arch}`) fs.mkdirSync(`./dist/${platform}_${arch}`)
} }
exec([ 'frameloom', '--target', 'host', '--output', `./dist/${platform}_${arch}/frameloom` ]).then(res => { 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') console.log('built')
}).catch(err => { }).catch(err => {
console.error(err) console.error(err)