-
Notifications
You must be signed in to change notification settings - Fork 12
1287 library assets url #1479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DNR500
wants to merge
9
commits into
main
Choose a base branch
from
1287-library-host-url
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
1287 library assets url #1479
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4d61522
feat: change to get the library host url prop working
DNR500 eb9dc48
feat: use library temple from env for scratch assets
DNR500 afbad2f
docs: update README with details for working with scratch editor locally
DNR500 b13863d
docs: update the readme to use the correct scratch commands
DNR500 3c58cf5
feat: use RPF scratch editor with image assets
DNR500 5d235c2
build: make sure the CDN is used on all environments
DNR500 d1cdca5
build: ensure use of NPM_AUTH_TOKEN
DNR500 b372476
chore: clean up github workflows
DNR500 6f0287c
docs: update PAT section
DNR500 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| @RaspberryPiFoundation:registry=https://npm.pkg.github.com | ||
| //npm.pkg.github.com/:_authToken=${NPM_AUTH_TOKEN} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,47 @@ This project provides a web component containing the Raspberry Pi Code Editor fo | |
|
|
||
| ## Install dependencies | ||
|
|
||
| This repository uses Yarn (see `package.json` → `packageManager`). Please install dependencies with Yarn: | ||
| This repository uses Yarn (see `package.json` → `packageManager`). | ||
|
|
||
| `@RaspberryPiFoundation/scratch-gui` is installed from [GitHub Packages](https://github.com/RaspberryPiFoundation/scratch-editor/pkgs/npm/scratch-gui). Complete the steps below, then run `yarn install`. | ||
|
|
||
| ### Set a personal access token | ||
|
|
||
| If you don't already have this set up you will need it to access deps in the RPF private registry | ||
|
|
||
| 1. On GitHub, create a **classic** personal access token: [Settings → Developer settings → Personal access tokens](https://github.com/settings/tokens). Enable **`read:packages`** and **`repo`**. For packages tied to private repositories, `read:packages` alone can cause `yarn install` to fail with `401`/`403`. | ||
| 2. If your organisation uses SAML SSO, open the token on GitHub and **Authorize** it for **RaspberryPiFoundation** (Configure SSO). | ||
| 3. Add the token to your shell profile (for example `~/.zshrc` on macOS): | ||
|
|
||
| ```bash | ||
| export GITHUB_TOKEN=ghp_your_token_here | ||
| export NPM_AUTH_TOKEN=$GITHUB_TOKEN | ||
| ``` | ||
|
|
||
| Replace `ghp_your_token_here` with your token. | ||
|
|
||
| 4. Load the profile in any terminal you are currently using for this project: | ||
|
|
||
| ```bash | ||
| source ~/.zshrc | ||
| ``` | ||
|
|
||
| 5. Confirm GitHub Packages is reachable from this directory: | ||
|
|
||
| ```bash | ||
| yarn npm info @RaspberryPiFoundation/scratch-gui version | ||
| ``` | ||
|
|
||
| You should see the version pinned in `package.json` (for example `13.7.3-code-classroom.20260522151700`), not an authentication error. If you see `unauthenticated` or `401`, run `source ~/.zshrc` again or check the token scopes and SSO authorisation. | ||
|
|
||
| 6. When you use Docker, run `docker compose up` from a shell where `NPM_AUTH_TOKEN` is set. Compose passes it from the host into the container so `yarn install` can run there too. | ||
|
|
||
| Then install dependencies: | ||
|
|
||
| ``` | ||
| yarn install | ||
| ``` | ||
|
|
||
| Using `npm install` can fail due to strict peer-dependency resolution in npm for some legacy packages in this project. | ||
|
|
||
| ## Environment variables | ||
|
|
||
| The app uses the `dotenv` package to provide access to environment variables. Copy the example file into `.env` and use this file for any other environment variables the web component may require: | ||
|
|
@@ -227,6 +260,109 @@ Python code snippets are styled and syntax-highlighted using the `language-pytho | |
| <code class="language-python">print('hello world')</code> | ||
| ``` | ||
|
|
||
| ### Linking a local scratch-editor (Scratch GUI) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be nice to add this to a seperate file and reference here since now the readme is getting very long |
||
|
|
||
| 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. | ||
|
|
||
| **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: | ||
|
|
||
| ```bash | ||
| cd ../scratch-editor | ||
| git fetch origin | ||
| git checkout code-classroom | ||
| ``` | ||
|
|
||
| Feature work should branch from `code-classroom`, not from upstream `main` or `code-classroom-base`. | ||
|
|
||
| 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. | ||
|
|
||
| **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. | ||
|
|
||
| #### Repository layout | ||
|
|
||
| Clone both repositories as siblings: | ||
|
|
||
| ```text | ||
| Development/ | ||
| editor-ui/ | ||
| scratch-editor/ ← github.com/RaspberryPiFoundation/scratch-editor | ||
| ``` | ||
|
|
||
| #### Temporary changes in editor-ui | ||
|
|
||
| **1. `package.json`** — replace the GitHub Packages dependency with a file link (the name must match the package in scratch-editor): | ||
|
|
||
| ```json | ||
| "@RaspberryPiFoundation/scratch-gui": "file:../scratch-editor/packages/scratch-gui" | ||
| ``` | ||
|
|
||
| **2. `docker-compose.yml`** — mount the scratch-editor repo into the container (read-only): | ||
|
|
||
| ```yaml | ||
| volumes: | ||
| - .:/app | ||
| - ../scratch-editor:/scratch-editor:ro | ||
| - node_modules:/app/node_modules | ||
| ``` | ||
|
|
||
| From `/app` in the container, `file:../scratch-editor/packages/scratch-gui` resolves to `/scratch-editor/packages/scratch-gui` on the mounted volume. | ||
|
|
||
| **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`. | ||
|
|
||
| #### Build scratch-gui | ||
|
|
||
| Build on your machine (the `scratch-editor` mount is read-only inside the editor-ui container): | ||
|
|
||
| ```bash | ||
| cd ../scratch-editor | ||
| nvm install | ||
| nvm use | ||
| NODE_ENV=development npm ci | ||
| npm run build | ||
| ``` | ||
|
|
||
| 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`. | ||
|
|
||
| #### Run with Docker | ||
|
|
||
| **editor-api** (Scratch projects and assets API): | ||
|
|
||
| ```bash | ||
| cd ../editor-api | ||
| docker compose up | ||
| ``` | ||
|
|
||
| **editor-ui**: | ||
|
|
||
| ```bash | ||
| cd ../editor-ui | ||
| docker compose up | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| #### Verify in the browser | ||
|
|
||
| Scratch runs in an iframe served from editor-ui (port **3011**), not from the main web-component bundle alone. | ||
|
|
||
| - Web component test page: open a **Scratch** sample, e.g. | ||
| `http://localhost:3011/web-component.html` | ||
| then choose **cool-scratch**. | ||
| - **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. | ||
|
|
||
| #### Revert when finished | ||
|
|
||
| 1. Restore the GitHub Packages pin in `package.json`, for example: | ||
|
|
||
| ```json | ||
| "@RaspberryPiFoundation/scratch-gui": "13.7.3-code-classroom.20260522151700" | ||
| ``` | ||
|
|
||
| Use the version your branch pins (see [scratch-gui on GitHub Packages](https://github.com/RaspberryPiFoundation/scratch-editor/pkgs/npm/scratch-gui)). | ||
| 2. Remove the `../scratch-editor:/scratch-editor:ro` volume from `docker-compose.yml`. | ||
| 3. Revert `yarn.lock` (e.g. `git checkout -- yarn.lock`) or run `yarn install` again after restoring `package.json`. | ||
| 4. Restart `docker compose up` in editor-ui. | ||
|
|
||
| ## Deployment | ||
|
|
||
| Deployment is managed through Github actions. The UI is deployed to staging and production environments through an S3 bucket, managed via Cloudflare. This requires the following environment variables to be set | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel strongly about this, but it might be simpler to put this in a constant in JS file rather than using an environment variable.
We don't need to vary this per environment, it's not secret, and we don't need to change it independently of deploys.
Having it as a env var just adds a little more setup that we'll have to do when deploying and locally.