1
- var async = require ( 'async ' ) ;
1
+ var pify = require ( 'pify ' ) ;
2
2
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' ) ) ;
6
6
7
7
/**
8
8
* Unpacks, parses, validates, and analyzes Scratch projects. If successful,
@@ -12,23 +12,15 @@ var validate = require('./lib/validate');
12
12
* @param {Function } callback Returns error or project data
13
13
*/
14
14
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 ) ;
34
26
} ;
0 commit comments