asajs 4.0.13 → 4.0.15-indev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import path from "path";
2
+ import { uiFiles } from "./utils.js";
3
+ import fs from "fs";
4
+ export function generateUIDefs(pack_folder) {
5
+ uiFiles(pack_folder).forEach(file => {
6
+ try {
7
+ const fileContent = JSON.parse(fs.readFileSync(path.join("custom", pack_folder, file), "utf-8"));
8
+ delete fileContent[""];
9
+ }
10
+ catch (error) { }
11
+ });
12
+ }
@@ -0,0 +1,29 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { uiFiles } from "./utils.js";
4
+ export function rebaseUIFiles(pack_folder) {
5
+ const ui = uiFiles(pack_folder);
6
+ const targetDir = path.join("custom", pack_folder);
7
+ if (!fs.existsSync(targetDir))
8
+ return;
9
+ const processDirectory = (currentDir) => {
10
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
11
+ for (const entry of entries) {
12
+ const fullPath = path.join(currentDir, entry.name);
13
+ if (entry.isDirectory()) {
14
+ processDirectory(fullPath);
15
+ if (fs.readdirSync(fullPath).length === 0) {
16
+ fs.rmdirSync(fullPath);
17
+ }
18
+ }
19
+ else if (entry.isFile()) {
20
+ const relativePath = fullPath.replace(targetDir + path.sep, "");
21
+ const normalizedPath = relativePath.split(path.sep).join("/");
22
+ if (!ui.has(normalizedPath)) {
23
+ fs.rmSync(fullPath, { force: true });
24
+ }
25
+ }
26
+ }
27
+ };
28
+ processDirectory(targetDir);
29
+ }
@@ -0,0 +1,42 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { parse } from "jsonc-parser";
4
+ import { uiFiles } from "./utils.js";
5
+ export function rebaseUIFiles(pack_folder) {
6
+ const ui = uiFiles(pack_folder);
7
+ const targetDir = path.join("custom", pack_folder);
8
+ if (!fs.existsSync(targetDir))
9
+ return;
10
+ const processDirectory = (currentDir) => {
11
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
12
+ for (const entry of entries) {
13
+ const fullPath = path.join(currentDir, entry.name);
14
+ if (entry.isDirectory()) {
15
+ processDirectory(fullPath);
16
+ if (fs.readdirSync(fullPath).length === 0) {
17
+ fs.rmdirSync(fullPath);
18
+ }
19
+ }
20
+ else if (entry.isFile()) {
21
+ const relativePath = fullPath.replace(targetDir + path.sep, "");
22
+ const normalizedPath = relativePath.split(path.sep).join("/");
23
+ if (!ui.has(normalizedPath)) {
24
+ fs.rmSync(fullPath, { force: true });
25
+ }
26
+ else {
27
+ try {
28
+ const fileContent = fs.readFileSync(fullPath, "utf-8");
29
+ const parsedData = parse(fileContent);
30
+ if (parsedData !== undefined) {
31
+ fs.writeFileSync(fullPath, JSON.stringify(parsedData, null, 4), "utf-8");
32
+ }
33
+ }
34
+ catch (error) {
35
+ console.error(`Lỗi parse file: ${fullPath}`, error);
36
+ }
37
+ }
38
+ }
39
+ }
40
+ };
41
+ processDirectory(targetDir);
42
+ }
@@ -0,0 +1,29 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { uiFiles } from "./utils.js";
4
+ export function removeNotUIFiles(pack_folder) {
5
+ const ui = uiFiles(pack_folder);
6
+ const targetDir = path.join("custom", pack_folder);
7
+ if (!fs.existsSync(targetDir))
8
+ return;
9
+ const processDirectory = (currentDir) => {
10
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
11
+ for (const entry of entries) {
12
+ const fullPath = path.join(currentDir, entry.name);
13
+ if (entry.isDirectory()) {
14
+ processDirectory(fullPath);
15
+ if (fs.readdirSync(fullPath).length === 0) {
16
+ fs.rmdirSync(fullPath);
17
+ }
18
+ }
19
+ else if (entry.isFile()) {
20
+ const relativePath = fullPath.replace(targetDir + path.sep, "");
21
+ const normalizedPath = relativePath.split(path.sep).join("/");
22
+ if (!ui.has(normalizedPath)) {
23
+ fs.rmSync(fullPath, { force: true });
24
+ }
25
+ }
26
+ }
27
+ };
28
+ processDirectory(targetDir);
29
+ }
@@ -0,0 +1,18 @@
1
+ import { paths } from "../types/vanilla/paths.js";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import jsonc from "jsonc-parser";
5
+ export const vanilla_ui_defs = Object.values(paths);
6
+ const vanillaUIDefsMap = new Map();
7
+ export function readUIDefs(pack_folder) {
8
+ const { ui_defs } = jsonc.parse(fs.readFileSync(path.join("custom", pack_folder, "ui/_ui_defs.json"), "utf-8"));
9
+ return ui_defs;
10
+ }
11
+ export function uiFiles(pack_folder) {
12
+ if (vanillaUIDefsMap.has(pack_folder))
13
+ return vanillaUIDefsMap.get(pack_folder);
14
+ const ui_defs = readUIDefs(pack_folder);
15
+ const set = new Set(ui_defs.concat(...vanilla_ui_defs, "ui/_ui_defs.json", "ui/_global_variables.json"));
16
+ vanillaUIDefsMap.set(pack_folder, set);
17
+ return set;
18
+ }