Skip to content

Commit

Permalink
@schematics/angular: added option for export class in default mode
Browse files Browse the repository at this point in the history
added option for export class in default mode

Closes angular#25023
  • Loading branch information
aparzi committed Aug 22, 2024
1 parent 5ba0b07 commit db43951
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
})
export class <%= classify(name) %><%= classify(type) %> {
export <% if(exportDefault) {%>default <% } %>class <%= classify(name) %><%= classify(type) %> {

}
16 changes: 16 additions & 0 deletions packages/schematics/angular/component/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,20 @@ describe('Component Schematic', () => {
await expectAsync(schematicRunner.runSchematic('component', options, appTree)).toBeRejected();
});
});

it('should use export default', async () => {
const options = { ...defaultOptions, exportDefault: true };

const tree = await schematicRunner.runSchematic('component', options, appTree);
const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
expect(tsContent).toMatch('export default class');
});

it('should use named export', async () => {
const options = { ...defaultOptions, exportDefault: false };

const tree = await schematicRunner.runSchematic('component', options, appTree);
const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
expect(tsContent).toMatch('export class');
});
});
5 changes: 5 additions & 0 deletions packages/schematics/angular/component/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
"type": "boolean",
"default": false,
"description": "The declaring NgModule exports this component."
},
"exportDefault": {
"type": "boolean",
"default": false,
"description": "Create a component with default export."
}
},
"required": ["name", "project"]
Expand Down

0 comments on commit db43951

Please sign in to comment.