@needle-tools/gltf-build-pipeline 1.6.0-alpha → 1.6.0-alpha.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.
@@ -7,10 +7,9 @@ import { MeshoptDecoder, MeshoptEncoder } from 'meshoptimizer';
7
7
  import { resample } from '@gltf-transform/functions';
8
8
  import { ALL_EXTENSIONS as NEEDLE_EXTENSIONS, NEEDLE_compression_texture, NEEDLE_mesh_compression, } from '../extensions/index.js';
9
9
  import { isMeshLOD, needle_animation_transform, needle_asset, needle_mesh_transform, needle_texture_transform, } from '../transforms/index.js';
10
- import { writeNodeIO, getVersion } from "../utils/index.js";
10
+ import { writeNodeIO } from "../utils/index.js";
11
11
  import { addToCache, getHash, tryGetFromCache, } from "../cache/index.js";
12
12
  import { getConfig } from '../config/index.js';
13
- console.log(`[Needle Build Pipeline] pack glTF — version ${getVersion()}`);
14
13
  /** Compress a glTF file
15
14
  */
16
15
  export async function packGLTF(inputFile, outputFile, options) {
@@ -1,18 +1,32 @@
1
- import { existsSync, readFileSync } from 'fs';
1
+ import { existsSync, readFileSync, statSync } from 'fs';
2
2
  let version = undefined;
3
3
  let isLocal = false;
4
4
  export function getVersion(marklocal = true) {
5
5
  if (version === undefined) {
6
- version = null;
7
- const path = process.cwd() + "/package.json";
8
- isLocal = !path.includes("node_modules");
9
- if (existsSync(path)) {
10
- const packageJson = readFileSync(path, "utf8");
11
- const packageVersion = JSON.parse(packageJson).version;
12
- version = packageVersion ?? null;
6
+ const scriptLocation = process.argv[1].replaceAll("\\", "/");
7
+ const path = scriptLocation.split('/');
8
+ let packageJsonPath = null;
9
+ while (path.length) {
10
+ const dirname = path.join('/');
11
+ if (statSync(dirname || '/').isDirectory()) {
12
+ const filename = dirname + '/package.json';
13
+ if (existsSync(filename)) {
14
+ packageJsonPath = filename;
15
+ break;
16
+ }
17
+ }
18
+ path.pop();
19
+ }
20
+ if (packageJsonPath) {
21
+ isLocal = !path.includes("node_modules");
22
+ if (existsSync(packageJsonPath)) {
23
+ const packageJson = readFileSync(packageJsonPath, "utf8");
24
+ const packageVersion = JSON.parse(packageJson).version;
25
+ version = packageVersion ?? null;
26
+ }
27
+ else
28
+ console.log("Could not find package.json at " + packageJsonPath);
13
29
  }
14
- else
15
- console.log("Could not find package.json at " + path);
16
30
  }
17
31
  let res = version;
18
32
  if (marklocal && isLocal)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "1.6.0-alpha",
3
+ "version": "1.6.0-alpha.1",
4
4
  "description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
5
5
  "main": "index.mjs",
6
6
  "type": "module",