@evitcastudio/kit 1.2.0 → 1.3.1

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.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /*!
4
- * @evitcastudio/kit@1.2.0 git+https://github.com/EvitcaStudio/Kit.git
5
- * Compiled Wed, 01 Jan 2025 09:48:35 UTC
4
+ * @evitcastudio/kit@1.3.1 git+https://github.com/EvitcaStudio/Kit.git
5
+ * Compiled Sat, 04 Jan 2025 15:50:23 UTC
6
6
  * Copyright (c) 2025 Jared Bates, Evitca Studio, "doubleactii"
7
7
  *
8
8
  * @evitcastudio/kit is licensed under the MIT License.
@@ -2491,14 +2491,14 @@ function isValidExtension(pExtension) {
2491
2491
  }
2492
2492
  async function processAllFiles() {
2493
2493
  try {
2494
- await clearResourceTypeDirectories(`${resourceOutDirectory}/resources`, RESOURCE_TYPES);
2494
+ await clearResourceTypeDirectories(`${resourceOutDirectory}/resources`);
2495
2495
  const copyOperations = resourcesToProcess.map(({ filePath, type }) => {
2496
2496
  const fileName = basename(filePath);
2497
2497
  const resource = resourceJSON[type].find((res) => res.fileName === fileName);
2498
2498
  if (!resource) {
2499
2499
  throw new Error(`Resource not found for file: ${fileName}`);
2500
2500
  }
2501
- const destination = join(resourceOutDirectory, "resources", type);
2501
+ const destination = join(resourceOutDirectory, "resources");
2502
2502
  return copyFile(filePath, destination, resource.resourceIdentifier);
2503
2503
  });
2504
2504
  await Promise.all(copyOperations);
@@ -2508,17 +2508,14 @@ async function processAllFiles() {
2508
2508
  logError(`[Error] Processing files in batch: ${pError.message}`);
2509
2509
  }
2510
2510
  }
2511
- async function clearResourceTypeDirectories(pBaseDirectory, pDirectoriesToRemove) {
2511
+ async function clearResourceTypeDirectories(pBaseDirectory) {
2512
2512
  try {
2513
- for (const directory of pDirectoriesToRemove) {
2514
- const directoryPath = join(pBaseDirectory, directory);
2515
- const directoryExists = await fs.stat(directoryPath).then((stat) => stat.isDirectory()).catch(() => false);
2516
- if (directoryExists) {
2517
- await fs.rm(directoryPath, { recursive: true });
2518
- }
2513
+ const directoryExists = await fs.stat(pBaseDirectory).then((stat) => stat.isDirectory()).catch(() => false);
2514
+ if (directoryExists) {
2515
+ await fs.rm(pBaseDirectory, { recursive: true });
2519
2516
  }
2520
2517
  } catch (pError) {
2521
- log(`${error(`[Error]`)} clearing directories: ${pError}`);
2518
+ log(`${error(`[Error]`)} clearing resource directory: ${pError}`);
2522
2519
  }
2523
2520
  }
2524
2521
  async function copyFile(pSource, pDestinationDir, pNewName) {
@@ -2530,7 +2527,7 @@ async function copyFile(pSource, pDestinationDir, pNewName) {
2530
2527
  }
2531
2528
  }
2532
2529
  async function saveResourceJSON() {
2533
- const filePath = join(resourceOutDirectory, "resource.json");
2530
+ const filePath = join(resourceOutDirectory, "resources", "resource.json");
2534
2531
  try {
2535
2532
  await fs.writeFile(filePath, JSON.stringify(resourceJSON, null, 2));
2536
2533
  } catch (pError) {
@@ -2575,7 +2572,7 @@ class KitCLI {
2575
2572
  // package.json
2576
2573
  var package_default = {
2577
2574
  name: "@evitcastudio/kit",
2578
- version: "1.2.0",
2575
+ version: "1.3.1",
2579
2576
  author: "doubleactii 56242467+doubleactii@users.noreply.github.com (https://evitcastudio.com)",
2580
2577
  main: "./lib/index.js",
2581
2578
  types: "./lib/index.d.ts",
@@ -2606,7 +2603,7 @@ var package_default = {
2606
2603
  pack: "bun pm pack --dry-run",
2607
2604
  "build-types": "bun tsc",
2608
2605
  build: "bun bun-build.ts",
2609
- "build-docs": "bun typedoc ./src/index.ts ./src/types/shared-types.ts",
2606
+ "build-docs": "bun typedoc ./src/index.ts",
2610
2607
  "build-all": "bun run build-types && bun run build && bun run build-docs"
2611
2608
  },
2612
2609
  bin: {
package/lib/kit.d.ts CHANGED
@@ -54,7 +54,7 @@ export declare class Kit {
54
54
  static off(pPluginName: string, pEventName: string, pListener: (pData: EmitterEvent) => void): void;
55
55
  /**
56
56
  * Sets the resource locator for the engine to reference the files we have in the resources folder. interface | map | icon | macro | sound are checked for.
57
- * @param pData - An array of each file that was found in the resources folder
57
+ * @param pData - An array of each file that was found in the resources folder.
58
58
  */
59
59
  private static setResource;
60
60
  /**
package/lib/kit.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAgB,QAAQ,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAevG,qBAAa,GAAG;IACZ;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiC;IACvD;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmC;IAC1D;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,MAAM,CAAuC;IAE5D,OAAO;IAIP;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI;IAM3E;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,IAAI;IAkBlF;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAInE;;OAEG;IACH,MAAM,CAAC,UAAU,IAAI,MAAM,EAAE;IAI7B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,IAAI;IAWlB;;;;;MAKE;IACH,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,GAAG,IAAI;IAQ7E;;;;;OAKG;IACH,MAAM,CAAC,GAAG,CA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7E;;;;;OAKG;IACH,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI;IAOnG;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAiB1B;;OAEG;WACU,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CA4C7C"}
package/lib/kit.js CHANGED
@@ -105,7 +105,7 @@ export class Kit {
105
105
  }
106
106
  /**
107
107
  * Sets the resource locator for the engine to reference the files we have in the resources folder. interface | map | icon | macro | sound are checked for.
108
- * @param pData - An array of each file that was found in the resources folder
108
+ * @param pData - An array of each file that was found in the resources folder.
109
109
  */
110
110
  static setResource(pData) {
111
111
  pData.forEach((pResource) => {
@@ -116,7 +116,7 @@ export class Kit {
116
116
  const fileNameWithoutExtension = fileNameWithoutExtensionMatch[0];
117
117
  const resourceType = extensionToPath[extension];
118
118
  if (resourceType) {
119
- globalThis.VYLO.Resource.setResource(resourceType, fileNameWithoutExtension, `resources/${resourceType}/${pResource.resourceIdentifier}`, true);
119
+ globalThis.VYLO.Resource.setResource(resourceType, fileNameWithoutExtension, `${pResource.resourceIdentifier}`);
120
120
  }
121
121
  }
122
122
  });
@@ -128,24 +128,39 @@ export class Kit {
128
128
  if (!globalThis.VYLO) {
129
129
  throw new Error('[Kit] VYLO is not defined. Please ensure the VYLO variable is available in the global namespace.');
130
130
  }
131
- const resourcePath = './resource.json';
132
- // Load the resource json and set the resources found
133
- try {
134
- const response = await fetch(resourcePath);
135
- if (!response.ok) {
136
- throw new Error(`[Kit] HTTP error! Status: ${response.status}`);
131
+ let resourcePath = './resources/resource.json';
132
+ let resourceJson;
133
+ // Server environment (we do not use fetch as the file:// protocol is not supported atm)
134
+ if (!globalThis.window) {
135
+ const [fsPromises, path] = await Promise.all([
136
+ import('fs/promises'),
137
+ import('path')
138
+ ]);
139
+ const { readFile } = fsPromises;
140
+ resourcePath = path.resolve('resources', 'resource.json');
141
+ const data = await readFile(resourcePath, 'utf-8');
142
+ resourceJson = JSON.parse(data);
143
+ // Client environment
144
+ }
145
+ else {
146
+ // Load the resource json and set the resources found
147
+ try {
148
+ const response = await fetch(resourcePath);
149
+ if (!response.ok) {
150
+ throw new Error(`[Kit] HTTP error! Status: ${response.status}`);
151
+ }
152
+ resourceJson = await response.json();
137
153
  }
138
- const resourceJSON = await response.json();
139
- if (resourceJSON) {
140
- const resources = Object.values(resourceJSON);
141
- // Group all data from separate arrays in object to one unified array of all resource data
142
- const consolidatedData = resources.flat();
143
- // Set all the resources
144
- this.setResource(consolidatedData);
154
+ catch (pError) {
155
+ console.error(`[Kit] error reading ${resourcePath}`, pError);
145
156
  }
146
157
  }
147
- catch (pError) {
148
- console.error(`[Kit] error reading ${resourcePath}`, pError);
158
+ if (resourceJson) {
159
+ const resources = Object.values(resourceJson);
160
+ // Group all data from separate arrays in object to one unified array of all resource data
161
+ const consolidatedData = resources.flat();
162
+ // Set all the resources
163
+ this.setResource(consolidatedData);
149
164
  }
150
165
  }
151
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evitcastudio/kit",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "author": "doubleactii 56242467+doubleactii@users.noreply.github.com (https://evitcastudio.com)",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "pack": "bun pm pack --dry-run",
32
32
  "build-types": "bun tsc",
33
33
  "build": "bun bun-build.ts",
34
- "build-docs": "bun typedoc ./src/index.ts ./src/types/shared-types.ts",
34
+ "build-docs": "bun typedoc ./src/index.ts",
35
35
  "build-all": "bun run build-types && bun run build && bun run build-docs"
36
36
  },
37
37
  "bin": {