Skip to content

Instantly share code, notes, and snippets.

@royhowie
Created July 31, 2015 06:17
Show Gist options
  • Save royhowie/ab2b126743cb7f17ed0e to your computer and use it in GitHub Desktop.
Save royhowie/ab2b126743cb7f17ed0e to your computer and use it in GitHub Desktop.
import Promise from 'bluebird'
let fs = Promise.promisifyAll(require('fs'))
let exec = Promise.promisify(require('child_process').exec)
function mapCommands (file) {
return file.split('\n').reduce((p, c) => {
let separation = c.indexOf(':')
p[c.slice(3, separation)] = c.slice(separation + 2)
return p
}, {})
}
function execCommands (obj) {
let commands = []
for (let key in obj) {
let cmd = exec(obj[key])
commands.push(cmd)
}
return Promise.all(commands)
}
export default {
createNew () {
fs.readFileAsync('C://test.txt', 'utf8')
.then(mapCommands)
.then(execCommands)
.then(() => {
// success; all commands executed
}).catch((err) => {
console.log(err) // handle err
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment