Skip to content

Commit 5160fa6

Browse files
committed
Update Node.js module documentation
1 parent cee195e commit 5160fa6

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

api/CHANGELOG.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

api/README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
# Node.js API for Packager
1+
# Node.js API
22

33
## Installing
44

55
```bash
66
npm install --save-exact @turbowarp/packager
77
```
88

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.
1010

1111
## About the API
1212

1313
### Stability
1414

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.
1618

1719
### Release cadence
1820

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.
2022

2123
### Feature support
2224

@@ -38,15 +40,17 @@ Large assets are cached in `node_modules/@turbowarp/packager/.packager-cache`. Y
3840

3941
## Using the API
4042

41-
See demo.js for a full example.
43+
See demo.js or demo-simple.js for a full example.
4244

4345
First, you can import the module like this:
4446

4547
```js
4648
const Packager = require('@turbowarp/packager');
4749
```
4850

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.
5054

5155
Then, convert your project data to an ArrayBuffer, Uint8Array, or Node.js Buffer.
5256

@@ -69,6 +73,8 @@ const progressCallback = (type, a, b) => {};
6973
const loadedProject = await Packager.loadProject(projectData, progressCallback);
7074
```
7175

76+
### Package the project
77+
7278
Now you can make a Packager.
7379

7480
```js
@@ -78,9 +84,15 @@ packager.project = loadedProject;
7884

7985
`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.
8086

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+
8193
Note that a Packager is a single-use object; you must make a new Packager each time you want to package a project.
8294

83-
Now, you're finally ready to actually package the project.
95+
Now you can finally actually package the project.
8496

8597
```js
8698
const result = await packager.package();
@@ -92,15 +104,10 @@ const type = result.type;
92104
const data = result.data;
93105
```
94106

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-
101107
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.
102108

103109
```js
110+
// do this before calling package()
104111
packager.addEventListener('zip-progress', ({detail}) => {
105112
// Used when compressing projects as zips
106113
console.log('Packager progress zip-progress', detail);

0 commit comments

Comments
 (0)