Skip to content

SB3 Schema/Validation #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,43 @@ var analyze = require('./lib/analyze');

/**
* Unpacks, parses, validates, and analyzes Scratch projects. If successful,
* will return a valid Scratch project object with appended metadata.
* will return a valid Scratch project object with appended metadata, as well
* as the unpacked zip object if originally provided.
*
* @param {Buffer | string} Input buffer or string representing scratch project
*
* @return {Object}
*/
module.exports = function (input, callback) {
async.waterfall([
function (cb) {
unpack(input, cb);
},
parse,
validate,
analyze
], 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
// unpackedProject can be refered to again)
unpack(input, function(err, unpackedProject) {
if (err) {
return callback(err);
}

async.waterfall([
function (cb) {
parse(unpackedProject[0], cb);
},
validate,
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]]);
});
});
};
File renamed without changes.
Loading