Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option --report-by-task #176

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/common/parse-cli-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ function parseCLIArgsCore(set, args) { // eslint-disable-line complexity
set.continueOnError = true
break

case "--report-by-task":
set.reportByTask = true
break

case "-l":
case "--print-label":
set.printLabel = true
Expand Down
1 change: 1 addition & 0 deletions bin/npm-run-all/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = function npmRunAll(args, stdout, stderr) {
parallel: group.parallel,
maxParallel: group.parallel ? argv.maxParallel : 1,
continueOnError: argv.continueOnError,
reportByTask: argv.reportByTask,
printLabel: argv.printLabel,
printName: argv.printName,
config: argv.config,
Expand Down
34 changes: 34 additions & 0 deletions lib/create-task-streams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @module create-task-streams
* See LICENSE file in root directory for full license.
*/
"use strict"

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const createWriteStream = require("fs").createWriteStream

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------

/**
* Creates output and error stream for a task
*
* @param {string} fileName - fileName
* @returns {object} streams outStream errStream
*/
module.exports = function createTaskStreams(fileName) {
if (!fileName) {
return undefined
}

const sanitizedFileName = fileName.replace(/\W/g, "_")

const outStream = createWriteStream(`${sanitizedFileName}.out`)
const errStream = createWriteStream(`${sanitizedFileName}.err`)

return { outStream, errStream }
}
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ module.exports = function npmRunAll(patternOrPatterns, options) { //eslint-disab
const parallel = Boolean(options && options.parallel)
const silent = Boolean(options && options.silent)
const continueOnError = Boolean(options && options.continueOnError)
const reportByTask = Boolean(options && options.reportByTask)
const printLabel = Boolean(options && options.printLabel)
const printName = Boolean(options && options.printName)
const race = Boolean(options && options.race)
Expand Down Expand Up @@ -266,6 +267,7 @@ module.exports = function npmRunAll(patternOrPatterns, options) { //eslint-disab
stderr,
prefixOptions,
continueOnError,
reportByTask,
labelState: {
enabled: printLabel,
width: labelWidth,
Expand Down
25 changes: 22 additions & 3 deletions lib/run-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const chalk = require("chalk")
const parseArgs = require("shell-quote").parse
const padEnd = require("string.prototype.padend")
const createHeader = require("./create-header")
const createTaskStreams = require("./create-task-streams")
const createPrefixTransform = require("./create-prefix-transform-stream")
const spawn = require("./spawn")

Expand Down Expand Up @@ -142,7 +143,19 @@ module.exports = function runTask(task, options) {
const stdinKind = detectStreamKind(stdin, process.stdin)
const stdoutKind = detectStreamKind(stdout, process.stdout)
const stderrKind = detectStreamKind(stderr, process.stderr)
const spawnOptions = { stdio: [stdinKind, stdoutKind, stderrKind] }
let spawnOutKind = stdoutKind
let spawnErrKind = stderrKind

let childStreams = undefined
if (options.reportByTask) {
childStreams = createTaskStreams(task)
if (childStreams) {
spawnOutKind = "pipe"
spawnErrKind = "pipe"
}
}

const spawnOptions = { stdio: [stdinKind, spawnOutKind, spawnErrKind] }

// Print task name.
if (options.printName && stdout != null) {
Expand Down Expand Up @@ -177,11 +190,17 @@ module.exports = function runTask(task, options) {
if (stdinKind === "pipe") {
stdin.pipe(cp.stdin)
}
if (stdoutKind === "pipe") {
if (spawnOutKind === "pipe") {
cp.stdout.pipe(stdout, { end: false })
if (childStreams) {
cp.stdout.pipe(childStreams.outStream)
}
}
if (stderrKind === "pipe") {
if (spawnErrKind === "pipe") {
cp.stderr.pipe(stderr, { end: false })
if (childStreams) {
cp.stderr.pipe(childStreams.errStream)
}
}

// Register
Expand Down