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.2.0 to 3.3.0

lib/getFlag.js

112

lib/loop.js
const chalk = require('chalk');
const debug = require('debug')('loop');
const expandCommand = require('../lib/expandCommand');
const getFlag = require('../lib/getFlag');
const getArgsForFlag = require('../lib/getArgsForFlag');

@@ -12,21 +13,21 @@ const listDirectories = require('../lib/listDirectories');

module.exports = (options, cb, errorCb) => {
const cwd = options.dir || process.cwd();
var dirs = options.directories || listDirectories(options.looprc, cwd);
var looprc = options["looprc"] || [];
var looprc = options['looprc'] || [];
options.exclude = options.exclude || getArgsForFlag(process.argv, '--exclude') || looprc.exclude,
options.excludeOnly = options.excludeOnly || getArgsForFlag(process.argv, '--exclude-only') || looprc.excludeOnly,
options.include = options.include || getArgsForFlag(process.argv, '--include') || looprc.include,
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')
options.exclude = options.exclude || getArgsForFlag(process.argv, '--exclude') || looprc.exclude;
options.excludeOnly = options.excludeOnly || getArgsForFlag(process.argv, '--exclude-only') || looprc.excludeOnly;
options.exitOnAggregateError =
options.exitOnAggregateError || getArgsForFlag(process.argv, '--exit-on-aggregate-error');
options.exitOnError = options.exitOnError || getArgsForFlag(process.argv, '--exit-on-error');
options.include = options.include || getArgsForFlag(process.argv, '--include') || looprc.include;
options.includeOnly = options.includeOnly || getArgsForFlag(process.argv, '--include-only') || looprc.includeOnly;
options.parallel = options.parallel || getFlag(process.argv, '--parallel') || looprc.parallel;
debug(`executing ${util.inspect(options)} ${process.argv}`);
debug(`executing ${util.inspect(options)}`);
if (options.excludeOnly) {
dirs = listDirectories({ ignore: options.excludeOnly }, options.dir)
dirs = listDirectories({ ignore: options.excludeOnly }, options.dir);
} else if (options.exclude) {
dirs = dirs.filter((dir) => {
dirs = dirs.filter(dir => {
return options.exclude.indexOf(path.basename(dir)) === -1;

@@ -39,3 +40,8 @@ });

} else if (options.include) {
dirs = _.union(dirs, options.include.map((i) => { return path.resolve(cwd, i); })).sort();
dirs = _.union(
dirs,
options.include.map(i => {
return path.resolve(cwd, i);
})
).sort();
}

@@ -50,48 +56,52 @@

mapExec(commands, (err, commandOutputs) => {
mapExec(
commands,
options,
(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);
}
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) => {
const color = commandOutput.error ? 'red' : 'green';
const code = commandOutput.error && commandOutput.error.code !== 0 ? commandOutput.error.code : null;
const output = commandOutput.output || commandOutput.error;
const results = commandOutputs.reduce((logMessage, commandOutput, index) => {
const color = commandOutput.error ? 'red' : 'green';
const code = commandOutput.error && commandOutput.error.code !== 0
? commandOutput.error.code
: null;
const output = commandOutput.output || commandOutput.error;
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 (commandOutput.error) {
if (options.exitOnError) {
console.log(`a child command executed by loop encountered an error:\n${commandOutput.error}`);
process.exit(1);
if (code && options.exitOnError) {
process.exit(code);
}
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);
}
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);
}
commandOutputsWithErrors.push(error);
});
);
};

@@ -6,13 +6,20 @@ const async = require('async');

module.exports = (commands, cb, errorCb) => {
return async.map(commands, (cmd, cb) => {
return exec({
command: cmd.command,
dir: cmd.dir,
exitOnError: cmd.exitOnError,
exitOnAggregateError: cmd.exitOnAggregateError,
}, cb, errorCb);
}, cb);
}
module.exports = (commands, options, cb, errorCb) => {
return async.map(
commands,
(cmd, cb) => {
return exec(
{
command: cmd.command,
dir: cmd.dir,
exitOnError: cmd.exitOnError,
exitOnAggregateError: cmd.exitOnAggregateError,
parallel: options && options.parallel,
},
cb,
errorCb
);
},
cb
);
};
{
"name": "loop",
"version": "3.2.0",
"version": "3.3.0",
"description": "loop through commands in fun and amazing ways!",

@@ -5,0 +5,0 @@ "main": "./index.js",

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