|
1 | | -# Electric v3 Starter App |
| 1 | +# Hyperfiddle demos repo — Electric Fiddle |
| 2 | + |
| 3 | +This is an **internal playground repo** where we host a lot of our demos, live examples, and little snippets and deploy them to prod. In its current form it's **not intended for public use**. We only leave it published so we can link to the source code of certain demos when we need to. |
| 4 | + |
| 5 | +For a minimalist Electric starter repo, see https://gitlab.com/hyperfiddle/electric3-starter-app. |
2 | 6 |
|
3 | 7 | ## Links |
4 | 8 |
|
5 | 9 | * Electric github with source code: https://github.com/hyperfiddle/electric |
6 | 10 | * Tutorial: https://electric.hyperfiddle.net/ |
7 | 11 |
|
8 | | -## Getting started - dev setup |
| 12 | +## Getting started — dev setup |
9 | 13 |
|
10 | | -* Shell: `clj -A:dev -X dev/-main`. |
| 14 | +* Shell: `clj -A:dev:private:electric-tutorial:dustingetz -X dev/-main` |
11 | 15 | * Login instructions will be printed |
12 | | -* REPL: `:dev` deps alias, `(dev/-main)` at the REPL to start dev build |
| 16 | +* REPL: `:dev:private:electric-tutorial:dustingetz` deps aliases, `(dev/-main)` at the REPL to start dev build |
13 | 17 | * App will start on http://localhost:8080 |
14 | | -* Electric root function: [src/electric_starter_app/main.cljc](src/electric_starter_app/main.cljc) |
15 | 18 | * Hot code reloading works: edit -> save -> see app reload in browser |
16 | 19 |
|
17 | 20 | > [!WARNING] |
18 | | -> Electric dev environments must run **one single JVM** that is shared by both the Clojure REPL and shadow-cljs ClojureScript compilation process! Electric uses a custom hot code reloading strategy to ensure that the Electric frontend and backend processes (DAGs) stay in sync as you change one or the other. This starter repo achieves this by booting shadow from the dev entrypoint[src-dev/dev.cljc](src-dev/dev.cljc). I believe this is compatible with both Calva and Cursive's "happy path" shadow-cljs support. For other editors, watch out as your boot sequence may run shadow-cljs in a second process! You will experience undefined behavior. |
| 21 | +> Electric dev environments must run **one single JVM** that is shared by both the Clojure REPL and shadow-cljs ClojureScript compilation process! Electric uses a custom hot code reloading strategy to ensure that the Electric frontend and backend processes (DAGs) stay in sync as you change one or the other. This starter repo achieves this by booting shadow from the dev entrypoint [src-dev/dev.cljc](src-dev/dev.cljc). I believe this is compatible with both Calva and Cursive's "happy path" shadow-cljs support. For other editors, watch out as your boot sequence may run shadow-cljs in a second process! You will experience undefined behavior. |
| 22 | +
|
| 23 | +## "Fiddle" classpath infrastructure (optional) |
| 24 | + |
| 25 | +This repo is structured to allow multiple "fiddles" (little apps) to share common dev infrastructure (e.g. routing, databases). During dev, these classpaths are merged, but prod classpaths are isolated so that each fiddle can deployed individually. |
| 26 | + |
| 27 | +* **local dev**: the [dev entrypoint](src-dev/dev.cljc) uses a [clever reader trick](src-dev/load_dev_fiddles!.cljc) to drive Clojure/Script namespace `:require` directives dynamically from a config file, [`electric-fiddle.edn`](src-dev/electric-fiddle.example.edn). Clone the example file to override it locally, and remember to restart your REPL. |
| 28 | + |
| 29 | +* **prod**: the [prod entrypoint](src-prod/prod.cljc) runs only one fiddle at a time, with an isolated classpath. Prod has a mandatory [build](src-build/build.clj), which bakes the Electric application client program. At compile time, both the Electric program hash (derived from git) and the fiddle entrypoint namespace are known statically, and built into both the client assets and also the server asset `resources/electric-manifest.edn` which is used to ensure that the client & server agree about the baked Electric program hash. At runtime, the prod entrypoint uses the reader trick to lookup the name of the entrypoint to run. |
| 30 | + |
| 31 | +This is all done in a rather tiny amount of LOC, so we feel it is reasonable to expect you to understand it. |
19 | 32 |
|
20 | 33 | ## Deployment |
21 | 34 |
|
22 | 35 | ```shell |
23 | | -# Prod build |
24 | | -clj -X:build:prod build-client |
25 | | -clj -M:prod -m prod |
26 | 36 |
|
27 | | -# Uberjar (optional) |
28 | | -clj -X:build:prod uberjar :build/jar-name "app.jar" |
| 37 | +clj -X:build:prod:electric-tutorial build-client :build/fiddle-ns docs-site.sitemap |
| 38 | +clj -M:prod:electric-tutorial -m prod |
| 39 | + |
| 40 | +# Uberjar |
| 41 | +clj -X:build:prod:electric-tutorial uberjar :build/fiddle-ns docs-site.sitemap :build/fiddle-deps-alias :electric-tutorial :build/jar-name '"app.jar"' |
29 | 42 | java -cp target/app.jar clojure.main -m prod |
30 | 43 |
|
31 | 44 | # Docker |
32 | | -docker build --build-arg VERSION=$(git rev-parse HEAD) -t electric3-starter-app:latest . |
33 | | -docker run --rm -it -p 8080:8080 electric3-starter-app:latest |
| 45 | +docker build --build-arg HYPERFIDDLE_FIDDLE_NS=docs-site.sitemap --build-arg HYPERFIDDLE_FIDDLE_DEPS_ALIAS=electric-tutorial --build-arg VERSION=$(git rev-parse HEAD) -t electric-fiddle:latest . |
| 46 | +docker run --rm -it -p 8080:8080 electric-fiddle:latest |
34 | 47 |
|
35 | 48 | # Fly |
36 | 49 | fly deploy --remote-only --build-arg VERSION=$(git rev-parse HEAD) |
|
0 commit comments