Skip to content

Instantly share code, notes, and snippets.

@Lxxyx
Created June 10, 2017 10:59
Show Gist options
  • Save Lxxyx/cb4bf292c7880092acddb291919e5bf0 to your computer and use it in GitHub Desktop.
Save Lxxyx/cb4bf292c7880092acddb291919e5bf0 to your computer and use it in GitHub Desktop.
const fs = require('fs')
const path = require('path')
const {
exec
} = require('child_process')
const file = process.argv[2]
const filename = file.split('.')[0]
if (!file) {
throw new Error('require file')
}
const content = fs.readFileSync(path.resolve(__dirname, file), 'utf-8')
let result = ''
content.split('\n').forEach((command, index) => {
if (command === '') return
if (index === 0) {
command += ' \\ \n'
} else {
command = '&& ' + command + ' \\ \n'
}
result += command
})
fs.writeFileSync(path.resolve(__dirname, filename + '.sh'), result, {
encoding: 'utf-8'
})
exec('open .')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment