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}
|
* @return {Object}
|
||||||
*/
|
*/
|
||||||
module.exports = function (input, callback) {
|
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) {
|
unpack(input, function(err, unpackedProject) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (cb) {
|
function (cb) {
|
||||||
parse(unpackedProject[0], cb);
|
parse(unpackedProject[0], cb);
|
||||||
},
|
},
|
||||||
validate,
|
validate,
|
||||||
analyze
|
analyzeWrapper
|
||||||
], function(err2, validatedInput) {
|
], function(error, validatedInput) {
|
||||||
if (err2) {
|
// One more callback wrapper so that we can re-package everything
|
||||||
return callback(err2);
|
// with the possible zip returned from unpack
|
||||||
|
if (error) {
|
||||||
|
return callback(error);
|
||||||
}
|
}
|
||||||
callback(null, [validatedInput, unpackedProject[1]]);
|
callback(null, [validatedInput, unpackedProject[1]]);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue