@bscotch/stitch-launcher
Version:
Manage GameMaker IDE and runtime installations for fast switching between versions.
107 lines • 5.14 kB
JavaScript
var GameMakerLauncher_1;
import { __decorate, __metadata } from "tslib";
import { ok } from 'assert';
import { GameMakerIde } from './GameMakerIde.js';
import { GameMakerRuntime } from './GameMakerRuntime.js';
import { bootstrapRuntimeVersion, setActiveRuntime, trace, } from './utility.js';
export * from './GameMakerLauncher.types.js';
let GameMakerLauncher = GameMakerLauncher_1 = class GameMakerLauncher {
/**
* Open a project with a specified IDE and
* Runtime version. If only the IDE version is
* specified, its matching Runtime version will
* be automatically selected.
*
* This method will guarantee that it will
* *either* successfully open the project with
* the target versions, or it will throw an error
* and not open anything. In particular, if a
* mismatched IDE and Runtime are specified,
* and the Runtime is not installed, this method
* will throw an error.
*/
static async openProject(projectYypPath, openProjectOptions) {
console.log(`Making sure that IDE v${openProjectOptions.ideVersion} is installed...`);
const ide = await GameMakerIde.install(openProjectOptions.ideVersion, {
programFiles: openProjectOptions.programFiles,
});
return ide.openProject(projectYypPath, openProjectOptions?.runtimeVersion, {
disableUpdatePrompt: openProjectOptions?.disableUpdatePrompt,
});
}
static async runProject(target, runtimeVersion, options) {
const runtime = await GameMakerLauncher_1.installRuntime(runtimeVersion, options?.runtimeInstallerVersion);
await setActiveRuntime(runtime);
return runtime.runProject(target);
}
/**
* List the installed Runtime versions
* (many Runtime versions can be installed
* at the same time, from both beta and stable
* channels). Each Runtime comes with its own
* GameMaker CLI artifact ("Igor").
*/
static async listInstalledRuntimes(options) {
return await GameMakerRuntime.listInstalled(options);
}
static async findInstalledRuntime(searchParams, logger) {
const installedRuntimes = await GameMakerLauncher_1.listInstalledRuntimes({
logger,
});
const { version, channel } = searchParams || {};
return installedRuntimes.find((v) => (!version || v.version === version) &&
(!channel || v.channel === channel));
}
/**
* Install the specified Runtime version. Many
* Runtime versions can be installed at the same
* time. Installing a runtime makes it available
* to be used, but does not make it the *active*
* Runtime.
*
* @param usingVersion - Runtimes are installed using other runtimes. This parameter specifies which runtime to use to install the new one. If not provided, will try to use an existing installed runtime.
*/
static async installRuntime(version, usingVersion = bootstrapRuntimeVersion) {
// See if we've already got it installed
let matchingRuntime = await GameMakerLauncher_1.findInstalledRuntime({
version,
});
if (matchingRuntime) {
console.log('Runtime', version, 'is already installed');
return matchingRuntime;
}
const release = await GameMakerRuntime.findRelease({
runtimeVersion: version,
});
ok(release, `Could not find runtime version ${version} in the feeds.`);
// Otherwise we need to install it using an existing
// runtime
const otherRuntime = await GameMakerLauncher_1.findInstalledRuntime({
version: usingVersion,
});
ok(otherRuntime, `Could not find an existing runtime to use to install the new runtime.`);
// Use this runtime to install the new runtime
const { stdout, compilerLogsPath } = await otherRuntime.installRuntime(release.runtime);
ok(!stdout.includes('License is invalid - Out of Date'), 'GameMaker CLI failed due to expired credentials. This can be caused by using a runtime that requires Enterprise credentials, or by using a runtime with a bug. Runtime v2022.300.0.476 is known to work -- you can install it via the IDE and use it for future programmatic installs.');
ok(stdout.includes('Verification Complete') &&
stdout.includes('Igor complete'), `Runtime installation failed. Check the logs at ${compilerLogsPath}`);
// Make sure it's actually installed
matchingRuntime = await GameMakerLauncher_1.findInstalledRuntime({
version,
channel: release.channel,
});
ok(matchingRuntime, 'Could not find runtime after installation');
return matchingRuntime;
}
};
__decorate([
trace,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], GameMakerLauncher, "openProject", null);
GameMakerLauncher = GameMakerLauncher_1 = __decorate([
trace
], GameMakerLauncher);
export { GameMakerLauncher };
//# sourceMappingURL=GameMakerLauncher.js.map