@needle-tools/gltf-build-pipeline 3.0.0-next.73f1606 → 3.0.0-next.7e6c33d

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 +42 -16
  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-next.73f1606";
1193
+ var version = "3.0.0-next.7e6c33d";
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,12 +3999,21 @@ 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
  }
3990
4006
 
3991
4007
  // src/cli/index.ts
4008
+ function warnUnknownOptions(options, logger) {
4009
+ if (!process.env.NEEDLE_WORKER) return;
4010
+ let knownKeys = new Set(Object.keys(options));
4011
+ for (let arg of process.argv) {
4012
+ if (!arg.startsWith("--")) continue;
4013
+ let raw = arg.split("=")[0].replace(/^--/, ""), key = raw.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
4014
+ knownKeys.has(key) || logger.warn(`[Needle Build Pipeline] v${getVersion()} Unknown option --${raw}, ignoring.`);
4015
+ }
4016
+ }
3992
4017
  async function gateAuth(authToken, org, logger) {
3993
4018
  try {
3994
4019
  await requireAuth(authToken, typeof org == "string" ? org : void 0);
@@ -3998,6 +4023,7 @@ async function gateAuth(authToken, org, logger) {
3998
4023
  }
3999
4024
  }
4000
4025
  program.cast(!1);
4026
+ process.env.NEEDLE_WORKER && program.strict(!1);
4001
4027
  program.command("version", "Print current version").action(async ({ logger }) => {
4002
4028
  logger.info(getVersion());
4003
4029
  }).command("clear-caches", "Clear all caches").help(`Clears all cached files
@@ -4005,8 +4031,8 @@ Caches are limited to ${cacheSizeLimit} MB disc space by default.
4005
4031
  `).action(async ({ logger }) => {
4006
4032
  logger.info("Clearing caches"), clearCache(logger);
4007
4033
  }).command("stats", "Calculate glTF stats").help(`
4008
- `).argument("<input>", "Path to a glTF, GLB or VRM file OR a directory").argument("<output>", "Output path for the stats", { default: null, validator: program.STRING }).option("--verbose", "Enable verbose output", { 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 }).action(async ({ logger, args, options }) => {
4009
- await gateAuth(options.authToken, options.org, logger), logger.level = options.verbose ? "debug" : "info", await ensureHashReady(), logger.info('Calculating stats for "' + args.input + '"');
4034
+ `).argument("<input>", "Path to a glTF, GLB or VRM file OR a directory").argument("<output>", "Output path for the stats", { default: "", validator: program.STRING }).option("--verbose", "Enable verbose output", { 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 }).action(async ({ logger, args, options }) => {
4035
+ warnUnknownOptions(options, logger), await gateAuth(options.authToken, options.org, logger), logger.level = options.verbose ? "debug" : "info", await ensureHashReady(), logger.info('Calculating stats for "' + args.input + '"');
4010
4036
  let input = args.input.toString(), filestats = new Array();
4011
4037
  await foreachGLTF(input, async (file) => {
4012
4038
  let stats = await calculateStats(file, { verbose: !!options.verbose });
@@ -4017,9 +4043,9 @@ Caches are limited to ${cacheSizeLimit} MB disc space by default.
4017
4043
  }).command("transform", "Transform (progressive loading) and compress glTF, GLB or VRM files").help(`
4018
4044
  This will produce multiple versions of the input file, each with a different level of optimization.
4019
4045
  Each version will be compressed and written to the output directory.
4020
- `).argument("<input>", "The input glTF, GLB or VRM file that should be compressed OR a directory that contains files to be compressed. Multiple files can be separated by commas.", { validator: program.STRING }).argument("<output>", "The output file or directory. It can be an absolute path or a relative path to the input file. If not provided, the input file will be overwritten.", { default: null, validator: program.STRING }).option("--compress", "When enabled files will be compressed", { validator: program.BOOLEAN, default: !0 }).option("--progressive", "When enabled files will processed to be progressively loaded", { validator: program.BOOLEAN, default: !0 }).option("--usecase <usecase>", `The usecase for the compression. This will set the compression settings. Possible options: [${UsecaseOptions.join(", ")}]`, { validator: program.STRING }).option("--config <config>", 'The path to a JSON file containing the compression settings. This can also be a needle.config.json file with a "compression" object or usecase string.', { validator: program.STRING }).option("--cache", `Use "--cache False" to disable caching.
4046
+ `).argument("<input>", "The input glTF, GLB or VRM file that should be compressed OR a directory that contains files to be compressed. Multiple files can be separated by commas.", { validator: program.STRING }).argument("<output>", "The output file or directory. It can be an absolute path or a relative path to the input file. If not provided, the input file will be overwritten.", { default: "", validator: program.STRING }).option("--compress", "When enabled files will be compressed", { validator: program.BOOLEAN, default: !0 }).option("--progressive", "When enabled files will processed to be progressively loaded", { validator: program.BOOLEAN, default: !0 }).option("--usecase <usecase>", `The usecase for the compression. This will set the compression settings. Possible options: [${UsecaseOptions.join(", ")}]`, { validator: program.STRING }).option("--config <config>", 'The path to a JSON file containing the compression settings. This can also be a needle.config.json file with a "compression" object or usecase string.', { validator: program.STRING }).option("--cache", `Use "--cache False" to disable caching.
4021
4047
  When caching is enabled then previously processed files will be detected and loaded from disc cache instead of being processed again if settings or the file contents have not changed.`, { validator: program.BOOLEAN, default: !0 }).option("--debug", 'Enable for more verbose outout with "--debug True"', { validator: program.BOOLEAN, default: !1 }).option("--verbose", 'Enable for more verbose outout 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 }).action(async ({ logger, args, options }) => {
4022
- if (await gateAuth(options.authToken, options.org, logger), logger.level = options.debug || options.verbose ? "debug" : "info", options.compress === !1 && options.progressive === !1) {
4048
+ if (warnUnknownOptions(options, logger), await gateAuth(options.authToken, options.org, logger), logger.level = options.debug || options.verbose ? "debug" : "info", options.compress === !1 && options.progressive === !1) {
4023
4049
  logger.error(`[Needle Build Pipeline] v${getVersion()} You need to enable at least one of the options: --compress or --progressive`);
4024
4050
  return;
4025
4051
  }
@@ -4047,7 +4073,7 @@ When caching is enabled then previously processed files will be detected and loa
4047
4073
  }
4048
4074
  let set = /* @__PURE__ */ new Set(), useCache = options.cache !== !1, debug = options.debug === !0, verbose = options.verbose === !0;
4049
4075
  await foreachGLTF(inputPaths, async (file) => {
4050
- if (existsSync13(file)) {
4076
+ if (existsSync14(file)) {
4051
4077
  if (file != input && options.progressive === !0 && isLOD(file)) {
4052
4078
  logger.debug(`\u2192 Ignore existing LOD file at ${file}`);
4053
4079
  return;
@@ -4063,7 +4089,7 @@ When caching is enabled then previously processed files will be detected and loa
4063
4089
  config
4064
4090
  }, file) : void 0;
4065
4091
  if (jobKey) {
4066
- let outputDir = output ? existsSync13(output) && isDirectory(output) ? output : dirname8(output) : dirname8(file), restored = tryRestoreJobResult(jobKey, outputDir, logger);
4092
+ let outputDir = output ? existsSync14(output) && isDirectory(output) ? output : dirname8(output) : dirname8(file), restored = tryRestoreJobResult(jobKey, outputDir, logger);
4067
4093
  if (restored) {
4068
4094
  let inputFileSize = statSync7(file).size / 1024 / 1024;
4069
4095
  for (let f of restored)
@@ -4136,16 +4162,16 @@ When caching is enabled then previously processed files will be detected and loa
4136
4162
  producing <name>.pmrem.ktx2. This is the same processing the Needle build pipeline
4137
4163
  applies to EXR textures inside GLB/GLTF files, exposed as a standalone command for
4138
4164
  raw .exr / .hdr inputs.
4139
- `).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
- await gateAuth(options.authToken, options.org, logger), logger.level = options.debug || options.verbose ? "debug" : "info", await ensureHashReady();
4165
+ `).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: "", 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 }) => {
4166
+ warnUnknownOptions(options, logger), await gateAuth(options.authToken, options.org, logger), logger.level = options.debug || options.verbose ? "debug" : "info", await ensureHashReady();
4141
4167
  let input = args.input.toString();
4142
- existsSync13(input) || (logger.error(`Input does not exist: ${input}`), process.exit(ERROR_CODES.INVALID_ARGS));
4168
+ existsSync14(input) || (logger.error(`Input does not exist: ${input}`), process.exit(ERROR_CODES.INVALID_ARGS));
4143
4169
  let inputFiles = [], inputIsDirectory = isDirectory(input);
4144
4170
  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
4171
  logger.warn(`No .exr/.hdr files found in ${input}`);
4146
4172
  return;
4147
4173
  }
4148
- let rawOutput = args.output?.toString() || null, outputArg = rawOutput && rawOutput !== "null" ? rawOutput : null;
4174
+ let outputArg = args.output?.toString() || null;
4149
4175
  if (outputArg && !path7.isAbsolute(outputArg)) {
4150
4176
  let base = inputIsDirectory ? input : dirname8(input);
4151
4177
  outputArg = resolve3(base, outputArg);
@@ -4158,7 +4184,7 @@ raw .exr / .hdr inputs.
4158
4184
  for (let inPath of inputFiles) {
4159
4185
  let outPath = resolvePmremOutputPath(inPath, input, inputIsDirectory, outputArg);
4160
4186
  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)(
4187
+ let srcBytes = readFileSync11(inPath), bytes = new Uint8Array(srcBytes.buffer, srcBytes.byteOffset, srcBytes.byteLength), ktx2Bytes = await (inPath.toLowerCase().endsWith(".hdr") ? convertHdrBytesToPmremKtx2 : convertExrBytesToPmremKtx2)(
4162
4188
  runtime,
4163
4189
  bytes,
4164
4190
  { useCache, logLabel: `pmrem ${basename4(inPath)}` }
@@ -4189,7 +4215,7 @@ function resolvePmremOutputPath(srcPath, input, inputIsDirectory, outputArg) {
4189
4215
  let rel = path7.relative(input, srcPath), relDir = dirname8(rel), outDir = relDir === "." ? outputArg : path7.join(outputArg, relDir);
4190
4216
  return ensureIsDirectory(outDir), path7.join(outDir, outName);
4191
4217
  }
4192
- return existsSync13(outputArg) && isDirectory(outputArg) ? path7.join(outputArg, outName) : outputArg.toLowerCase().endsWith(".ktx2") ? (ensureIsDirectory(dirname8(outputArg)), outputArg) : (ensureIsDirectory(outputArg), path7.join(outputArg, outName));
4218
+ return existsSync14(outputArg) && isDirectory(outputArg) ? path7.join(outputArg, outName) : outputArg.toLowerCase().endsWith(".ktx2") ? (ensureIsDirectory(dirname8(outputArg)), outputArg) : (ensureIsDirectory(outputArg), path7.join(outputArg, outName));
4193
4219
  }
4194
4220
  program.run().catch((err) => {
4195
4221
  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-next.73f1606",
3
+ "version": "3.0.0-next.7e6c33d",
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": {