diff --git a/packages/@angular/cli/blueprints/class/index.ts b/packages/@angular/cli/blueprints/class/index.ts index f3a631bbee5f..cb3ad7480602 100644 --- a/packages/@angular/cli/blueprints/class/index.ts +++ b/packages/@angular/cli/blueprints/class/index.ts @@ -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'); return { dynamicPath: this.dynamicPath.dir, diff --git a/packages/@angular/cli/blueprints/component/index.ts b/packages/@angular/cli/blueprints/component/index.ts index f189a07fd595..d8a0ab8cf735 100644 --- a/packages/@angular/cli/blueprints/component/index.ts +++ b/packages/@angular/cli/blueprints/component/index.ts @@ -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 }, @@ -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, ''), diff --git a/packages/@angular/cli/blueprints/directive/index.ts b/packages/@angular/cli/blueprints/directive/index.ts index e7af617e032d..09632b269650 100644 --- a/packages/@angular/cli/blueprints/directive/index.ts +++ b/packages/@angular/cli/blueprints/directive/index.ts @@ -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 }, @@ -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, diff --git a/packages/@angular/cli/blueprints/interface/index.ts b/packages/@angular/cli/blueprints/interface/index.ts index 6de7f773163d..2262dc19be5e 100644 --- a/packages/@angular/cli/blueprints/interface/index.ts +++ b/packages/@angular/cli/blueprints/interface/index.ts @@ -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, diff --git a/packages/@angular/cli/blueprints/module/index.ts b/packages/@angular/cli/blueprints/module/index.ts index 5d6f15ee54d2..de02ffb3008d 100644 --- a/packages/@angular/cli/blueprints/module/index.ts +++ b/packages/@angular/cli/blueprints/module/index.ts @@ -8,6 +8,7 @@ export default Blueprint.extend({ availableOptions: [ { name: 'spec', type: Boolean }, + { name: 'flat', type: Boolean }, { name: 'routing', type: Boolean, default: false } ], @@ -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, @@ -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; } }; diff --git a/packages/@angular/cli/blueprints/ng2/files/angular-cli.json b/packages/@angular/cli/blueprints/ng2/files/angular-cli.json index 8cea46679b8b..e04412e2f761 100644 --- a/packages/@angular/cli/blueprints/ng2/files/angular-cli.json +++ b/packages/@angular/cli/blueprints/ng2/files/angular-cli.json @@ -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": {} } } diff --git a/packages/@angular/cli/blueprints/pipe/index.ts b/packages/@angular/cli/blueprints/pipe/index.ts index bee149028d27..f3af4279a341 100644 --- a/packages/@angular/cli/blueprints/pipe/index.ts +++ b/packages/@angular/cli/blueprints/pipe/index.ts @@ -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'] }, @@ -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, diff --git a/packages/@angular/cli/blueprints/service/index.ts b/packages/@angular/cli/blueprints/service/index.ts index b86f0e3968c4..85683bae3124 100644 --- a/packages/@angular/cli/blueprints/service/index.ts +++ b/packages/@angular/cli/blueprints/service/index.ts @@ -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'] } ], @@ -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, diff --git a/packages/@angular/cli/lib/config/schema.json b/packages/@angular/cli/lib/config/schema.json index d586f9820361..95db7dff5758 100644 --- a/packages/@angular/cli/lib/config/schema.json +++ b/packages/@angular/cli/lib/config/schema.json @@ -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 } diff --git a/packages/@angular/cli/models/config.ts b/packages/@angular/cli/models/config.ts index 63f6e11e4650..05a97610f77d 100644 --- a/packages/@angular/cli/models/config.ts +++ b/packages/@angular/cli/models/config.ts @@ -52,6 +52,17 @@ export class CliConfig extends CliConfigBase { 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)) { console.error(chalk.yellow(oneLine` diff --git a/tests/e2e/tests/commands/config/get.ts b/tests/e2e/tests/commands/config/get.ts index ef454b44a7db..5f0aafc10dd7 100644 --- a/tests/e2e/tests/commands/config/get.ts +++ b/tests/e2e/tests/commands/config/get.ts @@ -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')); } diff --git a/tests/e2e/tests/generate/component/component-flat.ts b/tests/e2e/tests/generate/component/component-flat.ts new file mode 100644 index 000000000000..62f2f28675fe --- /dev/null +++ b/tests/e2e/tests/generate/component/component-flat.ts @@ -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')); +} diff --git a/tests/e2e/tests/generate/component/component-not-flat.ts b/tests/e2e/tests/generate/component/component-not-flat.ts new file mode 100644 index 000000000000..487e5a4542b4 --- /dev/null +++ b/tests/e2e/tests/generate/component/component-not-flat.ts @@ -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 componentDir = join('src', 'app', 'test-component'); + + return Promise.resolve() + .then(() => updateJsonFile('angular-cli.json', configJson => { + const comp = configJson.defaults.component; + comp.flat = false; + })) + .then(() => ng('generate', 'component', 'test-component')) + .then(() => expectFileToExist(componentDir)) + .then(() => expectFileToExist(join(componentDir, 'test-component.component.ts'))) + .then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts'))) + .then(() => expectFileToExist(join(componentDir, 'test-component.component.html'))) + .then(() => expectFileToExist(join(componentDir, 'test-component.component.css'))) + + // Try to run the unit tests. + .then(() => ng('test', '--single-run')); +}