diff --git a/.eslintrc.json b/.eslintrc.json index efedd32e..e93abc21 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -67,5 +67,8 @@ "@typescript-eslint/no-non-null-assertion": ["off"], "@typescript-eslint/no-var-requires": ["off"] }, - "ignorePatterns": ["*.js"] + "ignorePatterns": [ + "*.js", + "src/templates/lightningcomponent/lwc/typeScript/*" + ] } diff --git a/src/generators/lightningComponentGenerator.ts b/src/generators/lightningComponentGenerator.ts index f284e960..8a9c4dfe 100644 --- a/src/generators/lightningComponentGenerator.ts +++ b/src/generators/lightningComponentGenerator.ts @@ -148,17 +148,18 @@ export default class LightningComponentGenerator extends BaseGenerator from 'c/<%= camelCaseComponentName %>'; + +describe('c-<%= kebabCaseComponentName %>', () => { + afterEach(() => { + // The jsdom instance is shared across test cases in a single file so reset the DOM + while (document.body.firstChild) { + document.body.removeChild(document.body.firstChild); + } + }); + + it('TODO: test case generated by CLI command, please fill in test logic', () => { + // Arrange + const element = createElement('c-<%= kebabCaseComponentName %>', { + is: <%= pascalCaseComponentName %> + }); + + // Act + document.body.appendChild(element); + + // Assert + // const div = element.shadowRoot.querySelector('div'); + expect(1).toBe(1); + }); +}); \ No newline at end of file diff --git a/src/templates/lightningcomponent/lwc/typeScript/gitignore b/src/templates/lightningcomponent/lwc/typeScript/gitignore new file mode 100644 index 00000000..4c43fe68 --- /dev/null +++ b/src/templates/lightningcomponent/lwc/typeScript/gitignore @@ -0,0 +1 @@ +*.js \ No newline at end of file diff --git a/src/templates/lightningcomponent/lwc/typeScript/typeScript.html b/src/templates/lightningcomponent/lwc/typeScript/typeScript.html new file mode 100644 index 00000000..27e0f695 --- /dev/null +++ b/src/templates/lightningcomponent/lwc/typeScript/typeScript.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/src/templates/lightningcomponent/lwc/typeScript/typeScript.js-meta.xml b/src/templates/lightningcomponent/lwc/typeScript/typeScript.js-meta.xml new file mode 100644 index 00000000..0f1eb43d --- /dev/null +++ b/src/templates/lightningcomponent/lwc/typeScript/typeScript.js-meta.xml @@ -0,0 +1,5 @@ + + + <%= apiVersion %> + false + \ No newline at end of file diff --git a/src/templates/lightningcomponent/lwc/typeScript/typeScript.ts b/src/templates/lightningcomponent/lwc/typeScript/typeScript.ts new file mode 100644 index 00000000..d3b2b295 --- /dev/null +++ b/src/templates/lightningcomponent/lwc/typeScript/typeScript.ts @@ -0,0 +1,3 @@ +import { LightningElement } from 'lwc'; + +export default class <%= pascalCaseComponentName %> extends LightningElement {} \ No newline at end of file diff --git a/src/utils/types.ts b/src/utils/types.ts index 7022c064..c98e87f9 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -80,7 +80,11 @@ export interface LightningAppOptions extends TemplateOptions { export interface LightningComponentOptions extends TemplateOptions { componentname: string; - template: 'default' | 'analyticsDashboard' | 'analyticsDashboardWithStep'; + template: + | 'default' + | 'analyticsDashboard' + | 'analyticsDashboardWithStep' + | 'typeScript'; type: 'aura' | 'lwc'; internal: boolean; } diff --git a/test/service/templateService.test.ts b/test/service/templateService.test.ts index 1a4fe3fc..8abcb4de 100644 --- a/test/service/templateService.test.ts +++ b/test/service/templateService.test.ts @@ -638,6 +638,34 @@ describe('TemplateService', () => { ); }); + it('should create LightningComponent (lwc) with TypeScript', async () => { + await remove(path.join('testsoutput', 'libraryCreate', 'lwc')); + const templateService = TemplateService.getInstance(); + const result = await templateService.create( + TemplateType.LightningComponent, + { + componentname: 'LibraryCreateComponent', + outputdir: path.join('testsoutput', 'libraryCreate', 'lwc'), + template: 'typeScript', + type: 'lwc', + } + ); + + chai + .expect(result.created.sort()) + .to.deep.equal( + [ + 'testsoutput/libraryCreate/lwc/libraryCreateComponent/libraryCreateComponent.ts', + 'testsoutput/libraryCreate/lwc/libraryCreateComponent/libraryCreateComponent.html', + 'testsoutput/libraryCreate/lwc/libraryCreateComponent/__tests__/libraryCreateComponent.test.ts', + 'testsoutput/libraryCreate/lwc/libraryCreateComponent/libraryCreateComponent.js-meta.xml', + 'testsoutput/libraryCreate/lwc/libraryCreateComponent/.gitignore', + ] + .map((p) => path.normalize(p)) + .sort() + ); + }); + it('should create LightningEvent', async () => { await remove(path.join('testsoutput', 'libraryCreate', 'aura')); const templateService = TemplateService.getInstance(); diff --git a/tsconfig.json b/tsconfig.json index 5687f191..41f96ef8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,5 +5,6 @@ "allowSyntheticDefaultImports": true, "skipLibCheck": true }, - "include": ["./src/**/*"] + "include": ["./src/**/*"], + "exclude": ["./src/templates/lightningcomponent/lwc/typeScript/*"] }