@turbowarp/sb3fix 0.3.0 → 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 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
- // When sb3fix runs, it'll log what it's doing and what it's found. You can monitor those
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 considered part of the API. It may change without warning.
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 run watch
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.0",
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 an object was provided as `data`, the return value will be `data`.
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
  /**
@@ -218,6 +218,20 @@ const fixJSON = (data, options = {}) => {
218
218
  costume.name = String(costume.name);
219
219
  }
220
220
 
221
+ // https://github.com/scratchfoundation/scratch-parser/blob/665f05d739a202d565a4af70a201909393d456b2/lib/sb3_definitions.json#L51
222
+ const knownCostumeFormats = ['png', 'svg', 'jpeg', 'jpg', 'bmp', 'gif'];
223
+ if (!knownCostumeFormats.includes(costume.dataFormat)) {
224
+ if (typeof costume.md5ext === 'string' && costume.md5ext.endsWith('.svg')) {
225
+ log(`costume ${i} is vector, had invalid dataFormat ${costume.dataFormat}`);
226
+ costume.dataFormat = 'svg';
227
+ } else {
228
+ log(`costume ${i} is bitmap, had invalid dataFormat ${costume.dataFormat}`);
229
+ // dataFormat is only really used to detect vector or bitmap, so we don't
230
+ // need to set this to the real format
231
+ costume.dataFormat = 'png';
232
+ }
233
+ }
234
+
221
235
  if (!('assetId' in costume)) {
222
236
  log(`costume ${i} was missing assetId, deleted`);
223
237
  costumes.splice(i, 1);
@@ -247,6 +261,13 @@ const fixJSON = (data, options = {}) => {
247
261
  throw new Error(`sound ${i} is not an object`);
248
262
  }
249
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
+
250
271
  if (typeof sound.name !== 'string') {
251
272
  log(`sound ${i} name was not a string`);
252
273
  sound.name = String(sound.name);