Skip to content

Commit 37f9923

Browse files
SBRKzellski
authored andcommitted
Fixed the npm library output path
1 parent be627fa commit 37f9923

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

npm/fbx2gltf/index.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const binaries = {
1818
/**
1919
* Converts an FBX to a GTLF or GLB file.
2020
* @param string srcFile path to the source file.
21-
* @param string destFile path to the destination file.
21+
* @param string destFile path to the destination file or destination path.
2222
* This must end in `.glb` or `.gltf` (case matters).
2323
* @param string[] [opts] options to pass to the converter tool.
2424
* @return Promise<string> a promise that yields the full path to the converted
@@ -33,19 +33,31 @@ function convert(srcFile, destFile, opts = []) {
3333
throw new Error(`Unsupported OS: ${os.type()}`);
3434
}
3535

36-
let destExt;
37-
if (destFile.endsWith('.glb')) {
38-
destExt = '.glb';
39-
opts.includes('--binary') || opts.push('--binary');
40-
} else if (destFile.endsWith('.gltf')) {
41-
destExt = '.gltf';
42-
} else {
36+
let destExt = path.extname(destFile).toLowerCase();
37+
38+
if (!destExt) {
39+
destExt = '.gltf'
40+
41+
const srcFilename = path.basename(srcFile, path.extname(srcFile))
42+
destFile = path.join(destFile, srcFilename + destExt)
43+
}
44+
45+
if (destExt !== '.glb' && destExt !== '.gltf') {
4346
throw new Error(`Unsupported file extension: ${destFile}`);
4447
}
4548

49+
const binary = opts.includes('--binary') || opts.includes('-b');
50+
51+
if (binary && destExt !== '.glb') {
52+
destExt = '.glb';
53+
} else if (!binary && destExt === 'glb') {
54+
opts.push('--binary');
55+
}
56+
4657
let srcPath = fs.realpathSync(srcFile);
4758
let destDir = fs.realpathSync(path.dirname(destFile));
48-
let destPath = path.join(destDir, path.basename(destFile, destExt));
59+
let destFilename = path.basename(destFile, path.extname(destFile)) + destExt;
60+
let destPath = path.join(destDir, destFilename);
4961

5062
let args = opts.slice(0);
5163
args.push('--input', srcPath, '--output', destPath);
@@ -72,7 +84,7 @@ function convert(srcFile, destFile, opts = []) {
7284
reject(new Error(`Converter output:\n` +
7385
(output.length ? output : "<none>")));
7486
} else {
75-
resolve(destPath + destExt);
87+
resolve(destPath);
7688
}
7789
});
7890

0 commit comments

Comments
 (0)