Skip to content

Commit

Permalink
feat(nx): misc ux improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jul 29, 2019
1 parent c1435c4 commit 192a6a0
Show file tree
Hide file tree
Showing 24 changed files with 151 additions and 68 deletions.
6 changes: 6 additions & 0 deletions docs/api-workspace/schematics/preset.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ ng generate preset ...

## Options

### cli

Type: `string`

CLI powering the workspace.

### name

Type: `string`
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/schematics/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
toFileName,
updateJsonInTree,
updateWorkspace,
addGlobalLint
addLintFiles
} from '@nrwl/workspace';
import { join, normalize } from '@angular-devkit/core';
import ngAdd from '../ng-add/ng-add';
Expand Down Expand Up @@ -369,7 +369,7 @@ export default function(schema: Schema): Rule {
...options,
skipFormat: true
}),
addGlobalLint('tslint'),
addLintFiles(options.appProjectRoot, 'tslint', true),
externalSchematic('@schematics/angular', 'application', {
name: options.name,
inlineStyle: options.inlineStyle,
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/schematics/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
updateJsonInTree,
readJsonInTree,
offsetFromRoot,
addGlobalLint
addLintFiles
} from '@nrwl/workspace';
import { addGlobal, addIncludeToTsConfig, insert } from '@nrwl/workspace';
import { toClassName, toFileName, toPropertyName } from '@nrwl/workspace';
Expand Down Expand Up @@ -431,7 +431,7 @@ export default function(schema: Schema): Rule {
}

return chain([
addGlobalLint('tslint'),
addLintFiles(options.projectRoot, 'tslint', true),
addUnitTestRunner(options),
externalSchematic('@schematics/angular', 'library', {
name: options.name,
Expand Down
25 changes: 19 additions & 6 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ const presetOptions = [
name: 'react [a workspace with a single React application]'
},
{
value: 'full-stack',
value: 'nest-angular',
name:
'full-stack [a workspace with a full stack application (NestJS + Angular)]'
'angular-nest [a workspace with a full stack application (Angular + Nest)]'
}
// {
// value: 'react-express',
// name:
// 'react-express [a workspace with a full stack application (React + Express)]'
// }
];

const tsVersion = 'TYPESCRIPT_VERSION';
Expand Down Expand Up @@ -223,9 +228,13 @@ function determineCli(preset: string, parsedArgs: any) {
return Promise.resolve(parsedArgs.cli === 'angular' ? angular : nx);
}

if (preset == 'angular' || preset == 'full-stack') {
if (preset == 'angular' || preset == 'angular-nest') {
return Promise.resolve(angular);
} else if (preset === 'web-components' || preset === 'react') {
} else if (
preset === 'web-components' ||
preset === 'react' ||
preset === 'react-express'
) {
return Promise.resolve(nx);
} else {
return inquirer
Expand Down Expand Up @@ -332,15 +341,19 @@ function showNxWarning() {

function showCliWarning(preset: string, parsedArgs: any) {
if (!parsedArgs.cli) {
if (preset == 'angular' || preset == 'full-stack') {
if (preset === 'angular' || preset === 'angular-nest') {
output.addVerticalSeparator();
output.note({
title: `Because you selected an Angular-specific preset, we generated an Nx workspace powered by the Angular CLI.`,
bodyLines: [
`Run 'create-nx-workspace --help' to see how to select a different CLI.`
]
});
} else if (preset === 'web-components' || preset === 'react') {
} else if (
preset === 'web-components' ||
preset === 'react' ||
preset === 'react-express'
) {
output.addVerticalSeparator();
output.note({
title: `We generated an Nx workspace powered by the Nx CLi.`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
NxJson,
updateWorkspaceInTree,
generateProjectLint,
addGlobalLint
addLintFiles
} from '@nrwl/workspace';
import { offsetFromRoot } from '@nrwl/workspace';
import { toFileName } from '@nrwl/workspace';
Expand Down Expand Up @@ -87,7 +87,7 @@ function updateWorkspaceJson(options: CypressProjectSchema): Rule {
export default function(options: CypressProjectSchema): Rule {
options = normalizeOptions(options);
return chain([
addGlobalLint(options.linter),
addLintFiles(options.projectRoot, options.linter),
generateFiles(options),
updateWorkspaceJson(options),
updateNxJson(options)
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/schematics/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
updateJsonInTree,
updateWorkspaceInTree,
generateProjectLint,
addGlobalLint
addLintFiles
} from '@nrwl/workspace';
import { toFileName } from '@nrwl/workspace';
import { getProjectConfig } from '@nrwl/workspace';
Expand Down Expand Up @@ -151,7 +151,7 @@ export default function(schema: Schema): Rule {
ngAdd({
skipFormat: true
}),
addGlobalLint(options.linter),
addLintFiles(options.appProjectRoot, options.linter),
addAppFiles(options),
updateWorkspaceJson(options),
updateNxJson(options),
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions packages/react/src/schematics/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
toFileName,
updateJsonInTree,
generateProjectLint,
addGlobalLint
addLintFiles
} from '@nrwl/workspace';
import {
addDepsToPackageJson,
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function(schema: Schema): Rule {
ngAdd({
skipFormat: true
}),
addGlobalLint(options.linter),
addLintFiles(options.appProjectRoot, options.linter),
createApplicationFiles(options),
updateNxJson(options),
addProject(options),
Expand Down

This file was deleted.

4 changes: 0 additions & 4 deletions packages/react/src/schematics/library/files/lib/tslint.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/react/src/schematics/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
toFileName,
updateJsonInTree,
updateWorkspaceInTree,
addGlobalLint,
addLintFiles,
generateProjectLint
} from '@nrwl/workspace';
import { join, normalize, Path } from '@angular-devkit/core';
Expand All @@ -47,7 +47,7 @@ export default function(schema: Schema): Rule {
const options = normalizeOptions(schema);

return chain([
addGlobalLint(options.linter),
addLintFiles(options.projectRoot, options.linter),
createFiles(options),
!options.skipTsConfig ? updateTsConfig(options) : noop(),
addProject(options),
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/schematics/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
formatFiles,
updateWorkspaceInTree,
generateProjectLint,
addGlobalLint
addLintFiles
} from '@nrwl/workspace';
import ngAdd from '../ng-add/ng-add';

Expand Down Expand Up @@ -153,7 +153,7 @@ export default function(schema: Schema): Rule {
ngAdd({
skipFormat: true
}),
addGlobalLint(options.linter),
addLintFiles(options.appProjectRoot, options.linter),
createApplicationFiles(options),
updateNxJson(options),
addProject(options),
Expand Down
4 changes: 0 additions & 4 deletions packages/web/src/schematics/application/files/app/tslint.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export {

export { getWorkspace, updateWorkspace } from './src/utils/workspace';
export { addUpdateTask } from './src/utils/update-task';
export { addGlobalLint, generateProjectLint } from './src/utils/lint';
export { addLintFiles, generateProjectLint } from './src/utils/lint';

export { formatFiles } from './src/utils/rules/format-files';
export { deleteFile } from './src/utils/rules/deleteFile';
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions packages/workspace/src/schematics/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { updateJsonInTree, readJsonInTree } from '@nrwl/workspace';
import { toFileName, names } from '@nrwl/workspace';
import { formatFiles } from '@nrwl/workspace';
import { offsetFromRoot } from '@nrwl/workspace';
import { generateProjectLint, addGlobalLint } from '../../utils/lint';
import { generateProjectLint, addLintFiles } from '../../utils/lint';

export interface NormalizedSchema extends Schema {
name: string;
Expand Down Expand Up @@ -91,7 +91,7 @@ export default function(schema: Schema): Rule {
return (host: Tree, context: SchematicContext) => {
const options = normalizeOptions(schema);
return chain([
addGlobalLint(options.linter),
addLintFiles(options.projectRoot, options.linter),
createFiles(options),
!options.skipTsConfig ? updateTsConfig(options) : noop(),
addProject(options),
Expand Down
17 changes: 14 additions & 3 deletions packages/workspace/src/schematics/ng-new/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@
},
"preset": {
"description": "What to create in the new workspace",
"enum": ["angular", "react", "web-components", "full-stack", "empty"],
"enum": [
"angular",
"react",
"web-components",
"angular-nest",
"react-express",
"empty"
],
"default": "empty",
"x-prompt": {
"message": "What to create in the new workspace (You can create other applications and libraries at any point using 'ng g')",
Expand All @@ -112,8 +119,12 @@
"label": "web components [a workspace with a single app built using web components]"
},
{
"value": "full-stack",
"label": "full-stack [a workspace with a full stack application (NestJS + Angular Ivy)]"
"value": "angular-nest",
"label": "angular-nest [a workspace with a full stack application (Angular + Nest)]"
},
{
"value": "react-express",
"label": "react-express [a workspace with a full stack application (React + Express)]"
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions packages/workspace/src/schematics/preset/preset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ describe('preset', () => {
).toBe('@nrwl/web');
});

describe('--preset full-stack', () => {
describe('--preset angular-nest', () => {
it('should create files', async () => {
const tree = await runSchematic(
'preset',
{ name: 'proj', preset: 'full-stack' },
{ name: 'proj', preset: 'angular-nest' },
projectTree
);
expect(tree.exists('/apps/proj/src/app/app.component.ts')).toBe(true);
Expand All @@ -63,7 +63,7 @@ describe('preset', () => {
it('should work with unnormalized names', async () => {
const tree = await runSchematic(
'preset',
{ name: 'myProj', preset: 'full-stack' },
{ name: 'myProj', preset: 'angular-nest' },
projectTree
);

Expand Down
37 changes: 31 additions & 6 deletions packages/workspace/src/schematics/preset/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ export default function(options: Schema): Rule {
}

function createPreset(options: Schema): Rule {
// const linter = options.cli === 'angular' ? 'tslint' : 'eslint';
const linter = 'tslint';

if (options.preset === 'empty') {
return noop();
return setDefaultLinter(linter);
} else if (options.preset === 'angular') {
return chain([
externalSchematic(
Expand All @@ -51,11 +54,13 @@ function createPreset(options: Schema): Rule {
{
name: options.name,
style: options.style,
babel: true
babel: true,
linter
},
{ interactive: false }
),
setDefaultCollection('@nrwl/react')
setDefaultCollection('@nrwl/react'),
setDefaultLinter(linter)
]);
} else if (options.preset === 'web-components') {
return chain([
Expand All @@ -64,13 +69,15 @@ function createPreset(options: Schema): Rule {
'application',
{
name: options.name,
style: options.style
style: options.style,
linter
},
{ interactive: false }
),
setDefaultCollection('@nrwl/web')
setDefaultCollection('@nrwl/web'),
setDefaultLinter(linter)
]);
} else {
} else if (options.preset === 'angular-nest') {
return chain([
externalSchematic(
'@nrwl/angular',
Expand All @@ -95,6 +102,10 @@ function createPreset(options: Schema): Rule {
setDefaultCollection('@nrwl/angular'),
connectFrontendAndApi(options)
]);
} else if (options.preset === 'react-express') {
throw new Error(`Not implemented yet`);
} else {
throw new Error(`Invalid preset ${options.preset}`);
}
}

Expand Down Expand Up @@ -235,6 +246,20 @@ function setDefaultCollection(defaultCollection: string) {
});
}

function setDefaultLinter(linter: string) {
return updateWorkspaceInTree(json => {
if (!json.schematics) {
json.schematics = {};
}
json.schematics['@nrwl/workspace'] = { linter };
json.schematics['@nrwl/cypress'] = { linter };
json.schematics['@nrwl/react'] = { linter };
json.schematics['@nrwl/web'] = { linter };
json.schematics['@nrwl/node'] = { linter };
return json;
});
}

function normalizeOptions(options: Schema): Schema {
options.name = toFileName(options.name);
return options;
Expand Down
9 changes: 8 additions & 1 deletion packages/workspace/src/schematics/preset/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@ export interface Schema {
name: string;
npmScope?: string;
style?: string;
preset: 'empty' | 'angular' | 'react' | 'web-components' | 'full-stack';
cli: string;
preset:
| 'empty'
| 'angular'
| 'react'
| 'web-components'
| 'angular-nest'
| 'react-express';
}
Loading

0 comments on commit 192a6a0

Please sign in to comment.