Skip to content

Commit

Permalink
add post-publish command
Browse files Browse the repository at this point in the history
  • Loading branch information
RobMayer committed Sep 9, 2023
1 parent eed32dd commit b7b75fb
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ttpg-scripts",
"version": "1.3.2",
"version": "1.4.0",
"description": "",
"bin": {
"ttpg-scripts": "./bin/index.js"
Expand Down
1 change: 1 addition & 0 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/commands/libpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions src/commands/postpublish.ts
Original file line number Diff line number Diff line change
@@ -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");
}
};
15 changes: 14 additions & 1 deletion src/commands/purge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type Config = {
dev: string;
prd: string;
};
modId?: number;
};
local: {
ttpg_path: string;
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -26,6 +27,7 @@ const HANDLERS = {
libpack: runLibpack,
help: runHelp,
watch: runWatch,
postpublish: runPostPublish,
} as const;

const runCommand = async () => {
Expand Down

0 comments on commit b7b75fb

Please sign in to comment.