This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtailwind_module.sc
68 lines (52 loc) · 1.61 KB
/
tailwind_module.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// format: off
import $file.build_utils
import build_utils.BuildUtils
import $file.npm_run
import npm_run.NpmRunModule
// format: on
import mill._
import mill.scalajslib.ScalaJSModule
import mill.scalalib._
import os.Path
trait TailwindModule extends ScalaJSModule with NpmRunModule {
def projectRoot: Path
private lazy val isProd =
sys.env.getOrElse("PROD", "false").equalsIgnoreCase("true")
def tailwindSources = T.sources(millSourcePath / "tailwind")
def pkgServer = {
val bundleJS =
if (isProd) T.task {
rollupJS().path
}
else
T.task {
fastOpt().path
}
T {
val dir = T.dest
BuildUtils.copySources(resources().map(_.path), dir)
os.copy.over(bundleJS(), dir / "insight.js")
os.copy.into(tailwind().path, dir)
PathRef(dir)
}
}
def rollupJS = T {
def dir = T.dest
val fileRef =
s"""const file = '${fullOpt().path.toIO.getAbsolutePath}'
|module.exports = file""".stripMargin
BuildUtils.cloneDirectory(npmInstall().path, dir)
os.write.over(dir / "jsfile.js", fileRef.getBytes())
runAndWait(Seq("yarn", "install", "--force"), Map.empty, dir)
runAndWait(Seq("npx", "rollup", "-c"), Map.empty, dir)
PathRef(dir)
}
def tailwind = T {
val dir = T.dest
BuildUtils.cloneDirectory(npmInstall().path, dir)
runAndWait(Seq("yarn", "install", "--force"), Map.empty, dir)
BuildUtils.copySources(tailwindSources().map(_.path), dir)
runAndWait(Seq("npx", "tailwindcss", "-i", "./input.css", "-o", "insight.css"), Map.empty, dir)
PathRef(dir / "insight.css")
}
}