Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sisilicon
GitHub Repository: sisilicon/worldedit-be
Path: blob/master/tools/add_to_world.mjs
1780 views
1
import fs from "fs";
2
import path from "path";
3
import { Command } from "commander";
4
import { argv } from "process";
5
import { copyDir } from "./utils.mjs";
6
7
const program = new Command();
8
program.option("--world-path <path>", "Path to the world directory.");
9
program.parse(argv);
10
11
const args = program.opts();
12
const worldPath = args.worldPath;
13
14
function addPack(type, packFilePath) {
15
const packsJSON = fs.existsSync(`${worldPath}/world_${type}_packs.json`) ? JSON.parse(fs.readFileSync(`${worldPath}/world_${type}_packs.json`, "utf8")) : [];
16
const manifest = JSON.parse(fs.readFileSync(`${packFilePath}/manifest.json`, "utf8"));
17
18
packsJSON.push({
19
pack_id: manifest.header.uuid,
20
version: manifest.header.version,
21
});
22
23
fs.writeFileSync(`${worldPath}/world_${type}_packs.json`, JSON.stringify(packsJSON, null, 4), "utf8");
24
copyDir(packFilePath, `${worldPath}/${type}_packs/${path.basename(packFilePath)}`);
25
}
26
27
addPack("behavior", "builds/WorldEditBP");
28
addPack("resource", "builds/WorldEditRP");
29
30