asajs
Version:
Make your Minecraft JsonUI with ScriptingAPI
159 lines (158 loc) • 7.73 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Compiler_exports = {};
__export(Compiler_exports, {
installer: () => installer
});
module.exports = __toCommonJS(Compiler_exports);
var import_fs = __toESM(require("fs"));
var import_Manifest = require("./generator/Manifest");
var import_UIBuilder = require("./generator/UIBuilder");
var import_Config = require("./Config");
var import_Compress = require("./Compress");
var import_Sounds = require("./generator/Sounds");
var import_Audio = require("./reader/Audio");
var import_Log = require("./generator/Log");
var import_Encoder = require("./Encoder");
var import_PreCompile = require("./PreCompile");
var import_LocalizeText = require("../components/LocalizeText");
var import_LangBuilder = require("./generator/LangBuilder");
var import_Installer = require("../types/objects/Installer");
var import_Installer2 = require("./Installer");
const config = import_Config.Configs.getConfig();
const installer = new import_Installer2.ResourcePacks({
installGame: config.installer.previewVersion ? import_Installer.Minecraft.Preview : import_Installer.Minecraft.Stable,
installFolder: config.installer.developEvironment ? import_Installer.ResourcePack.Development : import_Installer.ResourcePack.Production
});
function manifestBuild(installPath) {
const { name, description, uuid, version, baseGameVersion } = config.manifest;
const manifest = new import_Manifest.Manifest({ name, description, uuid, version });
manifest.manifest.header.min_engine_version = baseGameVersion;
(0, import_PreCompile.UIWriteJson)("".concat(installPath, "/manifest.json"), manifest.manifest, "utf-8");
}
let isRunned = false;
process.on("beforeExit", () => {
if (isRunned) return;
isRunned = true;
const installPath = installer.getInstallPath();
config.installer.autoInstall = config.installer.autoInstall && import_fs.default.existsSync(installer.installPath);
const buildPath = config.installer.autoInstall ? installPath : ".build";
import_UIBuilder.UIBuilder.delete(buildPath);
if (import_fs.default.existsSync(".build")) import_fs.default.rmSync(".build", { recursive: true });
if (import_fs.default.existsSync(".minecraft")) import_fs.default.unlinkSync(".minecraft");
if (!import_fs.default.existsSync(".bedrock")) import_fs.default.mkdirSync(".bedrock");
if (!import_fs.default.existsSync("".concat(buildPath))) import_fs.default.mkdirSync("".concat(buildPath));
if (!import_fs.default.existsSync("".concat(buildPath, "/@"))) import_fs.default.mkdirSync("".concat(buildPath, "/@"));
try {
console.log("---------- COMPILING ----------");
(0, import_Audio.FormatAudio)();
if (config.installer.autoInstall) {
installer.packLink();
console.timeLog("COMPILER", "Symlink completed!");
console.log();
}
import_fs.default.cpSync(".bedrock", buildPath, { recursive: true });
console.timeLog("COMPILER", "Copy bedrock resources completed!");
console.log();
console.timeLog("COMPILER", "".concat(import_UIBuilder.UIBuilder.jsonUI(buildPath), " custom file(s) compiled!"));
console.log();
console.timeLog("COMPILER", "".concat(import_UIBuilder.UIBuilder.modify(buildPath), " modify file(s) compiled!"));
console.log();
if (Object.keys(import_LocalizeText.localizeText).length) {
console.timeLog("COMPILER", "".concat(import_LangBuilder.LangBuilder.build(buildPath), " lang file(s) compiled!"));
console.log();
}
manifestBuild(buildPath);
console.timeLog("COMPILER", "Manifest file has been compiled!");
console.timeLog(
"COMPILER",
"ui/_ui_defs.json ".concat(import_UIBuilder.UIBuilder.uiDefs(buildPath), " files path(s) found!")
);
console.timeLog(
"COMPILER",
"ui/_global_variables.json ".concat(import_UIBuilder.UIBuilder.globalVariables(
buildPath
), " variable(s) compiled!")
);
console.timeLog(
"COMPILER",
"textures/textures_list.json ".concat(import_UIBuilder.UIBuilder.texturesList(buildPath), " files path(s) found!")
);
const soundLength = import_Sounds.SoundHandler.compile(buildPath);
if (soundLength)
console.timeLog(
"COMPILER",
"sounds/sound_definitions.json ".concat(soundLength, " sound id has regisrer!")
);
console.timeLog(
"COMPILER",
"contents.json ".concat(import_UIBuilder.UIBuilder.contents(buildPath), " file path(s) found!")
);
if (config.installer.autoInstall) {
installer.installPack(config.manifest.uuid, config.manifest.version);
console.timeLog("COMPILER", "Resource Pack has been installed!");
}
if (config.compiler.autoCompress) {
(0, import_Compress.CompressPack)(buildPath);
console.timeLog("COMPILER", "Minecraft-UIBuild.mcpack Pack compress completed!");
}
if (config.compiler.encodeJson) {
import_Encoder.Encoder.start();
console.timeLog("COMPILER", "Encoded ".concat(import_Encoder.Encoder.count, " JSON file(s) successfully!"));
}
console.log();
console.timeLog("COMPILER", "Compile completed!");
if (import_Log.Logs.length) {
console.log("\n---------- Build Log ----------");
for (const log of import_Log.Logs) {
if (log.type === "warning") console.warn(log.message);
else if (log.type === "error") console.error(log.message);
}
}
console.log("\n---------- INFO ----------");
console.log("Name: \x1B[96m".concat(config.manifest.name, "\x1B[0m"));
console.log("Description: \x1B[96m".concat(config.manifest.description, "\x1B[0m"));
console.log("UUID: \x1B[96m".concat(config.manifest.uuid, "\x1B[0m"));
console.log(
"Pack Version: \x1B[96m".concat(config.manifest.version[0], ".").concat(config.manifest.version[1], ".").concat(config.manifest.version[2], "\x1B[0m")
);
console.log(
"Base Game Version: \x1B[96m".concat(config.manifest.baseGameVersion[0], ".").concat(config.manifest.baseGameVersion[1], ".").concat(config.manifest.baseGameVersion[2], "\x1B[0m")
);
if (config.installer.autoInstall)
console.log("Install Path: \x1B[96m".concat(installPath, "\x1B[0m"));
} catch (error) {
console.timeLog("COMPILER", "An error occurred while compiling!");
console.error(error);
}
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
installer
});