Skip to content

Commit

Permalink
grab thumbnail and modId properly
Browse files Browse the repository at this point in the history
  • Loading branch information
RobMayer committed Oct 26, 2023
1 parent df1b3b9 commit 912b16a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 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.4.1",
"version": "1.4.2",
"description": "",
"bin": {
"ttpg-scripts": "./bin/index.js"
Expand Down
10 changes: 10 additions & 0 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ export const runBuild = async () => {
Logger.error("Could not write production manifest");
throw e;
}
Logger.log("Copying Thumbnail");
try {
if (await pathExists(path.resolve("./Thumbnail.png"))) {
await fs.copyFile(path.resolve("./Thumbnail.png"), path.resolve(config.local.ttpg_path, `${config.project.slug}`, "Thumbnail.png"));
}
Logger.success("thumbnail copied");
} catch (e) {
Logger.error("Could not copy thumbnail");
throw e;
}
Logger.success("Your project is ready to be deployed to mod.io");
}
};
11 changes: 11 additions & 0 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ export const runDev = async () => {
await fs.mkdir(path.resolve("./dev", `${config.project.slug}_dev`), { recursive: true });
await fs.writeFile(path.resolve("./dev/", `${config.project.slug}_dev`, "Manifest.json"), JSON.stringify(manifest, null, 2), "utf8");
await Promise.all(ASSET_DIRS.map((dir) => fs.symlink(path.resolve("assets", dir), path.resolve("dev", `${config.project.slug}_dev`, dir), "junction")));

Logger.log("Copying Thumbnail");
try {
if (await pathExists(path.resolve("./Thumbnail.png"))) {
await fs.copyFile(path.resolve("./Thumbnail.png"), path.resolve(config.local.ttpg_path, `${config.project.slug}`, "Thumbnail.png"));
}
Logger.success("thumbnail copied");
} catch (e) {
Logger.error("Could not copy thumbnail");
throw e;
}
} catch (e) {
Logger.error("Failed to create dev folder");
throw e;
Expand Down
3 changes: 3 additions & 0 deletions src/commands/postpublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const runPostPublish = async () => {
} else {
Logger.warning("There was no mod Id in the package, have you published it yet?");
}
if (!(await pathExists(path.resolve("./Thumbnail.png"))) && (await pathExists(path.resolve(prodPath, "Thumbnail.png")))) {
await fs.copyFile(path.resolve(prodPath, "Thumbnail.png"), path.resolve("./Thumbnail.png"));
}
} else {
Logger.warning("There is no production build in your ttpg folder - aborting");
}
Expand Down
22 changes: 12 additions & 10 deletions src/commands/purge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ export const runPurge = async () => {
.trim()
.toLowerCase();

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);
const prodManifest = JSON.parse(await fs.readFile(path.resolve(prodPath, "Manifest.json"), "utf8"));

const saveProdInfo = process.argv.includes("-y") ? true : (await input.question("Save and mod.io data (thumbnail & id), if present, before purging (y/n")).trim().toLowerCase() === "y";
input.close();

if (saveProdInfo) {
if ("ModID" in prodManifest) {
config.project.modId = Number(prodManifest.ModID);
await fs.writeFile(path.resolve("./ttpgcfg.project.json"), JSON.stringify(config.project), "utf-8");
}
} else {
input.close();
if (!(await pathExists(path.resolve("./Thumbnail.png"))) && (await pathExists(path.resolve(prodPath, "Thumbnail.png")))) {
await fs.copyFile(path.resolve(prodPath, "Thumbnail.png"), path.resolve("./Thumbnail.png"));
}
}

if (confirm === "y") {
Logger.log("removing production build from ttpg");
try {
Expand Down

0 comments on commit 912b16a

Please sign in to comment.