@needle-tools/gltf-build-pipeline 3.0.0-alpha.1 → 3.0.0-alpha.2

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.
Files changed (2) hide show
  1. package/dist/cli/index.js +25 -9
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -1190,7 +1190,7 @@ function registerExtensions(node) {
1190
1190
  import { createTransform } from "@gltf-transform/functions";
1191
1191
 
1192
1192
  // src/utils/version.gen.ts
1193
- var version = "3.0.0-alpha.1";
1193
+ var version = "3.0.0-alpha.2";
1194
1194
 
1195
1195
  // src/utils/version.ts
1196
1196
  function getVersion(_marklocal = !0) {
@@ -3805,7 +3805,7 @@ function resolveConfig(filename, content, logger) {
3805
3805
  }
3806
3806
 
3807
3807
  // src/cli/index.ts
3808
- import { existsSync as existsSync13, readFileSync as readFileSync10, readdirSync as readdirSync3, statSync as statSync7, writeFileSync as writeFileSync7 } from "fs";
3808
+ import { existsSync as existsSync14, readFileSync as readFileSync11, readdirSync as readdirSync3, statSync as statSync7, writeFileSync as writeFileSync7 } from "fs";
3809
3809
  import path7, { basename as basename4, dirname as dirname8, resolve as resolve3 } from "path";
3810
3810
 
3811
3811
  // src/constants.ts
@@ -3922,17 +3922,33 @@ var PROD_KEYS = [
3922
3922
  var trusted = [...PROD_KEYS], TRUSTED_KEYS = trusted;
3923
3923
 
3924
3924
  // src/auth/verify.ts
3925
+ import { readFileSync as readFileSync10, existsSync as existsSync13 } from "fs";
3926
+ import { join as join8 } from "path";
3927
+ import { homedir } from "os";
3925
3928
  var AuthError = class extends Error {
3926
3929
  constructor(message) {
3927
3930
  super(message), this.name = "AuthError";
3928
3931
  }
3929
3932
  }, LOCAL_FETCH_TIMEOUT_MS = 2e3;
3933
+ function getLocalServerToken() {
3934
+ try {
3935
+ let file = join8(homedir(), ".needle", "local-server-token");
3936
+ if (!existsSync13(file)) return null;
3937
+ let data = JSON.parse(readFileSync10(file, "utf-8"));
3938
+ return typeof data.token == "string" ? data.token : null;
3939
+ } catch {
3940
+ return null;
3941
+ }
3942
+ }
3930
3943
  async function tryFetchLocalToken(org) {
3931
3944
  try {
3932
3945
  let baseUrl = process.env.NEEDLE_LICENSE_SERVER_URL || "http://localhost:8424/api/license", url = new URL(baseUrl);
3933
3946
  org && url.searchParams.set("org", org);
3947
+ let headers = {}, serverToken = getLocalServerToken();
3948
+ serverToken && (headers.Authorization = `Bearer ${serverToken}`);
3934
3949
  let res = await fetch(url, {
3935
- signal: AbortSignal.timeout(LOCAL_FETCH_TIMEOUT_MS)
3950
+ signal: AbortSignal.timeout(LOCAL_FETCH_TIMEOUT_MS),
3951
+ headers
3936
3952
  });
3937
3953
  if (!res.ok) return null;
3938
3954
  let jwt = (await res.json()).needle_license_jwt;
@@ -3983,7 +3999,7 @@ async function requireAuth(cliToken, org) {
3983
3999
  let token = typeof cliToken == "string" && cliToken.length > 0 ? cliToken : process.env.NEEDLE_CLOUD_TOKEN;
3984
4000
  if ((!token || typeof token == "string" && token.length === 0) && (token = await tryFetchLocalToken(org ?? process.env.NEEDLE_CLOUD_ORG)), !token)
3985
4001
  throw new AuthError(
3986
- "No valid auth token found. Provide one via --auth-token, NEEDLE_CLOUD_TOKEN env, or log in to the needle-cloud CLI (npx needle-cloud@version-1 start --restart). If you are logged in but still see this error, try updating: npx needle-cloud@version-1 start --restart"
4002
+ "No valid auth token found. Provide one via --auth-token, NEEDLE_CLOUD_TOKEN env, or log in to the needle-cloud CLI (npx needle-cloud@version-2 start --restart). If you are logged in but still see this error, try updating: npx needle-cloud@version-2 start --restart"
3987
4003
  );
3988
4004
  await verifyAuthToken(token);
3989
4005
  }
@@ -4047,7 +4063,7 @@ When caching is enabled then previously processed files will be detected and loa
4047
4063
  }
4048
4064
  let set = /* @__PURE__ */ new Set(), useCache = options.cache !== !1, debug = options.debug === !0, verbose = options.verbose === !0;
4049
4065
  await foreachGLTF(inputPaths, async (file) => {
4050
- if (existsSync13(file)) {
4066
+ if (existsSync14(file)) {
4051
4067
  if (file != input && options.progressive === !0 && isLOD(file)) {
4052
4068
  logger.debug(`\u2192 Ignore existing LOD file at ${file}`);
4053
4069
  return;
@@ -4063,7 +4079,7 @@ When caching is enabled then previously processed files will be detected and loa
4063
4079
  config
4064
4080
  }, file) : void 0;
4065
4081
  if (jobKey) {
4066
- let outputDir = output ? existsSync13(output) && isDirectory(output) ? output : dirname8(output) : dirname8(file), restored = tryRestoreJobResult(jobKey, outputDir, logger);
4082
+ let outputDir = output ? existsSync14(output) && isDirectory(output) ? output : dirname8(output) : dirname8(file), restored = tryRestoreJobResult(jobKey, outputDir, logger);
4067
4083
  if (restored) {
4068
4084
  let inputFileSize = statSync7(file).size / 1024 / 1024;
4069
4085
  for (let f of restored)
@@ -4139,7 +4155,7 @@ raw .exr / .hdr inputs.
4139
4155
  `).argument("<input>", "Path to a .exr/.hdr file OR a directory containing .exr/.hdr files (recursive)", { validator: program.STRING }).argument("<output>", "Output file (when input is a single .exr/.hdr) or output directory. Defaults to writing next to the input file.", { default: null, validator: program.STRING }).option("--cache", 'Use "--cache False" to disable caching.', { validator: program.BOOLEAN, default: !0 }).option("--debug", 'Enable verbose output with "--debug True"', { validator: program.BOOLEAN, default: !1 }).option("--verbose", 'Enable verbose output with "--verbose True"', { validator: program.BOOLEAN, default: !1 }).option("--auth-token <jwt>", "Required. A JWT minted by needle-cloud (alternatively set NEEDLE_CLOUD_TOKEN). Note: an `nc_*` needle-cloud access token is NOT a JWT and will be rejected.", { validator: program.STRING }).option("--org <org>", "Organization ID for local license-server fallback (or set NEEDLE_CLOUD_ORG).", { validator: program.STRING }).hide().action(async ({ logger, args, options }) => {
4140
4156
  await gateAuth(options.authToken, options.org, logger), logger.level = options.debug || options.verbose ? "debug" : "info", await ensureHashReady();
4141
4157
  let input = args.input.toString();
4142
- existsSync13(input) || (logger.error(`Input does not exist: ${input}`), process.exit(ERROR_CODES.INVALID_ARGS));
4158
+ existsSync14(input) || (logger.error(`Input does not exist: ${input}`), process.exit(ERROR_CODES.INVALID_ARGS));
4143
4159
  let inputFiles = [], inputIsDirectory = isDirectory(input);
4144
4160
  if (inputIsDirectory ? collectPmremInputFiles(input, inputFiles) : isPmremInputFile(input) ? inputFiles.push(input) : (logger.error(`Input is not an .exr/.hdr file or directory: ${input}`), process.exit(ERROR_CODES.INVALID_ARGS)), inputFiles.length === 0) {
4145
4161
  logger.warn(`No .exr/.hdr files found in ${input}`);
@@ -4158,7 +4174,7 @@ raw .exr / .hdr inputs.
4158
4174
  for (let inPath of inputFiles) {
4159
4175
  let outPath = resolvePmremOutputPath(inPath, input, inputIsDirectory, outputArg);
4160
4176
  logger.info(`\u2192 pmrem ${inPath} \u2192 ${outPath}`);
4161
- let srcBytes = readFileSync10(inPath), bytes = new Uint8Array(srcBytes.buffer, srcBytes.byteOffset, srcBytes.byteLength), ktx2Bytes = await (inPath.toLowerCase().endsWith(".hdr") ? convertHdrBytesToPmremKtx2 : convertExrBytesToPmremKtx2)(
4177
+ let srcBytes = readFileSync11(inPath), bytes = new Uint8Array(srcBytes.buffer, srcBytes.byteOffset, srcBytes.byteLength), ktx2Bytes = await (inPath.toLowerCase().endsWith(".hdr") ? convertHdrBytesToPmremKtx2 : convertExrBytesToPmremKtx2)(
4162
4178
  runtime,
4163
4179
  bytes,
4164
4180
  { useCache, logLabel: `pmrem ${basename4(inPath)}` }
@@ -4189,7 +4205,7 @@ function resolvePmremOutputPath(srcPath, input, inputIsDirectory, outputArg) {
4189
4205
  let rel = path7.relative(input, srcPath), relDir = dirname8(rel), outDir = relDir === "." ? outputArg : path7.join(outputArg, relDir);
4190
4206
  return ensureIsDirectory(outDir), path7.join(outDir, outName);
4191
4207
  }
4192
- return existsSync13(outputArg) && isDirectory(outputArg) ? path7.join(outputArg, outName) : outputArg.toLowerCase().endsWith(".ktx2") ? (ensureIsDirectory(dirname8(outputArg)), outputArg) : (ensureIsDirectory(outputArg), path7.join(outputArg, outName));
4208
+ return existsSync14(outputArg) && isDirectory(outputArg) ? path7.join(outputArg, outName) : outputArg.toLowerCase().endsWith(".ktx2") ? (ensureIsDirectory(dirname8(outputArg)), outputArg) : (ensureIsDirectory(outputArg), path7.join(outputArg, outName));
4193
4209
  }
4194
4210
  program.run().catch((err) => {
4195
4211
  if (!(err.message.includes("Unknown command") && !err.message.includes("Did you mean")))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-alpha.2",
4
4
  "description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
5
5
  "type": "module",
6
6
  "exports": {