From 37f992321eeb2d593f86371a1fe39c26a0e8467c Mon Sep 17 00:00:00 2001 From: Benjamin MICHEL Date: Wed, 9 Oct 2019 11:50:31 +0200 Subject: [PATCH] Fixed the npm library output path --- npm/fbx2gltf/index.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/npm/fbx2gltf/index.js b/npm/fbx2gltf/index.js index 70f2682..9810856 100644 --- a/npm/fbx2gltf/index.js +++ b/npm/fbx2gltf/index.js @@ -18,7 +18,7 @@ const binaries = { /** * Converts an FBX to a GTLF or GLB file. * @param string srcFile path to the source file. - * @param string destFile path to the destination file. + * @param string destFile path to the destination file or destination path. * This must end in `.glb` or `.gltf` (case matters). * @param string[] [opts] options to pass to the converter tool. * @return Promise a promise that yields the full path to the converted @@ -33,19 +33,31 @@ function convert(srcFile, destFile, opts = []) { throw new Error(`Unsupported OS: ${os.type()}`); } - let destExt; - if (destFile.endsWith('.glb')) { - destExt = '.glb'; - opts.includes('--binary') || opts.push('--binary'); - } else if (destFile.endsWith('.gltf')) { - destExt = '.gltf'; - } else { + let destExt = path.extname(destFile).toLowerCase(); + + if (!destExt) { + destExt = '.gltf' + + const srcFilename = path.basename(srcFile, path.extname(srcFile)) + destFile = path.join(destFile, srcFilename + destExt) + } + + if (destExt !== '.glb' && destExt !== '.gltf') { throw new Error(`Unsupported file extension: ${destFile}`); } + const binary = opts.includes('--binary') || opts.includes('-b'); + + if (binary && destExt !== '.glb') { + destExt = '.glb'; + } else if (!binary && destExt === 'glb') { + opts.push('--binary'); + } + let srcPath = fs.realpathSync(srcFile); let destDir = fs.realpathSync(path.dirname(destFile)); - let destPath = path.join(destDir, path.basename(destFile, destExt)); + let destFilename = path.basename(destFile, path.extname(destFile)) + destExt; + let destPath = path.join(destDir, destFilename); let args = opts.slice(0); args.push('--input', srcPath, '--output', destPath); @@ -72,7 +84,7 @@ function convert(srcFile, destFile, opts = []) { reject(new Error(`Converter output:\n` + (output.length ? output : ""))); } else { - resolve(destPath + destExt); + resolve(destPath); } });