Last active
January 19, 2016 10:46
-
-
Save balupton/8292502c3d4127c6b6a0 to your computer and use it in GitHub Desktop.
Babel Post-Install Hook Idea
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
#!/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') | |
}) | |
}) | |
} |
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
{ | |
"dependencies": { | |
"lazy-require": "^2.0.0" | |
}, | |
"scripts": { | |
"postinstall": "./es6guardian.js" | |
} | |
} |
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
Nice idea. :)