Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport fix(@schematics/angular): minimal should be honored in workspace crea… #12896

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 18 additions & 20 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
template,
url,
} from '@angular-devkit/schematics';
import { Schema as ComponentOptions } from '../component/schema';
import { Schema as E2eOptions } from '../e2e/schema';
import {
addProjectToWorkspace,
Expand Down Expand Up @@ -241,11 +242,9 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
}

function minimalPathFilter(path: string): boolean {
const toRemoveList: RegExp[] = [/e2e\//, /editorconfig/, /README/, /karma.conf.js/,
/protractor.conf.js/, /test.ts/, /tsconfig.spec.json/,
/tslint.json/, /favicon.ico/];
const toRemoveList = /(test.ts|tsconfig.spec.json|karma.conf.js)$/;

return !toRemoveList.some(re => re.test(path));
return !toRemoveList.test(path);
}

export default function (options: ApplicationOptions): Rule {
Expand All @@ -256,20 +255,20 @@ export default function (options: ApplicationOptions): Rule {
validateProjectName(options.name);
const prefix = options.prefix || 'app';
const appRootSelector = `${prefix}-root`;
const componentOptions = !options.minimal ?
{
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate,
spec: !options.skipTests,
styleext: options.style,
viewEncapsulation: options.viewEncapsulation,
} :
{
inlineStyle: true,
InlineTemplate: true,
spec: false,
styleext: options.style,
};
const componentOptions: Partial<ComponentOptions> = !options.minimal ?
{
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate,
spec: !options.skipTests,
styleext: options.style,
viewEncapsulation: options.viewEncapsulation,
} :
{
inlineStyle: true,
inlineTemplate: true,
spec: false,
styleext: options.style,
};

const workspace = getWorkspace(host);
let newProjectRoot = workspace.newProjectRoot;
Expand Down Expand Up @@ -323,9 +322,8 @@ export default function (options: ApplicationOptions): Rule {
}),
move(appDir),
])),
mergeWith(
options.minimal ? noop() : mergeWith(
apply(url('./files/lint'), [
options.minimal ? filter(minimalPathFilter) : noop(),
template({
utils: strings,
...options,
Expand Down
24 changes: 24 additions & 0 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,30 @@ describe('Application Schematic', () => {
expect(confContent.projects['foo-e2e']).toBeUndefined();
});

it('should create correct files when using minimal', () => {
const options = { ...defaultOptions, minimal: true };
const tree = schematicRunner.runSchematic('application', options, workspaceTree);
const files = tree.files;

expect(files.indexOf('/projects/foo/karma.conf.js')).toBe(-1);
expect(files.indexOf('/projects/foo/tsconfig.app.json')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/projects/foo/tsconfig.spec.json')).toBe(-1);
expect(files.indexOf('/projects/foo/tslint.json')).toBe(-1);
expect(files.indexOf('/projects/foo/src/environments/environment.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/projects/foo/src/environments/environment.prod.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/projects/foo/src/favicon.ico')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/projects/foo/src/index.html')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/projects/foo/src/main.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/projects/foo/src/polyfills.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/projects/foo/src/styles.css')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/projects/foo/src/test.ts')).toBe(-1);
expect(files.indexOf('/projects/foo/src/app/app.module.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/projects/foo/src/app/app.component.css')).toBe(-1);
expect(files.indexOf('/projects/foo/src/app/app.component.html')).toBe(-1);
expect(files.indexOf('/projects/foo/src/app/app.component.spec.ts')).toBe(-1);
expect(files.indexOf('/projects/foo/src/app/app.component.ts')).toBeGreaterThanOrEqual(0);
});

describe(`update package.json`, () => {
it(`should add build-angular to devDependencies`, () => {
const tree = schematicRunner.runSchematic('application', defaultOptions, workspaceTree);
Expand Down
6 changes: 6 additions & 0 deletions packages/schematics/angular/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ import { strings } from '@angular-devkit/core';
import {
Rule,
apply,
filter,
mergeWith,
noop,
template,
url,
} from '@angular-devkit/schematics';
import { latestVersions } from '../utility/latest-versions';
import { Schema as WorkspaceOptions } from './schema';


export default function (options: WorkspaceOptions): Rule {
const minimalFilesRegExp = /(.editorconfig|tslint.json)$/;

return mergeWith(apply(url('./files'), [
options.minimal ? filter(path => !minimalFilesRegExp.test(path)) : noop(),
template({
utils: strings,
...options,
Expand Down
12 changes: 12 additions & 0 deletions packages/schematics/angular/workspace/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,16 @@ describe('Workspace Schematic', () => {
expect(pkg.dependencies['zone.js']).toEqual(latestVersions.ZoneJs);
expect(pkg.devDependencies['typescript']).toEqual(latestVersions.TypeScript);
});

it('should create correct files when using minimal', () => {
const tree = schematicRunner.runSchematic('workspace', { ...defaultOptions, minimal: true });
const files = tree.files;
expect(files.indexOf('/angular.json')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/.gitignore')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/package.json')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/README.md')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/tsconfig.json')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/tslint.json')).toBe(-1);
expect(files.indexOf('/.editorconfig')).toBe(-1);
});
});