All files / web/src/lib/arcade/game-sdk load-manifest.ts

0% Statements 0/39
0% Branches 0/1
0% Functions 0/1
0% Lines 0/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40                                                                               
/**
 * Manifest loading and validation utilities
 */

import yaml from 'js-yaml'
import { readFileSync } from 'fs'
import { join } from 'path'
import { validateManifest, type GameManifest } from '../manifest-schema'

/**
 * Load and validate a game manifest from a YAML file
 *
 * @param manifestPath - Absolute path to game.yaml file
 * @returns Validated GameManifest object
 * @throws Error if manifest is invalid or file doesn't exist
 */
export function loadManifest(manifestPath: string): GameManifest {
  try {
    const fileContents = readFileSync(manifestPath, 'utf8')
    const data = yaml.load(fileContents)
    return validateManifest(data)
  } catch (error) {
    if (error instanceof Error) {
      throw new Error(`Failed to load manifest from ${manifestPath}: ${error.message}`)
    }
    throw error
  }
}

/**
 * Load manifest from a game directory
 *
 * @param gameDir - Absolute path to game directory
 * @returns Validated GameManifest object
 */
export function loadManifestFromDir(gameDir: string): GameManifest {
  const manifestPath = join(gameDir, 'game.yaml')
  return loadManifest(manifestPath)
}