Skip to content

Commit 684a3aa

Browse files
alan-agius4vikerman
authored andcommitted
fix(@schematics/angular): minimal should be honored in workspace creation (#12896)
1 parent 9aca82f commit 684a3aa

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
@@ -22,6 +22,7 @@ import {
2222
template,
2323
url,
2424
} from '@angular-devkit/schematics';
25+
import { Schema as ComponentOptions } from '../component/schema';
2526
import { Schema as E2eOptions } from '../e2e/schema';
2627
import {
2728
addProjectToWorkspace,
@@ -241,11 +242,9 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
241242
}
242243

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

248-
return !toRemoveList.some(re => re.test(path));
247+
return !toRemoveList.test(path);
249248
}
250249

251250
export default function (options: ApplicationOptions): Rule {
@@ -256,20 +255,20 @@ export default function (options: ApplicationOptions): Rule {
256255
validateProjectName(options.name);
257256
const prefix = options.prefix || 'app';
258257
const appRootSelector = `${prefix}-root`;
259-
const componentOptions = !options.minimal ?
260-
{
261-
inlineStyle: options.inlineStyle,
262-
inlineTemplate: options.inlineTemplate,
263-
spec: !options.skipTests,
264-
styleext: options.style,
265-
viewEncapsulation: options.viewEncapsulation,
266-
} :
267-
{
268-
inlineStyle: true,
269-
InlineTemplate: true,
270-
spec: false,
271-
styleext: options.style,
272-
};
258+
const componentOptions: Partial<ComponentOptions> = !options.minimal ?
259+
{
260+
inlineStyle: options.inlineStyle,
261+
inlineTemplate: options.inlineTemplate,
262+
spec: !options.skipTests,
263+
styleext: options.style,
264+
viewEncapsulation: options.viewEncapsulation,
265+
} :
266+
{
267+
inlineStyle: true,
268+
inlineTemplate: true,
269+
spec: false,
270+
styleext: options.style,
271+
};
273272

274273
const workspace = getWorkspace(host);
275274
let newProjectRoot = workspace.newProjectRoot;
@@ -323,9 +322,8 @@ export default function (options: ApplicationOptions): Rule {
323322
}),
324323
move(appDir),
325324
])),
326-
mergeWith(
325+
options.minimal ? noop() : mergeWith(
327326
apply(url('./files/lint'), [
328-
options.minimal ? filter(minimalPathFilter) : noop(),
329327
template({
330328
utils: strings,
331329
...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)