Comparing version 3.0.3 to 3.0.6
@@ -1,8 +0,10 @@ | ||
module.exports = function (dirs, command) { | ||
module.exports = function (dirs, command, options) { | ||
return dirs.map((dir) => { | ||
return { | ||
dir, | ||
command | ||
command, | ||
exitOnError: options.exitOnError, | ||
exitOnAggregateError: options.exitOnAggregateError, | ||
}; | ||
}); | ||
}; |
const chalk = require('chalk'); | ||
const debug = require('debug')('loop'); | ||
const expandCommand = require('../lib/expandCommand'); | ||
@@ -7,5 +8,6 @@ const getArgsForFlag = require('../lib/getArgsForFlag'); | ||
const path = require('path'); | ||
const util = require('util'); | ||
const _ = require('lodash'); | ||
module.exports = (options, cb) => { | ||
module.exports = (options, cb, errorCb) => { | ||
@@ -21,3 +23,7 @@ const cwd = options.dir || process.cwd(); | ||
options.includeOnly = options.includeOnly || getArgsForFlag(process.argv, '--include-only') || looprc.includeOnly | ||
options.exitOnError = options.exitOnError || getArgsForFlag(process.argv, '--exit-on-error'), | ||
options.exitOnAggregateError = options.exitOnAggregateError || getArgsForFlag(process.argv, '--exit-on-aggregate-error') | ||
debug(`executing ${util.inspect(options)}`); | ||
if (options.excludeOnly) { | ||
@@ -37,5 +43,21 @@ dirs = listDirectories({ ignore: options.excludeOnly }, options.dir) | ||
const commands = expandCommand(dirs, options.command); | ||
const commands = expandCommand(dirs, options.command, { | ||
exitOnError: options.exitOnError, | ||
exitOnAggregateError: options.exitOnAggregateError, | ||
}); | ||
let commandOutputsWithErrors = []; | ||
mapExec(commands, (err, commandOutputs) => { | ||
if (options.exitOnAggregateError && commandOutputsWithErrors.length > 0) { | ||
console.log(); | ||
let index = 0; | ||
console.log(`one or more child commands executed by loop encountered an error:\n${commandOutputsWithErrors.reduce((a, b) => { | ||
return `${a}\n${++index}: ${b}`; | ||
}, '')}`); | ||
console.log(); | ||
process.exit(1); | ||
} | ||
const results = commandOutputs.reduce((logMessage, commandOutput, index) => { | ||
@@ -47,7 +69,30 @@ const color = commandOutput.error ? 'red' : 'green'; | ||
const output = commandOutput.output || commandOutput.error; | ||
return `${logMessage}\n${output}`; | ||
if (commandOutput.error) { | ||
if (options.exitOnError) { | ||
console.log(`a child command executed by loop encountered an error:\n${commandOutput.error}`); | ||
process.exit(1); | ||
} | ||
commandOutputsWithErrors.push(commandOutput.error); | ||
} | ||
if (code && options.exitOnError) { | ||
process.exit(code); | ||
} | ||
return `${logMessage}\n${output}`; | ||
}, ''); | ||
if (cb) return cb(null, results); | ||
}, (error) => { | ||
if (options.exitOnError) { | ||
console.log(`a child command executed by loop encountered an error:\n${error}`); | ||
process.exit(1); | ||
} | ||
commandOutputsWithErrors.push(error); | ||
}); | ||
}; |
@@ -6,11 +6,13 @@ const async = require('async'); | ||
module.exports = (commands, cb) => { | ||
module.exports = (commands, cb, errorCb) => { | ||
async.map(commands, (cmd, cb) => { | ||
exec({ | ||
return async.map(commands, (cmd, cb) => { | ||
return exec({ | ||
command: cmd.command, | ||
dir: cmd.dir | ||
}, cb); | ||
dir: cmd.dir, | ||
exitOnError: cmd.exitOnError, | ||
exitOnAggregateError: cmd.exitOnAggregateError, | ||
}, cb, errorCb); | ||
}, cb); | ||
} |
{ | ||
"name": "loop", | ||
"version": "3.0.3", | ||
"version": "3.0.6", | ||
"description": "loop through commands in fun and amazing ways!", | ||
@@ -28,3 +28,3 @@ "main": "./index.js", | ||
"lodash": "^4.17.2", | ||
"meta-exec": "^0.0.7", | ||
"meta-exec": "^0.0.8", | ||
"mocha": "^3.2.0", | ||
@@ -31,0 +31,0 @@ "should": "^11.1.2", |
Sorry, the diff of this file is not supported yet
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
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
40492
153
+ Addedmeta-exec@0.0.8(transitive)
- Removedansi-escapes@3.2.0(transitive)
- Removedansi-regex@3.0.14.1.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedarr-diff@4.0.0(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarr-union@3.1.0(transitive)
- Removedarray-unique@0.3.2(transitive)
- Removedassign-symbols@1.0.0(transitive)
- Removedatob@2.1.2(transitive)
- Removedbase@0.11.2(transitive)
- Removedbraces@2.3.2(transitive)
- Removedcache-base@1.0.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedchardet@0.4.2(transitive)
- Removedclass-utils@0.3.6(transitive)
- Removedcli-cursor@2.1.0(transitive)
- Removedcli-width@2.2.1(transitive)
- Removedcollection-visit@1.0.0(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcopy-descriptor@0.1.1(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddefine-property@0.2.51.0.02.0.2(transitive)
- Removeddetect-file@1.0.0(transitive)
- Removedexpand-brackets@2.1.4(transitive)
- Removedexpand-tilde@2.0.2(transitive)
- Removedextend-shallow@2.0.13.0.2(transitive)
- Removedexternal-editor@2.2.0(transitive)
- Removedextglob@2.0.4(transitive)
- Removedfigures@2.0.0(transitive)
- Removedfill-range@4.0.0(transitive)
- Removedfindup-sync@2.0.0(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfragment-cache@0.2.1(transitive)
- Removedget-meta-file@0.0.5(transitive)
- Removedget-value@2.0.6(transitive)
- Removedglobal-modules@1.0.0(transitive)
- Removedglobal-prefix@1.0.2(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhas-value@0.3.11.0.0(transitive)
- Removedhas-values@0.1.41.0.0(transitive)
- Removedhomedir-polyfill@1.0.3(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedini@1.3.8(transitive)
- Removedinquirer@3.3.0(transitive)
- Removedis-accessor-descriptor@1.0.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-data-descriptor@1.0.1(transitive)
- Removedis-descriptor@0.1.71.0.3(transitive)
- Removedis-extendable@0.1.11.0.1(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedis-glob@3.1.0(transitive)
- Removedis-number@3.0.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedisobject@2.1.03.0.1(transitive)
- Removedkind-of@3.2.24.0.06.0.3(transitive)
- Removedmap-cache@0.2.2(transitive)
- Removedmap-visit@1.0.0(transitive)
- Removedmeta-exec@0.0.7(transitive)
- Removedmeta-loop@0.0.5(transitive)
- Removedmicromatch@3.1.10(transitive)
- Removedmimic-fn@1.2.0(transitive)
- Removedmixin-deep@1.3.2(transitive)
- Removedmute-stream@0.0.7(transitive)
- Removednanomatch@1.2.13(transitive)
- Removedobject-copy@0.1.0(transitive)
- Removedobject-visit@1.0.1(transitive)
- Removedobject.pick@1.3.0(transitive)
- Removedonetime@2.0.1(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedparse-passwd@1.0.0(transitive)
- Removedpascalcase@0.1.1(transitive)
- Removedposix-character-classes@0.1.1(transitive)
- Removedprompt-sync@4.2.0(transitive)
- Removedregex-not@1.0.2(transitive)
- Removedrepeat-element@1.1.4(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedresolve-dir@1.0.1(transitive)
- Removedresolve-url@0.2.1(transitive)
- Removedrestore-cursor@2.0.0(transitive)
- Removedret@0.1.15(transitive)
- Removedrun-async@2.4.1(transitive)
- Removedrx-lite@4.0.8(transitive)
- Removedrx-lite-aggregates@4.0.8(transitive)
- Removedsafe-regex@1.1.0(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedset-value@2.0.1(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedsnapdragon@0.8.2(transitive)
- Removedsnapdragon-node@2.1.1(transitive)
- Removedsnapdragon-util@3.0.1(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedsource-map-resolve@0.5.3(transitive)
- Removedsource-map-url@0.4.1(transitive)
- Removedsplit-string@3.1.0(transitive)
- Removedstatic-extend@0.1.2(transitive)
- Removedstring-width@2.1.1(transitive)
- Removedstrip-ansi@4.0.05.2.0(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedtmp@0.0.33(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedto-regex@3.0.2(transitive)
- Removedto-regex-range@2.1.1(transitive)
- Removedunion-value@1.0.1(transitive)
- Removedunset-value@1.0.0(transitive)
- Removedurix@0.1.0(transitive)
- Removeduse@3.1.1(transitive)
- Removedwhich@1.3.1(transitive)
Updatedmeta-exec@^0.0.8