diff --git a/README.md b/README.md index 0c93a28..e706ca1 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ Misc Options: --if Run main command only if this condition runs successfully --ifDependency Run main command only if packages dependencies passed the condition (not available in parallel mode) [boolean] + --if-private Run main command only if the package is private [boolean] + --if-public Run main command only if the package is public [boolean] Other Options: --help Show help [boolean] @@ -90,3 +92,7 @@ Examples `yarn wsrun --stages --if build-needed build` - for each package it will first try `yarn wsrun build-needed` and only if the exit code is zero (success) it will run `yarn wsrun build` `yarn wsrun --stages --if build-needed --if-dependency build` - it will run `build` for each package in stages, if either the package's own condition command was success, or any of the dependencies had a successful condition. + +#### Publishing public packages + +`yarn wsrun --stages --if-public publish` \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index c6bb39b..3720f45 100755 --- a/src/index.ts +++ b/src/index.ts @@ -74,7 +74,9 @@ let yargsParser = yargs 'exclude-missing', 'report', 'if', - 'ifDependency' + 'ifDependency', + 'if-private', + 'if-public' ], 'Misc Options:' ) @@ -87,6 +89,14 @@ let yargsParser = yargs 'Run main command only if packages dependencies passed the condition (not available in parallel mode)', boolean: true }, + 'if-private': { + describe: 'Run main command only if the package is private', + boolean: true + }, + 'if-public': { + describe: 'Run main command only if the package is public', + boolean: true + }, 'fast-exit': { boolean: true, describe: 'If at least one script exits with code > 0, abort' @@ -211,6 +221,8 @@ let runner = new RunGraph( excludeMissing, showReport, if: argv.if || null, + ifPrivate: argv.ifPrivate || false, + ifPublic: argv.ifPublic || false, ifDependency: argv.ifDependency || false, workspacePath: process.cwd(), concurrency diff --git a/src/run-graph.ts b/src/run-graph.ts index 3796f31..072d258 100644 --- a/src/run-graph.ts +++ b/src/run-graph.ts @@ -44,6 +44,8 @@ export interface GraphOptions { excludeMissing: boolean showReport: boolean if: string + ifPublic: boolean + ifPrivate: boolean ifDependency: boolean concurrency: number | null } @@ -168,11 +170,14 @@ export class RunGraph { let ifCondtition = Bromise.resolve(true) - if ( - this.opts.if && - (!this.opts.ifDependency || !depsStatuses.find(ds => ds === ProcResolution.Normal)) - ) { - ifCondtition = this.runCondition(this.opts.if, pkg) + if (!this.opts.ifDependency || !depsStatuses.find(ds => ds === ProcResolution.Normal)) { + if (this.opts.if) { + ifCondtition = this.runCondition(this.opts.if, pkg) + } else if (this.opts.ifPrivate && p) { + ifCondtition = Bromise.resolve(p.private || false) + } else if (this.opts.ifPublic && p) { + ifCondtition = Bromise.resolve(!p.private) + } } let child = ifCondtition.then(shouldExecute => { diff --git a/src/workspace.ts b/src/workspace.ts index 61278bf..95a75ac 100644 --- a/src/workspace.ts +++ b/src/workspace.ts @@ -11,6 +11,7 @@ export type Dict = { [key: string]: T } export interface PkgJson { name: string + private?: boolean dependencies?: Dict devDependencies?: Dict scripts?: { [name: string]: string } diff --git a/tests/basic.ts b/tests/basic.ts index 9f7efbd..775fbe3 100644 --- a/tests/basic.ts +++ b/tests/basic.ts @@ -1,14 +1,34 @@ import 'jest' import { withScaffold, echo, wsrun } from './test.util' -let pkgList = (errorp3: boolean = false, condition?: string) => [ - echo.makePkg({ name: 'p1', dependencies: { p2: '*' } }, condition), - echo.makePkg({ name: 'p2', dependencies: { p3: '*', p4: '*' } }, condition), +let pkgList = ( + errorp3: boolean = false, + condition?: string, + privatePackages: { [key: string]: boolean } = {} +) => [ + echo.makePkg( + { name: 'p1', private: privatePackages['p1'], dependencies: { p2: '*' } }, + condition + ), + echo.makePkg( + { name: 'p2', private: privatePackages['p2'], dependencies: { p3: '*', p4: '*' } }, + condition + ), errorp3 - ? echo.makePkgErr({ name: 'p3', dependencies: { p4: '*', p5: '*' } }) - : echo.makePkg({ name: 'p3', dependencies: { p4: '*', p5: '*' } }, condition), - echo.makePkg({ name: 'p4', dependencies: { p5: '*' } }, condition), - echo.makePkg({ name: 'p5', dependencies: {} }, condition) + ? echo.makePkgErr({ + name: 'p3', + private: privatePackages['p3'], + dependencies: { p4: '*', p5: '*' } + }) + : echo.makePkg( + { name: 'p3', private: privatePackages['p3'], dependencies: { p4: '*', p5: '*' } }, + condition + ), + echo.makePkg( + { name: 'p4', private: privatePackages['p4'], dependencies: { p5: '*' } }, + condition + ), + echo.makePkg({ name: 'p5', private: privatePackages['p5'], dependencies: {} }, condition) ] describe('basic', () => { @@ -90,6 +110,34 @@ describe('basic', () => { ) }) + it('should support if-private execution', async () => { + await withScaffold( + { + packages: pkgList(false, undefined, { p4: true }) + }, + async () => { + let tst = await wsrun('--stages -r --if-private -- doecho') + expect(tst.error).toBeFalsy() + let output = await echo.getOutput() + expect(output).toEqual(['p4', ''].join('\n')) + } + ) + }) + + it('should support if-public execution', async () => { + await withScaffold( + { + packages: pkgList(false, undefined, { p1: true, p2: true, p3: true, p5: true }) + }, + async () => { + let tst = await wsrun('--stages -r --if-public -- doecho') + expect(tst.error).toBeFalsy() + let output = await echo.getOutput() + expect(output).toEqual(['p4', ''].join('\n')) + } + ) + }) + it('should support dependant conditional execution', async () => { await withScaffold( { diff --git a/tests/test.util.ts b/tests/test.util.ts index 74c85be..68984ac 100644 --- a/tests/test.util.ts +++ b/tests/test.util.ts @@ -23,6 +23,7 @@ let mkdirpAsync = promisify(mkdirp) export type PackageJson = { name?: string + private?: boolean path?: string dependencies?: { [name: string]: string } devDependencies?: { [name: string]: string }