Skip to content

Commit

Permalink
fixing codacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cope committed Aug 18, 2018
1 parent f0897ce commit 5aa55e1
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions lib/updatejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,60 +75,63 @@ const find = (path, file, rootOnly) => {
return ret;
};

const update = (commander) => {
options = commander;

// Build lists of promises for npm:
const fillNpmPromises = (options) => {
let npmPromises = [];
if (options.npm) {
let npmLocations = find(process.cwd(), "package.json", true);
if (!_.isEmpty(npmLocations)) _.forEach(npmLocations, (location) => npmPromises.push(build(location, "npm", colors.magenta)));
else console.log("No package.json found, skipping npm calls.".yellow);
}
return npmPromises;
};

// Build lists of promises for bower:
const fillBowerPromises = (options) => {
let bowerPromises = [];
if (options.bower) {
let bowerLocations = find(process.cwd(), "bower.json");
if (!_.isEmpty(bowerLocations)) _.forEach(bowerLocations, (location) => bowerPromises.push(build(location, "bower", colors.blue)));
else console.log("No bower.json found, skipping bower calls.".yellow);
}
return bowerPromises;
};

// Parallel processing:
if (options.parallel) {
let parameters = params();

// Buffered output for parallel processing:
if (options.buffered) {
console.log("Running all npm calls...".magenta);
exec("updatejs -n" + parameters, (error, stdout) => console.log(stdout.magenta));

console.log("Running all bower calls...".blue);
exec("updatejs -b" + parameters, (error, stdout) => console.log(stdout.blue));

// Real time, non-buffered output for parallel processing:
} else {
let npmChild = exec("updatejs -n" + parameters);
npmChild.stdout.on("data", (data) => {
if (data.indexOf("For") >= 0) console.log(data.red);
else if (data.indexOf("Done") >= 0) console.log(data.green);
else console.log(data.magenta);
});

let bowerChild = exec("updatejs -b" + parameters);
bowerChild.stdout.on("data", (data) => {
if (data.indexOf("For") >= 0) console.log(data.red);
else if (data.indexOf("Done") >= 0) console.log(data.green);
else console.log(data.blue);
});
}
}
const bufferedParallelProcessing = (parameters) => {
console.log("Running all npm calls...".magenta);
exec("updatejs -n" + parameters, (error, stdout) => console.log(stdout.magenta));

// Sequential processing:
else {
let promises = _.concat(npmPromises, bowerPromises);
seq(promises).then(() => console.log("Done.".green));
}
console.log("Running all bower calls...".blue);
exec("updatejs -b" + parameters, (error, stdout) => console.log(stdout.blue));
};

const printData = (data) => {
if (data.indexOf("For") >= 0) console.log(data.red);
else if (data.indexOf("Done") >= 0) console.log(data.green);
else console.log(data.magenta);
};

const nonBufferedParallelProcessing = (parameters) => {
let npmChild = exec("updatejs -n" + parameters);
npmChild.stdout.on("data", printData);

let bowerChild = exec("updatejs -b" + parameters);
bowerChild.stdout.on("data", printData);
};

const parallelProcessing = (options) => {
let parameters = params();
if (options.buffered) bufferedParallelProcessing(parameters);
else nonBufferedParallelProcessing(parameters);
};

const sequentialProcessing = (options) => {
let promises = _.concat(fillNpmPromises(options), fillBowerPromises(options));
seq(promises).then(() => console.log("Done.".green));
};

const update = (commander) => {
options = commander;
if (options.parallel) parallelProcessing(options);
else sequentialProcessing(options);
};

module.exports = {update};

0 comments on commit 5aa55e1

Please sign in to comment.