diff --git a/packages/@angular/cli/blueprints/component/index.ts b/packages/@angular/cli/blueprints/component/index.ts index 2ef24c7c102e..1cef6aa80120 100644 --- a/packages/@angular/cli/blueprints/component/index.ts +++ b/packages/@angular/cli/blueprints/component/index.ts @@ -12,6 +12,27 @@ const getFiles = Blueprint.prototype.files; const stringUtils = require('ember-cli-string-utils'); const astUtils = require('../../utilities/ast-utils'); +const viewEncapsulationMap: any = { + 'emulated': 'Emulated', + 'native': 'Native', + 'none': 'None' +}; + +const changeDetectionMap: any = { + 'default': 'Default', + 'onpush': 'OnPush' +}; + +function correctCase(options: any) { + if (options.viewEncapsulation) { + options.viewEncapsulation = viewEncapsulationMap[options.viewEncapsulation.toLowerCase()]; + } + + if (options.changeDetection) { + options.changeDetection = changeDetectionMap[options.changeDetection.toLowerCase()]; + } +} + export default Blueprint.extend({ description: '', @@ -146,6 +167,8 @@ export default Blueprint.extend({ options.changeDetection = options.changeDetection !== undefined ? options.changeDetection : CliConfig.getValue('defaults.component.changeDetection'); + correctCase(options); + return { dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''), flat: options.flat, diff --git a/tests/e2e/tests/generate/component/component-flag-case.ts b/tests/e2e/tests/generate/component/component-flag-case.ts new file mode 100644 index 000000000000..dbbee3525756 --- /dev/null +++ b/tests/e2e/tests/generate/component/component-flag-case.ts @@ -0,0 +1,15 @@ +import {join} from 'path'; +import {ng} from '../../../utils/process'; +import {expectFileToMatch} from '../../../utils/fs'; + + +export default function() { + const compDir = join('src', 'app', 'test'); + + return Promise.resolve() + .then(() => ng('generate', 'component', 'test', '-cd', 'onpush', '-ve', 'emulated')) + .then(() => expectFileToMatch(join(compDir, 'test.component.ts'), + /changeDetection: ChangeDetectionStrategy.OnPush/)) + .then(() => expectFileToMatch(join(compDir, 'test.component.ts'), + /encapsulation: ViewEncapsulation.Emulated/)); +}