Skip to content

Commit ec17e58

Browse files
committed
refactor(@angular/cli): simplify default arguments in angular-cli.json
Fixes angular#4137
1 parent 16bceee commit ec17e58

File tree

15 files changed

+178
-63
lines changed

15 files changed

+178
-63
lines changed

packages/@angular/cli/blueprints/class/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default Blueprint.extend({
3030

3131
options.spec = options.spec !== undefined ?
3232
options.spec :
33-
this.project.ngConfigObj.get('defaults.spec.class');
33+
this.project.ngConfigObj.get('defaults.class.spec');
3434

3535
return {
3636
dynamicPath: this.dynamicPath.dir,

packages/@angular/cli/blueprints/component/index.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default Blueprint.extend({
1414
description: '',
1515

1616
availableOptions: [
17-
{ name: 'flat', type: Boolean, default: false },
17+
{ name: 'flat', type: Boolean },
1818
{ name: 'inline-template', type: Boolean, aliases: ['it'] },
1919
{ name: 'inline-style', type: Boolean, aliases: ['is'] },
2020
{ name: 'prefix', type: String, default: null },
@@ -82,23 +82,27 @@ export default Blueprint.extend({
8282

8383
options.inlineStyle = options.inlineStyle !== undefined ?
8484
options.inlineStyle :
85-
this.project.ngConfigObj.get('defaults.inline.style');
85+
this.project.ngConfigObj.get('defaults.component.inlineStyle');
8686

8787
options.inlineTemplate = options.inlineTemplate !== undefined ?
8888
options.inlineTemplate :
89-
this.project.ngConfigObj.get('defaults.inline.template');
89+
this.project.ngConfigObj.get('defaults.component.inlineTemplate');
90+
91+
options.flat = options.flat !== undefined ?
92+
options.flat :
93+
this.project.ngConfigObj.get('defaults.component.flat');
9094

9195
options.spec = options.spec !== undefined ?
9296
options.spec :
93-
this.project.ngConfigObj.get('defaults.spec.component');
97+
this.project.ngConfigObj.get('defaults.component.spec');
9498

9599
options.viewEncapsulation = options.viewEncapsulation !== undefined ?
96100
options.viewEncapsulation :
97-
this.project.ngConfigObj.get('defaults.viewEncapsulation');
101+
this.project.ngConfigObj.get('defaults.component.viewEncapsulation');
98102

99103
options.changeDetection = options.changeDetection !== undefined ?
100104
options.changeDetection :
101-
this.project.ngConfigObj.get('defaults.changeDetection');
105+
this.project.ngConfigObj.get('defaults.component.changeDetection');
102106

103107
return {
104108
dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''),

packages/@angular/cli/blueprints/directive/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default Blueprint.extend({
1414
description: '',
1515

1616
availableOptions: [
17-
{ name: 'flat', type: Boolean, default: true },
17+
{ name: 'flat', type: Boolean },
1818
{ name: 'prefix', type: String, default: null },
1919
{ name: 'spec', type: Boolean },
2020
{ name: 'skip-import', type: Boolean, default: false },
@@ -67,7 +67,11 @@ export default Blueprint.extend({
6767
locals: function (options: any) {
6868
options.spec = options.spec !== undefined ?
6969
options.spec :
70-
this.project.ngConfigObj.get('defaults.spec.directive');
70+
this.project.ngConfigObj.get('defaults.directive.spec');
71+
72+
options.flat = options.flat !== undefined ?
73+
options.flat :
74+
this.project.ngConfigObj.get('defaults.directive.flat');
7175

7276
return {
7377
dynamicPath: this.dynamicPath.dir,

packages/@angular/cli/blueprints/interface/index.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ export default Blueprint.extend({
2222
if (interfaceType) {
2323
this.fileName += '.' + interfaceType;
2424
}
25-
let prefix = '';
26-
if (this.project.ngConfig &&
27-
this.project.ngConfig.defaults &&
28-
this.project.ngConfig.defaults.prefixInterfaces) {
29-
prefix = 'I';
30-
}
25+
const prefix = this.project.ngConfigObj.get('defaults.interface.prefix');
3126
return {
3227
dynamicPath: this.dynamicPath.dir,
3328
flat: options.flat,

packages/@angular/cli/blueprints/module/index.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default Blueprint.extend({
88

99
availableOptions: [
1010
{ name: 'spec', type: Boolean },
11+
{ name: 'flat', type: Boolean },
1112
{ name: 'routing', type: Boolean, default: false }
1213
],
1314

@@ -20,9 +21,13 @@ export default Blueprint.extend({
2021
},
2122

2223
locals: function (options: any) {
24+
options.flat = options.flat !== undefined ?
25+
options.flat :
26+
this.project.ngConfigObj.get('defaults.module.flat');
27+
2328
options.spec = options.spec !== undefined ?
2429
options.spec :
25-
this.project.ngConfigObj.get('defaults.spec.module');
30+
this.project.ngConfigObj.get('defaults.module.spec');
2631

2732
return {
2833
dynamicPath: this.dynamicPath.dir,
@@ -49,9 +54,10 @@ export default Blueprint.extend({
4954
this.dasherizedModuleName = options.dasherizedModuleName;
5055
return {
5156
__path__: () => {
52-
this.generatePath = this.dynamicPath.dir
53-
+ path.sep
54-
+ options.dasherizedModuleName;
57+
this.generatePath = this.dynamicPath.dir;
58+
if (!options.locals.flat) {
59+
this.generatePath += path.sep + options.dasherizedModuleName;
60+
}
5561
return this.generatePath;
5662
}
5763
};

packages/@angular/cli/blueprints/ng2/files/angular-cli.json

+1-13
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@
5151
},
5252
"defaults": {
5353
"styleExt": "<%= styleExt %>",
54-
"prefixInterfaces": false,
55-
"inline": {
56-
"style": false,
57-
"template": false
58-
},
59-
"spec": {
60-
"class": false,
61-
"component": <%= tests %>,
62-
"directive": <%= tests %>,
63-
"module": false,
64-
"pipe": <%= tests %>,
65-
"service": <%= tests %>
66-
}
54+
"component": {}
6755
}
6856
}

packages/@angular/cli/blueprints/pipe/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default Blueprint.extend({
1414
description: '',
1515

1616
availableOptions: [
17-
{ name: 'flat', type: Boolean, default: true },
17+
{ name: 'flat', type: Boolean },
1818
{ name: 'spec', type: Boolean },
1919
{ name: 'skip-import', type: Boolean, default: false },
2020
{ name: 'module', type: String, aliases: ['m'] },
@@ -50,9 +50,13 @@ export default Blueprint.extend({
5050
},
5151

5252
locals: function (options: any) {
53+
options.flat = options.flat !== undefined ?
54+
options.flat :
55+
this.project.ngConfigObj.get('defaults.pipe.flat');
56+
5357
options.spec = options.spec !== undefined ?
5458
options.spec :
55-
this.project.ngConfigObj.get('defaults.spec.pipe');
59+
this.project.ngConfigObj.get('defaults.pipe.spec');
5660

5761
return {
5862
dynamicPath: this.dynamicPath.dir,

packages/@angular/cli/blueprints/service/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default Blueprint.extend({
1414
description: '',
1515

1616
availableOptions: [
17-
{ name: 'flat', type: Boolean, default: true },
17+
{ name: 'flat', type: Boolean },
1818
{ name: 'spec', type: Boolean },
1919
{ name: 'module', type: String, aliases: ['m'] }
2020
],
@@ -40,9 +40,13 @@ export default Blueprint.extend({
4040
},
4141

4242
locals: function (options: any) {
43+
options.flat = options.flat !== undefined ?
44+
options.flat :
45+
this.project.ngConfigObj.get('defaults.service.flat');
46+
4347
options.spec = options.spec !== undefined ?
4448
options.spec :
45-
this.project.ngConfigObj.get('defaults.spec.service');
49+
this.project.ngConfigObj.get('defaults.service.spec');
4650

4751
return {
4852
dynamicPath: this.dynamicPath.dir,

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

+67-21
Original file line numberDiff line numberDiff line change
@@ -248,55 +248,101 @@
248248
"styleExt": {
249249
"type": "string"
250250
},
251-
"prefixInterfaces": {
252-
"type": "boolean"
253-
},
254251
"poll": {
255252
"type": "number"
256253
},
257-
"viewEncapsulation": {
258-
"type": "string"
259-
},
260-
"changeDetection": {
261-
"type": "string"
254+
"class": {
255+
"type": "object",
256+
"properties": {
257+
"spec": {
258+
"type": "boolean",
259+
"default": false
260+
}
261+
}
262262
},
263-
"inline": {
263+
"component": {
264264
"type": "object",
265265
"properties": {
266-
"style": {
266+
"flat": {
267+
"type": "boolean",
268+
"default": false
269+
},
270+
"spec": {
271+
"type": "boolean",
272+
"default": true
273+
},
274+
"inlineStyle": {
267275
"type": "boolean",
268276
"default": false
269277
},
270-
"template": {
278+
"inlineTemplate": {
271279
"type": "boolean",
272280
"default": false
281+
},
282+
"viewEncapsulation": {
283+
"enum": ["Emulated", "Native", "None"]
284+
},
285+
"changeDetection": {
286+
"enum": ["Default", "OnPush"]
273287
}
274288
}
275289
},
276-
"spec": {
290+
"directive": {
277291
"type": "object",
278292
"properties": {
279-
"class": {
280-
"type": "boolean",
281-
"default": false
282-
},
283-
"component": {
293+
"flat": {
284294
"type": "boolean",
285295
"default": true
286296
},
287-
"directive": {
297+
"spec": {
288298
"type": "boolean",
289299
"default": true
300+
}
301+
}
302+
},
303+
"interface": {
304+
"type": "object",
305+
"properties": {
306+
"prefix": {
307+
"type": "string",
308+
"default": ""
309+
}
310+
}
311+
},
312+
"module": {
313+
"type": "object",
314+
"properties": {
315+
"flat": {
316+
"type": "boolean",
317+
"default": false
290318
},
291-
"module": {
319+
"spec": {
292320
"type": "boolean",
293321
"default": false
322+
}
323+
}
324+
},
325+
"pipe": {
326+
"type": "object",
327+
"properties": {
328+
"flat": {
329+
"type": "boolean",
330+
"default": true
294331
},
295-
"pipe": {
332+
"spec": {
333+
"type": "boolean",
334+
"default": true
335+
}
336+
}
337+
},
338+
"service": {
339+
"type": "object",
340+
"properties": {
341+
"flat": {
296342
"type": "boolean",
297343
"default": true
298344
},
299-
"service": {
345+
"spec": {
300346
"type": "boolean",
301347
"default": true
302348
}

packages/@angular/cli/models/config.ts

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
5252
cliConfig.alias('apps.0.prefix', 'defaults.prefix')
5353
];
5454

55+
// Additional aliases which do not emit any messages.
56+
cliConfig.alias('defaults.inline.prefixInterfaces', 'defaults.interface.prefix');
57+
cliConfig.alias('defaults.inline.style', 'defaults.component.inlineStyle');
58+
cliConfig.alias('defaults.inline.template', 'defaults.component.inlineTemplate');
59+
cliConfig.alias('defaults.spec.component', 'defaults.component.spec');
60+
cliConfig.alias('defaults.spec.class', 'defaults.class.spec');
61+
cliConfig.alias('defaults.spec.directive', 'defaults.component.directive');
62+
cliConfig.alias('defaults.spec.module', 'defaults.component.module');
63+
cliConfig.alias('defaults.spec.pipe', 'defaults.component.pipe');
64+
cliConfig.alias('defaults.spec.service', 'defaults.component.service');
65+
5566
// If any of them returned true, output a deprecation warning.
5667
if (aliases.some(x => !!x)) {
5768
console.error(chalk.yellow(oneLine`

packages/@ngtools/json-schema/src/schema-class-factory.ts

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ class SchemaClassBase<T> implements SchemaClass<T> {
117117
/** Get a value from a JSON path. */
118118
$$get(path: string): any {
119119
const node = _getSchemaNodeForPath(this.$$schema(), path);
120+
if (path === 'defaults.component.viewEncapsulation') {
121+
console.log('node');
122+
console.log(node);
123+
}
120124
return node ? node.get() : undefined;
121125
}
122126

packages/@ngtools/json-schema/src/schema-tree.ts

+1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ export abstract class LeafSchemaTreeNode<T> extends SchemaTreeNode<T> {
406406

407407
get() {
408408
if (!this.defined && this._forward) {
409+
console.log('fwd');
409410
return this._forward.get();
410411
}
411412
if (!this.defined) {

tests/e2e/tests/commands/config/get.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import {expectToFail} from '../../../utils/utils';
55
export default function() {
66
return Promise.resolve()
77
.then(() => process.chdir('/'))
8-
.then(() => expectToFail(() => ng('get', 'defaults.inline.style')))
9-
.then(() => ng('get', '--global', 'defaults.inline.style'))
8+
.then(() => expectToFail(() => ng('get', 'defaults.component.inlineStyle')))
9+
.then(() => ng('get', '--global', 'defaults.component.inlineStyle'))
1010
.then(output => {
1111
if (!output.match(/false\n?/)) {
1212
throw new Error(`Expected "false", received "${JSON.stringify(output)}".`);
1313
}
1414
})
1515
.then(() => expectToFail(() => {
16-
return ng('set', '--global', 'defaults.inline.style', 'INVALID_BOOLEAN');
16+
return ng('set', '--global', 'defaults.component.inlineStyle', 'INVALID_BOOLEAN');
1717
}))
18-
.then(() => ng('set', '--global', 'defaults.inline.style', 'true'))
19-
.then(() => ng('get', '--global', 'defaults.inline.style'))
18+
.then(() => ng('set', '--global', 'defaults.component.inlineStyle', 'true'))
19+
.then(() => ng('get', '--global', 'defaults.component.inlineStyle'))
2020
.then(output => {
2121
if (!output.match(/true\n?/)) {
2222
throw new Error(`Expected "true", received "${JSON.stringify(output)}".`);
2323
}
2424
})
25-
.then(() => ng('set', '--global', 'defaults.inline.style', 'false'));
25+
.then(() => ng('set', '--global', 'defaults.component.inlineStyle', 'false'));
2626
}

0 commit comments

Comments
 (0)