From 27c52fc83de32089edef02117ed7167b12e1eb34 Mon Sep 17 00:00:00 2001 From: Mike Brocchi Date: Thu, 9 Mar 2017 14:34:30 -0500 Subject: [PATCH] fix(@angular/cli): make flag values case insensitive Fixes #5344 --- .../cli/blueprints/component/index.ts | 29 +++++++++++++++++++ .../generate/component/component-flag-case.ts | 15 ++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/e2e/tests/generate/component/component-flag-case.ts diff --git a/packages/@angular/cli/blueprints/component/index.ts b/packages/@angular/cli/blueprints/component/index.ts index 2ef24c7c102e..64b23da7a69a 100644 --- a/packages/@angular/cli/blueprints/component/index.ts +++ b/packages/@angular/cli/blueprints/component/index.ts @@ -12,6 +12,33 @@ const getFiles = Blueprint.prototype.files; const stringUtils = require('ember-cli-string-utils'); const astUtils = require('../../utilities/ast-utils'); +function correctCase(options: any) { + if (options.viewEncapsulation) { + switch (options.viewEncapsulation.toLowerCase()) { + case 'emulated': + options.viewEncapsulation = 'Emulated'; + break; + case 'native': + options.viewEncapsulation = 'Native'; + break; + case 'none': + options.viewEncapsulation = 'None'; + break; + } + } + + if (options.changeDetection) { + switch (options.changeDetection.toLowerCase()) { + case 'default': + options.changeDetection = 'Default'; + break; + case 'onpush': + options.changeDetection = 'OnPush'; + break; + } + } +} + export default Blueprint.extend({ description: '', @@ -146,6 +173,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/)); +}