Comparing version 0.3.1 to 0.4.0
@@ -7,3 +7,4 @@ usage: viralify <path> <options> | ||
-t, --transform transform(s) to inject | ||
-t, --transform transform(s) to inject (required) | ||
-p, --packages packages into which to inject the transforms (required) | ||
-f, --front if set, the transform(s) are injected in the front of the transform field so they run first | ||
@@ -13,8 +14,9 @@ | ||
Inject 'browserify-swap' transform for package in current directory and all its dependencies | ||
Inject 'browserify-swap' transform for all foo dependencies of the package in the current directory | ||
viralify . -t browserify-swap | ||
viralify . -t browserify-swap -p foo | ||
Inject 'envify' and 'es6ify' transforms in front for all dependencies found in ./node_modules | ||
Inject 'envify' and 'es6ify' transforms in front for all foo and bar dependencies of the package | ||
in the current directory | ||
viralify ./node_modules --transform envify --transform es6ify --front | ||
viralify ./node_modules --transform envify --transform es6ify --front --package foo -p bar |
@@ -17,3 +17,3 @@ #!/usr/bin/env node | ||
, { 'boolean': [ 'f', 'front', 'h', 'help' ] } | ||
, { 'string': [ 'transform', 't' ] } | ||
, { 'string': [ 'transform', 't', 'package', 'p' ] } | ||
); | ||
@@ -34,2 +34,3 @@ | ||
var transform = [].concat(argv.t).concat(argv.transform).filter(Boolean); | ||
var packages = [].concat(argv.p).concat(argv.package).filter(Boolean); | ||
@@ -41,8 +42,17 @@ if (!transform.length) { | ||
console.log('viralify %s Processing %s', colors.green('INFO'), root); | ||
viralify(root, transform, front, function (err) { | ||
if (!packages.length) { | ||
console.error('\nviralify %s Need to specify at least one package\n', colors.red('ERR')); | ||
return usage(); | ||
} | ||
var vs = colors.magenta('viralify'); | ||
console.log('%s %s Processing %s', colors.green('info'), vs, root); | ||
console.log('%s %s Transforms: %s', colors.green('info'), vs, transform.join(', ')); | ||
console.log('%s %s Packages: %s', colors.green('info'), vs, packages.join(', ')); | ||
viralify(root, packages, transform, front, function (err) { | ||
if (err) return console.error(err); | ||
console.log('viralify %s Everything is OK', colors.green('INFO')); | ||
console.log('%s %s Everything is OK', colors.green('info'), vs); | ||
}) | ||
})() |
34
index.js
@@ -17,8 +17,16 @@ 'use strict'; | ||
} | ||
function addTransform(front, transform, packfile) { | ||
function addTransform(front, transform, packfile) { | ||
var pack = require(packfile); | ||
if (!pack.browserify) pack.browserify = {}; | ||
// "browserify": "index.js" => "browserify": { "index.js": "index.js" } so we can add our transforms | ||
if (typeof pack.browserify === 'string') { | ||
var k = pack.browserify; | ||
pack.browserify = {}; | ||
pack.browserify[k] = k; | ||
} | ||
if (!pack.browserify.transform) pack.browserify.transform = []; | ||
var before = [].concat(pack.browserify.transform); | ||
@@ -48,2 +56,5 @@ | ||
function globify(packnames) { | ||
return '{' + packnames.join(',') + '}'; | ||
} | ||
@@ -54,3 +65,3 @@ var go = module.exports = | ||
* Injects the given transform(s) into the `browserify.transform` field of all `package.json`s | ||
* at and below the given `root`. | ||
* of the packages below the given `root` that where specified. | ||
* | ||
@@ -63,2 +74,3 @@ * If the transform(s) were contained in the `package.json` already, no changes are made and no writes performed. | ||
* @param {String} root of the package | ||
* @param {Array.<String>} packages one or more packages to which the transforms should be added | ||
* @param {Array.<String>} transform one or more transforms to be added to the transform field | ||
@@ -68,3 +80,4 @@ * @param {Boolean=} front if set transforms are added to the front of the transform field so they run first | ||
*/ | ||
function viralify(root, transform, front, cb) { | ||
function viralify(root, packages, transform, front, cb) { | ||
if (!Array.isArray(packages)) packages = [ packages ]; | ||
if (!Array.isArray(transform)) transform = [ transform ]; | ||
@@ -77,3 +90,5 @@ | ||
glob('**/package.json', { cwd: root }, function (err, relPaths) { | ||
var globString = '**/node_modules/' + globify(packages) + '/package.json'; | ||
glob(globString, { cwd: root }, function (err, relPaths) { | ||
if (err) return cb(err); | ||
@@ -109,9 +124,14 @@ | ||
* @param {String} root of the package | ||
* @param {Array.<String>} packages one or more packages to which the transforms should be added | ||
* @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 | ||
* @param {Function(Error)} cb called when the transform injection is complete | ||
*/ | ||
function sync(root, transform, front) { | ||
function sync(root, packages, transform, front) { | ||
if (!Array.isArray(packages)) packages = [ packages ]; | ||
if (!Array.isArray(transform)) transform = [ transform ]; | ||
var relPaths = glob.sync('**/package.json', { cwd: root }) | ||
var globString = '**/node_modules/' + globify(packages) + '/package.json'; | ||
var relPaths = glob.sync(globString, { cwd: root }) | ||
var packs = packsWithTransforms(root, transform, front, relPaths); | ||
@@ -118,0 +138,0 @@ packs.forEach(function (p) { |
{ | ||
"name": "viralify", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Injects one or more browserify transforms into all dependencies of a package recursively.", | ||
@@ -29,5 +29,3 @@ "main": "index.js", | ||
"nave": "~0.4.3", | ||
"tap": "~0.4.3", | ||
"rimraf": "~2.2.5", | ||
"cpr": "~0.1.1" | ||
"tap": "~0.4.3" | ||
}, | ||
@@ -34,0 +32,0 @@ "keywords": [ |
@@ -6,3 +6,3 @@ # viralify [![build status](https://secure.travis-ci.org/thlorenz/viralify.png)](http://travis-ci.org/thlorenz/viralify) | ||
```sh | ||
viralify . -t browserify-swap | ||
viralify . -t browserify-swap -p ansicolors | ||
``` | ||
@@ -13,6 +13,6 @@ | ||
viralify(root, 'browserify-swap', function (err) { | ||
viralify(root, [ 'foo', 'bar' ] 'browserify-swap', function (err) { | ||
if (err) return console.error(err); | ||
// package.json's found in root and below now have 'browserify-swap' added | ||
// to the end of their 'browserify.transform' field | ||
// package.json's of packages 'foo' and 'bar' found in root and below | ||
// now have 'browserify-swap' added to the end of their 'browserify.transform' field | ||
}) | ||
@@ -34,3 +34,4 @@ ``` | ||
-t, --transform transform(s) to inject | ||
-t, --transform transform(s) to inject (required) | ||
-p, --packages packages into which to inject the transforms (required) | ||
-f, --front if set, the transform(s) are injected in the front of the transform field so they run first | ||
@@ -40,9 +41,10 @@ | ||
Inject 'browserify-swap' transform for package in current directory and all its dependencies | ||
Inject 'browserify-swap' transform for all foo dependencies of the package in the current directory | ||
viralify . -t browserify-swap | ||
viralify . -t browserify-swap -p foo | ||
Inject 'envify' and 'es6ify' transforms in front for all dependencies found in ./node_modules | ||
Inject 'envify' and 'es6ify' transforms in front for all foo and bar dependencies of the package | ||
in the current directory | ||
viralify ./node_modules --transform envify --transform es6ify --front | ||
viralify ./node_modules --transform envify --transform es6ify --front --package foo -p bar | ||
``` | ||
@@ -64,3 +66,3 @@ ## API | ||
<dt> | ||
<h4 class="name" id="viralify"><span class="type-signature"></span>viralify<span class="signature">(root, transform, <span class="optional">front</span>, cb)</span><span class="type-signature"></span></h4> | ||
<h4 class="name" id="viralify"><span class="type-signature"></span>viralify<span class="signature">(root, packages, transform, <span class="optional">front</span>, cb)</span><span class="type-signature"></span></h4> | ||
</dt> | ||
@@ -70,5 +72,5 @@ <dd> | ||
<p>Injects the given transform(s) into the <code>browserify.transform</code> field of all <code>package.json</code>s | ||
at and below the given <code>root</code>.</p> | ||
of the packages below the given <code>root</code> that where specified.</p> | ||
<p>If the transform(s) were contained in the <code>package.json</code> already, no changes are made and no writes performed. | ||
This means that all viralify runs succeeding the first one will be much faster than the first.</p> | ||
This means that all viralify runs succeeding the first one will be much faster.</p> | ||
</div> | ||
@@ -96,2 +98,11 @@ <h5>Parameters:</h5> | ||
<tr> | ||
<td class="name"><code>packages</code></td> | ||
<td class="type"> | ||
<span class="param-type">Array.<String></span> | ||
</td> | ||
<td class="attributes"> | ||
</td> | ||
<td class="description last"><p>one or more packages to which the transforms should be added</p></td> | ||
</tr> | ||
<tr> | ||
<td class="name"><code>transform</code></td> | ||
@@ -132,3 +143,3 @@ <td class="type"> | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/viralify/blob/master/index.js#L50">lineno 50</a> | ||
<a href="https://github.com/thlorenz/viralify/blob/master/index.js#L61">lineno 61</a> | ||
</li> | ||
@@ -147,3 +158,3 @@ </ul></dd> | ||
#### viralify.sync(root, transform, front) | ||
#### viralify.sync(root, packages, transform, front) | ||
@@ -150,0 +161,0 @@ Same as `viralify` but performed synchronously. |
@@ -16,9 +16,12 @@ 'use strict'; | ||
test('\nviralifying three transforms in different situations', function (t) { | ||
test('\nviralifying three transforms applying to all packages in different situations', function (t) { | ||
reset(original, copy, runTest); | ||
// original is not viralified since it is the root, however included as package to verify this behavior | ||
var packages = [ 'original', 'dep', 'sub-dep1', 'sub-sub-dep1', 'sub-dep2' ]; | ||
function runTest(err) { | ||
if (err) { t.fail(err); t.end(); } | ||
viralify(copy, [ 'einsify', 'zweiify', 'dreiify' ], function (err) { | ||
viralify(copy, packages, [ 'einsify', 'zweiify', 'dreiify' ], function (err) { | ||
if (err) return console.error(err); | ||
@@ -58,8 +61,3 @@ | ||
description: 'root project', | ||
main: 'index.js', | ||
browserify: | ||
{ transform: | ||
[ 'einsify', | ||
'zweiify', | ||
'dreiify' ] } }, | ||
main: 'index.js' }, | ||
{ name: 'dep', | ||
@@ -83,3 +81,3 @@ description: 'dep which itself has two transforms already', | ||
function addToFront() { | ||
viralify(copy, [ 'einsify', 'zweiify', 'dreiify' ], true, function (err) { | ||
viralify(copy, packages, [ 'einsify', 'zweiify', 'dreiify' ], true, function (err) { | ||
if (err) return console.error(err); | ||
@@ -119,8 +117,3 @@ | ||
description: 'root project', | ||
main: 'index.js', | ||
browserify: | ||
{ transform: | ||
[ 'einsify', | ||
'zweiify', | ||
'dreiify'] } }, | ||
main: 'index.js' }, | ||
{ name: 'dep', | ||
@@ -127,0 +120,0 @@ description: 'dep which itself has two transforms already', |
@@ -16,9 +16,12 @@ 'use strict'; | ||
test('\nviralifying three transforms synchronously in different situations', function (t) { | ||
test('\nviralifying three transforms applying to all packages synchronously in different situations', function (t) { | ||
reset(original, copy, runTest); | ||
// | ||
// original is not viralified since it is the root, however included as package to verify this behavior | ||
var packages = [ 'original', 'dep', 'sub-dep1', 'sub-sub-dep1', 'sub-dep2' ]; | ||
function runTest(err) { | ||
if (err) { t.fail(err); t.end(); } | ||
viralify.sync(copy, [ 'einsify', 'zweiify', 'dreiify' ]) | ||
viralify.sync(copy, packages, [ 'einsify', 'zweiify', 'dreiify' ]) | ||
@@ -57,8 +60,3 @@ getPacks(copy, function (err, packs) { | ||
description: 'root project', | ||
main: 'index.js', | ||
browserify: | ||
{ transform: | ||
[ 'einsify', | ||
'zweiify', | ||
'dreiify' ] } }, | ||
main: 'index.js' }, | ||
{ name: 'dep', | ||
@@ -81,3 +79,3 @@ description: 'dep which itself has two transforms already', | ||
function addToFront() { | ||
viralify.sync(copy, [ 'einsify', 'zweiify', 'dreiify' ], true) | ||
viralify.sync(copy, packages, [ 'einsify', 'zweiify', 'dreiify' ], true) | ||
@@ -116,8 +114,3 @@ getPacks(copy, function (err, packs) { | ||
description: 'root project', | ||
main: 'index.js', | ||
browserify: | ||
{ transform: | ||
[ 'einsify', | ||
'zweiify', | ||
'dreiify'] } }, | ||
main: 'index.js' }, | ||
{ name: 'dep', | ||
@@ -124,0 +117,0 @@ description: 'dep which itself has two transforms already', |
@@ -16,4 +16,6 @@ 'use strict'; | ||
test('\nviralifying one transform in different situations', function (t) { | ||
test('\nviralifying one transform for all packages in different situations', function (t) { | ||
reset(original, copy, runTest); | ||
// original is not viralified since it is the root, however included as package to verify this behavior | ||
var packages = [ 'original', 'dep', 'sub-dep1', 'sub-sub-dep1', 'sub-dep2' ]; | ||
@@ -23,3 +25,3 @@ function runTest(err) { | ||
viralify(copy, 'browserify-swap', function (err) { | ||
viralify(copy, packages, 'browserify-swap', function (err) { | ||
if (err) return console.error(err); | ||
@@ -33,27 +35,26 @@ | ||
, [ { name: 'sub-sub-dep1', | ||
description: 'has one transform already', | ||
main: 'index.js', | ||
browserify: { transform: [ 'unoify', 'browserify-swap' ] } }, | ||
{ name: 'sub-dep2', | ||
description: 'has no transforms', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
{ name: 'sub-dep1', | ||
description: 'Has no transforms', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
{ name: 'original', | ||
description: 'root project', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
{ name: 'dep', | ||
description: 'dep which itself has two transforms already', | ||
main: 'index.js', | ||
browserify: | ||
{ transform: | ||
[ 'unoify', | ||
'dosify', | ||
'browserify-swap' ] } } ] | ||
, 'adds transform to end when it was not present before' | ||
) | ||
description: 'has one transform already', | ||
main: 'index.js', | ||
browserify: { transform: [ 'unoify', 'browserify-swap' ] } }, | ||
{ name: 'sub-dep2', | ||
description: 'has no transforms', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
{ name: 'sub-dep1', | ||
description: 'Has no transforms', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
{ name: 'original', | ||
description: 'root project', | ||
main: 'index.js' }, | ||
{ name: 'dep', | ||
description: 'dep which itself has two transforms already', | ||
main: 'index.js', | ||
browserify: | ||
{ transform: | ||
[ 'unoify', | ||
'dosify', | ||
'browserify-swap' ] } } ] | ||
, 'adds transform to end when it was not present before' | ||
) | ||
addToEndAgain(); | ||
@@ -64,3 +65,3 @@ }) | ||
function addToEndAgain() { | ||
viralify(copy, 'browserify-swap', function (err) { | ||
viralify(copy, packages, 'browserify-swap', function (err) { | ||
if (err) return console.error(err); | ||
@@ -87,4 +88,3 @@ | ||
description: 'root project', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
main: 'index.js' }, | ||
{ name: 'dep', | ||
@@ -98,4 +98,4 @@ description: 'dep which itself has two transforms already', | ||
'browserify-swap' ] } } ] | ||
, 'leaves one transform at end when it was present before' | ||
) | ||
, 'leaves one transform at end when it was present before' | ||
) | ||
addToFront(); | ||
@@ -107,3 +107,3 @@ }) | ||
function addToFront() { | ||
viralify(copy, 'browserify-swap', true, function (err) { | ||
viralify(copy, packages, 'browserify-swap', true, function (err) { | ||
if (err) return console.error(err); | ||
@@ -117,25 +117,24 @@ | ||
, [ { name: 'sub-sub-dep1', | ||
description: 'has one transform already', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap', 'unoify' ] } }, | ||
{ name: 'sub-dep2', | ||
description: 'has no transforms', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
{ name: 'sub-dep1', | ||
description: 'Has no transforms', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
{ name: 'original', | ||
description: 'root project', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
{ name: 'dep', | ||
description: 'dep which itself has two transforms already', | ||
main: 'index.js', | ||
browserify: | ||
{ transform: | ||
[ 'browserify-swap', | ||
'unoify', | ||
'dosify' ] } } ] | ||
description: 'has one transform already', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap', 'unoify' ] } }, | ||
{ name: 'sub-dep2', | ||
description: 'has no transforms', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
{ name: 'sub-dep1', | ||
description: 'Has no transforms', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
{ name: 'original', | ||
description: 'root project', | ||
main: 'index.js' }, | ||
{ name: 'dep', | ||
description: 'dep which itself has two transforms already', | ||
main: 'index.js', | ||
browserify: | ||
{ transform: | ||
[ 'browserify-swap', | ||
'unoify', | ||
'dosify' ] } } ] | ||
, 'removes transform from end and adds it to front when it was present before and front flag was set' | ||
@@ -142,0 +141,0 @@ ) |
@@ -16,9 +16,12 @@ 'use strict'; | ||
test('\nviralifying one transform synchronously in different situations', function (t) { | ||
test('\nviralifying one transform applying to all packages synchronously in different situations', function (t) { | ||
reset(original, copy, runTest); | ||
// original is not viralified since it is the root, however included as package to verify this behavior | ||
var packages = [ 'original', 'dep', 'sub-dep1', 'sub-sub-dep1', 'sub-dep2' ]; | ||
function runTest(err) { | ||
if (err) { t.fail(err); t.end(); } | ||
viralify.sync(copy, 'browserify-swap'); | ||
viralify.sync(copy, packages, 'browserify-swap'); | ||
@@ -44,4 +47,3 @@ getPacks(copy, function (err, packs) { | ||
description: 'root project', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
main: 'index.js' }, | ||
{ name: 'dep', | ||
@@ -61,3 +63,3 @@ description: 'dep which itself has two transforms already', | ||
function addToEndAgain() { | ||
viralify.sync(copy, 'browserify-swap') | ||
viralify.sync(copy, packages, 'browserify-swap') | ||
@@ -83,4 +85,3 @@ getPacks(copy, function (err, packs) { | ||
description: 'root project', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
main: 'index.js' }, | ||
{ name: 'dep', | ||
@@ -101,3 +102,3 @@ description: 'dep which itself has two transforms already', | ||
function addToFront() { | ||
viralify.sync(copy, 'browserify-swap', true) | ||
viralify.sync(copy, packages, 'browserify-swap', true) | ||
@@ -123,4 +124,3 @@ getPacks(copy, function (err, packs) { | ||
description: 'root project', | ||
main: 'index.js', | ||
browserify: { transform: [ 'browserify-swap' ] } }, | ||
main: 'index.js' }, | ||
{ name: 'dep', | ||
@@ -127,0 +127,0 @@ description: 'dep which itself has two transforms already', |
'use strict'; | ||
var rmrf = require('rimraf') | ||
, cpr = require('cpr') | ||
var exec = require('child_process').exec | ||
module.exports = function reset(original, copy, cb) { | ||
rmrf(copy, function (err) { | ||
// expecting err since may not exist | ||
cpr(original, copy, cb); | ||
}); | ||
exec('rm -rf ' + copy + ' && cp -R ' + original + ' ' + copy, function (err, stdout, stderr) { | ||
console.log('stdout', stdout); | ||
console.log('stderr', stderr); | ||
cb(err); | ||
}) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41960
2
17
876
158
1