stupid
This commit is contained in:
parent
58a193455a
commit
12dadcac2c
5 changed files with 29 additions and 10 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ export class Parser {
|
|||
output: Expression
|
||||
tokens: Token[]
|
||||
|
||||
static hasError = false
|
||||
|
||||
constructor(
|
||||
private input: string,
|
||||
private cache = new Map<string, unknown>(),
|
||||
|
|
@ -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]}`,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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<T extends Type, K extends Renderer | null = null> extends Class {
|
||||
readonly path: string
|
||||
readonly name: string
|
||||
|
|
@ -56,8 +63,7 @@ export class UI<T extends Type, K extends Renderer | null = null> 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
|
||||
|
|
|
|||
Reference in a new issue