Skip to content

Commit 8215888

Browse files
mephistorineclydin
authored andcommitted
fix(@schematics/angular): add "type" option in enum schematic
closes: #20667 (cherry picked from commit 1b9577a)
1 parent 6b6aa75 commit 8215888

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

packages/schematics/angular/enum/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export default function (options: EnumOptions): Rule {
3333
options.name = parsedPath.name;
3434
options.path = parsedPath.path;
3535

36+
options.type = options.type ? `.${options.type}` : '';
37+
3638
const templateSource = apply(url('./files'), [
3739
applyTemplates({
3840
...strings,

packages/schematics/angular/enum/index_spec.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ describe('Enum Schematic', () => {
4848
.runSchematicAsync('enum', defaultOptions, appTree)
4949
.toPromise();
5050
const files = tree.files;
51-
expect(files).toContain('/projects/bar/src/app/foo.enum.ts');
51+
expect(files).toContain('/projects/bar/src/app/foo.ts');
5252
});
5353

5454
it('should create an enumeration', async () => {
5555
const tree = await schematicRunner
5656
.runSchematicAsync('enum', defaultOptions, appTree)
5757
.toPromise();
58-
const content = tree.readContent('/projects/bar/src/app/foo.enum.ts');
58+
const content = tree.readContent('/projects/bar/src/app/foo.ts');
5959
expect(content).toMatch('export enum Foo {');
6060
});
6161

@@ -64,6 +64,13 @@ describe('Enum Schematic', () => {
6464
config.projects.bar.sourceRoot = 'projects/bar/custom';
6565
appTree.overwrite('/angular.json', JSON.stringify(config, null, 2));
6666
appTree = await schematicRunner.runSchematicAsync('enum', defaultOptions, appTree).toPromise();
67-
expect(appTree.files).toContain('/projects/bar/custom/app/foo.enum.ts');
67+
expect(appTree.files).toContain('/projects/bar/custom/app/foo.ts');
68+
});
69+
70+
it('should put type in the file name', async () => {
71+
const options = { ...defaultOptions, type: 'enum' };
72+
73+
const tree = await schematicRunner.runSchematicAsync('enum', options, appTree).toPromise();
74+
expect(tree.files).toContain('/projects/bar/src/app/foo.enum.ts');
6875
});
6976
});

packages/schematics/angular/enum/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"$source": "projectName"
2929
}
3030
},
31+
"type": {
32+
"type": "string",
33+
"description": "Adds a developer-defined type to the filename, in the format \"name.type.ts\"."
34+
},
3135
"lintFix": {
3236
"type": "boolean",
3337
"description": "Apply lint fixes after generating the enum.",

0 commit comments

Comments
 (0)