asajs
Version:
Make your Minecraft JsonUI with ScriptingAPI
87 lines (86 loc) • 3.34 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 PreCompile_exports = {};
__export(PreCompile_exports, {
UIWriteJson: () => UIWriteJson,
WritePreComment: () => WritePreComment,
jsonFilePath: () => jsonFilePath
});
module.exports = __toCommonJS(PreCompile_exports);
var import_fs = __toESM(require("fs"));
var import_Config = require("./Config");
if (!import_fs.default.existsSync("comment.txt")) {
import_fs.default.writeFileSync("comment.txt", "", "utf-8");
}
const timeMap = {};
console.time = function(label) {
timeMap[label] = performance.now();
};
console.timeLog = function(tag, ...data) {
const now = performance.now();
const time = now - timeMap[tag];
console.log(
"\x1B[90m[".concat(time.toFixed(2), "ms]"),
"\x1B[32m[".concat(tag, "]\x1B[0m"),
">>",
...data,
"\x1B[0m"
);
};
console.timeEnd = function(label) {
delete timeMap[label];
};
function WritePreComment(data) {
const comment = "This file is generated by the AsaJS compiler. Do not edit it directly.";
if (import_fs.default.readFileSync("comment.txt", "utf-8").trim() !== "") {
const info = import_fs.default.readFileSync("comment.txt", "utf-8").replaceAll("\n", "\n * ");
return "/*\n * ".concat(comment, "\n * ----------------------------------------------------------------------\n * ").concat(info, "\n */\n").concat(JSON.stringify(
data
));
} else {
return "// ".concat(comment, "\n").concat(JSON.stringify(data));
}
}
const jsonFilePath = [];
function UIWriteJson(file, data, options) {
const writeData = JSON.stringify(data);
if (writeData == "{}") return;
if (import_Config.Configs.getConfig().compiler.encodeJson) {
import_fs.default.writeFileSync(file, writeData, options);
} else {
import_fs.default.writeFileSync(file, WritePreComment(data), options);
}
jsonFilePath.push(file);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
UIWriteJson,
WritePreComment,
jsonFilePath
});