babel-install
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -0,1 +1,7 @@ | ||
# v2.1.0 | ||
## Features | ||
* Enable passing specific versions: | ||
* `babel-install --plugins rewire@v1.0.0-beta-5` | ||
* `babel-install babel-plugin-rewire@v1.0.0-beta-5` | ||
# v2.0.0 | ||
@@ -2,0 +8,0 @@ ## Fixes |
27
index.js
@@ -81,15 +81,24 @@ #!/usr/bin/env node | ||
BabelInstaller.prototype.babelNameForField = function (packageName, field) { | ||
var semverMatcher = /@[a-z0-9.-]+$/i; | ||
var prefix = BabelPrefixes[field]; | ||
if (!prefix) throw new ReferenceError(field + ' is an invalid .babelrc field name'); | ||
return packageName.replace(semverMatcher, '').replace(prefix, ''); | ||
}; | ||
BabelInstaller.prototype.saveToBabel = function (names) { | ||
var _this3 = this; | ||
var fileName = '.babelrc'; | ||
return writeJSON(fileName, names.reduce(function (babelrc, name) { | ||
var prefix = undefined; | ||
var field = undefined; | ||
eachPrefixName(function (prfx) { | ||
return name.indexOf(BabelPrefixes[prfx]) === 0 && (prefix = prfx); | ||
return name.indexOf(BabelPrefixes[prfx]) === 0 && (field = prfx); | ||
}); | ||
babelrc[prefix] || (babelrc[prefix] = []); | ||
var savableName = name.replace(BabelPrefixes[prefix], ''); | ||
if (babelrc[prefix].indexOf(savableName) !== -1) { | ||
babelrc[field] || (babelrc[field] = []); | ||
var savableName = _this3.babelNameForField(name, field); | ||
if (babelrc[field].indexOf(savableName) !== -1) { | ||
console.error(savableName + ' (' + name + ') was already saved to ' + fileName); | ||
} else { | ||
babelrc[prefix].push(savableName); | ||
babelrc[field].push(savableName); | ||
} | ||
@@ -101,3 +110,3 @@ return babelrc; | ||
BabelInstaller.prototype.installAndDeclare = function (names, next) { | ||
var _this3 = this; | ||
var _this4 = this; | ||
@@ -117,4 +126,4 @@ typeof names === 'function' && (next = names) && (names = this.pkgNamesFromCLI); | ||
if (!installError) { | ||
_this3.saveToBabel(names); | ||
Object.keys(_this3.config).forEach(function (k) { | ||
_this4.saveToBabel(names); | ||
Object.keys(_this4.config).forEach(function (k) { | ||
return _npm2.default.config.set(k, undefined); | ||
@@ -121,0 +130,0 @@ }); |
{ | ||
"name": "babel-install", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Declare & install Babel plugins & transforms the easy way", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# babel-install | ||
![Travis badge](https://travis-ci.org/jameswomack/babel-install.svg?branch=master) | ||
## Declare & install Babel plugins & transforms the easy way | ||
`babel-install` is convenience for folks who are frequently trying out Babel plugins and presets. It installs and saves them to the appropriate place in your .babelrc and package.json file. It warns you when you're installing a module that has already been saved to your .babelrc. It also allows you to pass the module names using shorhand via CLI flags powered by yargs-parser. | ||
![Screengrabs](http://i.imgur.com/Fe0vzkd.gif) | ||
@@ -46,3 +51,3 @@ | ||
There are also several aliases installed to cover common typos | ||
There are several aliases installed to cover common typos | ||
* `babel-isntall` | ||
@@ -54,2 +59,9 @@ * `babelisntall` | ||
You can specify specific versions of Babel modules using both the full and short forms. E.g. | ||
``` | ||
babel-install --plugins rewire@v1.0.0-beta-5 | ||
# is the same as | ||
babel-install babel-plugin-rewire@v1.0.0-beta-5 | ||
``` | ||
#### Programmatic Usage | ||
@@ -56,0 +68,0 @@ ```js |
9888
137
81