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",
|
"name": "asajs",
|
||||||
"version": "4.1.2-indev",
|
"version": "4.1.3-indev",
|
||||||
"description": "Create your Minecraft JSON-UI resource packs using JavaScript",
|
"description": "Create your Minecraft JSON-UI resource packs using JavaScript",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Minecraft",
|
"Minecraft",
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ if (!fs.existsSync("asajs.config.js")) {
|
||||||
"asajs.config.js",
|
"asajs.config.js",
|
||||||
[
|
[
|
||||||
'import { RandomBindingString } from "asajs"\n',
|
'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"),
|
].join("\n"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ export class Parser {
|
||||||
output: Expression
|
output: Expression
|
||||||
tokens: Token[]
|
tokens: Token[]
|
||||||
|
|
||||||
|
static hasError = false
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private input: string,
|
private input: string,
|
||||||
private cache = new Map<string, unknown>(),
|
private cache = new Map<string, unknown>(),
|
||||||
|
|
@ -414,6 +416,7 @@ export class Parser {
|
||||||
private expect(kind: TokenKind, err: string) {
|
private expect(kind: TokenKind, err: string) {
|
||||||
const prev = this.at() || this.last()
|
const prev = this.at() || this.last()
|
||||||
if (!prev || prev.kind !== kind) {
|
if (!prev || prev.kind !== kind) {
|
||||||
|
Parser.hasError = true
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`\x1b[31m${this.getPointer(prev)}\n` + `[ERROR]: ${err}\x1b[0m - Expected ${TokenKind[kind]}`,
|
`\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 { Log } from "../PreCompile.js"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { API_events } from "../../components/API.js"
|
import { API_events } from "../../components/API.js"
|
||||||
|
import { Parser } from "../bindings/Parser.js"
|
||||||
|
|
||||||
async function buildUI() {
|
async function buildUI() {
|
||||||
const build = Memory.build()
|
const build = Memory.build()
|
||||||
|
|
@ -40,7 +41,9 @@ async function buildUI() {
|
||||||
),
|
),
|
||||||
"utf-8",
|
"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)
|
build.delete(file)
|
||||||
return file
|
return file
|
||||||
}),
|
}),
|
||||||
|
|
@ -58,12 +61,15 @@ async function buildUI() {
|
||||||
fs
|
fs
|
||||||
.stat(`${buildFolder}/pack_icon.png`)
|
.stat(`${buildFolder}/pack_icon.png`)
|
||||||
.catch(() =>
|
.catch(() =>
|
||||||
fs.copyFile(
|
fs
|
||||||
isTestMode ? "resources/pack_icon.png" : "node_modules/asajs/resources/pack_icon.png",
|
.copyFile(
|
||||||
|
isTestMode
|
||||||
|
? "resources/pack_icon.png"
|
||||||
|
: path.join(process.cwd(), "node_modules/asajs/resources/pack_icon.png"),
|
||||||
`${buildFolder}/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(() => Log("WARN", `cannot copy ${buildFolder}/pack_icon.png!`)),
|
||||||
]).catch(error => console.error(error))
|
]).catch(error => console.error(error))
|
||||||
|
|
||||||
|
|
@ -75,6 +81,10 @@ if (isBuildMode) {
|
||||||
process.on("beforeExit", async () => {
|
process.on("beforeExit", async () => {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false
|
first = false
|
||||||
|
if (Parser.hasError) {
|
||||||
|
console.error()
|
||||||
|
return
|
||||||
|
}
|
||||||
await createBuildFolder()
|
await createBuildFolder()
|
||||||
await buildUI()
|
await buildUI()
|
||||||
if (isLinkMode) await linkToGame()
|
if (isLinkMode) await linkToGame()
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { AnimationKeyframe } from "./AnimationKeyframe.js"
|
||||||
import { Class } from "./Class.js"
|
import { Class } from "./Class.js"
|
||||||
import { RandomString, ResolveBinding } from "./Utils.js"
|
import { RandomString, ResolveBinding } from "./Utils.js"
|
||||||
import { RandomNamespace } from "../compilers/Random.js"
|
import { RandomNamespace } from "../compilers/Random.js"
|
||||||
|
import nodepath from "path"
|
||||||
|
|
||||||
import util from "node:util"
|
import util from "node:util"
|
||||||
import { config, uiBuildFolder } from "../compilers/Configuration.js"
|
import { config, uiBuildFolder } from "../compilers/Configuration.js"
|
||||||
|
|
@ -22,6 +23,12 @@ interface ExtendUI {
|
||||||
toString(): string
|
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 {
|
export class UI<T extends Type, K extends Renderer | null = null> extends Class {
|
||||||
readonly path: string
|
readonly path: string
|
||||||
readonly name: 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.name = name?.match(/^(\w|\/)+/)?.[0] || RandomString(16)
|
||||||
this.namespace = namespace || RandomNamespace()
|
this.namespace = namespace || RandomNamespace()
|
||||||
|
|
||||||
if (!path)
|
if (!path) this.path = nodepath.join(uiBuildFolder, `${this.namespace}${fileExt}`)
|
||||||
this.path = `${uiBuildFolder}/${this.namespace}${config.compiler?.fileExtension ? (config.compiler.fileExtension.startsWith(".") ? config.compiler.fileExtension : `.${config.compiler.fileExtension}`) : ".json"}`
|
|
||||||
else this.path = path
|
else this.path = path
|
||||||
|
|
||||||
this.extendable = this.name.search("/") === -1
|
this.extendable = this.name.search("/") === -1
|
||||||
|
|
|
||||||
Reference in a new issue