-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
63 lines (54 loc) · 1.53 KB
/
build.js
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
import fs from 'fs'
import path from 'path'
import { Liquid } from 'liquidjs'
import CleanCss from 'clean-css'
import esbuild from 'esbuild'
// es-build of src/index.js
async function js() {
const result = await esbuild.build({
entryPoints: ["src/index.js"],
write: false,
bundle: true,
})
const [indexJs] = result.outputFiles
return indexJs.text
}
async function css() {
const directory = await fs.promises.readdir("src/css", {
withFileTypes: true
})
const cssFiles = directory
.filter(f => f.isFile())
.map(f => f.name)
.map(filename => path.join("src/css", filename))
const cssOutput = await (new CleanCss({
returnPromise: true
})).minify([
"node_modules/reveal.js/dist/reset.css",
"node_modules/reveal.js/dist/reveal.css",
...cssFiles
])
return cssOutput.styles
}
async function main() {
try {
await fs.promises.access("docs", fs.constants.R_OK | fs.constants.W_OK)
} catch (_) {
console.log("Creating docs directory")
await fs.promises.mkdir("docs")
} finally {
// clean`/docs` folder if exists
console.log("Cleaning docs")
await fs.promises.rm("docs/index.html", { force: true })
}
const liquid = new Liquid({
root: "src",
extname: ".html"
})
const [INLINE_JS, INLINE_CSS] = await Promise.all([js(), css()])
const htmlStream = await liquid.renderFileToNodeStream("index", { INLINE_CSS, INLINE_JS })
await fs.promises.writeFile("docs/index.html", htmlStream)
console.log("Updated docs/index.html")
}
await main()
export default main