From d93fb655a6b9ba93518b75943936ae2d69aa8829 Mon Sep 17 00:00:00 2001 From: Adam Dominec Date: Fri, 3 Jun 2022 19:58:21 +0200 Subject: [PATCH] when used as a library, return a Promise --- bin/obj23dtiles.js | 6 +++++- lib/obj23dtiles.js | 26 +++++--------------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/bin/obj23dtiles.js b/bin/obj23dtiles.js index 8f6ddd8..5a9f89e 100644 --- a/bin/obj23dtiles.js +++ b/bin/obj23dtiles.js @@ -257,4 +257,8 @@ var options = { outputDirectory : outputDirectory }; -obj23dtiles(objPath, outputPath, options); +console.time('Total'); +obj23dtiles(objPath, outputPath, options) + .then(() => { + console.timeEnd('Total'); + }); diff --git a/lib/obj23dtiles.js b/lib/obj23dtiles.js index 92b5fbb..dca6da4 100644 --- a/lib/obj23dtiles.js +++ b/lib/obj23dtiles.js @@ -11,7 +11,6 @@ module.exports = obj23dtiles; obj23dtiles.combine = combine; function obj23dtiles(objPath, outputPath, options) { - console.time('Total'); if(typeof options.tilesetOptions === 'string') { options.tilesetOptions = fsExtra.readJsonSync(options.tilesetOptions); @@ -29,7 +28,7 @@ function obj23dtiles(objPath, outputPath, options) { options.batchId = true; options.b3dm = true; - obj2Tileset(objPath, outputPath, options) + return obj2Tileset(objPath, outputPath, options) .then(function(result) { var b3dm = result.b3dm; var batchTableJson = result.batchTableJson; @@ -49,9 +48,6 @@ function obj23dtiles(objPath, outputPath, options) { tasks.push(fsExtra.writeJson(tilesetPath, tileset, {spaces: 2})); return Promise.all(tasks); }) - .then(function() { - console.timeEnd('Total'); - }) .catch(function(error) { console.log(error.message || error); process.exit(1); @@ -64,7 +60,7 @@ function obj23dtiles(objPath, outputPath, options) { process.exit(1); } - obj2Tileset(objPath, outputPath, options) + return obj2Tileset(objPath, outputPath, options) .then(function(result) { var i3dm = result.i3dm; var batchTableJson = result.batchTableJson; @@ -84,9 +80,6 @@ function obj23dtiles(objPath, outputPath, options) { tasks.push(fsExtra.writeJson(tilesetPath, tileset, {spaces: 2})); return Promise.all(tasks); }) - .then(function() { - console.timeEnd('Total'); - }) .catch(function(error) { console.log(error.message || error); process.exit(1); @@ -96,7 +89,7 @@ function obj23dtiles(objPath, outputPath, options) { else if (options && options.b3dm) { options.binary = true; options.batchId = true; - obj2B3dm(objPath, options) + return obj2B3dm(objPath, options) .then(function(result){ var b3dm = result.b3dm; var batchTableJson = result.batchTableJson; @@ -109,9 +102,6 @@ function obj23dtiles(objPath, outputPath, options) { fsExtra.ensureDirSync(path.dirname(outputPath)); return fsExtra.outputFile(outputPath, b3dm); }) - .then(function() { - console.timeEnd('Total'); - }) .catch(function(error) { console.log(error.message || error); process.exit(1); @@ -124,7 +114,7 @@ function obj23dtiles(objPath, outputPath, options) { console.log('Convert to i3dm need a custom FeatureTable.'); process.exit(1); } - obj2I3dm(objPath, options) + return obj2I3dm(objPath, options) .then(function(result){ var i3dm = result.i3dm; var batchTableJson = result.batchTableJson; @@ -137,16 +127,13 @@ function obj23dtiles(objPath, outputPath, options) { fsExtra.ensureDirSync(path.dirname(outputPath)); return fsExtra.outputFile(outputPath, i3dm); }) - .then(function() { - console.timeEnd('Total'); - }) .catch(function(error) { console.log(error.message || error); process.exit(1); }); } else { - obj2gltf(objPath, options) + return obj2gltf(objPath, options) .then(function(result){ var gltf = result.gltf; if (options && options.binary) { @@ -158,9 +145,6 @@ function obj23dtiles(objPath, outputPath, options) { }; return fsExtra.outputJson(outputPath, gltf, jsonOptions); }) - .then(function() { - console.timeEnd('Total'); - }) .catch(function(error) { console.log(error.message || error); process.exit(1);