Skip to content

Instantly share code, notes, and snippets.

@balupton
Last active January 19, 2016 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balupton/8292502c3d4127c6b6a0 to your computer and use it in GitHub Desktop.
Save balupton/8292502c3d4127c6b6a0 to your computer and use it in GitHub Desktop.
Babel Post-Install Hook Idea
#!/usr/bin/env node
try {
require('./')
} catch (err) {
var name = require('path').dirname(__dirname)
console.log('es6 not supported in your environment, downgrading '+name+' to es5')
var lazyRequire = require('lazy-require')
lazyRequire('babel', function(err){
if ( err ) {
process.stderr.write(err.stack.toString()+'\n')
process.exit(-1)
return
}
require('child_process').exec('./node_modules/.bin/babel lib --out-dir es5; rm -Rf lib; mv es5 lib', {stdio:'inherit'}, function(err){
if ( err ) {
process.stderr.write(err.stack.toString()+'\n')
process.exit(-1)
return
}
console.log(name+' was sucessfully downgraded from es6 to es5')
})
})
}
{
"dependencies": {
"lazy-require": "^2.0.0"
},
"scripts": {
"postinstall": "./es6guardian.js"
}
}
@lukehorvat
Copy link

Nice idea. :)

@balupton
Copy link
Author

I've abandoned the above postcompile idea for a precompile then fallback idea.

See https://github.com/bevry/esnextguardian and https://github.com/bevry/base for the latest way I do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment