@turbowarp/sb3fix 0.3.7 → 0.4.0
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/LICENSE +373 -373
- package/README.md +106 -100
- package/package.json +31 -31
- package/src/sb3fix.js +681 -606
package/README.md
CHANGED
|
@@ -1,100 +1,106 @@
|
|
|
1
|
-
# sb3fix
|
|
2
|
-
|
|
3
|
-
https://turbowarp.github.io/sb3fix/
|
|
4
|
-
|
|
5
|
-
Fix corrupted Scratch 3 projects.
|
|
6
|
-
|
|
7
|
-
## API
|
|
8
|
-
|
|
9
|
-
Install with:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm install @turbowarp/sb3fix
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Then use from Node.js:
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
const sb3fix = require('@turbowarp/sb3fix');
|
|
19
|
-
const fs = require('fs');
|
|
20
|
-
|
|
21
|
-
const run = async () => {
|
|
22
|
-
// Fix a .sb3 or .sprite3 with sb3fix.fixZip()
|
|
23
|
-
// Input can be an ArrayBuffer, Uint8Array, Blob, File, or Node.js Buffer.
|
|
24
|
-
// Output will be Uint8Array.
|
|
25
|
-
// This method returns a Promise. If there is an error, that promise will reject.
|
|
26
|
-
const brokenZip = fs.readFileSync('your-broken-project.sb3');
|
|
27
|
-
const fixedZip = await sb3fix.fixZip(brokenZip);
|
|
28
|
-
console.log(fixedZip);
|
|
29
|
-
|
|
30
|
-
// Fix just a project.json or sprite.json with sb3fix.fixJSON()
|
|
31
|
-
// Input can be a parsed project.json object or a parsed sprite.json object or a string.
|
|
32
|
-
// If the input is an object, that object will be modified in-place instead of being copied.
|
|
33
|
-
// Output will be a parsed project.json object or a parsed sprite.json object depending on input.
|
|
34
|
-
// This method is NOT async. If there is an error, a plain JavaScript error will be thrown.
|
|
35
|
-
const brokenJSON = fs.readFileSync('your-broken-project.json', 'utf-8');
|
|
36
|
-
const fixedJSON = sb3fix.fixJSON(brokenJSON);
|
|
37
|
-
console.log(fixedJSON);
|
|
38
|
-
|
|
39
|
-
// sb3fix is deterministic. The same input will always give the same output, bit-for-bit.
|
|
40
|
-
|
|
41
|
-
// Both sb3fix methods take in an optional options object.
|
|
42
|
-
const options = {
|
|
43
|
-
// While sb3fix runs, it'll log what it's doing and what it fixed. You can monitor those
|
|
44
|
-
// using this callback. These messages are primarily a debugging tool, so the exact output
|
|
45
|
-
// is not stable and may change without warning.
|
|
46
|
-
logCallback: (message) => {
|
|
47
|
-
console.log(message);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
npm
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
npm run
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
```bash
|
|
91
|
-
npm run
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
1
|
+
# sb3fix
|
|
2
|
+
|
|
3
|
+
https://turbowarp.github.io/sb3fix/
|
|
4
|
+
|
|
5
|
+
Fix corrupted Scratch 3 projects.
|
|
6
|
+
|
|
7
|
+
## API
|
|
8
|
+
|
|
9
|
+
Install with:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @turbowarp/sb3fix
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then use from Node.js:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const sb3fix = require('@turbowarp/sb3fix');
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
|
|
21
|
+
const run = async () => {
|
|
22
|
+
// Fix a .sb3 or .sprite3 with sb3fix.fixZip()
|
|
23
|
+
// Input can be an ArrayBuffer, Uint8Array, Blob, File, or Node.js Buffer.
|
|
24
|
+
// Output will be Uint8Array.
|
|
25
|
+
// This method returns a Promise. If there is an error, that promise will reject.
|
|
26
|
+
const brokenZip = fs.readFileSync('your-broken-project.sb3');
|
|
27
|
+
const fixedZip = await sb3fix.fixZip(brokenZip);
|
|
28
|
+
console.log(fixedZip);
|
|
29
|
+
|
|
30
|
+
// Fix just a project.json or sprite.json with sb3fix.fixJSON()
|
|
31
|
+
// Input can be a parsed project.json object or a parsed sprite.json object or a string.
|
|
32
|
+
// If the input is an object, that object will be modified in-place instead of being copied.
|
|
33
|
+
// Output will be a parsed project.json object or a parsed sprite.json object depending on input.
|
|
34
|
+
// This method is NOT async. If there is an error, a plain JavaScript error will be thrown.
|
|
35
|
+
const brokenJSON = fs.readFileSync('your-broken-project.json', 'utf-8');
|
|
36
|
+
const fixedJSON = sb3fix.fixJSON(brokenJSON);
|
|
37
|
+
console.log(fixedJSON);
|
|
38
|
+
|
|
39
|
+
// sb3fix is deterministic. The same input will always give the same output, bit-for-bit.
|
|
40
|
+
|
|
41
|
+
// Both sb3fix methods take in an optional options object.
|
|
42
|
+
const options = {
|
|
43
|
+
// While sb3fix runs, it'll log what it's doing and what it fixed. You can monitor those
|
|
44
|
+
// using this callback. These messages are primarily a debugging tool, so the exact output
|
|
45
|
+
// is not stable and may change without warning.
|
|
46
|
+
logCallback: (message) => {
|
|
47
|
+
console.log(message);
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// Different runtimes support different features. A project that is invalid in Scratch might
|
|
51
|
+
// be valid for another runtime. This lets you control which runtime sb3fix targets.
|
|
52
|
+
// Values: 'scratch' (default), 'turbowarp'
|
|
53
|
+
platform: 'scratch'
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// To use the above options, just supply as the second argument when you call sb3fix:
|
|
57
|
+
await sb3fix.fixZip(brokenZip, options);
|
|
58
|
+
sb3fix.fixJSON(brokenJSON, options);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
run();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Development
|
|
65
|
+
|
|
66
|
+
Install things:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
git clone https://github.com/TurboWarp/sb3fix.git
|
|
70
|
+
cd sb3fix
|
|
71
|
+
npm ci
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Source code is in the src folder. During development do:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm start
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Then open dist/index.html in your favorite browser (there isn't a localhost development server).
|
|
81
|
+
|
|
82
|
+
For the final build:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm run build
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
All changes should have a corresponding test. Add test sb3 files in tests/samples, then run:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm run update
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Then check that the changes in tests/expected-output match what you expect. No unexpected changes! You can check if all the tests still pass with:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm run test
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
Copyright (C) 2023-2025 Thomas Weber
|
|
103
|
+
|
|
104
|
+
This Source Code Form is subject to the terms of the Mozilla Public
|
|
105
|
+
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
106
|
+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@turbowarp/sb3fix",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Fix corrupted Scratch projects",
|
|
5
|
-
"main": "src/sb3fix.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "webpack -c webpack.config.js",
|
|
8
|
-
"watch": "webpack --watch -c webpack.config.js",
|
|
9
|
-
"start": "webpack --watch -c webpack.config.js",
|
|
10
|
-
"update": "node tests/snapshots --update",
|
|
11
|
-
"test": "node tests/snapshots --validate"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/TurboWarp/sb3fix.git"
|
|
16
|
-
},
|
|
17
|
-
"author": "GarboMuffin",
|
|
18
|
-
"license": "MPL-2.0",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/TurboWarp/sb3fix/issues"
|
|
21
|
-
},
|
|
22
|
-
"homepage": "https://github.com/TurboWarp/sb3fix#readme",
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@turbowarp/jszip": "^3.
|
|
25
|
-
},
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"copy-webpack-plugin": "^13.0.0",
|
|
28
|
-
"webpack": "^5.98.0",
|
|
29
|
-
"webpack-cli": "^6.0.1"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@turbowarp/sb3fix",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Fix corrupted Scratch projects",
|
|
5
|
+
"main": "src/sb3fix.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "webpack -c webpack.config.js",
|
|
8
|
+
"watch": "webpack --watch -c webpack.config.js",
|
|
9
|
+
"start": "webpack --watch -c webpack.config.js",
|
|
10
|
+
"update": "node tests/snapshots --update",
|
|
11
|
+
"test": "node tests/snapshots --validate"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/TurboWarp/sb3fix.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "GarboMuffin",
|
|
18
|
+
"license": "MPL-2.0",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/TurboWarp/sb3fix/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/TurboWarp/sb3fix#readme",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@turbowarp/jszip": "^3.12.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"copy-webpack-plugin": "^13.0.0",
|
|
28
|
+
"webpack": "^5.98.0",
|
|
29
|
+
"webpack-cli": "^6.0.1"
|
|
30
|
+
}
|
|
31
|
+
}
|