diff --git a/.npmignore b/.npmignore index 24a9309..703f145 100644 --- a/.npmignore +++ b/.npmignore @@ -7,4 +7,5 @@ test .tsbuildinfo tsconfig.json asajs.config.js -build \ No newline at end of file +build +*.js.map \ No newline at end of file diff --git a/config.d.ts b/config.d.ts index 28c11e1..d83aa08 100644 --- a/config.d.ts +++ b/config.d.ts @@ -15,6 +15,7 @@ export interface Config { fixInventoryItemRenderer?: boolean buildFolder?: string fileExtension?: string + uiBuildFolder?: string } ui_analyzer?: { diff --git a/src/analyzer/rebaseUIFiles.ts b/src/analyzer/rebaseUIFiles.ts index c7b0029..cd2c137 100644 --- a/src/analyzer/rebaseUIFiles.ts +++ b/src/analyzer/rebaseUIFiles.ts @@ -12,37 +12,20 @@ export function rebaseUIFiles(pack_folder: string) { if (!fs.existsSync(targetDir)) return - const processDirectory = (currentDir: string) => { - const entries = fs.readdirSync(currentDir, { withFileTypes: true }) + for (const relativePath of ui) { + const fullPath = path.join(targetDir, relativePath) - for (const entry of entries) { - const fullPath = path.join(currentDir, entry.name) + if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile()) { + try { + const fileContent = fs.readFileSync(fullPath, "utf-8") + const parsedData = parse(fileContent) - if (entry.isDirectory()) { - processDirectory(fullPath) - - if (fs.readdirSync(fullPath).length === 0) { - fs.rmdirSync(fullPath) - } - } else if (entry.isFile()) { - const relativePath = fullPath.replace(targetDir + path.sep, "") - const normalizedPath = relativePath.split(path.sep).join("/") - - if (ui.has(normalizedPath)) { - try { - const fileContent = fs.readFileSync(fullPath, "utf-8") - const parsedData = parse(fileContent) - - if (parsedData !== undefined) { - fs.writeFileSync(fullPath, JSON.stringify(parsedData, null, 4), "utf-8") - } - } catch (error) { - console.error(`Parser error: ${fullPath}`, error) - } + if (parsedData !== undefined) { + fs.writeFileSync(fullPath, JSON.stringify(parsedData, null, 4), "utf-8") } + } catch (error) { + console.error(`Parser error: ${fullPath}`, error) } } } - - processDirectory(targetDir) } diff --git a/src/compilers/Configuration.ts b/src/compilers/Configuration.ts index 4c4c066..2dd1118 100644 --- a/src/compilers/Configuration.ts +++ b/src/compilers/Configuration.ts @@ -63,6 +63,7 @@ export const isBuildMode = options["build"] ?? config.compiler?.enabled ?? false export const isLinkMode = options["link"] ?? config.compiler?.autoImport ?? false export const unLinked = options["unlink"] ?? !(config.compiler?.autoImport ?? true) export const buildFolder = config.compiler?.buildFolder || "build" +export const uiBuildFolder = config.compiler?.uiBuildFolder || "asajs" export const bindingFuntions = config.binding_functions diff --git a/src/components/UI.ts b/src/components/UI.ts index 25ddcfe..f9e4a05 100644 --- a/src/components/UI.ts +++ b/src/components/UI.ts @@ -14,7 +14,7 @@ import { RandomString, ResolveBinding } from "./Utils.js" import { RandomNamespace } from "../compilers/Random.js" import util from "node:util" -import { config } from "../compilers/Configuration.js" +import { config, uiBuildFolder } from "../compilers/Configuration.js" interface ExtendUI { name: string @@ -57,7 +57,7 @@ export class UI extends Class this.namespace = namespace || RandomNamespace() if (!path) - this.path = `asajs/${this.namespace}${config.compiler?.fileExtension ? (config.compiler.fileExtension.startsWith(".") ? config.compiler.fileExtension : `.${config.compiler.fileExtension}`) : ".json"}` + this.path = `${uiBuildFolder}/${this.namespace}${config.compiler?.fileExtension ? (config.compiler.fileExtension.startsWith(".") ? config.compiler.fileExtension : `.${config.compiler.fileExtension}`) : ".json"}` else this.path = path this.extendable = this.name.search("/") === -1 diff --git a/tsconfig.json b/tsconfig.json index faa887d..fb94435 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "outDir": "dist/js", "declarationDir": "dist/types", "declaration": true, - "sourceMap": false, + "sourceMap": true, "strict": true, "esModuleInterop": true, "incremental": true,