Skip to content

Commit 5e9e585

Browse files
authored
Merge pull request #41 from Quafadas/update_site
2 parents 5abff37 + b581253 commit 5e9e585

33 files changed

+745
-307
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -102,46 +102,47 @@ jobs:
102102
MILL_SONATYPE_PASSWORD: ${{ secrets.PUBLISH_PASSWORD }}
103103
MILL_SONATYPE_USERNAME: ${{ secrets.PUBLISH_USER }}
104104

105-
# site:
106-
# if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/tags/')
107-
# needs: build
108-
# runs-on: ubuntu-latest
109-
# steps:
110-
# - uses: coursier/setup-action@main
111-
# with:
112-
# jvm: temurin@21
113-
# apps: scala-cli
114-
# - uses: actions/checkout@main
115-
# with:
116-
# fetch-depth: 0
117-
# fetch-tags: true
118-
# - run: ./mill site.publishDocs
119-
# - name: Setup Pages
120-
# uses: actions/configure-pages@main
121-
# - uses: actions/upload-artifact@main
122-
# with:
123-
# name: page
124-
# path: out/site/publishDocs.dest
125-
# if-no-files-found: error
126-
127-
# deploy:
128-
# needs: site
129-
# permissions:
130-
# pages: write
131-
# id-token: write
132-
# environment:
133-
# name: github-pages
134-
# url: ${{ steps.deployment.outputs.page_url }}
135-
# runs-on: ubuntu-latest
136-
# steps:
137-
# - uses: actions/download-artifact@main
138-
# with:
139-
# name: page
140-
# path: .
141-
# - uses: actions/configure-pages@main
142-
# - uses: actions/upload-pages-artifact@main
143-
# with:
144-
# path: .
145-
# - name: Deploy to GitHub Pages
146-
# id: deployment
147-
# uses: actions/deploy-pages@main
105+
site:
106+
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
107+
needs: build
108+
runs-on: ubuntu-latest
109+
steps:
110+
- uses: coursier/setup-action@main
111+
with:
112+
jvm: temurin@21
113+
apps: scala-cli
114+
- uses: actions/checkout@main
115+
with:
116+
fetch-depth: 0
117+
fetch-tags: true
118+
- run: ./mill site.siteGen
119+
- name: Setup Pages
120+
uses: actions/configure-pages@main
121+
- uses: actions/upload-artifact@main
122+
with:
123+
name: page
124+
path: out/site/laika/generateSite.dest
125+
if-no-files-found: error
126+
127+
deploy:
128+
if: github.ref == 'refs/heads/main'
129+
needs: site
130+
permissions:
131+
pages: write
132+
id-token: write
133+
environment:
134+
name: github-pages
135+
url: ${{ steps.deployment.outputs.page_url }}
136+
runs-on: ubuntu-latest
137+
steps:
138+
- uses: actions/download-artifact@main
139+
with:
140+
name: page
141+
path: .
142+
- uses: actions/configure-pages@main
143+
- uses: actions/upload-pages-artifact@main
144+
with:
145+
path: .
146+
- name: Deploy to GitHub Pages
147+
id: deployment
148+
uses: actions/deploy-pages@main

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "3.9.7"
1+
version = "3.9.9"
22
project.git = true
33

44
runner.dialect = scala3

build.mill

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
//| mill-jvm-version: 21
2-
//| mill-version: 1.0.3
2+
//| mill-version: 1.0.4
33
//| mvnDeps:
44
//| - com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION
55
//| - com.goyeau::mill-scalafix::0.6.0
6-
7-
8-
package build
6+
//| - io.github.quafadas:millSite_mill1_3.7:0.0.50
97

108
import os.copy.over
119
// import io.github.quafadas.millSite._
1210
import mill._, scalalib._, publish._, scalanativelib._
1311
import mill.scalalib.scalafmt.ScalafmtModule
1412
import mill.util.*
13+
import mill.util.BuildInfo.millVersion
1514

1615
import com.goyeau.mill.scalafix.ScalafixModule
1716
import java.text.Format
18-
// import io.github.quafadas.millSite.SiteModule
17+
import io.github.quafadas.millSite.SiteModule
18+
import mill.util.VcsVersion
1919

2020

2121
object V{
@@ -27,10 +27,13 @@ object V{
2727
val laminar = "17.2.1"
2828
val scalaJsDom = "2.8.1"
2929
val scalaJs = "1.19.0"
30+
val fs2 = "3.11.0"
31+
val millLibs = mvn"com.lihaoyi::mill-libs:$millVersion"
3032
}
3133

3234
trait FormatFix extends ScalafmtModule with ScalafixModule with ScalaModule
3335

36+
3437
trait FormatFixPublish extends ScalaModule with FormatFix with PublishModule{
3538
override def scalaVersion = V.scalaVersion
3639

@@ -67,19 +70,6 @@ trait Testy extends TestModule.Munit with FormatFix {
6770
}
6871

6972

70-
// object site extends SiteModule {
71-
72-
// def scalaVersion = V.scalaVersion
73-
// def unidocDeps = Seq(build.sjsls, build.routes)
74-
// override def unidocTitle = "Scala JS Live Server API"
75-
76-
// override def repoLink = "https://github.com/Quafadas/live-server-scala-cli-js"
77-
78-
// override def latestVersion = "0.2.11"
79-
80-
81-
// }
82-
8373
// SN deps which aren't yet there.
8474
/**
8575
1 targets failed

plugin/package.mill

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package build.plugin
2+
3+
import mill.util.BuildInfo. millBinPlatform
4+
import mill._, scalalib._, publish._
5+
import mill.util.VcsVersion
6+
import build.V
7+
import build.FormatFixPublish
8+
9+
object `package` extends ScalaModule with FormatFixPublish:
10+
def platformSuffix = s"_mill$millBinPlatform"
11+
12+
def scalaVersion = build.V.scalaVersion
13+
14+
def scalaArtefactVersion: Task[String] =
15+
scalaVersion.map(_.split("\\.").take(2).mkString("."))
16+
17+
override def artifactName = "sjsls_plugin"
18+
19+
def mvnDeps = Task{
20+
super.mvnDeps() ++
21+
Seq(
22+
V.millLibs,
23+
mvn"co.fs2:fs2-io_3:${V.fs2}"
24+
)
25+
}
26+
27+
def moduleDeps = Seq(build.sjsls)
28+
29+
def artifactSuffix = s"${platformSuffix()}_${scalaArtefactVersion()}"
30+
31+
def publishVersion = VcsVersion.vcsState().format()
32+
// def publishVersion = "DONTUSEME"
33+
34+
override def pomSettings = Task {
35+
PomSettings(
36+
description = "Mill plugin for mdoc, static site generation",
37+
organization = "io.github.quafadas",
38+
url = "https://github.com/Quafadas/millSite",
39+
licenses = Seq(License.`Apache-2.0`),
40+
versionControl = VersionControl.github("quafadas", "millSite"),
41+
developers = Seq(
42+
Developer("quafadas", "Simon Parten", "https://github.com/quafadas")
43+
)
44+
)
45+
}

plugin/src/refresh_plugin.scala

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package io.github.quafadas
2+
import fs2.concurrent.Topic
3+
4+
import cats.effect.IO
5+
import cats.effect.unsafe.implicits.global
6+
7+
import io.github.quafadas.sjsls.LiveServerConfig
8+
import mill.*
9+
import mill.api.BuildCtx
10+
import mill.api.Task.Simple
11+
import mill.scalajslib.*
12+
import mill.scalajslib.api.Report
13+
implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global
14+
15+
trait ScalaJsRefreshModule extends ScalaJSModule:
16+
17+
lazy val updateServer = Topic[IO, Unit].unsafeRunSync()
18+
19+
def indexHtml = Task {
20+
os.write.over(Task.dest / "index.html", io.github.quafadas.sjsls.vanillaTemplate(withStyles()))
21+
PathRef(Task.dest / "index.html")
22+
}
23+
24+
def assetsDir =
25+
super.moduleDir / "assets"
26+
27+
def withStyles = Task(true)
28+
29+
def assets = Task.Source {
30+
assetsDir
31+
}
32+
33+
def port = Task {
34+
8080
35+
}
36+
37+
def openBrowser = Task {
38+
true
39+
}
40+
41+
def logLevel = Task {
42+
"warn"
43+
}
44+
45+
def dezombify = Task {
46+
true
47+
}
48+
49+
def siteGen = Task {
50+
val assets_ = assets()
51+
val path = fastLinkJS().dest.path
52+
os.copy.over(indexHtml().path, Task.dest / "index.html")
53+
os.copy(assets_.path, Task.dest, mergeFolders = true)
54+
updateServer.publish1(println("publish update")).unsafeRunSync()
55+
(Task.dest.toString(), assets_.path.toString(), path.toString())
56+
57+
}
58+
59+
def lcs = Task.Worker {
60+
val (site, assets, js) = siteGen()
61+
println("Gen lsc")
62+
LiveServerConfig(
63+
baseDir = None,
64+
outDir = Some(js),
65+
port =
66+
com.comcast.ip4s.Port.fromInt(port()).getOrElse(throw new IllegalArgumentException(s"invalid port: ${port()}")),
67+
indexHtmlTemplate = Some(site),
68+
buildTool = io.github.quafadas.sjsls.NoBuildTool(), // Here we are a slave to the build tool
69+
openBrowserAt = "/index.html",
70+
preventBrowserOpen = !openBrowser(),
71+
dezombify = dezombify(),
72+
logLevel = logLevel(),
73+
customRefresh = Some(updateServer)
74+
)
75+
}
76+
77+
def serve = Task.Worker {
78+
79+
println(lcs())
80+
BuildCtx.withFilesystemCheckerDisabled {
81+
new RefreshServer(lcs())
82+
}
83+
}
84+
85+
class RefreshServer(lcs: LiveServerConfig) extends AutoCloseable:
86+
val server = io.github.quafadas.sjsls.LiveServer.main(lcs).allocated
87+
88+
server.map(_._1).unsafeRunSync()
89+
90+
override def close(): Unit =
91+
// This is the shutdown hook for http4s
92+
println("Shutting down server...")
93+
server.map(_._2).flatten.unsafeRunSync()
94+
end close
95+
end RefreshServer
96+
end ScalaJsRefreshModule

site/docs/Configuration/config.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Config
22

3-
The server is a CLI. It has a number of flags that can be used to configure it. Here is the current list of flags and what they do. You can see these flags by running ` --help` in your terminal.
3+
The CLI launches an http server. It has a number of flags that can be used to configure it. Here is the current list of flags and what they do. You can see these flags by running ` --help` in your terminal.
44

5-
```
6-
cs launch io.github.quafadas::sjsls:{{projectVersion}} -- --help
5+
```sh
6+
cs launch io.github.quafadas::sjsls:latest.version -- --help
77

88
```
99

@@ -56,7 +56,7 @@ Fire up a terminal in projectDir
5656
```
5757

5858
```sh
59-
cs launch io.github.quafadas::sjsls:{{projectVersion}}
59+
cs launch io.github.quafadas::sjsls:latest.version
6060
```
6161
This is the classic [viteless](https://github.com/Quafadas/viteless/tree/main) example
6262

@@ -73,7 +73,7 @@ With styles.
7373
Run
7474

7575
```sh
76-
cs launch io.github.quafadas::sjsls:{{projectVersion}} -- --styles-dir --fully/qualified/dir/to/styles
76+
cs launch io.github.quafadas::sjsls:latest.version -- --styles-dir --fully/qualified/dir/to/styles
7777
```
7878

7979
## Did I mention I want a full blown SPA?
@@ -89,7 +89,7 @@ With client side routing under `/app`?
8989
Run
9090

9191
```sh
92-
cs launch io.github.quafadas::sjsls:{{projectVersion}} -- --client-routes-prefix app
92+
cs launch io.github.quafadas::sjsls:latest.version -- --client-routes-prefix app
9393
```
9494

9595
## Stop generating my HTML. I want to bring my own.
@@ -105,7 +105,7 @@ Okay.
105105
```
106106
With
107107
```sh
108-
cs launch io.github.quafadas::sjsls:{{projectVersion}} -- --path-to-index-html fully/qualified/path/to/assets
108+
cs launch io.github.quafadas::sjsls:latest.version -- --path-to-index-html fully/qualified/path/to/assets
109109
```
110110

111111
Note: if you're brining your own html, drop the `--styles` flag - reference `index.less` from your html and read [docs](https://lesscss.org) to get it working in browser.
@@ -134,7 +134,7 @@ With a backend running on `8080` and a frontend on `3000`, it is configured that
134134
Also, we're now using mill. We need to tell the cli the frontend module name and the directory the compiles JS ends up in.
135135

136136
```sh
137-
cs launch io.github.quafadas::sjsls:{{projectVersion}} -- \
137+
cs launch io.github.quafadas::sjsls:latest.version -- \
138138
--path-to-index-html /Users/simon/Code/mill-full-stack/frontend/ui \
139139
--build-tool mill \
140140
--mill-module-name frontend \
@@ -153,7 +153,6 @@ This would serve the static site build with the `docJar` tool.
153153
C:\temp\live-server-scala-cli-js> cs launch io.github.quafadas::sjsls:0.2.0 -- --path-to-index-html C:\\temp\\live-server-scala-cli-js\\out\\site\\live.dest\\site --build-tool none --browse-on-open-at /docs/index.html
154154
```
155155

156-
***
157156
You need to include this javascript script tag in the body html - otherwise no page refresh.
158157

159158
```html
@@ -167,5 +166,4 @@ You need to include this javascript script tag in the body html - otherwise no p
167166
if ("PageRefresh" in msg) location.reload();
168167
});
169168
</script>
170-
```
171-
***
169+
```

site/docs/Configuration/library.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Library
2+
3+
The LiveServerConfig can also accept an `fs2.Topic` as a parameter. This allows any tool which can instantiate an `fs2.Topic` to emit a pulse, which will refresh the client. Have a look at the mill plugin code for details.

site/docs/advantages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Here are the key advantages of this approach:
88

99
- Because there's no seperate ecosystem or NPM to configure, configuring build and CI is a lot easier. No `node_modules` to worry about. I found that this simplicity infected everything around it.
1010

11-
- In terms of performance; NPM dependancies are loaded out the CDN. This is slow the first time - but seriously - check the network browser tools when you refresh the page. The second time they are all served out of browser cache - it takes 0ms. Even better, that cache _survives application redeployment!_. If you pre-load the (fat) "internal-" xxx dependancies scalaJS produces, this combination crushes page load times.
11+
- In terms of performance; NPM dependancies are loaded out the CDN. This is slow the first time, but check the network browser tools when you refresh the page. The second time they are all served out of browser cache - it takes 0ms. Even better, that cache _survives application redeployment!_.
1212

1313
- You can use the same build tool for both backend and frontend, and share code between them.
1414

0 commit comments

Comments
 (0)