feat: build system

This commit is contained in:
Asaki Yuki 2026-01-27 18:53:08 +07:00
parent 0c8a9cc622
commit 53375ea11c
9 changed files with 83 additions and 9 deletions

View file

@ -1 +1,3 @@
AsaJS Logo made by [Kammasy](https://www.youtube.com/channel/UCrmjDWdM8-ZSeekzLeCnftg) a.k.a **[E.G.G](https://www.youtube.com/channel/UCrmjDWdM8-ZSeekzLeCnftg)**
![image](/resources/logo.png)

View file

@ -1,6 +1,6 @@
import { AnimationKeyframe } from "../components/AnimationKeyframe.js"
import { Class } from "../components/Class.js"
import { UI } from "../components/UI.js"
import { ModifyUI, UI } from "../components/UI.js"
import { AnimType } from "../types/enums/AnimType.js"
import { Renderer } from "../types/enums/Renderer.js"
import { Type } from "../types/enums/Type.js"
@ -13,6 +13,8 @@ interface FileInterface {
}
type Files = Map<string, FileInterface>
export const MemoryModify: Record<string, Record<string, unknown>> = {}
export class Memory extends Class {
protected static files: Files = new Map<string, FileInterface>()

7
src/compilers/Random.ts Normal file
View file

@ -0,0 +1,7 @@
import { RandomString } from "../components/Utils.js"
const namespaces = Array.from({ length: 15 }, () => RandomString(16))
export function RandomNamespace() {
return namespaces[Math.floor(Math.random() * namespaces.length)]
}

View file

@ -55,3 +55,9 @@ FuntionMap.set("sqrt", number => {
value: rtn,
}
})
FuntionMap.set("translatable", key => {
return {
value: `'%' + ${key}`,
}
})

View file

@ -1,8 +1,38 @@
import { isBuildMode } from "../Configuration.js"
import { Memory } from "../Memory.js"
import { createBuildFolder } from "./linker.js"
import fs from "fs/promises"
async function buildUI() {
const build = Memory.build()
let i = 0
build.set("ui/ui_defs.json", {
ui_defs: Array.from(build.keys()),
})
await Promise.all(
build.entries().map(async ([file, value]) => {
const outFile = `build/build/${file}`
await fs
.stat(outFile.split(/\\|\//g).slice(0, -1).join("/"))
.catch(async () => await fs.mkdir(outFile.split(/\\|\//g).slice(0, -1).join("/"), { recursive: true }))
await fs.writeFile(outFile, JSON.stringify(value), "utf-8")
i++
}),
)
return i - 1
}
if (isBuildMode) {
process.on("beforeExit", () => {
console.log(JSON.stringify(Memory.build(), null, 2))
let first = true
process.on("beforeExit", async () => {
if (first) {
await createBuildFolder()
await buildUI()
}
first = false
})
}

View file

@ -0,0 +1,12 @@
import fs from "fs/promises"
export async function clearBuild() {
await fs.rm("build/build", { recursive: true, force: true })
}
export async function createBuildFolder() {
return fs
.stat("build")
.catch(() => fs.mkdir("build"))
.then(() => clearBuild())
}

View file

@ -5,6 +5,7 @@ import { KeyframeAnimationProperties } from "../types/properties/element/Animati
import { Animation } from "./Animation.js"
import { Class } from "./Class.js"
import { RandomString } from "./Utils.js"
import { RandomNamespace } from "../compilers/Random.js"
import util from "node:util"
@ -35,7 +36,7 @@ export class AnimationKeyframe<T extends AnimType> extends Class {
}
this.name = name || RandomString(16)
this.namespace = namespace || RandomString(16)
this.namespace = namespace || RandomNamespace()
this.path = path || `@/${this.namespace}`
Memory.add(this)

View file

@ -11,6 +11,7 @@ import { Animation } from "./Animation.js"
import { AnimationKeyframe } from "./AnimationKeyframe.js"
import { Class } from "./Class.js"
import { ExtendsOf, RandomString, ResolveBinding } from "./Utils.js"
import { RandomNamespace } from "../compilers/Random.js"
import util from "node:util"
@ -50,7 +51,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 || RandomString(16)
this.namespace = namespace || RandomNamespace()
if (!path) this.path = `@/${this.namespace}`
else this.path = path

View file

@ -37,8 +37,8 @@ import { AnimationKeyframe } from "./AnimationKeyframe.js"
import { AnimationProperties, KeyframeAnimationProperties } from "../types/properties/element/Animation.js"
import { Animation } from "./Animation.js"
import { SmartAnimation } from "../types/enums/SmartAnimation.js"
import { Memory, MemoryModify } from "../compilers/Memory.js"
const CHARS = "0123456789abcdefghijklmnopqrstuvwxyz"
type CompileBinding = `[${string}]`
export function Color(hex: string | number): Array3<number> {
@ -90,7 +90,7 @@ export function ResolveBinding(...bindings: BindingItem[]) {
}
export function RandomString(length: number, base: number = 32) {
const chars = CHARS.slice(0, base)
const chars = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, base)
const out = new Array<string>(length)
try {
@ -140,8 +140,21 @@ export function b(input: string): CompileBinding {
// Quick Elements
export function Modify<T extends Namespace, K extends Element<T>>(namespace: T, name: K) {
// @ts-ignore -- TS cannot prove this, but runtime guarantees it
return new ModifyUI<VanillaType<T, K>, VanillaElementChilds<T, K>>(namespace, name, paths[namespace][name])
// @ts-ignore
const memoryUI = MemoryModify[paths[namespace][name]]?.[name]
// @ts-ignore
if (memoryUI) return memoryUI as ModifyUI<VanillaType<T, K>, VanillaElementChilds<T, K>>
// @ts-ignore
const modifyUI = new ModifyUI<VanillaType<T, K>, VanillaElementChilds<T, K>>(
namespace,
name,
// @ts-ignore
paths[namespace][name],
)
// @ts-ignore
;(MemoryModify[paths[namespace][name]] ||= {})[name] = modifyUI
return modifyUI
}
export function Panel(properties?: Panel, namespace?: string, name?: string) {