Skip to content

Commit

Permalink
feat(nx): delegate to cli when command is not recognized
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jul 8, 2019
1 parent dc556bd commit 7b00b92
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 421 deletions.
79 changes: 0 additions & 79 deletions docs/api-workspace/npmscripts/update-check.md

This file was deleted.

79 changes: 0 additions & 79 deletions docs/api-workspace/npmscripts/update-skip.md

This file was deleted.

79 changes: 0 additions & 79 deletions docs/api-workspace/npmscripts/update.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# lint [files..]
# workspace-lint [files..]

Lint workspace or list of files

## Usage

```bash
lint [files..]
workspace-lint [files..]
```

## Options
Expand Down
2 changes: 1 addition & 1 deletion e2e/schematics/command-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Command line', () => {
runCLI(`generate @nrwl/angular:app ${appBefore}`);
runCommand(`mv apps/${appBefore} apps/${appAfter}`);

const stdout = runCommand('./node_modules/.bin/nx lint');
const stdout = runCommand('./node_modules/.bin/nx workspace-lint');
expect(stdout).toContain(
`Cannot find project '${appBefore}' in 'apps/${appBefore}'`
);
Expand Down
23 changes: 23 additions & 0 deletions e2e/schematics/delegate-to-cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ensureProject, uniq, runCommand, checkFilesExist } from '../utils';

describe('Delegate to CLI', () => {
it('should delegate to the Angular CLI all non-standard commands', async () => {
ensureProject();

const appName = uniq('app');
runCommand(`npm run nx -- g app ${appName}`);
runCommand(`npm run nx -- build ${appName}`);

checkFilesExist(
`dist/apps/${appName}/index.html`,
`dist/apps/${appName}/polyfills-es2015.js`,
`dist/apps/${appName}/runtime-es2015.js`,
`dist/apps/${appName}/main-es2015.js`,
`dist/apps/${appName}/styles-es2015.js`,
`dist/apps/${appName}/polyfills-es5.js`,
`dist/apps/${appName}/runtime-es5.js`,
`dist/apps/${appName}/main-es5.js`,
`dist/apps/${appName}/styles-es5.js`
);
}, 120000);
});
3 changes: 2 additions & 1 deletion e2e/schematics/ng-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ describe('Nrwl Convert to Nx Workspace', () => {
expect(updatedPackageJson.description).toEqual('some description');
expect(updatedPackageJson.scripts).toEqual({
ng: 'ng',
nx: 'nx',
start: 'ng serve',
build: 'ng build',
test: 'ng test',
lint: 'nx lint && ng lint',
lint: 'nx workspace-lint && ng lint',
e2e: 'ng e2e',
'affected:apps': 'nx affected:apps',
'affected:libs': 'nx affected:libs',
Expand Down
5 changes: 5 additions & 0 deletions packages/workspace/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"version": "8.2.0-beta.1",
"description": "Add exclusions to lint config",
"factory": "./src/migrations/update-8-2-0/update-8-2-0"
},
"rename-lint-into-workspace-lint": {
"version": "8.3.0-beta.1",
"description": "Rename 'nx lint' into 'nx workspace-lint' to avoid confusion",
"factory": "./src/migrations/update-8-3-0/rename-lint"
}
}
}
36 changes: 25 additions & 11 deletions packages/workspace/src/command-line/nx-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,31 @@ import * as yargs from 'yargs';

import { affected } from './affected';
import { format } from './format';
import { update } from './update';
import { lint } from './lint';
import { workspaceSchematic } from './workspace-schematic';
import { generateGraph, OutputType } from './dep-graph';

const noop = (yargs: yargs.Argv): yargs.Argv => yargs;

export const supportedNxCommands = [
'affected',
'affected:apps',
'affected:libs',
'affected:build',
'affected:test',
'affected:e2e',
'affected:dep-graph',
'affected:lint',
'dep-graph',
'format',
'format:check',
'format:write',
'workspace-schematic',
'workspace-lint',
'--help',
'--version'
];

/**
* Exposing the Yargs commands object so the documentation generator can
* parse it. The CLI will consume it and call the `.argv` to bootstrapped
Expand Down Expand Up @@ -114,15 +132,12 @@ export const commandsObject = yargs
args => format('write', args)
)
.alias('format:write', 'format')
.command('lint [files..]', 'Lint workspace or list of files', noop, _ =>
lint()
)
.command('update:check', 'Check for workspace updates', noop, _ =>
update(['check'])
.command(
'workspace-lint [files..]',
'Lint workspace or list of files',
noop,
_ => lint()
)
.command('update:skip', 'Skip workspace updates', noop, _ => update(['skip']))
.command('update', 'Update workspace', noop, _ => update([]))
.alias('update', 'migrates') // TODO: Remove after 1.0
.command(
'workspace-schematic [name]',
'Runs a workspace schematic from the tools/schematics directory',
Expand All @@ -147,8 +162,7 @@ export const commandsObject = yargs
)
.help('help')
.version()
.option('quiet', { type: 'boolean', hidden: true })
.demandCommand();
.option('quiet', { type: 'boolean', hidden: true });

function withFormatOptions(yargs: yargs.Argv): yargs.Argv {
return withAffectedOptions(yargs).option('apps-and-libs', {
Expand Down
15 changes: 9 additions & 6 deletions packages/workspace/src/command-line/nx.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/usr/bin/env node
import { commandsObject } from '@nrwl/workspace';
import { commandsObject, supportedNxCommands } from './nx-commands';
import { closestCli } from '../utils/app-root';

export interface GlobalNxArgs {
help?: boolean;
version?: boolean;
quiet?: boolean;
}

/**
* The commandsObject is a Yargs object declared in `nx-commands.ts`,
* It is exposed and bootstrapped here to provide CLI features.
*/
commandsObject.argv; // .argv bootstraps the CLI creation;
if (supportedNxCommands.includes(process.argv[2])) {
// The commandsObject is a Yargs object declared in `nx-commands.ts`,
// It is exposed and bootstrapped here to provide CLI features.
commandsObject.argv; // .argv bootstraps the CLI creation;
} else {
require(closestCli(__dirname));
}
Loading

0 comments on commit 7b00b92

Please sign in to comment.