Skip to content

Instantly share code, notes, and snippets.

@Thoughtscript
Last active Feb 4, 2021
Embed
What would you like to do?
Node CMD and BIN stuff
#!/usr/bin/env node
/**
* Commands to execute at runtime.
*
* @Author - Adam InTae Gerard - https://www.linkedin.com/in/adamintaegerard/
*/
'use strict'
const doLinux = command => new Promise((resolve, reject) => {
const opts = {
encoding: 'utf8',
timeout: 0,
maxBuffer: 200 * 1024,
killSignal: 'SIGTERM',
cwd: null,
env: null
}
require('child_process').exec(command, opts, (error, stdout, stderr) => {
if (error != null) return reject(console.log(`Exception running script: ${command}`));
if (stdout != null) return resolve(console.log(`${command} successful: ${stdout}!`));
})
})
const copy = async (to, from) => await doLinux(`cp -R "${from}" "${to}"`)
const remove = async path => await doLinux(`rm -rf ${path}`)
const mkdir = async path => await doLinux(`mkdir -p ${path}`)
module.exports = {
copy: copy,
remove: remove,
mkdir: mkdir
}
/**
* Init build file.
*
* @Author - Adam InTae Gerard - https://www.linkedin.com/in/adamintaegerard/
*/
'use strict'
const c = require('../config.js')
const cmd = require('../cmd')
const init = () => new Promise((resolve, reject) => {
console.log("Cleaning build...")
try {
cmd.remove(`${c.ROOT}/deploy/assets/*.json`).then(aa => {
cmd.remove(`${c.ROOT}/deploy/*.html`).then(bb => {
cmd.remove(`${c.ROOT}/deploy/assets/img/*`).then(cc => {
cmd.remove(`${c.ROOT}/deploy/assets/pdf/*.pdf`).then(dd => {
cmd.remove(`${c.ROOT}/deploy/blog/*.html`).then(ee => {
cmd.remove(`${c.ROOT}/deploy/papers/*.html`).then(ff => {
cmd.remove(`${c.ROOT}/deploy/scripts/*.js`).then(gg => {
cmd.remove(`${c.ROOT}/deploy/styles/*.css`).then(hh => {
console.log("Initializing blog build with the following settings...")
console.log(JSON.stringify(c.BUILD, null, 2))
return resolve(console.log(JSON.stringify(c.STATIC, null, 2)))
})
})
})
})
})
})
})
})
} catch (ex) {
const msg = `Init error encountered: ${ex}!`
console.error(msg)
throw reject(new Error(ex), msg)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment