Skip to content

refactor(@angular/cli): simplify default arguments in angular-cli.json #4389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@angular/cli/blueprints/class/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default Blueprint.extend({

options.spec = options.spec !== undefined ?
options.spec :
this.project.ngConfigObj.get('defaults.spec.class');
this.project.ngConfigObj.get('defaults.class.spec');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an alias for these, and a warning if the alias is used.

See here for an example.


return {
dynamicPath: this.dynamicPath.dir,
Expand Down
16 changes: 10 additions & 6 deletions packages/@angular/cli/blueprints/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default Blueprint.extend({
description: '',

availableOptions: [
{ name: 'flat', type: Boolean, default: false },
{ name: 'flat', type: Boolean },
{ name: 'inline-template', type: Boolean, aliases: ['it'] },
{ name: 'inline-style', type: Boolean, aliases: ['is'] },
{ name: 'prefix', type: String, default: null },
Expand Down Expand Up @@ -82,23 +82,27 @@ export default Blueprint.extend({

options.inlineStyle = options.inlineStyle !== undefined ?
options.inlineStyle :
this.project.ngConfigObj.get('defaults.inline.style');
this.project.ngConfigObj.get('defaults.component.inlineStyle');

options.inlineTemplate = options.inlineTemplate !== undefined ?
options.inlineTemplate :
this.project.ngConfigObj.get('defaults.inline.template');
this.project.ngConfigObj.get('defaults.component.inlineTemplate');

options.flat = options.flat !== undefined ?
options.flat :
this.project.ngConfigObj.get('defaults.component.flat');

options.spec = options.spec !== undefined ?
options.spec :
this.project.ngConfigObj.get('defaults.spec.component');
this.project.ngConfigObj.get('defaults.component.spec');

options.viewEncapsulation = options.viewEncapsulation !== undefined ?
options.viewEncapsulation :
this.project.ngConfigObj.get('defaults.viewEncapsulation');
this.project.ngConfigObj.get('defaults.component.viewEncapsulation');

options.changeDetection = options.changeDetection !== undefined ?
options.changeDetection :
this.project.ngConfigObj.get('defaults.changeDetection');
this.project.ngConfigObj.get('defaults.component.changeDetection');

return {
dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''),
Expand Down
8 changes: 6 additions & 2 deletions packages/@angular/cli/blueprints/directive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default Blueprint.extend({
description: '',

availableOptions: [
{ name: 'flat', type: Boolean, default: true },
{ name: 'flat', type: Boolean },
{ name: 'prefix', type: String, default: null },
{ name: 'spec', type: Boolean },
{ name: 'skip-import', type: Boolean, default: false },
Expand Down Expand Up @@ -67,7 +67,11 @@ export default Blueprint.extend({
locals: function (options: any) {
options.spec = options.spec !== undefined ?
options.spec :
this.project.ngConfigObj.get('defaults.spec.directive');
this.project.ngConfigObj.get('defaults.directive.spec');

options.flat = options.flat !== undefined ?
options.flat :
this.project.ngConfigObj.get('defaults.directive.flat');

return {
dynamicPath: this.dynamicPath.dir,
Expand Down
7 changes: 1 addition & 6 deletions packages/@angular/cli/blueprints/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ export default Blueprint.extend({
if (interfaceType) {
this.fileName += '.' + interfaceType;
}
let prefix = '';
if (this.project.ngConfig &&
this.project.ngConfig.defaults &&
this.project.ngConfig.defaults.prefixInterfaces) {
prefix = 'I';
}
const prefix = this.project.ngConfigObj.get('defaults.interface.prefix');
return {
dynamicPath: this.dynamicPath.dir,
flat: options.flat,
Expand Down
14 changes: 10 additions & 4 deletions packages/@angular/cli/blueprints/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default Blueprint.extend({

availableOptions: [
{ name: 'spec', type: Boolean },
{ name: 'flat', type: Boolean },
{ name: 'routing', type: Boolean, default: false }
],

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

locals: function (options: any) {
options.flat = options.flat !== undefined ?
options.flat :
this.project.ngConfigObj.get('defaults.module.flat');

options.spec = options.spec !== undefined ?
options.spec :
this.project.ngConfigObj.get('defaults.spec.module');
this.project.ngConfigObj.get('defaults.module.spec');

return {
dynamicPath: this.dynamicPath.dir,
Expand All @@ -49,9 +54,10 @@ export default Blueprint.extend({
this.dasherizedModuleName = options.dasherizedModuleName;
return {
__path__: () => {
this.generatePath = this.dynamicPath.dir
+ path.sep
+ options.dasherizedModuleName;
this.generatePath = this.dynamicPath.dir;
if (!options.locals.flat) {
this.generatePath += path.sep + options.dasherizedModuleName;
}
return this.generatePath;
}
};
Expand Down
14 changes: 1 addition & 13 deletions packages/@angular/cli/blueprints/ng2/files/angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@
},
"defaults": {
"styleExt": "<%= styleExt %>",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": <%= tests %>,
"directive": <%= tests %>,
"module": false,
"pipe": <%= tests %>,
"service": <%= tests %>
}
"component": {}
}
}
8 changes: 6 additions & 2 deletions packages/@angular/cli/blueprints/pipe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default Blueprint.extend({
description: '',

availableOptions: [
{ name: 'flat', type: Boolean, default: true },
{ name: 'flat', type: Boolean },
{ name: 'spec', type: Boolean },
{ name: 'skip-import', type: Boolean, default: false },
{ name: 'module', type: String, aliases: ['m'] },
Expand Down Expand Up @@ -50,9 +50,13 @@ export default Blueprint.extend({
},

locals: function (options: any) {
options.flat = options.flat !== undefined ?
options.flat :
this.project.ngConfigObj.get('defaults.pipe.flat');

options.spec = options.spec !== undefined ?
options.spec :
this.project.ngConfigObj.get('defaults.spec.pipe');
this.project.ngConfigObj.get('defaults.pipe.spec');

return {
dynamicPath: this.dynamicPath.dir,
Expand Down
8 changes: 6 additions & 2 deletions packages/@angular/cli/blueprints/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default Blueprint.extend({
description: '',

availableOptions: [
{ name: 'flat', type: Boolean, default: true },
{ name: 'flat', type: Boolean },
{ name: 'spec', type: Boolean },
{ name: 'module', type: String, aliases: ['m'] }
],
Expand All @@ -40,9 +40,13 @@ export default Blueprint.extend({
},

locals: function (options: any) {
options.flat = options.flat !== undefined ?
options.flat :
this.project.ngConfigObj.get('defaults.service.flat');

options.spec = options.spec !== undefined ?
options.spec :
this.project.ngConfigObj.get('defaults.spec.service');
this.project.ngConfigObj.get('defaults.service.spec');

return {
dynamicPath: this.dynamicPath.dir,
Expand Down
88 changes: 67 additions & 21 deletions packages/@angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,55 +248,101 @@
"styleExt": {
"type": "string"
},
"prefixInterfaces": {
"type": "boolean"
},
"poll": {
"type": "number"
},
"viewEncapsulation": {
"type": "string"
},
"changeDetection": {
"type": "string"
"class": {
"type": "object",
"properties": {
"spec": {
"type": "boolean",
"default": false
}
}
},
"inline": {
"component": {
"type": "object",
"properties": {
"style": {
"flat": {
"type": "boolean",
"default": false
},
"spec": {
"type": "boolean",
"default": true
},
"inlineStyle": {
"type": "boolean",
"default": false
},
"template": {
"inlineTemplate": {
"type": "boolean",
"default": false
},
"viewEncapsulation": {
"enum": ["Emulated", "Native", "None"]
},
"changeDetection": {
"enum": ["Default", "OnPush"]
}
}
},
"spec": {
"directive": {
"type": "object",
"properties": {
"class": {
"type": "boolean",
"default": false
},
"component": {
"flat": {
"type": "boolean",
"default": true
},
"directive": {
"spec": {
"type": "boolean",
"default": true
}
}
},
"interface": {
"type": "object",
"properties": {
"prefix": {
"type": "string",
"default": ""
}
}
},
"module": {
"type": "object",
"properties": {
"flat": {
"type": "boolean",
"default": false
},
"module": {
"spec": {
"type": "boolean",
"default": false
}
}
},
"pipe": {
"type": "object",
"properties": {
"flat": {
"type": "boolean",
"default": true
},
"pipe": {
"spec": {
"type": "boolean",
"default": true
}
}
},
"service": {
"type": "object",
"properties": {
"flat": {
"type": "boolean",
"default": true
},
"service": {
"spec": {
"type": "boolean",
"default": true
}
Expand Down
11 changes: 11 additions & 0 deletions packages/@angular/cli/models/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
cliConfig.alias('apps.0.prefix', 'defaults.prefix')
];

// Additional aliases which do not emit any messages.
cliConfig.alias('defaults.interface.prefix', 'defaults.inline.prefixInterfaces');
cliConfig.alias('defaults.component.inlineStyle', 'defaults.inline.style');
cliConfig.alias('defaults.component.inlineTemplate', 'defaults.inline.template');
cliConfig.alias('defaults.component.spec', 'defaults.spec.component');
cliConfig.alias('defaults.class.spec', 'defaults.spec.class');
cliConfig.alias('defaults.component.directive', 'defaults.spec.directive');
cliConfig.alias('defaults.component.module', 'defaults.spec.module');
cliConfig.alias('defaults.component.pipe', 'defaults.spec.pipe');
cliConfig.alias('defaults.component.service', 'defaults.spec.service');

// If any of them returned true, output a deprecation warning.
if (aliases.some(x => !!x)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning should also be updated. Maybe it should be a generic warning? Not sure. I have a PR that will also need to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hansl and I chatted and we decided to leave the remapping of these as silent, as the correct values will still be handled correctly in the config file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do the same to mine then.

console.error(chalk.yellow(oneLine`
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/tests/commands/config/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import {expectToFail} from '../../../utils/utils';
export default function() {
return Promise.resolve()
.then(() => process.chdir('/'))
.then(() => expectToFail(() => ng('get', 'defaults.inline.style')))
.then(() => ng('get', '--global', 'defaults.inline.style'))
.then(() => expectToFail(() => ng('get', 'defaults.component.inlineStyle')))
.then(() => ng('get', '--global', 'defaults.component.inlineStyle'))
.then(output => {
if (!output.match(/false\n?/)) {
throw new Error(`Expected "false", received "${JSON.stringify(output)}".`);
}
})
.then(() => expectToFail(() => {
return ng('set', '--global', 'defaults.inline.style', 'INVALID_BOOLEAN');
return ng('set', '--global', 'defaults.component.inlineStyle', 'INVALID_BOOLEAN');
}))
.then(() => ng('set', '--global', 'defaults.inline.style', 'true'))
.then(() => ng('get', '--global', 'defaults.inline.style'))
.then(() => ng('set', '--global', 'defaults.component.inlineStyle', 'true'))
.then(() => ng('get', '--global', 'defaults.component.inlineStyle'))
.then(output => {
if (!output.match(/true\n?/)) {
throw new Error(`Expected "true", received "${JSON.stringify(output)}".`);
}
})
.then(() => ng('set', '--global', 'defaults.inline.style', 'false'));
.then(() => ng('set', '--global', 'defaults.component.inlineStyle', 'false'));
}
24 changes: 24 additions & 0 deletions tests/e2e/tests/generate/component/component-flat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {join} from 'path';
import {ng} from '../../../utils/process';
import {expectFileToExist} from '../../../utils/fs';
import {updateJsonFile} from '../../../utils/project';


export default function() {
const appDir = join('src', 'app');

return Promise.resolve()
.then(() => updateJsonFile('angular-cli.json', configJson => {
const comp = configJson.defaults.component;
comp.flat = true;
}))
.then(() => ng('generate', 'component', 'test-component'))
.then(() => expectFileToExist(appDir))
.then(() => expectFileToExist(join(appDir, 'test-component.component.ts')))
.then(() => expectFileToExist(join(appDir, 'test-component.component.spec.ts')))
.then(() => expectFileToExist(join(appDir, 'test-component.component.html')))
.then(() => expectFileToExist(join(appDir, 'test-component.component.css')))

// Try to run the unit tests.
.then(() => ng('test', '--single-run'));
}
Loading