Skip to content

Commit

Permalink
Validation (#9)
Browse files Browse the repository at this point in the history
* feat: add validation phase during the save

see https://bugtracker.codiodev.com/issue/codio-15588
  • Loading branch information
destitutus authored Apr 15, 2024
1 parent 4c866ce commit b2130f1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/update-i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Update i18n

on:
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
schedule:
- cron: 0 0 * * * # daily at midnight UTC = 7-8pm US Eastern

concurrency:
group: '${{ github.workflow }}'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ npm-*

# Localization
/translations

scratch-vm.iml
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codioedu/scratch-vm",
"version": "2.1.12",
"version": "2.1.13",
"description": "Virtual Machine for Scratch 3.0",
"author": "Massachusetts Institute of Technology",
"license": "BSD-3-Clause",
Expand Down
26 changes: 19 additions & 7 deletions src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,26 @@ class VirtualMachine extends EventEmitter {
zip.file('project.json', projectJson);
this._addFileDescsToZip(soundDescs.concat(costumeDescs), zip);

return zip.generateAsync({
type: type,
mimeType: 'application/x.scratch.sb3',
compression: 'DEFLATE',
compressionOptions: {
level: 6 // Tradeoff between best speed (1) and best compression (9)
}
const validationPromise = new Promise((resolve, reject) => {
const validate = require('scratch-parser');
// The second argument of false below indicates to the validator that the
// input should be parsed/validated as an entire project (and not a single sprite)
validate(projectJson, false, (error, res) => {
if (error) return reject(error);
resolve(res);
});
});

return validationPromise.then(() =>
zip.generateAsync({
type: type,
mimeType: 'application/x.scratch.sb3',
compression: 'DEFLATE',
compressionOptions: {
level: 6 // Tradeoff between best speed (1) and best compression (9)
}
})
);
}

saveProjectSb3ToCodio () {
Expand Down

0 comments on commit b2130f1

Please sign in to comment.