Skip to content

Commit c5cc58e

Browse files
authored
Merge pull request #52 from mzgoddard/waterfall-into-promise
Replace the async.waterfall in index with a Promise chain
2 parents fb5874f + b78d017 commit c5cc58e

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

index.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var async = require('async');
1+
var pify = require('pify');
22

3-
var unpack = require('./lib/unpack');
4-
var parse = require('./lib/parse');
5-
var validate = require('./lib/validate');
3+
var unpack = pify(require('./lib/unpack'));
4+
var parse = pify(require('./lib/parse'));
5+
var validate = pify(require('./lib/validate'));
66

77
/**
88
* Unpacks, parses, validates, and analyzes Scratch projects. If successful,
@@ -12,23 +12,15 @@ var validate = require('./lib/validate');
1212
* @param {Function} callback Returns error or project data
1313
*/
1414
module.exports = function (input, isSprite, callback) {
15-
// First unpack the input (need this outside of the async waterfall so that
16-
// unpackedProject can be refered to again)
17-
unpack(input, isSprite, function (err, unpackedProject) {
18-
if (err) return callback(err);
19-
20-
async.waterfall([
21-
function (cb) {
22-
parse(unpackedProject[0], cb);
23-
},
24-
// TODO is there a better way to pass this arg
25-
// than partially applying this funciton?
26-
validate.bind(null, isSprite)
27-
], function (error, validatedInput) {
28-
// One more callback wrapper so that we can re-package everything
29-
// with the possible zip returned from unpack
30-
if (error) return callback(error);
31-
callback(null, [validatedInput, unpackedProject[1]]);
32-
});
33-
});
15+
// Unpack the input and further transform the json portion by parsing and
16+
// validating it.
17+
unpack(input, isSprite)
18+
.then(function (unpackedProject) {
19+
return parse(unpackedProject[0])
20+
.then(validate.bind(null, isSprite))
21+
.then(function (validatedProject) {
22+
return [validatedProject, unpackedProject[1]];
23+
});
24+
})
25+
.then(callback.bind(null, null), callback);
3426
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
},
2222
"dependencies": {
2323
"ajv": "6.3.0",
24-
"async": "2.6.0",
24+
"gzip-js": "0.3.2",
2525
"jszip": "3.1.5",
26-
"gzip-js": "0.3.2"
26+
"pify": "4.0.1"
2727
},
2828
"devDependencies": {
2929
"@commitlint/cli": "7.2.1",

0 commit comments

Comments
 (0)