-
Notifications
You must be signed in to change notification settings - Fork 5
/
ssgo.ts
89 lines (65 loc) 路 1.83 KB
/
ssgo.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { parse } from "https://deno.land/std@0.129.0/flags/mod.ts"
import { build, init, serve, sitemap, upgrade, watch } from "./src/index.ts"
import {
BUILD_FLAG,
CLEAN_OPTION,
CWD_OPTION,
DEV_FLAG,
HELP_FLAG,
HELP_TEXT,
INIT_FLAG,
SERVE_FLAG,
SITEMAP_OPTION,
UPGRADE_FLAG,
VERSION_FLAG,
} from "./src/constants.ts"
import { checkAreValidCLIOptions, getSecondsFrom, log } from "./src/utils.ts"
import getVersion from "./version.ts"
const t0 = performance.now()
log.info(`ssgo ${getVersion()}`)
const FLAGS = checkAreValidCLIOptions(parse(Deno.args))
const clean = !!FLAGS[CLEAN_OPTION]
if (FLAGS[CWD_OPTION]) {
log.info(`Setting the current working directory to ${FLAGS[CWD_OPTION]}`)
}
switch (true) {
// display version only
case FLAGS["_"].includes(VERSION_FLAG):
break
// display help
case FLAGS["_"].includes(HELP_FLAG):
log.info(HELP_TEXT)
break
// upgrade ssgo version if exists
case FLAGS["_"].includes(UPGRADE_FLAG):
upgrade()
break
// dev: build, watch files and serve
case FLAGS["_"].includes(DEV_FLAG):
build(clean).then(() => {
log.success(`Project started in ${getSecondsFrom(t0)} seconds.`)
// pairs of [WebSockets, IP address]
const listeners: Array<[WebSocket, string]> = []
serve(listeners)
watch(listeners)
})
break
// init: create missing project directories
case FLAGS["_"].includes(INIT_FLAG):
init()
break
// build only
case FLAGS["_"].includes(BUILD_FLAG) || FLAGS["_"].length === 0:
build(true).then(() => {
sitemap(FLAGS[SITEMAP_OPTION])
log.success(`Project built in ${getSecondsFrom(t0)} seconds.`)
})
break
// serve only
case FLAGS["_"].includes(SERVE_FLAG):
serve()
break
// unknow arguments
default:
log.error(`Unknow arguments: '${FLAGS["_"].join(" ")}'`)
}