Last active
June 7, 2017 12:28
-
-
Save hangxingliu/0b9604ef8ea5e11df36d8919613609be to your computer and use it in GitHub Desktop.
Install babel dependencies according to babelrc
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 | |
//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