Skip to content

Commit

Permalink
fix(schematics): filter nx specific flags from being passed to ng cli
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored and vsavkin committed May 8, 2018
1 parent f746d7d commit 9a1e6c0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
1 change: 1 addition & 0 deletions e2e/schematics/command-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ describe('Command line', () => {
'npm run affected:build -- --files="libs/mylib/src/index.ts"'
);
expect(build).toContain('Building myapp');
expect(build).not.toContain('is not registered with the build command');

const e2e = runCommand(
'npm run affected:e2e -- --files="libs/mylib/src/index.ts"'
Expand Down
47 changes: 30 additions & 17 deletions packages/schematics/src/command-line/affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ import {
ProjectType
} from '@nrwl/schematics/src/command-line/affected-apps';

export function affected(args: string[]): void {
const command = args[0];
export function affected(
command: string,
parsedArgs: any,
args: string[]
): void {
let apps: string[];
let e2eProjects: string[];
let projects: string[];
let rest: string[];

try {
const p = parseFiles(args.slice(1));
const p = parseFiles(args);
rest = p.rest;
apps = getAffectedApps(p.files);
e2eProjects = getAffectedE2e(p.files);
Expand All @@ -40,10 +43,10 @@ export function affected(args: string[]): void {
console.log(apps.join(' '));
break;
case 'build':
build(apps, rest);
build(apps, rest, parsedArgs.parallel);
break;
case 'test':
test(projects, rest);
test(projects, rest, parsedArgs.parallel);
break;
case 'e2e':
e2e(e2eProjects, rest);
Expand All @@ -58,13 +61,14 @@ function printError(command: string, e: any) {
console.error(e.message);
}

function build(apps: string[], rest: string[]) {
function build(apps: string[], rest: string[], parallel: boolean) {
if (apps.length > 0) {
console.log(`Building ${apps.join(', ')}`);
runCommand(
'build',
apps,
rest,
parallel,
'Building ',
'Build succeeded.',
'Build failed.'
Expand All @@ -74,7 +78,7 @@ function build(apps: string[], rest: string[]) {
}
}

function test(projects: string[], rest: string[]) {
function test(projects: string[], rest: string[], parallel: boolean) {
const depGraph = readDepGraph();
const sortedProjects = topologicallySortProjects(depGraph);
const sortedAffectedProjects = sortedProjects.filter(
Expand All @@ -90,6 +94,7 @@ function test(projects: string[], rest: string[]) {
'test',
projectsToTest,
rest,
parallel,
'Testing ',
'Tests passed.',
'Tests failed.'
Expand All @@ -103,20 +108,12 @@ function runCommand(
command: string,
projects: string[],
args: string[],
parallel: boolean,
iterationMessage: string,
successMessage: string,
errorMessage: string
) {
const parallel = yargsParser(args, {
default: {
parallel: false
},
boolean: ['parallel']
}).parallel;

const normalizedArgs = args.filter(
a => !a.startsWith('--parallel') && !a.startsWith('--no-parallel')
);
const normalizedArgs = filterNxSpecificArgs(args);
if (parallel) {
runAll(
projects.map(
Expand Down Expand Up @@ -182,6 +179,22 @@ function e2e(apps: string[], rest: string[]) {
}
}

function filterNxSpecificArgs(args: string[]): string[] {
const nxSpecificFlags = [
'--parallel',
'--no-parallel',
'--base',
'--head',
'--files',
'--uncommitted',
'--untracked'
];

return args.filter(
arg => !nxSpecificFlags.some(flag => arg.startsWith(flag))
);
}

function ngPath() {
const basePath = path.dirname(
path.dirname(
Expand Down
10 changes: 5 additions & 5 deletions packages/schematics/src/command-line/nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ yargs
'affected:apps',
'Print applications affected by changes',
withAffectedOptions,
() => affected(['apps', ...process.argv.slice(3)])
args => affected('apps', args, process.argv.slice(3))
)
.command(
'affected:test',
'Test applications affected by the change',
yargs => withAffectedOptions(withParallel(yargs)),
() => affected(['test', ...process.argv.slice(3)])
args => affected('test', args, process.argv.slice(3))
)
.command(
'affected:build',
'Build applications affected by changes',
yargs => withAffectedOptions(withParallel(yargs)),
() => affected(['build', ...process.argv.slice(3)])
args => affected('build', args, process.argv.slice(3))
)
.command(
'affected:e2e',
'Run e2e tests for the applications affected by changes',
withAffectedOptions,
() => affected(['e2e', ...process.argv.slice(3)])
args => affected('e2e', args, process.argv.slice(3))
)
.command(
'affected:dep-graph',
'Graph dependencies affected by changes',
yargs => withAffectedOptions(withDepGraphOptions(yargs)),
() => affected(['dep-graph', ...process.argv.slice(3)])
args => affected('dep-graph', args, process.argv.slice(3))
)
.command(
'dep-graph',
Expand Down

0 comments on commit 9a1e6c0

Please sign in to comment.