Skip to content

Commit

Permalink
Fixed the npm library output path
Browse files Browse the repository at this point in the history
  • Loading branch information
SBRK authored and zellski committed Oct 9, 2019
1 parent be627fa commit 37f9923
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions npm/fbx2gltf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> a promise that yields the full path to the converted
Expand All @@ -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);
Expand All @@ -72,7 +84,7 @@ function convert(srcFile, destFile, opts = []) {
reject(new Error(`Converter output:\n` +
(output.length ? output : "<none>")));
} else {
resolve(destPath + destExt);
resolve(destPath);
}
});

Expand Down

0 comments on commit 37f9923

Please sign in to comment.