feat(schemas): add support for sprite files for 2.0 and 3.0

refactor schemas to support sprite2 and sprite3 files, while reusing rules in common with sb2 and
sb3 files

BREAKING CHANGE: Change to main API which now takes an additional boolean argument indicating
whether a sprite or project is being validated
This commit is contained in:
Karishma Chadha 2018-05-02 17:10:52 -04:00
parent 5daad968a4
commit b808e7447f
11 changed files with 759 additions and 616 deletions

View file

@ -7,20 +7,21 @@ var validate = require('./lib/validate');
/**
* Unpacks, parses, validates, and analyzes Scratch projects. If successful,
* will return a valid Scratch project object with appended metadata.
* @param {boolean} isSprite Whether this is a sprite (true) or whole project (false)
* @param {Buffer | string} input Buffer or string representing project
* @param {Function} callback Returns error or project data
*/
module.exports = function (input, callback) {
module.exports = function (isSprite, input, callback) {
// First unpack the input (need this outside of the async waterfall so that
// unpackedProject can be refered to again)
unpack(input, function (err, unpackedProject) {
unpack(isSprite, input, function (err, unpackedProject) {
if (err) return callback(err);
async.waterfall([
function (cb) {
parse(unpackedProject[0], cb);
},
validate
validate.bind(null, isSprite)
], function (error, validatedInput) {
// One more callback wrapper so that we can re-package everything
// with the possible zip returned from unpack