Skip to content

Commit

Permalink
Merge pull request #52 from mzgoddard/waterfall-into-promise
Browse files Browse the repository at this point in the history
Replace the async.waterfall in index with a Promise chain
  • Loading branch information
mzgoddard authored Mar 6, 2019
2 parents fb5874f + b78d017 commit c5cc58e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
38 changes: 15 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var async = require('async');
var pify = require('pify');

var unpack = require('./lib/unpack');
var parse = require('./lib/parse');
var validate = require('./lib/validate');
var unpack = pify(require('./lib/unpack'));
var parse = pify(require('./lib/parse'));
var validate = pify(require('./lib/validate'));

/**
* Unpacks, parses, validates, and analyzes Scratch projects. If successful,
Expand All @@ -12,23 +12,15 @@ var validate = require('./lib/validate');
* @param {Function} callback Returns error or project data
*/
module.exports = function (input, isSprite, callback) {
// First unpack the input (need this outside of the async waterfall so that
// unpackedProject can be refered to again)
unpack(input, isSprite, function (err, unpackedProject) {
if (err) return callback(err);

async.waterfall([
function (cb) {
parse(unpackedProject[0], cb);
},
// TODO is there a better way to pass this arg
// than partially applying this funciton?
validate.bind(null, isSprite)
], function (error, validatedInput) {
// One more callback wrapper so that we can re-package everything
// with the possible zip returned from unpack
if (error) return callback(error);
callback(null, [validatedInput, unpackedProject[1]]);
});
});
// Unpack the input and further transform the json portion by parsing and
// validating it.
unpack(input, isSprite)
.then(function (unpackedProject) {
return parse(unpackedProject[0])
.then(validate.bind(null, isSprite))
.then(function (validatedProject) {
return [validatedProject, unpackedProject[1]];
});
})
.then(callback.bind(null, null), callback);
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
},
"dependencies": {
"ajv": "6.3.0",
"async": "2.6.0",
"gzip-js": "0.3.2",
"jszip": "3.1.5",
"gzip-js": "0.3.2"
"pify": "4.0.1"
},
"devDependencies": {
"@commitlint/cli": "7.2.1",
Expand Down

0 comments on commit c5cc58e

Please sign in to comment.