config
This commit is contained in:
parent
4ad9e832bd
commit
a2ad1bf977
9 changed files with 37 additions and 20 deletions
12
config.d.ts
vendored
12
config.d.ts
vendored
|
|
@ -9,6 +9,18 @@ export interface Config {
|
||||||
name?: string
|
name?: string
|
||||||
description?: string
|
description?: string
|
||||||
version?: [number, number, number]
|
version?: [number, number, number]
|
||||||
|
|
||||||
|
metadata?: {
|
||||||
|
authors?: string[]
|
||||||
|
license?: string
|
||||||
|
url?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
subpacks?: {
|
||||||
|
folder_name?: string
|
||||||
|
name?: string
|
||||||
|
memory_performance_tier?: number
|
||||||
|
}[]
|
||||||
}
|
}
|
||||||
global_variables?: Record<Variable, string>
|
global_variables?: Record<Variable, string>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "asajs",
|
"name": "asajs",
|
||||||
"version": "4.0.0-indev-2",
|
"version": "4.0.0-indev-3",
|
||||||
"description": "Create your Minecraft JSON-UI resource packs using JavaScript",
|
"description": "Create your Minecraft JSON-UI resource packs using JavaScript",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Minecraft",
|
"Minecraft",
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,12 @@
|
||||||
* @type {import('asajs/config.d.ts').Config}
|
* @type {import('asajs/config.d.ts').Config}
|
||||||
*/
|
*/
|
||||||
export const config = {
|
export const config = {
|
||||||
|
packinfo: {
|
||||||
|
name: "AsaJS",
|
||||||
|
description: "Create your Minecraft JSON-UI resource packs using JavaScript.",
|
||||||
|
},
|
||||||
compiler: {
|
compiler: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
linked: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@ if (!fs.existsSync("asajs.config.cjs")) {
|
||||||
fs.copyFileSync("node_modules/asajs/resources/asajs.config.cjs", "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 const config: Config = require(path.resolve(process.cwd(), "asajs.config.cjs")).config
|
||||||
|
|
||||||
export let isBuildMode = config.compiler?.enabled ?? false
|
export let isBuildMode = config.compiler?.enabled ?? false
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { genManifest } from "./manifest.js"
|
||||||
import { UI } from "../../components/UI.js"
|
import { UI } from "../../components/UI.js"
|
||||||
import { Type } from "../../types/enums/Type.js"
|
import { Type } from "../../types/enums/Type.js"
|
||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
|
import { BuildCache } from "./buildcache.js"
|
||||||
|
|
||||||
async function buildUI() {
|
async function buildUI() {
|
||||||
const build = Memory.build()
|
const build = Memory.build()
|
||||||
|
|
@ -15,10 +16,6 @@ async function buildUI() {
|
||||||
|
|
||||||
if (config.global_variables) build.set("ui/_global_variables.json", config.global_variables)
|
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(
|
const out = await Promise.all(
|
||||||
build.entries().map(async ([file, value]) => {
|
build.entries().map(async ([file, value]) => {
|
||||||
const outFile = `build/${file}`
|
const outFile = `build/${file}`
|
||||||
|
|
@ -46,6 +43,7 @@ async function buildUI() {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
fs.writeFile("build/manifest.json", await genManifest(), "utf-8"),
|
fs.writeFile("build/manifest.json", await genManifest(), "utf-8"),
|
||||||
fs.writeFile("build/.gitignore", [...out, "manifest.json"].join("\n"), "utf-8"),
|
fs.writeFile("build/.gitignore", [...out, "manifest.json"].join("\n"), "utf-8"),
|
||||||
|
BuildCache.set("build-files", [...out, "manifest.json"]),
|
||||||
fs
|
fs
|
||||||
.stat("build/pack_icon.png")
|
.stat("build/pack_icon.png")
|
||||||
.catch(() => fs.copyFile("node_modules/asajs/resources/pack_icon.png", "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 fs from "fs/promises"
|
||||||
import { BuildCache } from "./buildcache.js"
|
import { BuildCache } from "./buildcache.js"
|
||||||
import { RandomString } from "../../components/Utils.js"
|
import { RandomString } from "../../components/Utils.js"
|
||||||
import { prevData } from "./prevdata.js"
|
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { getGamedataPath } from "./installer.js"
|
import { getGamedataPath } from "./installer.js"
|
||||||
|
|
||||||
|
|
@ -25,7 +24,8 @@ function genUUID(): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function clearBuild() {
|
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() {
|
export async function createBuildFolder() {
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ export async function genManifest() {
|
||||||
format_version: 2,
|
format_version: 2,
|
||||||
header: {
|
header: {
|
||||||
name: config.packinfo?.name || "AsaJS",
|
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,
|
uuid: uuid1,
|
||||||
version: config.packinfo?.version || [4, 0, 0],
|
version: config.packinfo?.version || [4, 0, 0],
|
||||||
min_engine_version: [1, 21, 132],
|
min_engine_version: [1, 21, 80],
|
||||||
},
|
},
|
||||||
modules: [
|
modules: [
|
||||||
{
|
{
|
||||||
|
|
@ -20,5 +21,7 @@ export async function genManifest() {
|
||||||
version: [4, 0, 0],
|
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]
|
const memoryUI = MemoryModify[paths[namespace][name]]?.[name]
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (memoryUI) return memoryUI as ModifyUI<VanillaType<T, K>, VanillaElementChilds<T, K>>
|
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
|
// @ts-ignore
|
||||||
const modifyUI = new ModifyUI<VanillaType<T, K>, VanillaElementChilds<T, K>>(
|
const modifyUI = new ModifyUI<VanillaType<T, K>, VanillaElementChilds<T, K>>(
|
||||||
namespace,
|
namespace,
|
||||||
|
|
|
||||||
Reference in a new issue