Skip to content

Commit

Permalink
fix(@angular/cli): make flag values case insensitive
Browse files Browse the repository at this point in the history
Fixes #5344
  • Loading branch information
Brocco committed Mar 9, 2017
1 parent 1f8363a commit 27c52fc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/@angular/cli/blueprints/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',

Expand Down Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e/tests/generate/component/component-flag-case.ts
Original file line number Diff line number Diff line change
@@ -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/));
}

0 comments on commit 27c52fc

Please sign in to comment.