-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
52 lines (46 loc) · 1.46 KB
/
main.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
import { assertPlugin } from './src/plugins/asserts.js'
import { Core } from './src/plugins/core.js'
import { feedPlugin } from './src/plugins/feed.js'
import { pagesPlugin } from './src/plugins/pages.js'
import { postPlugin } from './src/plugins/posts.js'
import { existsSync } from 'fs'
import { startServer } from './src/util/utils.js'
import 'https://deno.land/[email protected]/dotenv/load.ts'
async function createConfig() {
const baseConfig = {
dist: import.meta.resolve('./dist/'),
src: import.meta.resolve('./src/'),
website: Deno.env.get('WEBSITE'),
author: Deno.env.get('AUTHOR'),
port: Deno.env.get('PORT'),
version: Math.floor(Math.random() * 1000000),
}
const header = await Deno.readTextFile(
new URL('./util/header.html', baseConfig.src),
)
const footer = await Deno.readTextFile(
new URL('./util/footer.html', baseConfig.src),
)
return { ...baseConfig, header, footer }
}
const config = await createConfig()
async function main() {
if (existsSync(new URL(config.dist))) {
Deno.removeSync(new URL(config.dist), { recursive: true })
}
const core = new Core()
core.use(postPlugin)
core.use(assertPlugin)
core.use(feedPlugin)
core.use(pagesPlugin)
await core.runHook('beforeBuild', config)
await core.runHook('afterBuild', config)
}
// Handle the http server
const mode = Deno.env.get('MODE')
if (mode === 'DEV' || mode === 'PRO') {
main()
}
if (mode === 'DEV' || mode === 'PRE') {
startServer(config.port)
}