chore: move build script into scripts folder, copy it to the dist on run
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import fs from "fs";
|
||||
import archiver from "archiver";
|
||||
import path from "path";
|
||||
|
||||
export const toSafeName = (name: string) => {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.replace(/[<>:"/\\|?*]/g, "_")
|
||||
.replace(/[\x00-\x1F\x7F]/g, "_")
|
||||
.replace(/[\s-]+/g, "_")
|
||||
.replace(/_+/g, "_")
|
||||
.replace(/[. ]+$/g, "_");
|
||||
};
|
||||
|
||||
const themeInfo = JSON.parse(fs.readFileSync("theme.json", "utf-8"));
|
||||
|
||||
const distDir = path.resolve("dist");
|
||||
const output = fs.createWriteStream(
|
||||
path.join(distDir, `${toSafeName(themeInfo.name)}.ezpplauncher-theme`),
|
||||
);
|
||||
|
||||
const archive = archiver("zip", { zlib: { level: 9 } });
|
||||
archive.pipe(output);
|
||||
|
||||
archive.file("theme.json", { name: "theme.json" });
|
||||
archive.file(path.join(distDir, "bundle.js"), { name: "bundle.js" });
|
||||
|
||||
if (fs.existsSync(path.join(distDir, "ezpp-theme.css"))) {
|
||||
archive.file(path.join(distDir, "ezpp-theme.css"), { name: "style.css" });
|
||||
}
|
||||
|
||||
if (fs.existsSync("public/assets")) {
|
||||
archive.directory("public/assets", "assets");
|
||||
}
|
||||
|
||||
archive.finalize();
|
||||
|
||||
output.on("close", () => {
|
||||
console.log("✅ Theme packaged:", output.path);
|
||||
});
|
||||
Reference in New Issue
Block a user