diff --git a/package.json b/package.json index cbe1a1d..442be78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ttpg-scripts", - "version": "1.3.2", + "version": "1.4.0", "description": "", "bin": { "ttpg-scripts": "./bin/index.js" diff --git a/src/commands/build.ts b/src/commands/build.ts index 290d0be..4fa6d38 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -77,6 +77,7 @@ export const runBuild = async () => { Name: config.project.name, Version: config.project.version, GUID: config.project.guid.prd, + ModID: config.project.modId, }; Logger.log("writing production manifest"); try { diff --git a/src/commands/libpack.ts b/src/commands/libpack.ts index 755ca2c..442f511 100644 --- a/src/commands/libpack.ts +++ b/src/commands/libpack.ts @@ -142,6 +142,7 @@ export const runLibpack = async () => { Name: config.project.name, Version: config.project.version, GUID: config.project.guid.prd, + ModID: config.project.modId, }; Logger.log("writing production manifest"); try { diff --git a/src/commands/postpublish.ts b/src/commands/postpublish.ts new file mode 100644 index 0000000..77e56f5 --- /dev/null +++ b/src/commands/postpublish.ts @@ -0,0 +1,24 @@ +import path = require("path"); +import { Logger, assertSetup, loadConfig, pathExists } from "../common"; +import * as fs from "fs/promises"; + +export const runPostPublish = async () => { + await assertSetup(); + + const config = await loadConfig(); + + const prodPath = path.resolve(config.local.ttpg_path, config.project.slug); + + if (await pathExists(prodPath)) { + const curManifest = JSON.parse(await fs.readFile(path.resolve(prodPath, "Manifest.json"), "utf8")); + if ("ModID" in curManifest) { + config.project.modId = Number(curManifest.ModID); + await fs.writeFile(path.resolve("./ttpgcfg.project.json"), JSON.stringify(config.project), "utf-8"); + Logger.success(`Captured MOD.io Mod Id: ${curManifest.ModID}`); + } else { + Logger.warning("There was no mod Id in the package, have you published it yet?"); + } + } else { + Logger.warning("There is no production build in your ttpg folder - aborting"); + } +}; diff --git a/src/commands/purge.ts b/src/commands/purge.ts index 27c8b3e..0ff72c6 100644 --- a/src/commands/purge.ts +++ b/src/commands/purge.ts @@ -25,7 +25,20 @@ export const runPurge = async () => { ) .trim() .toLowerCase(); - input.close(); + + const curManifest = JSON.parse(await fs.readFile(path.resolve(prodPath, "Manifest.json"), "utf8")); + if ("ModID" in curManifest) { + const grabModId = process.argv.includes("-y") + ? true + : (await input.question("There is a ModID associated with this production package, would you like to save it before purging (y/n")).trim().toLowerCase() === "y"; + input.close(); + if (grabModId) { + config.project.modId = Number(curManifest.ModID); + await fs.writeFile(path.resolve("./ttpgcfg.project.json"), JSON.stringify(config.project), "utf-8"); + } + } else { + input.close(); + } if (confirm === "y") { Logger.log("removing production build from ttpg"); try { diff --git a/src/common.ts b/src/common.ts index 1deb337..244bb4e 100644 --- a/src/common.ts +++ b/src/common.ts @@ -29,6 +29,7 @@ export type Config = { dev: string; prd: string; }; + modId?: number; }; local: { ttpg_path: string; diff --git a/src/index.ts b/src/index.ts index fbb1b92..7351adf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ import path = require("path"); import { runLibpack } from "./commands/libpack"; import { runHelp } from "./help"; import { runWatch } from "./commands/watch"; +import { runPostPublish } from "./commands/postpublish"; const cmd = process.argv[2] ?? "setup"; @@ -26,6 +27,7 @@ const HANDLERS = { libpack: runLibpack, help: runHelp, watch: runWatch, + postpublish: runPostPublish, } as const; const runCommand = async () => {