Last active
December 2, 2016 13:20
-
-
Save domjtalbot/31dd3e885fe5b9fe4cc99395664d9b10 to your computer and use it in GitHub Desktop.
Nodejs script to automate RubyGems update to fix SSL errors.
Ruby version controlled via environment variable RUBYVERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import download from 'download'; | |
import { exec } from 'child_process'; | |
import { unlinkSync} from 'fs'; | |
import Ora from 'ora'; | |
import './env.es6'; | |
import { Debug } from './debug.es6'; | |
import { green } from 'ansicolors'; | |
const debug = new Debug('ruby:ssl'); | |
const version = process.env.RUBYVERSION; | |
const cwd = process.cwd(); | |
const downloadSpinner = new Ora(`Downloading rubygems-update-${version}`); | |
downloadSpinner.start(); | |
download(`https://rubygems.org/downloads/rubygems-update-${version}.gem`, 'npmtmp').then(() => { | |
downloadSpinner.succeed(); | |
const installSpinner = new Ora(`Installing rubygems-update-${version}`); | |
debug(`Installing rubygems-update-${version}`); | |
installSpinner.start(); | |
exec(`gem install --local npmtmp/rubygems-update-${version}.gem`, { | |
cwd, | |
}, (err) => { | |
if (err) { | |
installSpinner.fail(); | |
throw err; | |
} | |
installSpinner.succeed(); | |
const updateSpinner = new Ora('Running update_rubygems'); | |
debug('Running update_rubygems'); | |
updateSpinner.start(); | |
exec('update_rubygems --no-ri --no-rdoc', { | |
cwd, | |
}, (err2) => { | |
if (err2) throw err2; | |
updateSpinner.succeed(); | |
const uninstallSpinner = new Ora('Uninstalling rubygems-update'); | |
debug('Uninstalling rubygems-update'); | |
uninstallSpinner.start(); | |
exec('gem uninstall rubygems-update -x', { | |
cwd, | |
}, (err3) => { | |
if (err3) throw err3; | |
uninstallSpinner.succeed(); | |
const cleanup = new Ora('Cleaning tmp files'); | |
debug('Cleaning tmp files'); | |
cleanup.start(); | |
exec('rimraf npmtmp', { | |
cwd, | |
}, (err4) => { | |
if (err4) throw err4; | |
cleanup.succeed(); | |
debug(green('Done')); | |
}); | |
}) | |
}) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment