mirror of
https://github.com/scratchfoundation/scratch-analysis.git
synced 2025-05-04 09:53:27 -04:00
Address feedback from PR review
This commit is contained in:
parent
020d3ea167
commit
1181cd8313
3 changed files with 14 additions and 16 deletions
|
@ -4,11 +4,11 @@ const sb2 = require('./sb2');
|
|||
const sb3 = require('./sb3');
|
||||
|
||||
module.exports = function (buffer, callback) {
|
||||
parser(buffer, false, (err, project) => {
|
||||
parser(buffer, false, (err, result) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
// Flatten array
|
||||
project = project[0];
|
||||
// Extract only the project object from the parser results
|
||||
const project = result[0];
|
||||
|
||||
// Push project object to the appropriate analysis handler
|
||||
switch (project.projectVersion) {
|
||||
|
@ -18,8 +18,6 @@ module.exports = function (buffer, callback) {
|
|||
case 3:
|
||||
sb3(project, callback);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unsupported project version');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -139,12 +139,12 @@ const blocks = function (project) {
|
|||
*/
|
||||
const extensions = function (project) {
|
||||
const result = {count: 0, id: []};
|
||||
const ext = project.info.savedExtensions;
|
||||
|
||||
// Check to ensure project includes any extensions
|
||||
if (typeof project.info.savedExtensions === 'undefined') return result;
|
||||
if (typeof ext === 'undefined') return result;
|
||||
|
||||
// Iterate over extensions and build list
|
||||
var ext = project.info.savedExtensions;
|
||||
for (let i in ext) {
|
||||
result.id.push(ext[i].extensionName);
|
||||
}
|
||||
|
|
18
lib/sb3.js
18
lib/sb3.js
|
@ -2,35 +2,35 @@ const utility = require('./utility');
|
|||
|
||||
const scripts = function (targets) {
|
||||
// Storage objects
|
||||
let occurances = 0;
|
||||
let occurrences = 0;
|
||||
|
||||
// Iterate over all blocks in each target, and look for "top level" blocks
|
||||
for (let t in targets) {
|
||||
for (let b in targets[t].blocks) {
|
||||
if (targets[t].blocks[b].topLevel) occurances++;
|
||||
if (targets[t].blocks[b].topLevel) occurrences++;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
count: occurances
|
||||
count: occurrences
|
||||
};
|
||||
};
|
||||
|
||||
const variables = function (targets, attribute) {
|
||||
// Storage objects
|
||||
let occurances = 0;
|
||||
let occurrences = 0;
|
||||
let idList = [];
|
||||
|
||||
for (let t in targets) {
|
||||
for (let a in targets[t][attribute]) {
|
||||
const variable = targets[t][attribute][a];
|
||||
occurances++;
|
||||
occurrences++;
|
||||
idList.push(variable[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
count: occurances,
|
||||
count: occurrences,
|
||||
id: idList
|
||||
};
|
||||
};
|
||||
|
@ -38,20 +38,20 @@ const variables = function (targets, attribute) {
|
|||
// Iterate over targets, extract attribute, and aggregate results
|
||||
const extract = function (targets, attribute, id, hash) {
|
||||
// Storage objects
|
||||
let occurances = 0;
|
||||
let occurrences = 0;
|
||||
let idList = [];
|
||||
let hashList = [];
|
||||
|
||||
for (let t in targets) {
|
||||
for (let a in targets[t][attribute]) {
|
||||
const asset = targets[t][attribute][a];
|
||||
occurances++;
|
||||
occurrences++;
|
||||
if (typeof id !== 'undefined') idList.push(asset[id]);
|
||||
if (typeof hash !== 'undefined') hashList.push(asset[hash]);
|
||||
}
|
||||
}
|
||||
|
||||
const result = {count: occurances};
|
||||
const result = {count: occurrences};
|
||||
if (typeof id !== 'undefined') result.id = idList;
|
||||
if (typeof hash !== 'undefined') result.hash = hashList;
|
||||
return result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue