Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loop

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loop - npm Package Compare versions

Comparing version 3.0.3 to 3.0.6

6

lib/expandCommand.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc