UNPKG

@bscotch/stitch

Version:

Stitch: The GameMaker Studio 2 Asset Pipeline Development Kit.

125 lines 4.14 kB
import { Pathy } from '@bscotch/pathy'; import { ok } from 'assert'; import os from 'os'; import { runBuildCommand, runGameMakerCommand } from './GameMakerEngine.run.js'; import { GameMakerEngineStatic } from './GameMakerEngine.static.js'; import { GameMakerUser } from './GameMakerUser.js'; export * from './GameMakerEngine.types.js'; /** * Discover and convert the currently installed GameMaker Studio * into an internal representation that can * be manipulated programmatically. */ export class GameMakerEngine extends GameMakerEngineStatic { dir; isBeta; constructor(options) { super(); ok(os.platform() === 'win32', `The GameMakerEngine class only supports Windows.`); this.isBeta = options?.beta || false; this.dir = GameMakerEngine.directory(options?.beta); this.dir.existsSync({ assert: true }); } get name() { return GameMakerEngine.engineName(this.isBeta); } get runtimesConfigPath() { return this.dir.join('runtime.json'); } get uiLogPath() { return this.dir.join('ui.log'); } get appDataPath() { ok(process.env.APPDATA, 'APPDATA is not defined'); return new Pathy(process.env.APPDATA, process.env.APPDATA); } get usersDirectory() { return this.appDataPath.join(this.name); } get usersConfigFilePath() { return this.usersDirectory.join('um.json'); } get currentOs() { const platform = os.platform(); const platformNiceName = platform === 'win32' ? 'windows' : platform === 'darwin' ? 'osx' : platform === 'linux' ? 'linux' : undefined; ok(platformNiceName, `Unsupported platform: ${platform}`); return platformNiceName; } get currentArchitecture() { const arch = os.arch(); ok(['x64', 'arm', 'arm64'].includes(arch), `Unsupported architecture: ${arch}`); return arch; } async run(project, options) { return await this.runBuildCommand(project, options); } async build(project, options) { return await this.runBuildCommand(project, { ...options, compile: true, }); } async runBuildCommand(project, options) { return await runBuildCommand.bind(this)(project, options); } /** * The local directory for the currently active user. */ async userDirectory() { const user = await this.user(); const folderName = `${user.userName}_${user.userId}`; const dir = this.usersDirectory.join(folderName); return dir; } /** * The currently active user. */ async user() { return new GameMakerUser(await this.userConfig()); } /** * The contents of the config file for the active * user. */ async userConfig() { return await this.usersConfigFilePath.read({ fallback: {}, }); } async runtimesConfig() { return await this.runtimesConfigPath.read(); } /** * The path to the current runtime's folder, * which contains config information and the * runtime executable, plus Igor etc. */ async runtimeDirectory() { const config = await this.runtimesConfig(); const version = config.active; return new Pathy(GameMakerEngine.runtimeDirectory(version)); } /** * Path to the most recently used rumtime CLI executable. */ async cliPath() { return (await this.runtimeDirectory()).join('bin', 'igor', this.currentOs, this.currentArchitecture, `Igor${this.currentOs === 'windows' ? '.exe' : ''}`); } /** * The most recently used runtime version. */ async runtimeVersion() { const config = await this.runtimesConfig(); return config.active; } async execute(project, worker, command, executionOptions, otherOptions) { return await runGameMakerCommand(this, project, worker, command, executionOptions, otherOptions); } } //# sourceMappingURL=GameMakerEngine.js.map