leopard-js / sb-edit

Javascript library for manipulating Scratch project files
MIT License
55 stars 15 forks source link

Add "--leopard-url" CLI option #148

Closed towerofnix closed 4 months ago

towerofnix commented 4 months ago

Enables testing a custom Leopard build locally, or providing any other alternate Leopard library host.

The default value is the same one that is used by default in toLeopard.ts. It would be nice not to duplicate this definition, but unless toLeopard defined it as an export (this would probably be awkward) or stops providing a default at all, it is what it is.

This option is used in both leopard and leopard-zip output formats, and ignored in other formats.

Only fully qualified URLs are supported, i.e. you can't just do /leopard/dist. This is to make the output folder work regardless where it's hosted (provided the specified URL is accessible there), and to avoid confusing a path on a hypothetical file server with a path on your own system.

There's no magic about e.g. taking a specified path to Leopard and copying out the dist/ files at time of sb-edit run (to make a self-contained folder/zip). That's out of scope for this PR, and may require adjustments to toLeopard internals (e.g. supporting relative imports there).

Typical development setup 1:

# terminal 1
cd leopard
npm run dev

# terminal 2
cd leopard/dist
npx vite --port 6201

# terminal 3
npx vite --port 6200

# terminal 4
sb-edit -i /path/to/proj.sb3 -o demo \
  --leopard-url http://localhost:6201/

# in browser, navigate to:
# http://localhost:6200/demo/

Typical development setup 2:

# terminal 1
cd leopard
npm run dev

# terminal 2
npx vite --port 6200

# terminal 3
rm -rf demo
sb-edit -i /path/to/proj.sb3 -o demo \
  --leopard-url http://localhost:6200/leopard/dist/

# in browser, navigate to:
# http://localhost:6200/demo/
towerofnix commented 4 months ago

Merged, thanks! I'm going to push 0.15.0 with this and other recent merges.