Skip to content

Commit

Permalink
fix(@angular/cli): make flag values case insensitive (#5355)
Browse files Browse the repository at this point in the history
Fixes #5344
  • Loading branch information
Brocco authored Mar 12, 2017
1 parent c8e5359 commit 8d8ddfc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
23 changes: 23 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,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: '',

Expand Down Expand Up @@ -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,
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 8d8ddfc

Please sign in to comment.