From deef8949309a049e8ca1cf853e3f9d95cb2e570c Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 8 Nov 2018 17:02:54 +0100 Subject: [PATCH] fix(@schematics/angular): minimal should be honored in workspace creation --- .../schematics/angular/application/index.ts | 38 +++++++++---------- .../angular/application/index_spec.ts | 24 ++++++++++++ .../schematics/angular/workspace/index.ts | 6 +++ .../angular/workspace/index_spec.ts | 12 ++++++ 4 files changed, 60 insertions(+), 20 deletions(-) diff --git a/packages/schematics/angular/application/index.ts b/packages/schematics/angular/application/index.ts index 74f30c7b8164..302f8c246582 100644 --- a/packages/schematics/angular/application/index.ts +++ b/packages/schematics/angular/application/index.ts @@ -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, @@ -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 { @@ -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 = !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; @@ -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, diff --git a/packages/schematics/angular/application/index_spec.ts b/packages/schematics/angular/application/index_spec.ts index 931d9049ab43..9ddb893418c6 100644 --- a/packages/schematics/angular/application/index_spec.ts +++ b/packages/schematics/angular/application/index_spec.ts @@ -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); diff --git a/packages/schematics/angular/workspace/index.ts b/packages/schematics/angular/workspace/index.ts index 11f4d81f72fc..6f2dd14589af 100644 --- a/packages/schematics/angular/workspace/index.ts +++ b/packages/schematics/angular/workspace/index.ts @@ -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, diff --git a/packages/schematics/angular/workspace/index_spec.ts b/packages/schematics/angular/workspace/index_spec.ts index 6ddba08d3bea..3b80d61d15ab 100644 --- a/packages/schematics/angular/workspace/index_spec.ts +++ b/packages/schematics/angular/workspace/index_spec.ts @@ -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); + }); });