From 12dadcac2c3f8ea8e6b2554bb0b8cb867d8f97c3 Mon Sep 17 00:00:00 2001 From: Asaki Yuki Date: Mon, 23 Feb 2026 14:22:10 +0700 Subject: [PATCH] stupid --- package.json | 2 +- src/compilers/Configuration.ts | 2 +- src/compilers/bindings/Parser.ts | 3 +++ src/compilers/ui/builder.ts | 22 ++++++++++++++++------ src/components/UI.ts | 10 ++++++++-- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 9b8f7dc..8fe98b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "asajs", - "version": "4.1.2-indev", + "version": "4.1.3-indev", "description": "Create your Minecraft JSON-UI resource packs using JavaScript", "keywords": [ "Minecraft", diff --git a/src/compilers/Configuration.ts b/src/compilers/Configuration.ts index 2dd1118..da9ea95 100644 --- a/src/compilers/Configuration.ts +++ b/src/compilers/Configuration.ts @@ -51,7 +51,7 @@ if (!fs.existsSync("asajs.config.js")) { "asajs.config.js", [ 'import { RandomBindingString } from "asajs"\n', - fs.readFileSync("node_modules/asajs/resources/example-config.js", "utf-8"), + fs.readFileSync(path.join(process.cwd(), "node_modules/asajs/resources/example-config.js"), "utf-8"), ].join("\n"), ) } diff --git a/src/compilers/bindings/Parser.ts b/src/compilers/bindings/Parser.ts index 70bd8b7..ba2bb9d 100644 --- a/src/compilers/bindings/Parser.ts +++ b/src/compilers/bindings/Parser.ts @@ -13,6 +13,8 @@ export class Parser { output: Expression tokens: Token[] + static hasError = false + constructor( private input: string, private cache = new Map(), @@ -414,6 +416,7 @@ export class Parser { private expect(kind: TokenKind, err: string) { const prev = this.at() || this.last() if (!prev || prev.kind !== kind) { + Parser.hasError = true throw new Error( `\x1b[31m${this.getPointer(prev)}\n` + `[ERROR]: ${err}\x1b[0m - Expected ${TokenKind[kind]}`, ) diff --git a/src/compilers/ui/builder.ts b/src/compilers/ui/builder.ts index 33fe14b..40c1e9d 100644 --- a/src/compilers/ui/builder.ts +++ b/src/compilers/ui/builder.ts @@ -10,6 +10,7 @@ import { disableRSP, enableRSP } from "./installer.js" import { Log } from "../PreCompile.js" import path from "path" import { API_events } from "../../components/API.js" +import { Parser } from "../bindings/Parser.js" async function buildUI() { const build = Memory.build() @@ -40,7 +41,9 @@ async function buildUI() { ), "utf-8", ) - .then(() => Log("INFO", `${outFile} with ${Object.keys(value).length} elements created!`)) + .then(() => + Log("INFO", `${outFile.replace(/\\/g, "/")} with ${Object.keys(value).length} elements created!`), + ) build.delete(file) return file }), @@ -58,12 +61,15 @@ async function buildUI() { fs .stat(`${buildFolder}/pack_icon.png`) .catch(() => - fs.copyFile( - isTestMode ? "resources/pack_icon.png" : "node_modules/asajs/resources/pack_icon.png", - `${buildFolder}/pack_icon.png`, - ), + fs + .copyFile( + isTestMode + ? "resources/pack_icon.png" + : path.join(process.cwd(), "node_modules/asajs/resources/pack_icon.png"), + `${buildFolder}/pack_icon.png`, + ) + .then(() => Log("INFO", `${buildFolder}/pack_icon.png copied!`)), ) - .then(() => Log("INFO", `${buildFolder}/pack_icon.png copied!`)) .catch(() => Log("WARN", `cannot copy ${buildFolder}/pack_icon.png!`)), ]).catch(error => console.error(error)) @@ -75,6 +81,10 @@ if (isBuildMode) { process.on("beforeExit", async () => { if (first) { first = false + if (Parser.hasError) { + console.error() + return + } await createBuildFolder() await buildUI() if (isLinkMode) await linkToGame() diff --git a/src/components/UI.ts b/src/components/UI.ts index f9e4a05..63cdb7d 100644 --- a/src/components/UI.ts +++ b/src/components/UI.ts @@ -12,6 +12,7 @@ import { AnimationKeyframe } from "./AnimationKeyframe.js" import { Class } from "./Class.js" import { RandomString, ResolveBinding } from "./Utils.js" import { RandomNamespace } from "../compilers/Random.js" +import nodepath from "path" import util from "node:util" import { config, uiBuildFolder } from "../compilers/Configuration.js" @@ -22,6 +23,12 @@ interface ExtendUI { toString(): string } +const fileExt = config.compiler?.fileExtension + ? config.compiler.fileExtension.startsWith(".") + ? config.compiler.fileExtension + : `.${config.compiler.fileExtension}` + : ".json" + export class UI extends Class { readonly path: string readonly name: string @@ -56,8 +63,7 @@ export class UI extends Class this.name = name?.match(/^(\w|\/)+/)?.[0] || RandomString(16) this.namespace = namespace || RandomNamespace() - if (!path) - this.path = `${uiBuildFolder}/${this.namespace}${config.compiler?.fileExtension ? (config.compiler.fileExtension.startsWith(".") ? config.compiler.fileExtension : `.${config.compiler.fileExtension}`) : ".json"}` + if (!path) this.path = nodepath.join(uiBuildFolder, `${this.namespace}${fileExt}`) else this.path = path this.extendable = this.name.search("/") === -1