Skip to content

Commit df1715c

Browse files
Add Electric template (#1)
* [dev] POC custom template with options * % * [electric] Add electric template * generate html page --------- Co-authored-by: iain <iain@soulflyer.co.uk>
1 parent 732bfab commit df1715c

File tree

928 files changed

+283065
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

928 files changed

+283065
-12
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
# flexiana/xiana-deps
1+
# flexiana/xiana-deps-template
22

3-
FIXME: my new template.
3+
New Xiana template using deps-new
44

55
## Usage
66

7-
FIXME: write usage documentation!
8-
97
This is a template project for use with [deps-new](https://github.com/seancorfield/deps-new).
10-
As originally generated, it will produce a new library project when run:
11-
12-
$ clojure -Sdeps '{:deps {net.clojars.flexiana/xiana-deps {:local/root "."}}}' -Tnew create :template flexiana/xiana-deps :name myusername/mycoollib
13-
148
Assuming you have installed `deps-new` as your `new` "tool" via:
159

1610
```bash
1711
clojure -Ttools install io.github.seancorfield/deps-new '{:git/tag "v0.5.1"}' :as new
1812
```
1913

14+
As originally generated, it will produce a new library project when run:
15+
16+
$ clojure -Sdeps '{:deps {flexiana/xiana-deps-template {:git/url "https://github.com/Flexiana/xiana-deps-template" :git/sha "732bfab7203388aa5ca84207a38e9278b4ad03df"}}}' -Tnew create :template flexiana/xiana-deps-template :name myusername/mycoollib
17+
18+
2019
> Note: once the template has been published (to a public git repo), the invocation will be the same, except the `:local/root` dependency will be replaced by a git or Maven-like coordinate.
2120
2221
Run this template project's tests (by default, this just validates your template's `template.edn`
@@ -26,7 +25,7 @@ file -- that it is valid EDN and it satisfies the `deps-new` Spec for template f
2625

2726
## License
2827

29-
Copyright © 2023 Apollo
28+
Copyright © 2023 Flexiana
3029

3130
_EPLv1.0 is just the default for projects generated by `deps-new`: you are not_
3231
_required to open source this project, nor are you required to use EPLv1.0!_
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(ns {{top/file}}.{{main/file}}
2+
(:require [hyperfiddle.electric :as e]
3+
[hyperfiddle.electric-dom2 :as dom]))
4+
5+
(e/defn TwoClocks []
6+
(e/client
7+
(dom/h1 (dom/text "Two Clocks — Electric Clojure TEMPLATE"))
8+
9+
(let [c (e/client e/system-time-ms)
10+
s (e/server e/system-time-ms)]
11+
12+
(dom/div (dom/text "client time: " c))
13+
(dom/div (dom/text "server time: " s))
14+
(dom/div (dom/text "latency: " (- s c))))))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(ns ^:dev/always user ; Electric currently needs to rebuild everything when any file changes. Will fix
2+
(:require
3+
{{top/file}}.{{main/file}}
4+
hyperfiddle.electric
5+
hyperfiddle.electric-dom2))
6+
7+
(def electric-main
8+
(hyperfiddle.electric/boot ; Electric macroexpansion - Clojure to signals compiler
9+
(binding [hyperfiddle.electric-dom2/node js/document.body]
10+
({{top/file}}.{{main/file}}/TwoClocks.))))
11+
12+
(defonce reactor nil)
13+
14+
(defn ^:dev/after-load ^:export start! []
15+
(assert (nil? reactor) "reactor already running")
16+
(set! reactor (electric-main
17+
#(js/console.log "Reactor success:" %)
18+
#(js/console.error "Reactor failure:" %))))
19+
20+
(defn ^:dev/before-load stop! []
21+
(when reactor (reactor)) ; teardown
22+
(set! reactor nil))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link rel="icon" type="image/x-icon" href="favicon.ico">
7+
<title>{{main/file}}</title>
8+
</head>
9+
<body>
10+
<noscript>You need to enable JavaScript to run this app.</noscript>
11+
<script type="text/javascript" src="$:hyperfiddle.client.module/main$"></script>
12+
</body>
13+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM clojure:openjdk-11-tools-deps AS clojure-deps
2+
WORKDIR /app
3+
COPY deps.edn deps.edn
4+
COPY src-build src-build
5+
RUN clojure -A:dev -M -e :ok # preload deps
6+
RUN clojure -T:build noop # preload build deps
7+
8+
FROM clojure:openjdk-11-tools-deps AS build
9+
WORKDIR /app
10+
COPY --from=clojure-deps /root/.m2 /root/.m2
11+
COPY shadow-cljs.edn shadow-cljs.edn
12+
COPY deps.edn deps.edn
13+
COPY src src
14+
COPY src-build src-build
15+
COPY resources resources
16+
ARG REBUILD=unknown
17+
ARG VERSION
18+
RUN clojure -X:build uberjar :jar-name "app.jar" :verbose true :version '"'$VERSION'"'
19+
20+
FROM amazoncorretto:11 AS app
21+
WORKDIR /app
22+
COPY --from=build /app/app.jar app.jar
23+
EXPOSE 8080
24+
ARG VERSION
25+
ENV VERSION=$VERSION
26+
CMD java -DHYPERFIDDLE_ELECTRIC_VERSION=$VERSION -jar app.jar
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# electric-starter-app
2+
3+
```
4+
$ clj -A:dev -X user/main
5+
6+
Starting Electric compiler and server...
7+
shadow-cljs - server version: 2.20.1 running at http://localhost:9630
8+
shadow-cljs - nREPL server started on port 9001
9+
[:app] Configuring build.
10+
[:app] Compiling ...
11+
[:app] Build completed. (224 files, 0 compiled, 0 warnings, 1.93s)
12+
13+
👉 App server available at http://0.0.0.0:8080
14+
```
15+
16+
# Deployment
17+
18+
ClojureScript optimized build, Dockerfile, Uberjar, Github actions CD to fly.io
19+
20+
```
21+
clojure -X:build build-client # optimized release build
22+
clojure -X:build uberjar # contains demos and demo server, currently
23+
HYPERFIDDLE_ELECTRIC_APP_VERSION=`git describe --tags --long --always --dirty`
24+
docker build --build-arg VERSION='"'$HYPERFIDDLE_ELECTRIC_APP_VERSION'"' -t electric-starter-app .
25+
docker run --rm -p 7070:8080 electric-starter-app
26+
# flyctl launch ... ? create fly app, generate fly.toml, see dashboard
27+
# https://fly.io/apps/electric-starter-app
28+
29+
NO_COLOR=1 flyctl deploy --build-arg VERSION='$HYPERFIDDLE_ELECTRIC_APP_VERSION'
30+
# https://electric-starter-app.fly.dev/
31+
```
32+
33+
- `NO_COLOR=1` disables docker-cli fancy shell GUI, so that we see the full log (not paginated) in case of exception
34+
- `--build-only` tests the build on fly.io without deploying
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{:paths ["src" "resources"]
2+
:deps {com.hyperfiddle/electric {:mvn/version "v2-alpha-263-g89da9d11"}
3+
com.hyperfiddle/rcf {:mvn/version "20220926-202227"}
4+
info.sunng/ring-jetty9-adapter
5+
{:mvn/version "0.14.3" ; (Jetty 9) is Java 8 compatible;
6+
;:mvn/version "0.17.7" ; (Jetty 10) is NOT Java 8 compatible
7+
:exclusions [org.slf4j/slf4j-api info.sunng/ring-jetty9-adapter-http3]} ; no need
8+
org.clojure/clojure {:mvn/version "1.11.1"}
9+
org.clojure/clojurescript {:mvn/version "1.11.60"}
10+
org.clojure/tools.logging {:mvn/version "1.2.4"}
11+
ch.qos.logback/logback-classic {:mvn/version "1.2.11"}
12+
ring-basic-authentication/ring-basic-authentication {:mvn/version "1.1.1"}}
13+
:aliases {:dev
14+
{:extra-deps
15+
{binaryage/devtools {:mvn/version "1.0.6"}
16+
thheller/shadow-cljs {:mvn/version "2.20.1"}}
17+
:jvm-opts
18+
["-Xss2m" ; https://github.com/hyperfiddle/photon/issues/11
19+
"-XX:-OmitStackTraceInFastThrow" ;; RCF
20+
]
21+
:exec-fn user/main
22+
:exec-args {}}
23+
:build
24+
{:extra-paths ["src-build"]
25+
:ns-default build
26+
:extra-deps {io.github.clojure/tools.build {:git/tag "v0.8.2" :git/sha "ba1a2bf"}
27+
io.github.seancorfield/build-clj {:git/tag "v0.8.0" :git/sha "9bd8b8a"}
28+
thheller/shadow-cljs {:mvn/version "2.20.1"}}
29+
:jvm-opts ["-Xss2m"]}}}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
app = "electric-starter-app"
2+
kill_signal = "SIGINT"
3+
kill_timeout = 5
4+
processes = []
5+
6+
[env]
7+
8+
[experimental]
9+
allowed_public_ports = []
10+
auto_rollback = true
11+
12+
[[services]]
13+
http_checks = []
14+
internal_port = 8080
15+
processes = ["app"]
16+
protocol = "tcp"
17+
script_checks = []
18+
[services.concurrency]
19+
hard_limit = 200
20+
soft_limit = 150
21+
type = "connections"
22+
23+
[[services.ports]]
24+
force_https = true
25+
handlers = ["http"]
26+
port = 80
27+
28+
[[services.ports]]
29+
handlers = ["tls", "http"]
30+
port = 443
31+
32+
[[services.tcp_checks]]
33+
grace_period = "1s"
34+
interval = "15s"
35+
restart_limit = 0
36+
timeout = "2s"
14.7 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link rel="icon" type="image/x-icon" href="favicon.ico">
7+
<title>Electric Starter App</title>
8+
</head>
9+
<body>
10+
<noscript>You need to enable JavaScript to run this app.</noscript>
11+
<script type="text/javascript" src="$:hyperfiddle.client.module/main$"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)