Skip to content

Commit

Permalink
chore: update map
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxuanzhangsfdx committed Aug 6, 2024
1 parent c2ed958 commit 25b4956
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 36 deletions.
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@
"engines": {
"node": ">=18.18.2"
},
"resolutions": {
"yeoman-generator": "^5.6.1",
"@types/yeoman-generator": "^5.2.9"
},
"scripts": {
"build": "yarn run clean:lib && yarn build:templates && yarn compile",
"build:templates": "node scripts/build-templates",
Expand Down
27 changes: 14 additions & 13 deletions src/generators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { TemplateType } from '../utils/types';
import analyticsTemplateGenerator from './analyticsTemplateGenerator';
import apexClassGenerator from './apexClassGenerator';
import apexTriggerGenerator from './apexTriggerGenerator';
Expand Down Expand Up @@ -31,17 +32,17 @@ export type Generators =
| typeof visualforceComponentGenerator
| typeof visualforcePageGenerator;

export const generators = new Map<string, Generators>([
['analyticsTemplateGenerator', analyticsTemplateGenerator],
['apexClassGenerator', apexClassGenerator],
['apexTriggerGenerator', apexTriggerGenerator],
['lightningAppGenerator', lightningAppGenerator],
['lightningComponentGenerator', lightningComponentGenerator],
['lightningEventGenerator', lightningEventGenerator],
['lightningInterfaceGenerator', lightningInterfaceGenerator],
['lightningTestGenerator', lightningTestGenerator],
['projectGenerator', projectGenerator],
['staticResourceGenerator', staticResourceGenerator],
['visualforceComponentGenerator', visualforceComponentGenerator],
['visualforcePageGenerator', visualforcePageGenerator],
export const generators = new Map<TemplateType, Generators>([
[TemplateType.AnalyticsTemplate, analyticsTemplateGenerator],
[TemplateType.ApexClass, apexClassGenerator],
[TemplateType.ApexTrigger, apexTriggerGenerator],
[TemplateType.LightningApp, lightningAppGenerator],
[TemplateType.LightningComponent, lightningComponentGenerator],
[TemplateType.LightningEvent, lightningEventGenerator],
[TemplateType.LightningInterface, lightningInterfaceGenerator],
[TemplateType.LightningTest, lightningTestGenerator],
[TemplateType.Project, projectGenerator],
[TemplateType.VisualforceComponent, visualforceComponentGenerator],
[TemplateType.VisualforcePage, visualforcePageGenerator],
[TemplateType.StaticResource, staticResourceGenerator],
]);
1 change: 0 additions & 1 deletion src/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ export const messages = {
LightningEventBundle: 'A Lightning Event Bundle',
LightningInterfaceBundle: 'A Lightning Interface Bundle',
LightningTest: 'A Lightning Test',
templateTypeNotFound: 'The template type does not exist',
RawOutput: 'target dir = %s\n%s',
};
13 changes: 1 addition & 12 deletions src/service/templateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,9 @@

import { type CreateOutput, TemplateType } from '../utils/types';
import { Generators, generators } from '../generators';
import { nls } from '../i18n';

export function importGenerator(templateType: TemplateType) {
let generatorClass;
try {
generatorClass =
TemplateType[templateType].toString().charAt(0).toLowerCase() +
TemplateType[templateType].toString().slice(1) +
'Generator';
} catch (error) {
throw new Error(nls.localize('templateTypeNotFound'));
}

const generator = generators.get(generatorClass) as Generators;
const generator = generators.get(templateType) as Generators;
return generator;
}

Expand Down
6 changes: 0 additions & 6 deletions test/service/templateService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,6 @@ describe('TemplateService', () => {
}
});

it('should return an error if the generator does not exist', () => {
chai
.expect(() => importGenerator(20 as TemplateType))
.to.throw(Error, nls.localize('templateTypeNotFound'));
});

it('should create AnalyticsTemplate', async () => {
await remove(path.join('testsoutput', 'libraryCreate', 'waveTemplates'));
const templateService = TemplateService.getInstance();
Expand Down

0 comments on commit 25b4956

Please sign in to comment.