UNPKG

cbt-game-generator

Version:

Configuration generator for CBT animation apps

68 lines (56 loc) 2.06 kB
import * as fs from 'fs'; import * as path from 'path'; export class GameMappingUpdater { constructor( private skillName: string, private gameName: string, private gameId: string ) {} public update(): void { this.updateGamesTs(); this.updateSkillLoMapping(); } private updateGamesTs(): void { const gamesPath = path.join('src/experience/shared/constants/Games.ts'); const content = fs.readFileSync(gamesPath, 'utf-8'); // Add new game to EGames enum const newGameEntry = ` ${this.gameName} = "${this.gameId}",`; const updatedContent = content.replace( /(\s+export enum EGames {)/, `$1\n${newGameEntry}` ); fs.writeFileSync(gamesPath, updatedContent); } private updateSkillLoMapping(): void { const mappingPath = path.join('src/experience/shared/constants/skillLoMapping.ts'); const content = fs.readFileSync(mappingPath, 'utf-8'); // Add new import statement const importPath = `../../games/${this.skillName}/${this.convertToKebabCase(this.gameName)}/${this.gameName}`; const newImport = `const ${this.gameName} = lazy(() => import("${importPath}"));\n`; const newMainImport = `const ${this.gameName}Main = lazy(() => import("${importPath}/Main"));\n`; // Add imports after the first import statement let updatedContent = content.replace( /(import { lazy } from "react";\n)/, `$1${newImport}${newMainImport}` ); // Add new mapping entry const newMapping = ` ${this.gameId}: { skill: "${this.skillName}", lo: "${this.convertToKebabCase(this.gameName)}", id: "${this.gameId}", MainComp: ${this.gameName}Main, GameComp: ${this.gameName}, },`; // Add mapping before the closing brace of skillLoMapping updatedContent = updatedContent.replace( /(\s+};\s*$)/, `${newMapping}\n$1` ); fs.writeFileSync(mappingPath, updatedContent); } private convertToKebabCase(str: string): string { return str .replace(/([a-z])([A-Z])/g, '$1-$2') .toLowerCase(); } }