-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.ls
59 lines (52 loc) · 1.57 KB
/
server.ls
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
t1 = Date.now!
require! <[fs path yargs @plotdb/colors @plotdb/srcbuild]>
lib = path.dirname fs.realpathSync __filename
server = require "#lib/lib/server"
api = require "#lib/api/index"
# TODO legacy support. remove this in future version.
if /\.json$/.exec(process.argv.2 or '') => cfgfile = process.argv.2
else
argv = yargs
.option \root, do
alias: \r
description: "root directory"
type: \string
.option \config, do
alias: \c
description: "config json"
type: \string
.option \port, do
alias: \p
description: "port to listen"
type: \number
.option \open, do
alias: \o
description: "open browser on startup"
type: \bool
.help \help
.alias \help, \h
.check (argv, options) -> return true
.argv
root = argv.r
cfgfile = argv.c or \config.json # TODO legacy default value. set to null in future version.
do-open = argv.o
port = argv.p
# TODO legacy support. remove this in future version.
if !cfgfile => cfgfile = 'config.json'
main = do
opt: {api: api, start-time: t1}
set-opt: (o) -> @opt <<< o
init: ->
server.init @opt
.then ~> srcbuild.i18n(@opt.i18n)
.then (i18n) ~>
srcbuild.lsp({bundle: {configFile: 'bundle.json'}} <<< (@opt.lsp or {}) <<< {base: '.', i18n})
if require.main == module =>
if fs.exists-sync(cfgfile) =>
config = JSON.parse(fs.read-file-sync cfgfile .toString!)
main.set-opt config
if do-open? => main.set-opt {open: do-open}
if port? => main.set-opt {port}
if root? => process.chdir root
main.init!
module.exports = main