-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular-output-target): generate single component angular modules (
#298)
- Loading branch information
1 parent
f20a778
commit ba1f285
Showing
6 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
packages/angular-output-target/__tests__/generate-angular-modules.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { generateAngularModuleForComponent } from '../src/generate-angular-modules'; | ||
|
||
describe('generateAngularModuleForComponent()', () => { | ||
it('should generate an Angular module for each component', () => { | ||
const modules = generateAngularModuleForComponent('my-component'); | ||
|
||
expect(modules).toEqual(`@NgModule({ | ||
declarations: [MyComponent], | ||
exports: [MyComponent] | ||
}) | ||
export class MyComponentModule { }`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/angular-output-target/src/generate-angular-modules.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { dashToPascalCase } from './utils'; | ||
|
||
/** | ||
* Creates an Angular module declaration for a component wrapper. | ||
* @param componentTagName The tag name of the Stencil component. | ||
* @returns The Angular module declaration as a string. | ||
*/ | ||
export const generateAngularModuleForComponent = (componentTagName: string) => { | ||
const tagNameAsPascal = dashToPascalCase(componentTagName); | ||
const componentClassName = `${tagNameAsPascal}`; | ||
const moduleClassName = `${tagNameAsPascal}Module`; | ||
|
||
const moduleDefinition = `@NgModule({ | ||
declarations: [${componentClassName}], | ||
exports: [${componentClassName}] | ||
}) | ||
export class ${moduleClassName} { }`; | ||
|
||
return moduleDefinition; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters