UNPKG

cbt-game-generator

Version:

Configuration generator for CBT animation apps

65 lines (57 loc) 2.07 kB
#!/usr/bin/env node import { GameConfigGenerator } from './gameConfigGenerator'; import { GameType } from './index'; import * as fs from 'fs'; import * as path from 'path'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; // Configure command line arguments const argv = yargs(hideBin(process.argv)) .option('config-path', { alias: 'c', description: 'Path to the configuration JSON file', type: 'string', demandOption: true }) .help() .alias('help', 'h') .parseSync(); try { // Read and parse the JSON file const configContent = fs.readFileSync(argv['config-path'], 'utf-8'); const config = JSON.parse(configContent); // Validate required fields const requiredFields = ['skillName', 'gameName', 'gameType', 'numberOfVariants', 'targets']; const missingFields = requiredFields.filter(field => !(field in config)); if (missingFields.length > 0) { console.error('Missing required fields in configuration:', missingFields.join(', ')); process.exit(1); } // Validate gameType if (!Object.values(GameType).includes(config.gameType)) { console.error('Invalid gameType. Must be one of:', Object.values(GameType).join(', ')); process.exit(1); } // Create and run the generator const generator = new GameConfigGenerator({ skillName: config.skillName, gameName: config.gameName, gameType: config.gameType as GameType, numberOfVariants: config.numberOfVariants, targets: config.targets, isIncremental: config.isIncremental }); generator.generate(); console.log('Game configuration generated successfully!'); } catch (error: unknown) { if (error instanceof SyntaxError) { console.error('Invalid JSON file:', error.message); } else if (error instanceof Error && 'code' in error && error.code === 'ENOENT') { console.error('Configuration file not found:', argv['config-path']); } else if (error instanceof Error) { console.error('Error:', error.message); } else { console.error('An unknown error occurred'); } process.exit(1); }