config
This commit is contained in:
parent
4ad9e832bd
commit
a2ad1bf977
9 changed files with 37 additions and 20 deletions
|
|
@ -7,6 +7,10 @@ if (!fs.existsSync("asajs.config.cjs")) {
|
|||
fs.copyFileSync("node_modules/asajs/resources/asajs.config.cjs", "asajs.config.cjs")
|
||||
}
|
||||
|
||||
if (!fs.existsSync(".gitignore")) {
|
||||
fs.writeFileSync(".gitignore", `node_modules`, "utf-8")
|
||||
}
|
||||
|
||||
export const config: Config = require(path.resolve(process.cwd(), "asajs.config.cjs")).config
|
||||
|
||||
export let isBuildMode = config.compiler?.enabled ?? false
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { genManifest } from "./manifest.js"
|
|||
import { UI } from "../../components/UI.js"
|
||||
import { Type } from "../../types/enums/Type.js"
|
||||
import fs from "fs/promises"
|
||||
import { BuildCache } from "./buildcache.js"
|
||||
|
||||
async function buildUI() {
|
||||
const build = Memory.build()
|
||||
|
|
@ -15,10 +16,6 @@ async function buildUI() {
|
|||
|
||||
if (config.global_variables) build.set("ui/_global_variables.json", config.global_variables)
|
||||
|
||||
build.set("build.json", {
|
||||
files: Array.from(build.keys()),
|
||||
})
|
||||
|
||||
const out = await Promise.all(
|
||||
build.entries().map(async ([file, value]) => {
|
||||
const outFile = `build/${file}`
|
||||
|
|
@ -46,6 +43,7 @@ async function buildUI() {
|
|||
await Promise.all([
|
||||
fs.writeFile("build/manifest.json", await genManifest(), "utf-8"),
|
||||
fs.writeFile("build/.gitignore", [...out, "manifest.json"].join("\n"), "utf-8"),
|
||||
BuildCache.set("build-files", [...out, "manifest.json"]),
|
||||
fs
|
||||
.stat("build/pack_icon.png")
|
||||
.catch(() => fs.copyFile("node_modules/asajs/resources/pack_icon.png", "build/pack_icon.png")),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import fs from "fs/promises"
|
||||
import { BuildCache } from "./buildcache.js"
|
||||
import { RandomString } from "../../components/Utils.js"
|
||||
import { prevData } from "./prevdata.js"
|
||||
import path from "path"
|
||||
import { getGamedataPath } from "./installer.js"
|
||||
|
||||
|
|
@ -25,7 +24,8 @@ function genUUID(): string {
|
|||
}
|
||||
|
||||
export async function clearBuild() {
|
||||
await Promise.all(prevData.files.map(file => fs.rm(`build/${file}`).catch(() => null)))
|
||||
const files: string[] = (await BuildCache.get("build-files")) || []
|
||||
await Promise.all(files.map(file => fs.rm(`build/${file}`).catch(() => null)))
|
||||
}
|
||||
|
||||
export async function createBuildFolder() {
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ export async function genManifest() {
|
|||
format_version: 2,
|
||||
header: {
|
||||
name: config.packinfo?.name || "AsaJS",
|
||||
description: config.packinfo?.description || "A framework for creating UIs for AsaJS.",
|
||||
description:
|
||||
config.packinfo?.description || "Create your Minecraft JSON-UI resource packs using JavaScript.",
|
||||
uuid: uuid1,
|
||||
version: config.packinfo?.version || [4, 0, 0],
|
||||
min_engine_version: [1, 21, 132],
|
||||
min_engine_version: [1, 21, 80],
|
||||
},
|
||||
modules: [
|
||||
{
|
||||
|
|
@ -20,5 +21,7 @@ export async function genManifest() {
|
|||
version: [4, 0, 0],
|
||||
},
|
||||
],
|
||||
subpacks: config.packinfo?.subpacks,
|
||||
metadata: config.packinfo?.metadata,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
import fs from "fs"
|
||||
|
||||
export let prevData: {
|
||||
files: string[]
|
||||
}
|
||||
|
||||
try {
|
||||
prevData = JSON.parse(fs.readFileSync("build/build.json", "utf-8"))
|
||||
} catch (error) {
|
||||
prevData = { files: [] }
|
||||
}
|
||||
|
|
@ -144,6 +144,12 @@ export function Modify<T extends Namespace, K extends Element<T>>(namespace: T,
|
|||
const memoryUI = MemoryModify[paths[namespace][name]]?.[name]
|
||||
// @ts-ignore
|
||||
if (memoryUI) return memoryUI as ModifyUI<VanillaType<T, K>, VanillaElementChilds<T, K>>
|
||||
if (!paths[namespace]) {
|
||||
throw new Error(`Namespace '${namespace}' does not exist`)
|
||||
// @ts-ignore
|
||||
} else if (!paths[namespace][name]) {
|
||||
throw new Error(`Element '${name}' does not exist in namespace '${namespace}'`)
|
||||
}
|
||||
// @ts-ignore
|
||||
const modifyUI = new ModifyUI<VanillaType<T, K>, VanillaElementChilds<T, K>>(
|
||||
namespace,
|
||||
|
|
|
|||
Reference in a new issue