|
| 1 | +# Linking a local scratch-editor (Scratch GUI) |
| 2 | + |
| 3 | +When you are working on the [Raspberry Pi Foundation scratch-editor](https://github.com/RaspberryPiFoundation/scratch-editor) fork (for example changes to `scratch-gui`), you may want editor-ui to load that build instead of the `@RaspberryPiFoundation/scratch-gui` version from GitHub Packages. |
| 4 | + |
| 5 | +**Use the `code-classroom` branch** in scratch-editor as your base for editor-ui work. That branch is the integration line for this editor (RPF packaging, publish, and GUI props such as `libraryAssetUrlTemplate`). Check it out before you link or build: |
| 6 | + |
| 7 | +```bash |
| 8 | +cd ../scratch-editor |
| 9 | +git fetch origin |
| 10 | +git checkout code-classroom |
| 11 | +``` |
| 12 | + |
| 13 | +Feature work should branch from `code-classroom`, not from upstream `main` or `code-classroom-base`. |
| 14 | + |
| 15 | +editor-ui does not bundle Scratch GUI into the main webpack app. It copies a prebuilt `dist/scratch-gui.js` (and static assets) from `node_modules` into the dev server output. Pointing the dependency at your local clone is enough to test GUI changes in the Scratch iframe. |
| 16 | + |
| 17 | +**Do not commit these linking changes.** They are temporary for local development only. These changes to `package.json`, `yarn.lock`, and `docker-compose.yml` are for local development only. |
| 18 | + |
| 19 | +## Repository layout |
| 20 | + |
| 21 | +Clone both repositories as siblings: |
| 22 | + |
| 23 | +```text |
| 24 | +Development/ |
| 25 | + editor-ui/ |
| 26 | + scratch-editor/ ← github.com/RaspberryPiFoundation/scratch-editor |
| 27 | +``` |
| 28 | + |
| 29 | +## Temporary changes in editor-ui |
| 30 | + |
| 31 | +**1. `package.json`** — replace the GitHub Packages dependency with a file link (the name must match the package in scratch-editor): |
| 32 | + |
| 33 | +```json |
| 34 | +"@RaspberryPiFoundation/scratch-gui": "file:../scratch-editor/packages/scratch-gui" |
| 35 | +``` |
| 36 | + |
| 37 | +**2. `docker-compose.yml`** — mount the scratch-editor repo into the container (read-only): |
| 38 | + |
| 39 | +```yaml |
| 40 | +volumes: |
| 41 | + - .:/app |
| 42 | + - ../scratch-editor:/scratch-editor:ro |
| 43 | + - node_modules:/app/node_modules |
| 44 | +``` |
| 45 | +
|
| 46 | +From `/app` in the container, `file:../scratch-editor/packages/scratch-gui` resolves to `/scratch-editor/packages/scratch-gui` on the mounted volume. |
| 47 | + |
| 48 | +**3. `yarn.lock`** — run `yarn install` inside Docker (see below) and commit nothing; the lockfile will change while the link is active. Revert it when you restore the GitHub Packages version in `package.json`. |
| 49 | + |
| 50 | +## Build scratch-gui |
| 51 | + |
| 52 | +Build on your machine (the `scratch-editor` mount is read-only inside the editor-ui container): |
| 53 | + |
| 54 | +```bash |
| 55 | +cd ../scratch-editor |
| 56 | +nvm install |
| 57 | +nvm use |
| 58 | +NODE_ENV=development npm ci |
| 59 | +npm run build |
| 60 | +``` |
| 61 | + |
| 62 | +After every scratch-gui code change, run the build again, then restart the editor-ui container so webpack copies the new `dist/scratch-gui.js`. |
| 63 | + |
| 64 | +## Run with Docker |
| 65 | + |
| 66 | +**editor-api** (Scratch projects and assets API): |
| 67 | + |
| 68 | +```bash |
| 69 | +cd ../editor-api |
| 70 | +docker compose up |
| 71 | +``` |
| 72 | + |
| 73 | +**editor-ui**: |
| 74 | + |
| 75 | +```bash |
| 76 | +cd ../editor-ui |
| 77 | +docker compose up |
| 78 | +``` |
| 79 | + |
| 80 | +The container runs `yarn install` then `yarn start` on each start. The first start after switching to the file link may take longer while dependencies are linked. |
| 81 | + |
| 82 | +## Verify in the browser |
| 83 | + |
| 84 | +Scratch runs in an iframe served from editor-ui (port **3011**), not from the main web-component bundle alone. |
| 85 | + |
| 86 | +- Web component test page: open a **Scratch** sample, e.g. |
| 87 | + `http://localhost:3011/web-component.html` |
| 88 | + then choose **cool-scratch**. |
| 89 | +- **editor-standalone** (port **3012**): also loads the web component from `http://localhost:3011`; open a Scratch project under `/en-US/projects/…` with editor-ui and editor-api running. |
| 90 | + |
| 91 | +## Revert when finished |
| 92 | + |
| 93 | +1. Restore the GitHub Packages pin in `package.json`, for example: |
| 94 | + |
| 95 | + ```json |
| 96 | + "@RaspberryPiFoundation/scratch-gui": "13.7.3-code-classroom.20260522151700" |
| 97 | + ``` |
| 98 | + |
| 99 | + Use the version your branch pins (see [scratch-gui on GitHub Packages](https://github.com/RaspberryPiFoundation/scratch-editor/pkgs/npm/scratch-gui)). |
| 100 | +2. Remove the `../scratch-editor:/scratch-editor:ro` volume from `docker-compose.yml`. |
| 101 | +3. Revert `yarn.lock` (e.g. `git checkout -- yarn.lock`) or run `yarn install` again after restoring `package.json`. |
| 102 | +4. Restart `docker compose up` in editor-ui. |
| 103 | + |
0 commit comments