You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: api/README.md
+20-13Lines changed: 20 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,24 @@
1
-
# Node.js API for Packager
1
+
# Node.js API
2
2
3
3
## Installing
4
4
5
5
```bash
6
6
npm install --save-exact @turbowarp/packager
7
7
```
8
8
9
-
Note the `--save-exact`: this is important.
9
+
We suggest that you use `--save-exact` (or, with yarn, `--exact`) to make sure you always install the same version. This is important because we don't promise API stability.
10
10
11
11
## About the API
12
12
13
13
### Stability
14
14
15
-
There are no promises of stability between updates. Make sure to pin your versions and don't blindly bump without testing. We don't go out of our way to break the Node.js API, but we also don't let it stop us from making changes. See [CHANGELOG.md](CHANGELOG.md) for a list of API changes.
15
+
The Node.js API is still in beta. Expect to find bugs.
16
+
17
+
There are no promises of API stability between updates. Always pin to an exact version and don't update without testing. We don't go out of our way to break the Node.js API, but we don't let it stop us from making changes. We will try to mention noteworthy changes in the [GitHub releases](https://github.com/TurboWarp/packager/releases) changelog.
16
18
17
19
### Release cadence
18
20
19
-
The plan is to release an updated version of the npm module after every release of the standalone version of the packager. Effectively that means there won't be more than a couple releases per month.
21
+
The plan is to release an updated version of the npm module with every release of the standalone version of the packager, which currently happens about once a month.
20
22
21
23
### Feature support
22
24
@@ -38,15 +40,17 @@ Large assets are cached in `node_modules/@turbowarp/packager/.packager-cache`. Y
38
40
39
41
## Using the API
40
42
41
-
See demo.js for a full example.
43
+
See demo.js or demo-simple.js for a full example.
42
44
43
45
First, you can import the module like this:
44
46
45
47
```js
46
48
constPackager=require('@turbowarp/packager');
47
49
```
48
50
49
-
Next you have to get a project file from somewhere. It can be a project.json or a full sb, sb2, or sb3 file. You will have to do this on your own as the packager does not have any way to help you. The easiest way to get a project is probably to fetch one from https://projects.scratch.mit.edu/1.
51
+
### Load a project
52
+
53
+
Next you have to get a project file from somewhere. It can be a project.json or a full sb, sb2, or sb3 file. The packager doesn't provide any API for this, you have to find it on your own. The easiest way to get a project is probably to fetch one from https://projects.scratch.mit.edu/1.
50
54
51
55
Then, convert your project data to an ArrayBuffer, Uint8Array, or Node.js Buffer.
52
56
@@ -69,6 +73,8 @@ const progressCallback = (type, a, b) => {};
`packager.options` has a lot of options on it for you to consider. You can log the object or see [packager.js](../src/packager/packager.js) and look for `DEFAULT_OPTIONS` to see what options are available.
80
86
87
+
We recommend that you avoid overwriting the entirety of `packager.options` as this may cause issues when you try to update the packager as options change. Instead, just update what you need to.
88
+
89
+
```js
90
+
packager.options.turbo=true;
91
+
```
92
+
81
93
Note that a Packager is a single-use object; you must make a new Packager each time you want to package a project.
82
94
83
-
Now, you're finally ready to actually package the project.
95
+
Now you can finally actually package the project.
84
96
85
97
```js
86
98
constresult=awaitpackager.package();
@@ -92,15 +104,10 @@ const type = result.type;
92
104
constdata=result.data;
93
105
```
94
106
95
-
After calling package(), it is possible to cancel the process. This should stop any ongoing work, although that isn't guaranteed.
96
-
97
-
```js
98
-
packager.abort();
99
-
```
100
-
101
107
You can also add progress listeners on the packager using something similar to the addEventListener you're familiar with. Note that these aren't actually EventTargets, just a tiny shim that looks similar, so some things like `once` won't work and the events don't have very many properties on them.
0 commit comments