Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Commit

Permalink
fix(@schematics/angular): Allow prefix to be an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
Brocco authored and hansl committed May 10, 2018
1 parent fa1e740 commit fbcdb11
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/schematics/angular/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function buildSelector(options: ComponentOptions, projectPrefix: string) {
let selector = strings.dasherize(options.name);
if (options.prefix) {
selector = `${options.prefix}-${selector}`;
} else if (projectPrefix) {
} else if (options.prefix === undefined && projectPrefix) {
selector = `${projectPrefix}-${selector}`;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/schematics/angular/component/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ describe('Component Schematic', () => {
expect(content).toMatch(/selector: 'app-foo'/);
});

it('should use the supplied prefix if it is ""', () => {
const options = { ...defaultOptions, prefix: '' };

const tree = schematicRunner.runSchematic('component', options, appTree);
const content = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
expect(content).toMatch(/selector: 'foo'/);
});

it('should respect the inlineTemplate option', () => {
const options = { ...defaultOptions, inlineTemplate: true };
const tree = schematicRunner.runSchematic('component', options, appTree);
Expand Down
12 changes: 10 additions & 2 deletions packages/schematics/angular/component/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@
},
"prefix": {
"type": "string",
"format": "html-selector",
"description": "The prefix to apply to generated selectors.",
"alias": "p"
"alias": "p",
"oneOf": [
{
"maxLength": 0
},
{
"minLength": 1,
"format": "html-selector"
}
]
},
"styleext": {
"description": "The file extension to be used for style files.",
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/directive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function buildSelector(options: DirectiveOptions, projectPrefix: string) {
let selector = options.name;
if (options.prefix) {
selector = `${options.prefix}-${selector}`;
} else if (projectPrefix) {
} else if (options.prefix === undefined && projectPrefix) {
selector = `${projectPrefix}-${selector}`;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/schematics/angular/directive/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,12 @@ describe('Directive Schematic', () => {
const content = tree.readContent('/projects/bar/src/app/foo.directive.ts');
expect(content).toMatch(/selector: '\[appFoo\]'/);
});

it('should use the supplied prefix if it is ""', () => {
const options = { ...defaultOptions, prefix: '' };
const tree = schematicRunner.runSchematic('directive', options, appTree);

const content = tree.readContent('/projects/bar/src/app/foo.directive.ts');
expect(content).toMatch(/selector: '\[foo\]'/);
});
});
13 changes: 10 additions & 3 deletions packages/schematics/angular/directive/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@
},
"prefix": {
"type": "string",
"format": "html-selector",
"description": "The prefix to apply to generated selectors.",
"default": "app",
"alias": "p"
"alias": "p",
"oneOf": [
{
"maxLength": 0
},
{
"minLength": 1,
"format": "html-selector"
}
]
},
"spec": {
"type": "boolean",
Expand Down

0 comments on commit fbcdb11

Please sign in to comment.