Skip to content

Commit

Permalink
fix(options): allow underscore in names
Browse files Browse the repository at this point in the history
  • Loading branch information
Zlatin Stanimirov committed Mar 1, 2022
1 parent 62bcc61 commit 83e6e16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/schematics/schematic.option.ts
@@ -1,5 +1,3 @@
import { strings } from '@angular-devkit/core';

export class SchematicOption {
constructor(private name: string, private value: boolean | string) {}

Expand All @@ -13,16 +11,15 @@ export class SchematicOption {
return `--${this.name}="${this.value}"`;
}
} else if (typeof this.value === 'boolean') {
const str = strings.dasherize(this.name);
const str = this.dasherize(this.name);
return this.value ? `--${str}` : `--no-${str}`;
} else {
return `--${strings.dasherize(this.name)}=${this.value}`;
return `--${this.dasherize(this.name)}=${this.value}`;
}
}

private format() {
return strings
.dasherize(this.value as string)
return this.dasherize(this.value as string)
.split('')
.reduce((content, char) => {
if (char === '(' || char === ')' || char === '[' || char === ']') {
Expand All @@ -31,4 +28,13 @@ export class SchematicOption {
return `${content}${char}`;
}, '');
}

private dasherize(str: string) {
const STRING_DASHERIZE_REGEXP = /[\s]/g;
const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g;
return str
.replace(STRING_DECAMELIZE_REGEXP, '$1-$2')
.toLowerCase()
.replace(STRING_DASHERIZE_REGEXP, '-');
}
}
6 changes: 6 additions & 0 deletions test/lib/schematics/schematic.option.spec.ts
Expand Up @@ -38,6 +38,12 @@ describe('Schematic Option', () => {
input: 'myApp',
expected: 'my-app',
},
{
description: 'should allow underscore string option value name',
option: 'name',
input: 'my_app',
expected: 'my_app',
},
{
description: 'should manage classified string option value name',
option: 'name',
Expand Down

0 comments on commit 83e6e16

Please sign in to comment.