asajs configuration file
This commit is contained in:
parent
e75e45d056
commit
4ad9e832bd
10 changed files with 76 additions and 18 deletions
14
config.d.ts
vendored
Normal file
14
config.d.ts
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { Variable } from "./src/types/properties/value.ts"
|
||||||
|
|
||||||
|
export interface Config {
|
||||||
|
compiler?: {
|
||||||
|
enabled?: boolean
|
||||||
|
linked?: boolean
|
||||||
|
}
|
||||||
|
packinfo?: {
|
||||||
|
name?: string
|
||||||
|
description?: string
|
||||||
|
version?: [number, number, number]
|
||||||
|
}
|
||||||
|
global_variables?: Record<Variable, string>
|
||||||
|
}
|
||||||
9
resources/asajs.config.cjs
Normal file
9
resources/asajs.config.cjs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
/**
|
||||||
|
* Configuration object for the AsaJS build process.
|
||||||
|
* @type {import('asajs/config.d.ts').Config}
|
||||||
|
*/
|
||||||
|
export const config = {
|
||||||
|
compiler: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -1 +1,20 @@
|
||||||
export const isBuildMode = process.argv.includes("--build")
|
import fs from "fs"
|
||||||
|
import path from "path"
|
||||||
|
// @ts-ignore
|
||||||
|
import { Config } from "../../config.js"
|
||||||
|
|
||||||
|
if (!fs.existsSync("asajs.config.cjs")) {
|
||||||
|
fs.copyFileSync("node_modules/asajs/resources/asajs.config.cjs", "asajs.config.cjs")
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config: Config = require(path.resolve(process.cwd(), "asajs.config.cjs")).config
|
||||||
|
|
||||||
|
export let isBuildMode = config.compiler?.enabled ?? false
|
||||||
|
export let isLinkMode = config.compiler?.linked ?? false
|
||||||
|
export let unLinked = !(config.compiler?.linked ?? true)
|
||||||
|
|
||||||
|
for (const arg of process.argv) {
|
||||||
|
if (arg === "--build") isBuildMode = true
|
||||||
|
if (arg === "--link") isLinkMode = true
|
||||||
|
else if (arg === "--unlink") unLinked = true
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { isBuildMode } from "../Configuration.js"
|
import { config, isBuildMode, isLinkMode, unLinked } from "../Configuration.js"
|
||||||
import { Memory } from "../Memory.js"
|
import { Memory } from "../Memory.js"
|
||||||
import { createBuildFolder, linkToGame } from "./linker.js"
|
import { createBuildFolder, linkToGame, unlink } from "./linker.js"
|
||||||
import { genManifest } from "./manifest.js"
|
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"
|
||||||
|
|
@ -13,13 +13,15 @@ async function buildUI() {
|
||||||
ui_defs: Array.from(build.keys()),
|
ui_defs: Array.from(build.keys()),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (config.global_variables) build.set("ui/_global_variables.json", config.global_variables)
|
||||||
|
|
||||||
build.set("build.json", {
|
build.set("build.json", {
|
||||||
files: Array.from(build.keys()),
|
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/build/${file}`
|
const outFile = `build/${file}`
|
||||||
await fs
|
await fs
|
||||||
.stat(outFile.split(/\\|\//g).slice(0, -1).join("/"))
|
.stat(outFile.split(/\\|\//g).slice(0, -1).join("/"))
|
||||||
.catch(async () => await fs.mkdir(outFile.split(/\\|\//g).slice(0, -1).join("/"), { recursive: true }))
|
.catch(async () => await fs.mkdir(outFile.split(/\\|\//g).slice(0, -1).join("/"), { recursive: true }))
|
||||||
|
|
@ -42,11 +44,11 @@ async function buildUI() {
|
||||||
)
|
)
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
fs.writeFile("build/build/manifest.json", await genManifest(), "utf-8"),
|
fs.writeFile("build/manifest.json", await genManifest(), "utf-8"),
|
||||||
fs.writeFile("build/build/.gitignore", [...out, "manifest.json"].join("\n"), "utf-8"),
|
fs.writeFile("build/.gitignore", [...out, "manifest.json"].join("\n"), "utf-8"),
|
||||||
fs
|
fs
|
||||||
.stat("build/build/pack_icon.png")
|
.stat("build/pack_icon.png")
|
||||||
.catch(() => fs.copyFile("node_modules/asajs/resources/pack_icon.png", "build/build/pack_icon.png")),
|
.catch(() => fs.copyFile("node_modules/asajs/resources/pack_icon.png", "build/pack_icon.png")),
|
||||||
])
|
])
|
||||||
|
|
||||||
return out.length
|
return out.length
|
||||||
|
|
@ -58,8 +60,9 @@ if (isBuildMode) {
|
||||||
if (first) {
|
if (first) {
|
||||||
await createBuildFolder()
|
await createBuildFolder()
|
||||||
await buildUI()
|
await buildUI()
|
||||||
await linkToGame()
|
if (isLinkMode) await linkToGame()
|
||||||
}
|
}
|
||||||
first = false
|
first = false
|
||||||
})
|
})
|
||||||
}
|
} else if (isLinkMode) linkToGame()
|
||||||
|
else if (unLinked) unlink()
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ function genUUID(): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function clearBuild() {
|
export async function clearBuild() {
|
||||||
await Promise.all(prevData.files.map(file => fs.rm(`build/build/${file}`).catch(() => null)))
|
await Promise.all(prevData.files.map(file => fs.rm(`build/${file}`).catch(() => null)))
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createBuildFolder() {
|
export async function createBuildFolder() {
|
||||||
|
|
@ -40,13 +40,22 @@ export async function getBuildFolderName() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function linkToGame() {
|
export async function linkToGame() {
|
||||||
const sourcePath = path.resolve("build/build")
|
const sourcePath = path.resolve("build")
|
||||||
const targetPath = path.resolve(getGamedataPath(), "development_resource_packs", await getBuildFolderName())
|
const targetPath = path.resolve(getGamedataPath(), "development_resource_packs", await getBuildFolderName())
|
||||||
await fs.stat(targetPath).catch(async () => {
|
await fs.stat(targetPath).catch(async () => {
|
||||||
await fs.symlink(sourcePath, targetPath, "junction")
|
await fs.symlink(sourcePath, targetPath, "junction")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function unlink() {
|
||||||
|
const targetPath = path.resolve(getGamedataPath(), "development_resource_packs", await getBuildFolderName())
|
||||||
|
try {
|
||||||
|
await fs.unlink(targetPath)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getUUID(): Promise<[string, string]> {
|
export async function getUUID(): Promise<[string, string]> {
|
||||||
return await BuildCache.getWithSetDefault("uuid", () => {
|
return await BuildCache.getWithSetDefault("uuid", () => {
|
||||||
return [genUUID(), genUUID()]
|
return [genUUID(), genUUID()]
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { config } from "../Configuration.js"
|
||||||
import { getUUID } from "./linker.js"
|
import { getUUID } from "./linker.js"
|
||||||
|
|
||||||
export async function genManifest() {
|
export async function genManifest() {
|
||||||
|
|
@ -5,10 +6,10 @@ export async function genManifest() {
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
format_version: 2,
|
format_version: 2,
|
||||||
header: {
|
header: {
|
||||||
name: "AsaJS UI",
|
name: config.packinfo?.name || "AsaJS",
|
||||||
description: "A framework for creating UIs for AsaJS.",
|
description: config.packinfo?.description || "A framework for creating UIs for AsaJS.",
|
||||||
uuid: uuid1,
|
uuid: uuid1,
|
||||||
version: [4, 0, 0],
|
version: config.packinfo?.version || [4, 0, 0],
|
||||||
min_engine_version: [1, 21, 132],
|
min_engine_version: [1, 21, 132],
|
||||||
},
|
},
|
||||||
modules: [
|
modules: [
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ export let prevData: {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
prevData = JSON.parse(fs.readFileSync("build/build/build.json", "utf-8"))
|
prevData = JSON.parse(fs.readFileSync("build/build.json", "utf-8"))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
prevData = { files: [] }
|
prevData = { files: [] }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ export class AnimationKeyframe<T extends AnimType> extends Class {
|
||||||
|
|
||||||
this.name = name || RandomString(16)
|
this.name = name || RandomString(16)
|
||||||
this.namespace = namespace || RandomNamespace()
|
this.namespace = namespace || RandomNamespace()
|
||||||
this.path = path || `@/${this.namespace}.json`
|
this.path = path || `asajs/${this.namespace}.json`
|
||||||
|
|
||||||
Memory.add(this)
|
Memory.add(this)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import "./compilers/Configuration.js"
|
||||||
import "./compilers/PreCompile.js"
|
import "./compilers/PreCompile.js"
|
||||||
import "./compilers/ui/builder.js"
|
import "./compilers/ui/builder.js"
|
||||||
import "./compilers/ui/installer.js"
|
import "./compilers/ui/installer.js"
|
||||||
|
|
@ -11,3 +12,5 @@ export * from "./types/enums/index.js"
|
||||||
export * as Properties from "./types/properties/index.js"
|
export * as Properties from "./types/properties/index.js"
|
||||||
|
|
||||||
export { ItemAuxID } from "./types/enums/Items.js"
|
export { ItemAuxID } from "./types/enums/Items.js"
|
||||||
|
|
||||||
|
export { ArrayName, Operation } from "./types/properties/index.js"
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,6 @@
|
||||||
"incremental": true,
|
"incremental": true,
|
||||||
"tsBuildInfoFile": ".tsbuildinfo"
|
"tsBuildInfoFile": ".tsbuildinfo"
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*", "config.d.ts"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue