Skip to content

Commit

Permalink
v2.10.16
Browse files Browse the repository at this point in the history
  • Loading branch information
smell-of-curry committed Jul 20, 2024
1 parent c475d28 commit 66b615f
Showing 1 changed file with 45 additions and 43 deletions.
88 changes: 45 additions & 43 deletions generator/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,59 @@ const exclude = [
"package.json",
];

try {
const manifestData = fs.readFileSync("manifest.json", "utf8");
const manifest = JSON.parse(manifestData);
const version = manifest.header.version.join(".");
const fileName = `PokeBedrock RES ${version}`;
const filePath = `${fileName}.mcpack`;
(async () => {
try {
const manifestData = fs.readFileSync("manifest.json", "utf8");
const manifest = JSON.parse(manifestData);
const version = manifest.header.version.join(".");
const fileName = `PokeBedrock RES ${version}`;
const filePath = `${fileName}.mcpack`;

if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
if (fs.existsSync(filePath)) fs.unlinkSync(filePath);

const output = fs.createWriteStream(filePath);
const archive = archiver("zip", { zlib: { level: 9 } });
const output = fs.createWriteStream(filePath);
const archive = archiver("zip", { zlib: { level: 9 } });

output.on("close", () => {
console.log(archive.pointer() + " total bytes");
console.log((archive.pointer() / 1024 ** 2).toFixed(2) + "MB");
console.log(`MCPack created for version: ${version}`);
});
output.on("close", () => {
console.log(archive.pointer() + " total bytes");
console.log((archive.pointer() / 1024 ** 2).toFixed(2) + "MB");
console.log(`MCPack created for version: ${version}`);
});

archive.on("warning", (err) => {
if (err.code === "ENOENT") {
console.warn(err);
} else {
throw err;
}
});
archive.on("warning", (err) => {
if (err.code === "ENOENT") {
console.warn(err);
} else {
throw err;
}
});

archive.on("error", (err) => {
throw err;
});
archive.on("error", (err) => {
throw err;
});

const contents = fs
.readdirSync(__dirname)
.filter((v) => !exclude.includes(v));
const contents = fs
.readdirSync(__dirname)
.filter((v) => !exclude.includes(v));

for (const content of contents) {
if (content.includes(fileName)) continue;
const contentPath = path.join(__dirname, content);
for (const content of contents) {
if (content.includes(fileName)) continue;
const contentPath = path.join(__dirname, content);

if (fs.lstatSync(contentPath).isDirectory()) {
archive.directory(contentPath, content);
} else {
archive.file(contentPath, { name: content });
if (fs.lstatSync(contentPath).isDirectory()) {
archive.directory(contentPath, content);
} else {
archive.file(contentPath, { name: content });
}
}
}

archive.pipe(output);
await archive.finalize();
archive.pipe(output);
await archive.finalize();

const MCPackContents = fs.readFileSync(filePath);
fs.writeFileSync(`${fileName}.zip`, MCPackContents);
} catch (error) {
console.error("Error:", error);
process.exit(1);
}
const MCPackContents = fs.readFileSync(filePath);
fs.writeFileSync(`${fileName}.zip`, MCPackContents);
} catch (error) {
console.error("Error:", error);
process.exit(1);
}
})();

0 comments on commit 66b615f

Please sign in to comment.