Skip to content

Commit a12a4e0

Browse files
alan-agius4Keen Yee Liau
authored andcommitted
feat(@schematics/angular): consistent naming of options and arguments that do the same thing
This aligns options that do the same thing: 1) `skipSpecs` and `spec` has been deprecated in favor of `skipTests`. 2) `styleext` has been deprecated in favor of `style` since the latest is two words. Fixes #12784
1 parent 1cdeccf commit a12a4e0

File tree

23 files changed

+158
-53
lines changed

23 files changed

+158
-53
lines changed

packages/angular/cli/lib/config/schema.json

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@
139139
"type": "string",
140140
"default": "css"
141141
},
142+
"style": {
143+
"description": "The file extension to use for style files.",
144+
"type": "string",
145+
"default": "css"
146+
},
142147
"viewEncapsulation": {
143148
"description": "Specifies the view encapsulation strategy.",
144149
"enum": ["Emulated", "Native", "None", "ShadowDom"],
@@ -186,6 +191,11 @@
186191
"type": "boolean",
187192
"description": "Specifies if a spec file is generated.",
188193
"default": true
194+
},
195+
"skipTests": {
196+
"type": "boolean",
197+
"description": "When true, does not create test files.",
198+
"default": false
189199
}
190200
}
191201
},
@@ -203,11 +213,6 @@
203213
"description": "The scope for the generated routing.",
204214
"default": "Child"
205215
},
206-
"spec": {
207-
"type": "boolean",
208-
"description": "Specifies if a spec file is generated.",
209-
"default": true
210-
},
211216
"flat": {
212217
"type": "boolean",
213218
"description": "Flag to indicate if a directory is created.",
@@ -236,8 +241,13 @@
236241
},
237242
"spec": {
238243
"type": "boolean",
239-
"default": true,
240-
"description": "Specifies if a spec file is generated."
244+
"description": "Specifies if a spec file is generated.",
245+
"default": true
246+
},
247+
"skipTests": {
248+
"type": "boolean",
249+
"description": "When true, does not create test files.",
250+
"default": false
241251
}
242252
}
243253
},
@@ -251,8 +261,13 @@
251261
},
252262
"spec": {
253263
"type": "boolean",
254-
"default": true,
255-
"description": "Specifies if a spec file is generated."
264+
"description": "Specifies if a spec file is generated.",
265+
"default": true
266+
},
267+
"skipTests": {
268+
"type": "boolean",
269+
"description": "When true, does not create test files.",
270+
"default": false
256271
},
257272
"skipImport": {
258273
"type": "boolean",
@@ -277,8 +292,13 @@
277292
"properties": {
278293
"spec": {
279294
"type": "boolean",
280-
"default": true,
281-
"description": "Specifies if a spec file is generated."
295+
"description": "Specifies if a spec file is generated.",
296+
"default": true
297+
},
298+
"skipTests": {
299+
"type": "boolean",
300+
"description": "When true, does not create test files.",
301+
"default": false
282302
}
283303
}
284304
}

packages/schematics/angular/application/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
136136
if (!(`@schematics/angular:${type}` in schematics)) {
137137
schematics[`@schematics/angular:${type}`] = {};
138138
}
139-
(schematics[`@schematics/angular:${type}`] as JsonObject).spec = false;
139+
(schematics[`@schematics/angular:${type}`] as JsonObject).skipTests = true;
140140
});
141141
}
142142

@@ -264,15 +264,15 @@ export default function (options: ApplicationOptions): Rule {
264264
{
265265
inlineStyle: options.inlineStyle,
266266
inlineTemplate: options.inlineTemplate,
267-
spec: !options.skipTests,
268-
styleext: options.style,
267+
skipTests: options.skipTests,
268+
style: options.style,
269269
viewEncapsulation: options.viewEncapsulation,
270270
} :
271271
{
272272
inlineStyle: true,
273273
inlineTemplate: true,
274-
spec: false,
275-
styleext: options.style,
274+
skipTests: true,
275+
style: options.style,
276276
};
277277

278278
const workspace = getWorkspace(host);
@@ -361,7 +361,7 @@ export default function (options: ApplicationOptions): Rule {
361361
mergeWith(
362362
apply(url('./other-files'), [
363363
componentOptions.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),
364-
!componentOptions.spec ? filter(path => !path.endsWith('.spec.ts')) : noop(),
364+
componentOptions.skipTests ? filter(path => !/[.|-]spec.ts$/.test(path)) : noop(),
365365
template({
366366
utils: strings,
367367
...options as any, // tslint:disable-line:no-any

packages/schematics/angular/application/index_spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ describe('Application Schematic', () => {
2929
inlineStyle: false,
3030
inlineTemplate: false,
3131
routing: false,
32-
style: 'css',
33-
skipTests: false,
3432
skipPackageJson: false,
3533
};
3634

packages/schematics/angular/application/other-files/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { Component } from '@angular/core';
2828
`,<% } else { %>
2929
templateUrl: './app.component.html',<% } if(inlineStyle) { %>
3030
styles: []<% } else { %>
31-
styleUrls: ['./app.component.<%= styleext %>']<% } %>
31+
styleUrls: ['./app.component.<%= style %>']<% } %>
3232
})
3333
export class AppComponent {
3434
title = '<%= name %>';

packages/schematics/angular/class/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ export default function (options: ClassOptions): Rule {
4242
options.name = parsedPath.name;
4343
options.path = parsedPath.path;
4444

45+
// todo remove these when we remove the deprecations
46+
options.skipTests = options.skipTests || !options.spec;
47+
4548
const templateSource = apply(url('./files'), [
46-
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
49+
options.skipTests ? filter(path => !path.endsWith('.spec.ts')) : noop(),
4750
template({
4851
...strings,
4952
...options,

packages/schematics/angular/class/schema.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@
2929
},
3030
"spec": {
3131
"type": "boolean",
32-
"description": "When true, generates a \"spec.ts\" test file for the new class.",
32+
"description": "When true (the default), generates a \"spec.ts\" test file for the new class.",
33+
"default": true,
34+
"x-deprecated": "Use \"skipTests\" instead."
35+
},
36+
"skipTests": {
37+
"type": "boolean",
38+
"description": "When true, does not create \"spec.ts\" test files for the new class.",
3339
"default": false
3440
},
3541
"type": {

packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }
99
`,<% } else { %>
1010
templateUrl: './<%= dasherize(name) %>.component.html',<% } if(inlineStyle) { %>
1111
styles: []<% } else { %>
12-
styleUrls: ['./<%= dasherize(name) %>.component.<%= styleext %>']<% } %><% if(!!viewEncapsulation) { %>,
12+
styleUrls: ['./<%= dasherize(name) %>.component.<%= style %>']<% } %><% if(!!viewEncapsulation) { %>,
1313
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
1414
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
1515
})

packages/schematics/angular/component/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function buildSelector(options: ComponentOptions, projectPrefix: string) {
125125
}
126126

127127

128-
export default function(options: ComponentOptions): Rule {
128+
export default function (options: ComponentOptions): Rule {
129129
return (host: Tree) => {
130130
if (!options.project) {
131131
throw new SchematicsException('Option (project) is required.');
@@ -143,12 +143,19 @@ export default function(options: ComponentOptions): Rule {
143143
options.path = parsedPath.path;
144144
options.selector = options.selector || buildSelector(options, project.prefix);
145145

146+
// todo remove these when we remove the deprecations
147+
options.style = (
148+
options.style && options.style !== 'css'
149+
? options.style : options.styleext
150+
) || 'css';
151+
options.skipTests = options.skipTests || !options.spec;
152+
146153
validateName(options.name);
147154
validateHtmlSelector(options.selector);
148155

149156
const templateSource = apply(url('./files'), [
150-
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
151-
options.inlineStyle ? filter(path => !path.endsWith('.__styleext__')) : noop(),
157+
options.skipTests ? filter(path => !path.endsWith('.spec.ts')) : noop(),
158+
options.inlineStyle ? filter(path => !path.endsWith('.__style__')) : noop(),
152159
options.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),
153160
template({
154161
...strings,

packages/schematics/angular/component/index_spec.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ describe('Component Schematic', () => {
2424
inlineStyle: false,
2525
inlineTemplate: false,
2626
changeDetection: ChangeDetection.Default,
27-
styleext: 'css',
28-
spec: true,
27+
style: 'css',
28+
skipTests: false,
2929
module: undefined,
3030
export: false,
3131
project: 'bar',
@@ -249,8 +249,8 @@ describe('Component Schematic', () => {
249249
expect(tree.files).not.toContain('/projects/bar/src/app/foo/foo.component.css');
250250
});
251251

252-
it('should respect the styleext option', () => {
253-
const options = { ...defaultOptions, styleext: 'scss' };
252+
it('should respect the style option', () => {
253+
const options = { ...defaultOptions, style: 'scss' };
254254
const tree = schematicRunner.runSchematic('component', options, appTree);
255255
const content = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
256256
expect(content).toMatch(/styleUrls: \['.\/foo.component.scss/);
@@ -310,4 +310,34 @@ describe('Component Schematic', () => {
310310
appTree = schematicRunner.runSchematic('component', defaultOptions, appTree);
311311
expect(appTree.files).toContain('/projects/bar/custom/app/foo/foo.component.ts');
312312
});
313+
314+
// testing deprecating options don't cause conflicts
315+
it('should respect the deprecated styleext (scss) option', () => {
316+
const options = { ...defaultOptions, style: undefined, styleext: 'scss' };
317+
const tree = schematicRunner.runSchematic('component', options, appTree);
318+
const files = tree.files;
319+
expect(files).toContain('/projects/bar/src/app/foo/foo.component.scss');
320+
});
321+
322+
it('should respect the deprecated styleext (css) option', () => {
323+
const options = { ...defaultOptions, style: undefined, styleext: 'css' };
324+
const tree = schematicRunner.runSchematic('component', options, appTree);
325+
const files = tree.files;
326+
expect(files).toContain('/projects/bar/src/app/foo/foo.component.css');
327+
});
328+
329+
it('should respect the deprecated spec option when false', () => {
330+
const options = { ...defaultOptions, skipTests: undefined, spec: false };
331+
const tree = schematicRunner.runSchematic('component', options, appTree);
332+
const files = tree.files;
333+
expect(files).not.toContain('/projects/bar/src/app/foo/foo.component.spec.ts');
334+
});
335+
336+
it('should respect the deprecated spec option when true', () => {
337+
const options = { ...defaultOptions, skipTests: false, spec: true };
338+
const tree = schematicRunner.runSchematic('component', options, appTree);
339+
const files = tree.files;
340+
expect(files).toContain('/projects/bar/src/app/foo/foo.component.spec.ts');
341+
});
342+
313343
});

0 commit comments

Comments
 (0)