Create a gist now

Instantly share code, notes, and snippets.

Automate script for upgrading multiple packages at once to latest conventions. For some reason the wgets didn't actually work.
const commands = [
'git reset --hard',
'rm -Rf esnextguardian.js .babelrc nakefile.js',
'wget -N https://raw.githubusercontent.com/bevry/base/master/.editorconfig',
'wget -N https://raw.githubusercontent.com/bevry/base/master/.eslintrc.js',
'wget -N https://raw.githubusercontent.com/bevry/base/master/.gitignore',
'wget -N https://raw.githubusercontent.com/bevry/base/master/LICENSE.md',
'wget -N https://raw.githubusercontent.com/bevry/base/master/.npmignore',
'wget -N https://raw.githubusercontent.com/bevry/base/master/CONTRIBUTING.md',
'wget -N https://raw.githubusercontent.com/bevry/base/master/index.js',
'rm -Rf source',
'mkdir source',
'git mv esnext/lib/*.js source/',
'git mv esnext/test/*.js source/test.js',
'rm -Rf esnext',
'echo "you now have to do package.json, HISTORY.md, and .travis.yml"'
]
const {exec} = require('child_process')
const {readdir} = require('fs')
const {join} = require('path')
function runCommands (paths, commands, pathIndex = 0, commandIndex = 0) {
const path = paths[pathIndex]
const command = commands[commandIndex]
if ( path ) {
if ( command ) {
console.log(path, command)
exec(command, {cwd:path, env:process.env}, function (error, a, b) {
if ( error ) {
return console.error(error, a, b)
}
console.log(a, b)
runCommands(paths, commands, pathIndex, commandIndex + 1)
})
}
else {
console.log(path, 'all done')
runCommands(paths, commands, pathIndex + 1, 0)
}
}
else {
console.log('all done')
}
}
const cwd = process.cwd()
readdir(cwd, function (error, files) {
if ( error ) return console.error(error)
const paths = files.filter((f) => f.indexOf('.') === -1).map((f) => join(cwd, f))
runCommands(paths, commands)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment