@turbowarp/sb3fix 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/package.json +2 -1
- package/src/sb3fix.js +10 -3
package/README.md
CHANGED
|
@@ -40,9 +40,9 @@ const run = async () => {
|
|
|
40
40
|
|
|
41
41
|
// Both sb3fix methods take in an optional options object.
|
|
42
42
|
const options = {
|
|
43
|
-
//
|
|
43
|
+
// While sb3fix runs, it'll log what it's doing and what it fixed. You can monitor those
|
|
44
44
|
// using this callback. These messages are primarily a debugging tool, so the exact output
|
|
45
|
-
// is not
|
|
45
|
+
// is not stable and may change without warning.
|
|
46
46
|
logCallback: (message) => {
|
|
47
47
|
console.log(message);
|
|
48
48
|
}
|
|
@@ -68,10 +68,10 @@ npm ci
|
|
|
68
68
|
Source code is in the src folder. During development do:
|
|
69
69
|
|
|
70
70
|
```bash
|
|
71
|
-
npm
|
|
71
|
+
npm start
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
Then open dist/index.html in your favorite browser.
|
|
74
|
+
Then open dist/index.html in your favorite browser (there isn't a localhost development server).
|
|
75
75
|
|
|
76
76
|
For the final build:
|
|
77
77
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turbowarp/sb3fix",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Fix corrupted Scratch projects",
|
|
5
5
|
"main": "src/sb3fix.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "webpack -c webpack.config.js",
|
|
8
8
|
"watch": "webpack --watch -c webpack.config.js",
|
|
9
|
+
"start": "webpack --watch -c webpack.config.js",
|
|
9
10
|
"update": "node tests/snapshots --update",
|
|
10
11
|
"test": "node tests/snapshots --validate"
|
|
11
12
|
},
|
package/src/sb3fix.js
CHANGED
|
@@ -67,7 +67,7 @@ const getKnownExtensions = (project) => {
|
|
|
67
67
|
/**
|
|
68
68
|
* @param {string|object} data project.json as a string or as a parsed object already. If object provided, it will be modified in-place.
|
|
69
69
|
* @param {Options} [options]
|
|
70
|
-
* @returns {object} Fixed project.json object. If
|
|
70
|
+
* @returns {object} Fixed project.json object. If the `data` argument was an object, this will point to the same object.
|
|
71
71
|
*/
|
|
72
72
|
const fixJSON = (data, options = {}) => {
|
|
73
73
|
/**
|
|
@@ -219,8 +219,8 @@ const fixJSON = (data, options = {}) => {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
// https://github.com/scratchfoundation/scratch-parser/blob/665f05d739a202d565a4af70a201909393d456b2/lib/sb3_definitions.json#L51
|
|
222
|
-
const
|
|
223
|
-
if (!
|
|
222
|
+
const knownCostumeFormats = ['png', 'svg', 'jpeg', 'jpg', 'bmp', 'gif'];
|
|
223
|
+
if (!knownCostumeFormats.includes(costume.dataFormat)) {
|
|
224
224
|
if (typeof costume.md5ext === 'string' && costume.md5ext.endsWith('.svg')) {
|
|
225
225
|
log(`costume ${i} is vector, had invalid dataFormat ${costume.dataFormat}`);
|
|
226
226
|
costume.dataFormat = 'svg';
|
|
@@ -261,6 +261,13 @@ const fixJSON = (data, options = {}) => {
|
|
|
261
261
|
throw new Error(`sound ${i} is not an object`);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
+
// https://github.com/scratchfoundation/scratch-parser/blob/665f05d739a202d565a4af70a201909393d456b2/lib/sb3_definitions.json#L81
|
|
265
|
+
const knownSoundFormats = ['wav', 'wave', 'mp3'];
|
|
266
|
+
if (!knownSoundFormats.includes(sound.dataFormat)) {
|
|
267
|
+
log(`sound ${i} had invalid dataFormat ${sound.dataFormat}`);
|
|
268
|
+
sound.dataFormat = 'mp3';
|
|
269
|
+
}
|
|
270
|
+
|
|
264
271
|
if (typeof sound.name !== 'string') {
|
|
265
272
|
log(`sound ${i} name was not a string`);
|
|
266
273
|
sound.name = String(sound.name);
|