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

@ -3,12 +3,14 @@ var GZip = require('gzip-js');
/**
* Unpacks a zip or gzip file.
* @param {boolean} isSprite Whether the input should be treated as
* a sprite (true) or whole project (false)
* @param {string} input Zip file provided as a string
* @param {boolean} isGZip Whether the input is a GZip file, otherwise treat as zip
* @param {array} callback Array including both the project and zip archive
* @return {void}
*/
module.exports = function (input, isGZip, callback) {
module.exports = function (isSprite, input, isGZip, callback) {
var msg = 'Failed to unzip and extract project.json, with error: ';
if (isGZip) {
var unpackedProject = null;
@ -21,7 +23,7 @@ module.exports = function (input, isGZip, callback) {
}
return JSZip.loadAsync(input)
.then(function (zip) {
return zip.file('project.json').async('string')
return zip.file(isSprite ? 'sprite.json' : 'project.json').async('string')
.then(function (project) {
return callback(null, [project, zip]);
});