Skip to content

Commit

Permalink
fix(@schematics/angular): add "type" option in enum schematic
Browse files Browse the repository at this point in the history
closes: #20667
  • Loading branch information
mephistorine authored and clydin committed May 3, 2021
1 parent b2594bc commit 1b9577a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/schematics/angular/enum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export default function (options: EnumOptions): Rule {
options.name = parsedPath.name;
options.path = parsedPath.path;

options.type = options.type ? `.${options.type}` : '';

const templateSource = apply(url('./files'), [
applyTemplates({
...strings,
Expand Down
13 changes: 10 additions & 3 deletions packages/schematics/angular/enum/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ describe('Enum Schematic', () => {
.runSchematicAsync('enum', defaultOptions, appTree)
.toPromise();
const files = tree.files;
expect(files).toContain('/projects/bar/src/app/foo.enum.ts');
expect(files).toContain('/projects/bar/src/app/foo.ts');
});

it('should create an enumeration', async () => {
const tree = await schematicRunner
.runSchematicAsync('enum', defaultOptions, appTree)
.toPromise();
const content = tree.readContent('/projects/bar/src/app/foo.enum.ts');
const content = tree.readContent('/projects/bar/src/app/foo.ts');
expect(content).toMatch('export enum Foo {');
});

Expand All @@ -64,6 +64,13 @@ describe('Enum Schematic', () => {
config.projects.bar.sourceRoot = 'projects/bar/custom';
appTree.overwrite('/angular.json', JSON.stringify(config, null, 2));
appTree = await schematicRunner.runSchematicAsync('enum', defaultOptions, appTree).toPromise();
expect(appTree.files).toContain('/projects/bar/custom/app/foo.enum.ts');
expect(appTree.files).toContain('/projects/bar/custom/app/foo.ts');
});

it('should put type in the file name', async () => {
const options = { ...defaultOptions, type: 'enum' };

const tree = await schematicRunner.runSchematicAsync('enum', options, appTree).toPromise();
expect(tree.files).toContain('/projects/bar/src/app/foo.enum.ts');
});
});
4 changes: 4 additions & 0 deletions packages/schematics/angular/enum/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"$source": "projectName"
}
},
"type": {
"type": "string",
"description": "Adds a developer-defined type to the filename, in the format \"name.type.ts\"."
},
"lintFix": {
"type": "boolean",
"description": "Apply lint fixes after generating the enum.",
Expand Down

0 comments on commit 1b9577a

Please sign in to comment.