chore: move build script into scripts folder, copy it to the dist on run
This commit is contained in:
@@ -60,7 +60,12 @@ async function main() {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const buildThemeScript = path.resolve(__dirname, `../scripts/build-theme.ts`);
|
||||
|
||||
fs.cpSync(templateDir, targetDir, { recursive: true });
|
||||
fs.cpSync(buildThemeScript, path.join(targetDir, "build-theme.ts"), {
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
const pkgPath = path.join(targetDir, "package.json");
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
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);
|
||||
});
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
"strict": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src"]
|
||||
"include": ["src", "scripts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user