2019-01-04 02:58:24 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const { exec } = require('pkg')
|
2019-01-04 03:28:12 +00:00
|
|
|
const execRaw = require('child_process').exec
|
2019-01-04 02:58:24 +00:00
|
|
|
const os = require('os')
|
|
|
|
const fs = require('fs-extra')
|
2019-01-04 03:28:12 +00:00
|
|
|
const packageJson = require('./package.json')
|
2019-01-04 02:58:24 +00:00
|
|
|
|
|
|
|
const platform = os.platform()
|
|
|
|
const arch = os.arch()
|
|
|
|
|
2019-01-04 03:28:12 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-04 02:58:24 +00:00
|
|
|
//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}`)
|
|
|
|
}
|
|
|
|
|
2019-01-04 03:28:12 +00:00
|
|
|
console.log(`Building frameloom and saving in dist/${platform}_${arch}...`)
|
|
|
|
console.time('frameloom')
|
2019-08-05 16:21:29 +00:00
|
|
|
exec([ 'frameloom', '--target', 'node10', '--output', `./dist/${platform}_${arch}/frameloom` ]).then(async (res) => {
|
2019-01-04 03:28:12 +00:00
|
|
|
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')
|
2019-01-04 02:58:24 +00:00
|
|
|
console.log('built')
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
})
|
|
|
|
// do something with app.exe, run, test, upload, deploy, etc
|