Skip to content

Commit d3d4336

Browse files
alan-agius4vikerman
authored andcommitted
fix(@schematics/angular): minimal should be honored in workspace creation
1 parent 53118c6 commit d3d4336

File tree

4 files changed

+60
-20
lines changed

4 files changed

+60
-20
lines changed

packages/schematics/angular/application/index.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
url,
2424
} from '@angular-devkit/schematics';
2525
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
26+
import { Schema as ComponentOptions } from '../component/schema';
2627
import { Schema as E2eOptions } from '../e2e/schema';
2728
import {
2829
addProjectToWorkspace,
@@ -246,11 +247,9 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
246247
}
247248

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

253-
return !toRemoveList.some(re => re.test(path));
252+
return !toRemoveList.test(path);
254253
}
255254

256255
export default function (options: ApplicationOptions): Rule {
@@ -261,20 +260,20 @@ export default function (options: ApplicationOptions): Rule {
261260
validateProjectName(options.name);
262261
const prefix = options.prefix || 'app';
263262
const appRootSelector = `${prefix}-root`;
264-
const componentOptions = !options.minimal ?
265-
{
266-
inlineStyle: options.inlineStyle,
267-
inlineTemplate: options.inlineTemplate,
268-
spec: !options.skipTests,
269-
styleext: options.style,
270-
viewEncapsulation: options.viewEncapsulation,
271-
} :
272-
{
273-
inlineStyle: true,
274-
InlineTemplate: true,
275-
spec: false,
276-
styleext: options.style,
277-
};
263+
const componentOptions: Partial<ComponentOptions> = !options.minimal ?
264+
{
265+
inlineStyle: options.inlineStyle,
266+
inlineTemplate: options.inlineTemplate,
267+
spec: !options.skipTests,
268+
styleext: options.style,
269+
viewEncapsulation: options.viewEncapsulation,
270+
} :
271+
{
272+
inlineStyle: true,
273+
inlineTemplate: true,
274+
spec: false,
275+
styleext: options.style,
276+
};
278277

279278
const workspace = getWorkspace(host);
280279
let newProjectRoot = workspace.newProjectRoot;
@@ -327,9 +326,8 @@ export default function (options: ApplicationOptions): Rule {
327326
}),
328327
move(appDir),
329328
])),
330-
mergeWith(
329+
options.minimal ? noop() : mergeWith(
331330
apply(url('./files/lint'), [
332-
options.minimal ? filter(minimalPathFilter) : noop(),
333331
template({
334332
utils: strings,
335333
...options,

packages/schematics/angular/application/index_spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,30 @@ describe('Application Schematic', () => {
146146
expect(confContent.projects['foo-e2e']).toBeUndefined();
147147
});
148148

149+
it('should create correct files when using minimal', () => {
150+
const options = { ...defaultOptions, minimal: true };
151+
const tree = schematicRunner.runSchematic('application', options, workspaceTree);
152+
const files = tree.files;
153+
154+
expect(files.indexOf('/projects/foo/karma.conf.js')).toBe(-1);
155+
expect(files.indexOf('/projects/foo/tsconfig.app.json')).toBeGreaterThanOrEqual(0);
156+
expect(files.indexOf('/projects/foo/tsconfig.spec.json')).toBe(-1);
157+
expect(files.indexOf('/projects/foo/tslint.json')).toBe(-1);
158+
expect(files.indexOf('/projects/foo/src/environments/environment.ts')).toBeGreaterThanOrEqual(0);
159+
expect(files.indexOf('/projects/foo/src/environments/environment.prod.ts')).toBeGreaterThanOrEqual(0);
160+
expect(files.indexOf('/projects/foo/src/favicon.ico')).toBeGreaterThanOrEqual(0);
161+
expect(files.indexOf('/projects/foo/src/index.html')).toBeGreaterThanOrEqual(0);
162+
expect(files.indexOf('/projects/foo/src/main.ts')).toBeGreaterThanOrEqual(0);
163+
expect(files.indexOf('/projects/foo/src/polyfills.ts')).toBeGreaterThanOrEqual(0);
164+
expect(files.indexOf('/projects/foo/src/styles.css')).toBeGreaterThanOrEqual(0);
165+
expect(files.indexOf('/projects/foo/src/test.ts')).toBe(-1);
166+
expect(files.indexOf('/projects/foo/src/app/app.module.ts')).toBeGreaterThanOrEqual(0);
167+
expect(files.indexOf('/projects/foo/src/app/app.component.css')).toBe(-1);
168+
expect(files.indexOf('/projects/foo/src/app/app.component.html')).toBe(-1);
169+
expect(files.indexOf('/projects/foo/src/app/app.component.spec.ts')).toBe(-1);
170+
expect(files.indexOf('/projects/foo/src/app/app.component.ts')).toBeGreaterThanOrEqual(0);
171+
});
172+
149173
describe(`update package.json`, () => {
150174
it(`should add build-angular to devDependencies`, () => {
151175
const tree = schematicRunner.runSchematic('application', defaultOptions, workspaceTree);

packages/schematics/angular/workspace/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ import { strings } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
apply,
12+
filter,
1213
mergeWith,
14+
noop,
1315
template,
1416
url,
1517
} from '@angular-devkit/schematics';
1618
import { latestVersions } from '../utility/latest-versions';
1719
import { Schema as WorkspaceOptions } from './schema';
1820

21+
1922
export default function (options: WorkspaceOptions): Rule {
23+
const minimalFilesRegExp = /(.editorconfig|tslint.json)$/;
24+
2025
return mergeWith(apply(url('./files'), [
26+
options.minimal ? filter(path => !minimalFilesRegExp.test(path)) : noop(),
2127
template({
2228
utils: strings,
2329
...options,

packages/schematics/angular/workspace/index_spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,16 @@ describe('Workspace Schematic', () => {
5454
expect(pkg.dependencies['zone.js']).toEqual(latestVersions.ZoneJs);
5555
expect(pkg.devDependencies['typescript']).toEqual(latestVersions.TypeScript);
5656
});
57+
58+
it('should create correct files when using minimal', () => {
59+
const tree = schematicRunner.runSchematic('workspace', { ...defaultOptions, minimal: true });
60+
const files = tree.files;
61+
expect(files.indexOf('/angular.json')).toBeGreaterThanOrEqual(0);
62+
expect(files.indexOf('/.gitignore')).toBeGreaterThanOrEqual(0);
63+
expect(files.indexOf('/package.json')).toBeGreaterThanOrEqual(0);
64+
expect(files.indexOf('/README.md')).toBeGreaterThanOrEqual(0);
65+
expect(files.indexOf('/tsconfig.json')).toBeGreaterThanOrEqual(0);
66+
expect(files.indexOf('/tslint.json')).toBe(-1);
67+
expect(files.indexOf('/.editorconfig')).toBe(-1);
68+
});
5769
});

0 commit comments

Comments
 (0)