mirror of
https://github.com/scratchfoundation/scratch-parser.git
synced 2025-08-28 22:18:45 -04:00
refactor($index): Selectively call analyze on 2.0 projects only.
This commit is contained in:
parent
b7c1cfd347
commit
9e45007e7e
1 changed files with 18 additions and 4 deletions
22
index.js
22
index.js
|
@ -15,19 +15,33 @@ var analyze = require('./lib/analyze');
|
|||
* @return {Object}
|
||||
*/
|
||||
module.exports = function (input, callback) {
|
||||
// A wrapper around the analyze function, so that
|
||||
// it only gets called on 2.0 projects
|
||||
var analyzeWrapper = function (validatedProject, cb) {
|
||||
if (validatedProject.projectVersion !== 2) {
|
||||
return cb(null, validatedProject);
|
||||
}
|
||||
analyze(validatedProject, cb);
|
||||
};
|
||||
|
||||
// First unpack the input (need this outside of the async waterfall so that
|
||||
// unoackedProject can be refered to again)
|
||||
unpack(input, function(err, unpackedProject) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (cb) {
|
||||
parse(unpackedProject[0], cb);
|
||||
},
|
||||
validate,
|
||||
analyze
|
||||
], function(err2, validatedInput) {
|
||||
if (err2) {
|
||||
return callback(err2);
|
||||
analyzeWrapper
|
||||
], 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]]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue