asajs 4.0.9 → 4.0.11-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.
package/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BindingItem, Variable } from "./src/types/properties/value.ts"
1
+ import { Variable } from "./src/types/properties/value.ts"
2
2
 
3
3
  export interface RetBindingValue {
4
4
  generate_bindings?: Array<{ source_property_name: string; target_property_name: string }>
@@ -13,6 +13,7 @@ export interface Config {
13
13
  autoEnable?: boolean
14
14
  gdkUserId?: string
15
15
  fixInventoryItemRenderer?: boolean
16
+ buildFolder?: string
16
17
  }
17
18
  packinfo?: {
18
19
  name?: string
@@ -49,6 +49,7 @@ export const config = createRequire(import.meta.url)(path.resolve(process.cwd(),
49
49
  export const isBuildMode = options["build"] ?? config.compiler?.enabled ?? false;
50
50
  export const isLinkMode = options["link"] ?? config.compiler?.autoImport ?? false;
51
51
  export const unLinked = options["unlink"] ?? !(config.compiler?.autoImport ?? true);
52
+ export const buildFolder = config.compiler?.buildFolder || "build";
52
53
  export const bindingFuntions = config.binding_functions;
53
54
  if (!fs.existsSync(".gitignore")) {
54
55
  fs.writeFileSync(".gitignore", `node_modules`, "utf-8");
@@ -11,6 +11,8 @@ function TypeHighlight(type) {
11
11
  switch (type) {
12
12
  case "INFO":
13
13
  return `\x1b[32mINFO\x1b[0m`;
14
+ case "WARN":
15
+ return `\x1b[33mWARN\x1b[0m`;
14
16
  default:
15
17
  return type;
16
18
  }
@@ -1,4 +1,5 @@
1
1
  import fs from "fs/promises";
2
+ import { buildFolder } from "../Configuration.js";
2
3
  export class BuildCache {
3
4
  static queue = Promise.resolve();
4
5
  static async enqueue(task) {
@@ -11,7 +12,9 @@ export class BuildCache {
11
12
  static async get(key) {
12
13
  return this.enqueue(async () => {
13
14
  try {
14
- return await fs.readFile("build/cache.json", "utf-8").then(data => JSON.parse(data)[key] ?? null);
15
+ return await fs
16
+ .readFile(`${buildFolder}/cache.json`, "utf-8")
17
+ .then(data => JSON.parse(data)[key] ?? null);
15
18
  }
16
19
  catch (error) {
17
20
  return null;
@@ -27,26 +30,26 @@ export class BuildCache {
27
30
  return this.enqueue(async () => {
28
31
  let data = {};
29
32
  try {
30
- data = JSON.parse(await fs.readFile("build/cache.json", "utf-8"));
33
+ data = JSON.parse(await fs.readFile(`${buildFolder}/cache.json`, "utf-8"));
31
34
  }
32
35
  catch { }
33
36
  if (key in data)
34
37
  return data[key];
35
38
  data[key] = outVal;
36
- await fs.writeFile("build/cache.json", JSON.stringify(data), "utf-8");
39
+ await fs.writeFile(`${buildFolder}/cache.json`, JSON.stringify(data), "utf-8");
37
40
  return outVal;
38
41
  });
39
42
  }
40
43
  static async set(key, value) {
41
44
  return this.enqueue(async () => {
42
45
  try {
43
- return fs.writeFile("build/cache.json", JSON.stringify({
44
- ...(await fs.readFile("build/cache.json", "utf-8").then(data => JSON.parse(data))),
46
+ return fs.writeFile(`${buildFolder}/cache.json`, JSON.stringify({
47
+ ...(await fs.readFile(`${buildFolder}/cache.json`, "utf-8").then(data => JSON.parse(data))),
45
48
  [key]: value,
46
49
  }), "utf-8");
47
50
  }
48
51
  catch (error) {
49
- return fs.writeFile("build/cache.json", JSON.stringify({ [key]: value }), "utf-8");
52
+ return fs.writeFile(`${buildFolder}/cache.json`, JSON.stringify({ [key]: value }), "utf-8");
50
53
  }
51
54
  });
52
55
  }
@@ -1,4 +1,4 @@
1
- import { config, isBuildMode, isLinkMode, isTestMode, unLinked } from "../Configuration.js";
1
+ import { buildFolder, config, isBuildMode, isLinkMode, isTestMode, unLinked } from "../Configuration.js";
2
2
  import { Memory } from "../Memory.js";
3
3
  import { createBuildFolder, gamePath, getBuildFolderName, linkToGame, unlink } from "./linker.js";
4
4
  import { genManifest, version } from "./manifest.js";
@@ -7,6 +7,7 @@ import { BuildCache } from "./buildcache.js";
7
7
  import { disableRSP, enableRSP } from "./installer.js";
8
8
  import { Log } from "../PreCompile.js";
9
9
  import path from "path";
10
+ import { API_events } from "../../components/API.js";
10
11
  async function buildUI() {
11
12
  const build = Memory.build();
12
13
  build.set("ui/_ui_defs.json", {
@@ -15,7 +16,7 @@ async function buildUI() {
15
16
  if (config.global_variables)
16
17
  build.set("ui/_global_variables.json", config.global_variables);
17
18
  const out = await Promise.all(Array.from(build.entries()).map(async ([file, value]) => {
18
- const outFile = `build/${file}`;
19
+ const outFile = `${buildFolder}/${file}`;
19
20
  await fs
20
21
  .stat(outFile.split(/\\|\//g).slice(0, -1).join("/"))
21
22
  .catch(async () => await fs.mkdir(outFile.split(/\\|\//g).slice(0, -1).join("/"), { recursive: true }));
@@ -30,17 +31,18 @@ async function buildUI() {
30
31
  }));
31
32
  await Promise.all([
32
33
  fs
33
- .writeFile("build/manifest.json", await genManifest(), "utf-8")
34
- .then(() => Log("INFO", "build/manifest.json created!")),
34
+ .writeFile(`${buildFolder}/manifest.json`, await genManifest(), "utf-8")
35
+ .then(() => Log("INFO", `${buildFolder}/manifest.json created!`)),
35
36
  fs
36
- .writeFile("build/.gitignore", [...out, "manifest.json"].join("\n"), "utf-8")
37
- .then(() => Log("INFO", "build/.gitignore created!")),
37
+ .writeFile(`${buildFolder}/.gitignore`, [...out, "manifest.json"].join("\n"), "utf-8")
38
+ .then(() => Log("INFO", `${buildFolder}/.gitignore created!`)),
38
39
  BuildCache.set("build-files", [...out, "manifest.json"]).then(() => Log("INFO", "build-files set!")),
39
40
  BuildCache.set("version", version).then(() => Log("INFO", "version set!")),
40
41
  fs
41
- .stat("build/pack_icon.png")
42
- .catch(() => fs.copyFile(isTestMode ? "resources/pack_icon.png" : "node_modules/asajs/resources/pack_icon.png", "build/pack_icon.png"))
43
- .then(() => Log("INFO", "build/pack_icon.png copied!")),
42
+ .stat(`${buildFolder}/pack_icon.png`)
43
+ .catch(() => fs.copyFile(isTestMode ? "resources/pack_icon.png" : "node_modules/asajs/resources/pack_icon.png", `${buildFolder}/pack_icon.png`))
44
+ .then(() => Log("INFO", `${buildFolder}/pack_icon.png copied!`))
45
+ .catch(() => Log("WARN", `cannot copy ${buildFolder}/pack_icon.png!`)),
44
46
  ]).catch(error => console.error(error));
45
47
  return out.length;
46
48
  }
@@ -66,6 +68,8 @@ if (isBuildMode) {
66
68
  if (gamePath)
67
69
  console.log("Install Path:", `\x1b[32m"${path.join(gamePath, "development_resource_packs", await getBuildFolderName())}"\x1b[0m`);
68
70
  console.log("=============================================================");
71
+ // API events
72
+ API_events.onBuildFinish.forEach(v => v(config));
69
73
  }
70
74
  });
71
75
  }
@@ -0,0 +1,8 @@
1
+ export const API_events = {
2
+ onBuildFinish: [],
3
+ };
4
+ export const API = {
5
+ onBuildFinish: function (callback) {
6
+ API_events.onBuildFinish.push(callback);
7
+ },
8
+ };
package/dist/js/index.js CHANGED
@@ -11,3 +11,4 @@ export * as Properties from "./types/properties/index.js";
11
11
  export { ItemAuxID } from "./types/enums/Items.js";
12
12
  export { ArrayName, Operation } from "./types/properties/index.js";
13
13
  export * from "./compilers/bindings/Binary.js";
14
+ export { API } from "./components/API.js";
@@ -4,4 +4,5 @@ export declare const config: Config;
4
4
  export declare const isBuildMode: {};
5
5
  export declare const isLinkMode: {};
6
6
  export declare const unLinked: {};
7
+ export declare const buildFolder: string;
7
8
  export declare const bindingFuntions: Record<string, (...args: string[]) => RetBindingValue> | undefined;
@@ -6,6 +6,6 @@ declare global {
6
6
  lastItem(): T;
7
7
  }
8
8
  }
9
- type LogType = "INFO";
9
+ type LogType = "INFO" | "WARN";
10
10
  export declare function Log(type: LogType, message: string): void;
11
11
  export {};
@@ -0,0 +1,7 @@
1
+ import { Config } from "../../config.js";
2
+ export declare const API_events: {
3
+ onBuildFinish: ((config: Config) => void)[];
4
+ };
5
+ export declare const API: {
6
+ onBuildFinish: (callback: (config: Config) => void) => void;
7
+ };
@@ -11,3 +11,4 @@ export * as Properties from "./types/properties/index.js";
11
11
  export { ItemAuxID } from "./types/enums/Items.js";
12
12
  export { ArrayName, Operation } from "./types/properties/index.js";
13
13
  export * from "./compilers/bindings/Binary.js";
14
+ export { API } from "./components/API.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asajs",
3
- "version": "4.0.9",
3
+ "version": "4.0.11-indev",
4
4
  "description": "Create your Minecraft JSON-UI resource packs using JavaScript",
5
5
  "keywords": [
6
6
  "Minecraft",
@@ -14,7 +14,7 @@
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/asakiyuki/asajs.git"
16
16
  },
17
- "license": "MIT",
17
+ "license": "GPL-3.0-only",
18
18
  "author": "Asaki Yuki",
19
19
  "type": "module",
20
20
  "main": "dist/js/index.js",