|
2 | 2 |
|
3 | 3 | The playground is a place where users can explore GopherJS without needing to install anything, or to share code with others. |
4 | 4 |
|
| 5 | +- [Building the playgound](#building-the-playgound) |
| 6 | +- [Development](#development) |
| 7 | +- [Upgrading GopherJS release](#upgrading-gopherjs-release) |
| 8 | +- [Adding a new predefined snippet](#adding-a-new-predefined-snippet) |
| 9 | + |
| 10 | +## Building the playgound |
| 11 | + |
| 12 | +To build the entire playground environment, |
| 13 | +run `go generate`. |
| 14 | + |
| 15 | +This assumes that your `go` matches the current version of `go` that `gopherjs` supports. |
| 16 | +If you have a different version of `go` then install the other versions as |
| 17 | +described in [Managing Go installations](https://go.dev/doc/manage-install). |
| 18 | + |
| 19 | +For example, to build for [GopherJS 1.20.0 for Go 1.20.14](https://github.com/gopherjs/gopherjs/releases/tag/v1.20.0) |
| 20 | +run `go1.20.14 generate`. |
| 21 | + |
| 22 | +Generate will: |
| 23 | + |
| 24 | +1. Install your local version of GopherJS compiler |
| 25 | +2. Build the playground |
| 26 | +3. Build the web worker compiler |
| 27 | +4. Create precompiled standard library packages in the `pkg` directory |
| 28 | + |
| 29 | +To manually build the playground: |
| 30 | + |
| 31 | +1. See [GopherJS](https://github.com/gopherjs/gopherjs) documentation about building GopherJS |
| 32 | +2. Build the playgound with `gopherjs build ./playground.go` |
| 33 | +3. Build the web worker compiler with `gopherjs build ./internal/cmd/compile/compile.go` |
| 34 | +4. Create the precompiled standard library packages with `go run ./internal/cmd/precompile`. |
| 35 | + Use the same `go` as `gopherjs` as described above |
| 36 | + |
5 | 37 | ## Development |
6 | 38 |
|
7 | | -To update the entire playground environment, just run `go generate github.com/gopherjs/gopherjs.github.io/playground`. It will install your local version of GopherJS compiler, build the playground, make a temporary copy of Go to /tmp/gopherjsplayground_goroot, rebuild and copy the standard library into the `pkg` directory. |
| 39 | +Working on the playground application itself is made easier by using the |
| 40 | +`gopherjs serve` command serve the playground locally. |
8 | 41 |
|
9 | | -Working on the playground application itself is made easier by using the `gopherjs serve` command to rebuild and serve the playground every time you refresh the browser. |
| 42 | +Then open <http://localhost:8080?debug=true&local=true>. |
10 | 43 |
|
11 | | -```bash |
12 | | -gopherjs serve |
13 | | -``` |
| 44 | +The `debug` query will enable debugging for react and verbose output. |
| 45 | + |
| 46 | +If running locally or from a fork, trying to access the remote store will |
| 47 | +fail with a a CORS error. Use the `local` query to make the snippet store |
| 48 | +(used when clicking "Share" or loading with a shared url) use local cache only. |
| 49 | + |
| 50 | +There are a few ways to check changes. When working on the playground itself |
| 51 | +it may be simpliest to run `gopherjs build ./playground.go && gopherjs serve` |
| 52 | +after you have made changes so that the changes will be built and served. |
14 | 53 |
|
15 | | -Then open <http://localhost:8080/github.com/gopherjs/gopherjs.github.io/playground>. |
| 54 | +When running code in the playground, the JS that is being run can be seen |
| 55 | +by checking the page source files and finding the webworker that is running |
| 56 | +the code. The webworker should have a GUID name, e.g. `fb29b3a9-d5b0-478d-aaf7-85cb60ddbd6d`, |
| 57 | +and the JS compiled for that code will have the same name (usually without `.js`). |
16 | 58 |
|
17 | 59 | ## Upgrading GopherJS release |
18 | 60 |
|
| 61 | +To upgrade to the newest version, run |
| 62 | + |
19 | 63 | ```shell |
20 | 64 | VERSION="$(go list -m -versions -f "{{ range .Versions }}{{ println . }}{{ end }}" github.com/gopherjs/gopherjs | tail -n 1)" |
21 | 65 | echo "$VERSION" |
22 | 66 | go get -v "github.com/gopherjs/gopherjs@$VERSION" |
23 | 67 | go mod tidy |
24 | 68 | ``` |
| 69 | + |
| 70 | +then rebuild the playground with the correct version of `go`. |
| 71 | + |
| 72 | +When committing the update, make sure that `compile.js` at minimum has been |
| 73 | +updated to use the new version of GopherJS so that we can build in that version. |
| 74 | + |
| 75 | +## Adding a new predefined snippet |
| 76 | + |
| 77 | +The snippets are prewritten example programs such as `Hello` and `Donut`. |
| 78 | +To add new snippets: |
| 79 | + |
| 80 | +1. Write the code you would like to add |
| 81 | +2. Test it in the playground and check the console to make sure it does |
| 82 | + what you expected it to do |
| 83 | +3. Create file in the [snippets folder](./internal/snippets) for that code and change |
| 84 | + file extension to `.go.txt` |
| 85 | +4. In [`snippets.go`](./internal/snippets/snippets.go) add the new file as |
| 86 | + an embedded string and add that string to the `predefined` map. |
0 commit comments