-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async to promises. writeGltf, writeBinaryGltf, writeFile -- callbacks to Promises #135
Merged
Merged
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ce234e8
Switched to promises, but using anti-patterns. Needs fixing
51da324
Merge master
0b51b63
Fix preemptive resolve issue
bd2f5b6
Fix most promise issues. One issue left. Not ready for review
9e62453
Missed a couple minor fixes
375180f
Merge branch 'master' of github.com:AnalyticalGraphicsInc/gltf-pipeli…
lasalvavida 378c45e
Fix promises and other cleanup
lasalvavida 296849e
fix jsHint errors
lasalvavida 15b6a86
Fix jsHint (?)
4f97452
Resolve Travis Failure
eb3d12e
Delete commented line and whitespace
34f11a0
Only promisify individual functions
6aaa0f2
Cleanup
9050252
More cleanup
86c468b
Address comments
5a155ae
expect promises to resolve
f1c468f
Merge branch 'master' into async-to-promises
ab36432
Correct AO spec
0a2af08
Address final comments
0c4a792
Merge conflicts
2965a43
Merge branch 'master' of github.com:AnalyticalGraphicsInc/gltf-pipeli…
lasalvavida befafbb
Missing excluded _OCCLUSION from bad merge
lasalvavida File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
'use strict'; | ||
var fsExtra = require('fs-extra'); | ||
var path = require('path'); | ||
var async = require('async'); | ||
var Promise = require('bluebird'); | ||
var fsExtra = Promise.promisifyAll(require('fs-extra')); | ||
|
||
var writeSource = require('./writeSource'); | ||
// var outputJson = Promise.promisify(fsExtra.outputJson); | ||
|
||
var removePipelineExtras = require('./removePipelineExtras'); | ||
var Cesium = require('cesium'); | ||
var defined = Cesium.defined; | ||
var DeveloperError = Cesium.DeveloperError; | ||
|
||
module.exports = writeGltf; | ||
|
||
function writeGltf(gltf, outputPath, embed, embedImage, createDirectory, callback) { | ||
function writeGltf(gltf, options) { | ||
var outputPath = options.outputPath; | ||
var embed = options.embed; | ||
var embedImage = options.embedImage; | ||
var createDirectory = options.createDirectory; | ||
|
||
if (!defined(outputPath)) { | ||
throw new DeveloperError('Output path is undefined.'); | ||
} | ||
|
@@ -19,31 +27,23 @@ function writeGltf(gltf, outputPath, embed, embedImage, createDirectory, callbac | |
if (outputExtension !== '.gltf') { | ||
throw new DeveloperError('Invalid output path extension.'); | ||
} | ||
|
||
// Create the output directory if specified | ||
if (createDirectory) { | ||
outputPath = path.join(path.dirname(outputPath), 'output', path.basename(outputPath)); | ||
} | ||
var basePath = path.dirname(outputPath); | ||
|
||
async.each(['buffers', 'images', 'shaders'], function(name, asyncCallback) { | ||
writeSource(gltf, basePath, name, embed, embedImage, asyncCallback); | ||
}, function(err) { | ||
if (err) { | ||
if (callback) { | ||
callback(err); | ||
} else { | ||
throw err; | ||
} | ||
} else { | ||
var writeSources = [ | ||
writeSource(gltf, basePath, 'buffers', embed, embedImage), | ||
writeSource(gltf, basePath, 'images', embed, embedImage), | ||
writeSource(gltf, basePath, 'shaders', embed, embedImage) | ||
]; | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra line. |
||
return Promise.all(writeSources) | ||
.then(function() { | ||
removePipelineExtras(gltf); | ||
fsExtra.outputJson(outputPath, gltf, function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
if (callback) { | ||
callback(); | ||
} | ||
}); | ||
} | ||
}); | ||
return fsExtra.outputJson(outputPath, gltf); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this fsReadFile for consistency with the node guide.