cbt-game-generator
Version:
Configuration generator for CBT animation apps
85 lines (84 loc) • 3.63 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameMappingUpdater = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
class GameMappingUpdater {
constructor(skillName, gameName, gameId) {
this.skillName = skillName;
this.gameName = gameName;
this.gameId = gameId;
}
update() {
this.updateGamesTs();
this.updateSkillLoMapping();
}
updateGamesTs() {
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);
}
updateSkillLoMapping() {
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);
}
convertToKebabCase(str) {
return str
.replace(/([a-z])([A-Z])/g, '$1-$2')
.toLowerCase();
}
}
exports.GameMappingUpdater = GameMappingUpdater;