UNPKG

isaacscript

Version:

A command line tool for managing Isaac mods written in TypeScript.

88 lines 4.13 kB
import chalk from "chalk"; import { deleteFileOrDirectory, getFileNamesInDirectory, getPackageJSONVersion, isDirectory, isFile, readFile, } from "complete-node"; import path from "node:path"; import { getConfigFromFile } from "../../configFile.js"; import { CWD, MOD_SOURCE_PATH, MOD_UPLOADER_PATH, PUBLISH_POST_COPY_PY_PATH, PUBLISH_PRE_COPY_PY_PATH, } from "../../constants.js"; import { execExe, execShell, execShellString } from "../../exec.js"; import { getReleaseGitCommitMessage, gitCommitAllAndPush } from "../../git.js"; import { getPackageManagerUsedForExistingProject } from "../../packageManager.js"; import { getModTargetDirectoryName } from "../../utils.js"; import { compileAndCopy } from "../copy/copy.js"; export async function publishIsaacScriptMod(dryRun, verbose) { const packageManager = await getPackageManagerUsedForExistingProject(); const config = await getConfigFromFile(); const modTargetDirectoryName = getModTargetDirectoryName(config); const modTargetPath = path.join(config.modsDirectory, modTargetDirectoryName); const version = await getPackageJSONVersion(undefined); await runReleaseScriptPreCopy(verbose); await compileAndCopy(MOD_SOURCE_PATH, modTargetPath, packageManager, config.isaacScriptCommonDev, verbose); await purgeRoomXMLs(modTargetPath); await runReleaseScriptPostCopy(verbose); if (dryRun) { execShellString("git reset --hard", verbose); // Revert the version changes. } else { const releaseGitCommitMessage = getReleaseGitCommitMessage(version); gitCommitAllAndPush(releaseGitCommitMessage, verbose); await uploadMod(modTargetPath, verbose); } const dryRunSuffix = dryRun ? " (dry run)" : ""; console.log(`\nPublished version ${version} successfully${dryRunSuffix}.`); } async function runReleaseScriptPreCopy(verbose) { const file = await isFile(PUBLISH_PRE_COPY_PY_PATH); if (!file) { return; } console.log(`Running the "${PUBLISH_PRE_COPY_PY_PATH}" script.`); const { stdout } = execShell("python", [PUBLISH_PRE_COPY_PY_PATH], verbose); if (stdout !== "") { console.log(stdout); } } async function runReleaseScriptPostCopy(verbose) { const file = await isFile(PUBLISH_POST_COPY_PY_PATH); if (!file) { return; } console.log(`Running the "${PUBLISH_POST_COPY_PY_PATH}" script.`); const { stdout } = execShell("python", [PUBLISH_POST_COPY_PY_PATH], verbose); if (stdout !== "") { console.log(stdout); } } async function purgeRoomXMLs(modTargetPath) { const roomsPath = path.join(modTargetPath, "resources", "rooms"); const directory = await isDirectory(roomsPath); if (!directory) { return; } const fileNames = await getFileNamesInDirectory(roomsPath); const xmlFileNames = fileNames.filter((fileName) => path.extname(fileName) === ".xml"); for (const xmlFileName of xmlFileNames) { const roomFilePath = path.join(roomsPath, xmlFileName); // eslint-disable-next-line no-await-in-loop await deleteFileOrDirectory(roomFilePath); } } async function uploadMod(modTargetPath, verbose) { const hasGitHubAction = await hasIsaacSteamWorkshopUploadGitHubAction(); if (hasGitHubAction) { // CI will automatically upload the new version to the Steam Workshop, so there is no need to // open the mod uploader program. return; } console.log(`The "isaac-steam-workshop-upload" action was not found in the "${chalk.green("ci.yml")}" file; assuming that we want to use the "ModUploader.exe" tool.`); execExe(MOD_UPLOADER_PATH, [], verbose, modTargetPath); } async function hasIsaacSteamWorkshopUploadGitHubAction() { const ciYMLPath = path.join(CWD, ".github", "workflows", "ci.yml"); const file = await isFile(ciYMLPath); if (!file) { return false; } const ciYML = await readFile(ciYMLPath); const lines = ciYML.split("\n"); return lines.some((line) => line.match(/^\s*uses: IsaacScript\/isaac-steam-workshop-upload/) !== null); } //# sourceMappingURL=isaacscriptMod.js.map