From 8bd58b5ae2d2010cd9cbeea04aee8a6847440246 Mon Sep 17 00:00:00 2001 From: johanblumenberg Date: Sun, 29 Sep 2019 17:37:26 +0200 Subject: [PATCH] Add name-prefix option --- src/index.ts | 10 +++++++++- src/run-graph.ts | 7 ++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index aba97c7..fd5024b 100755 --- a/src/index.ts +++ b/src/index.ts @@ -67,6 +67,7 @@ let yargsParser = yargs 'fast-exit', 'collect-logs', 'no-prefix', + 'name-prefix', 'rewrite-paths', 'bin', 'done-criteria', @@ -99,6 +100,12 @@ let yargsParser = yargs boolean: true, describe: "Don't prefix output" }, + 'name-prefix': { + alias: 'n', + default: false, + boolean: true, + describe: "Prefix output with package name" + }, 'rewrite-paths': { boolean: true, describe: @@ -202,7 +209,8 @@ let runner = new RunGraph( bin, fastExit, collectLogs, - addPrefix, + addPrefix: addPrefix || argv.namePrefix, + linePrefix: argv.namePrefix ? '' : ' | ', rewritePaths, mode: mode as any, recursive, diff --git a/src/run-graph.ts b/src/run-graph.ts index d974d82..1421efa 100644 --- a/src/run-graph.ts +++ b/src/run-graph.ts @@ -16,12 +16,12 @@ let mkThroat = require('throat')(Bromise) as ((limit: number) => PromiseFnRunner let passThrough: PromiseFnRunner = f => f() class Prefixer { - constructor(private wspath: string) {} + constructor(private wspath: string, private linePrefix: string) { } private currentName = '' prefixer = (basePath: string, pkg: string, line: string) => { let l = '' if (this.currentName != pkg) l += chalk.bold((this.currentName = pkg)) + '\n' - l += ' | ' + line // this.processFilePaths(basePath, line) + l += this.linePrefix + line // this.processFilePaths(basePath, line) return l } } @@ -31,6 +31,7 @@ export interface GraphOptions { fastExit: boolean collectLogs: boolean addPrefix: boolean + linePrefix: string; rewritePaths: boolean mode: 'parallel' | 'serial' | 'stages' recursive: boolean @@ -52,7 +53,7 @@ export class RunGraph { private runList = new Set() private resultMap = new Map() private throat: PromiseFnRunner = passThrough - prefixer = new Prefixer(this.opts.workspacePath).prefixer + prefixer = new Prefixer(this.opts.workspacePath, this.opts.linePrefix).prefixer pathRewriter = (pkgPath: string, line: string) => fixPaths(this.opts.workspacePath, pkgPath, line) constructor(