Comparing version 0.2.0 to 0.3.0
36
index.js
@@ -26,2 +26,9 @@ 'use strict'; | ||
function packsWithTransforms(root, transform, front, relPaths) { | ||
return relPaths | ||
.map(function (x) { return path.resolve(root, x) }) | ||
.map(addTransform.bind(null, front, transform)); | ||
} | ||
var go = module.exports = | ||
@@ -48,11 +55,9 @@ | ||
glob('**/package.json', { cwd: root }, function (err, res) { | ||
glob('**/package.json', { cwd: root }, function (err, relPaths) { | ||
if (err) return cb(err); | ||
// nothing to do | ||
if (!res.length) return cb(); | ||
if (!relPaths.length) return cb(); | ||
var packs = res | ||
.map(function (x) { return path.resolve(root, x) }) | ||
.map(addTransform.bind(null, front, transform)); | ||
var packs = packsWithTransforms(root, transform, front, relPaths); | ||
@@ -70,1 +75,22 @@ var tasks = packs | ||
}; | ||
module.exports.sync = | ||
/** | ||
* Same as `viralify` but performed synchronously. | ||
* | ||
* @name viralivy.sync | ||
* @function | ||
* @param {String} root of the package | ||
* @param {Array.<String>} transform one or more transforms to be added to the transform field | ||
* @param {Boolean=} front if set transforms are added to the front of the transform field so they run first | ||
*/ | ||
function sync(root, transform, front) { | ||
if (!Array.isArray(transform)) transform = [ transform ]; | ||
var relPaths = glob.sync('**/package.json', { cwd: root }) | ||
var packs = packsWithTransforms(root, transform, front, relPaths); | ||
packs.forEach(function (p) { | ||
fs.writeFileSync(p.file, JSON.stringify(p.pack, null, 2), 'utf8'); | ||
}) | ||
} |
{ | ||
"name": "viralify", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Injects one or more browserify transforms into all dependencies of a package recursively.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -123,3 +123,3 @@ # viralify [](http://travis-ci.org/thlorenz/viralify) | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/viralify/blob/master/index.js#L28">lineno 28</a> | ||
<a href="https://github.com/thlorenz/viralify/blob/master/index.js#L35">lineno 35</a> | ||
</li> | ||
@@ -138,2 +138,6 @@ </ul></dd> | ||
#### viralify.sync(root, transform, front) | ||
Same as `viralify` but performed synchronously. | ||
## License | ||
@@ -140,0 +144,0 @@ |
30009
15
632
145