Skip to content

Commit

Permalink
fix(nx): allow more types of arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Mar 21, 2018
1 parent c81fe9e commit 117a922
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 7,536 deletions.
39 changes: 39 additions & 0 deletions e2e/schematics/command-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,43 @@ describe('Command line', () => {
},
1000000
);

describe('Testing:', () => {
beforeAll(() => {
newProject();
newApp('app1');
}, 1000000);

it('should pass tests', () => {
expect(runCommand('npm run test -- --single-run').toString())
.toContain('Executed 1 of 1 SUCCESS');
});

it('should not be able to run tests on an individual app', () => {
try {
expect(runCommand('npm run test -- --app app1 --single-run'));
fail('boom');
} catch (e) {
const errorOutput = e.stderr.toString();
expect(errorOutput)
.toContain('Nx only supports running unit tests for all apps and libs.');
}
});

it('should pass e2e tests', () => {
expect(runCommand('npm run e2e -- --app app1').toString())
.toContain('should display welcome message');
});

it('should not be able to run e2e tests without specifying an app', () => {
try {
expect(runCommand('npm run e2e'));
fail('boom');
} catch (e) {
const errorOutput = e.stderr.toString();
expect(errorOutput)
.toContain('Please provide the app name using --app or -a.')
}
});
});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"angular": "1.6.6",
"app-root-path": "^2.0.1",
"cosmiconfig": "^4.0.0",
"ng-packagr": "2.2.0",
"husky": "^0.14.3",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
Expand All @@ -53,6 +52,7 @@
"karma-chrome-launcher": "~2.2.0",
"karma-jasmine": "~1.1.0",
"karma-webpack": "2.0.4",
"ng-packagr": "2.2.0",
"precise-commits": "1.0.0",
"prettier": "1.10.2",
"rxjs": "^5.5.6",
Expand All @@ -61,6 +61,7 @@
"tmp": "0.0.33",
"tslint": "5.9.1",
"typescript": "2.6.2",
"yargs-parser": "9.0.2",
"zone.js": "^0.8.19"
},
"author": "Victor Savkin",
Expand Down
3 changes: 2 additions & 1 deletion packages/bazel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"app-root-path": "^2.0.1",
"semver": "5.4.1",
"tmp": "0.0.33"
"tmp": "0.0.33",
"yargs-parser": "9.0.2"
}
}
28 changes: 13 additions & 15 deletions packages/bazel/src/utils/cli-config-utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import * as fs from 'fs';
import * as yargsParser from 'yargs-parser';

export function getAppDirectoryUsingCliConfig() {
const appArg = findAppArg();
const cli = JSON.parse(
fs.readFileSync(process.cwd() + '/.angular-cli.json', 'UTF-8')
);

if (appArg) {
const appName = appArg.split('=')[1];
const app = cli.apps.filter(a => a.name === appName)[0];
const appName = getAppName();

if (appName) {
const app = cli.apps.find(a => a.name === appName);
if (!app) {
console.error(`Cannot find app '${appName}'.`);
process.exit(1);
Expand All @@ -25,22 +26,19 @@ export function getAppDirectoryUsingCliConfig() {
}

export function makeSureNoAppIsSelected() {
if (findAppArg()) {
if (getAppName()) {
console.error('Nx only supports running unit tests for all apps and libs.');
console.error('You cannot use -a or --app.');
console.error('Use fdescribe or fit to select a subset of tests to run.');
process.exit(1);
}
}

function findAppArg() {
return process.argv.filter(
a =>
a.startsWith(`-a=`) ||
a.startsWith(`--app=`) ||
a.startsWith(`"-a="`) ||
a.startsWith(`"--app="`) ||
a.startsWith(`'-a='`) ||
a.startsWith(`'--app='`)
)[0];
function getAppName() {
return yargsParser(process.argv, {
alias: {
app: ['a']
},
string: ['app']
}).app;
}
22 changes: 15 additions & 7 deletions packages/schematics/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ import {
writeFileSync
} from 'fs';
import * as path from 'path';
import * as yargsParser from 'yargs-parser';

const useYarn = process.argv.filter(p => p === '--yarn').length > 0;
interface CommandOptions {
directory?: string;
yarn: boolean;
}

const parsedArgs = yargsParser(process.argv, {
string: ['directory'],
boolean: ['yarn']
});

const useYarn = parsedArgs.yarn;

if (!useYarn) {
try {
Expand All @@ -31,9 +42,7 @@ if (!useYarn) {
}
}

const projectName = process.argv
.slice(2)
.filter(arg => !arg.startsWith('--'))[0];
const projectName = parsedArgs._[2];

// check that the workspace name is passed in
if (!projectName) {
Expand Down Expand Up @@ -85,9 +94,8 @@ execSync(
}
);

const dir = process.argv.filter(
a => a.startsWith('-dir') || a.startsWith('--directory')
)[0];
const dir = parsedArgs.directory;

const cwd = dir ? dir.split('=')[1] : projectName;

if (useYarn) {
Expand Down
3 changes: 2 additions & 1 deletion packages/schematics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"app-root-path": "^2.0.1",
"semver": "5.4.1",
"tmp": "0.0.33"
"tmp": "0.0.33",
"yargs-parser": "9.0.2"
}
}
10 changes: 9 additions & 1 deletion packages/schematics/src/command-line/nx.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#!/usr/bin/env node
import * as yargsParser from 'yargs-parser';

import { affected } from './affected';
import { format } from './format';
import { update } from './update';
import { patchNg } from './patch-ng';

const command = process.argv[2];
const processedArgs = yargsParser(process.argv, {
alias: {
app: ['a']
},
string: ['app']
});
const command = processedArgs._[2];
const args = process.argv.slice(3);

switch (command) {
Expand Down
28 changes: 13 additions & 15 deletions packages/schematics/src/utils/cli-config-utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import * as fs from 'fs';
import * as yargsParser from 'yargs-parser';

export function getAppDirectoryUsingCliConfig() {
const appArg = findAppArg();
const cli = JSON.parse(
fs.readFileSync(process.cwd() + '/.angular-cli.json', 'UTF-8')
);

if (appArg) {
const appName = appArg.split('=')[1];
const app = cli.apps.filter(a => a.name === appName)[0];
const appName = getAppName();

if (appName) {
const app = cli.apps.find(a => a.name === appName);
if (!app) {
console.error(`Cannot find app '${appName}'.`);
process.exit(1);
Expand All @@ -25,22 +26,19 @@ export function getAppDirectoryUsingCliConfig() {
}

export function makeSureNoAppIsSelected() {
if (findAppArg()) {
if (getAppName()) {
console.error('Nx only supports running unit tests for all apps and libs.');
console.error('You cannot use -a or --app.');
console.error('Use fdescribe or fit to select a subset of tests to run.');
process.exit(1);
}
}

function findAppArg() {
return process.argv.filter(
a =>
a.startsWith(`-a=`) ||
a.startsWith(`--app=`) ||
a.startsWith(`"-a="`) ||
a.startsWith(`"--app="`) ||
a.startsWith(`'-a='`) ||
a.startsWith(`'--app='`)
)[0];
function getAppName() {
return yargsParser(process.argv, {
alias: {
app: ['a']
},
string: ['app']
}).app;
}
Loading

0 comments on commit 117a922

Please sign in to comment.