scratch-analysis/lib/index.js

32 lines
963 B
JavaScript
Raw Permalink Normal View History

2018-12-17 18:11:08 -05:00
const parser = require('scratch-parser');
const {SB1Analyzer} = require('./sb1');
2018-12-17 18:11:08 -05:00
const sb2 = require('./sb2');
const sb3 = require('./sb3');
module.exports = function (buffer, callback) {
2018-12-18 12:26:14 -05:00
parser(buffer, false, (err, result) => {
2025-01-29 14:32:27 +01:00
if (err === 'Parser only supports Scratch 2.X and above') {
return new SB1Analyzer().analyze(buffer, callback);
2025-01-29 14:32:27 +01:00
} else if (err) {
return callback(err);
}
2018-12-17 18:11:08 -05:00
// Extract the project object from the parser results
2018-12-18 12:26:14 -05:00
const project = result[0];
// Check if the input buffer was a zip file
const zip = result[1];
2025-01-22 09:46:05 +01:00
project.isBundle = typeof zip !== 'undefined' && zip !== null;
2018-12-17 18:11:08 -05:00
// Push project object to the appropriate analysis handler
switch (project.projectVersion) {
case 2:
sb2(project, callback);
break;
case 3:
sb3(project, callback);
break;
}
});
};