Skip to content

Instantly share code, notes, and snippets.

@hangxingliu
Last active June 7, 2017 12:28
Show Gist options
  • Save hangxingliu/0b9604ef8ea5e11df36d8919613609be to your computer and use it in GitHub Desktop.
Save hangxingliu/0b9604ef8ea5e11df36d8919613609be to your computer and use it in GitHub Desktop.
Install babel dependencies according to babelrc
#!/usr/bin/env node
//https://gist.github.com/hangxingliu/0b9604ef8ea5e11df36d8919613609be
let fs = require('fs'),
fatal = msg => console.error(`\n error: ${msg}\n`) + process.exit(1);
let babelrcPath = process.argv[2] || '.babelrc';
fs.existsSync(babelrcPath) || (
process.argv[2] ? fatal(`babelrc file is not existed!`)
: fatal(`Please passing babelrc file path paramter`));
let json = JSON.parse(fs.readFileSync(babelrcPath)),
installList = ['i', `babel-core`];
json.presets.map(preset => Array.isArray(preset) ? preset[0] : preset)
.map(preset => installList.push(`babel-preset-${preset}`));
json.plugins.map(plugin => Array.isArray(plugin) ? plugin[0] : plugin)
.map(plugin => installList.push(`babel-plugin-${plugin}`));
console.log('\n# please executing: \n');
console.log(' npm ' + installList.join(' \\\n ') + '\n');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment