-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·57 lines (42 loc) · 1.03 KB
/
index.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
#! /usr/bin/env node
const chalk = require("chalk")
const colors = require("./utils/colors")
const chokidar = require("chokidar")
const fs = require("fs")
const minimist = require("minimist")
const prints = require("./utils/prints")
const server = require("./utils/server")
let args = minimist(process.argv.slice(2))
if (args["help"]) {
prints.printHelp()
}
if (args["port"] === true) {
prints.printError("Missing port number")
process.exit(1)
}
const PORT = args["port"] || 7000
if (args["_"].length > 1) {
prints.printError("More than one file specified")
process.exit(1)
}
if (args["_"].length === 0) {
prints.printHelp()
}
const filepath = args["_"][0]
if (!fs.statSync(filepath).isFile()) {
prints.printError("Not a file")
process.exit(1)
}
const watcher = chokidar.watch(filepath, {
awaitWriteFinish: false,
usePolling: true,
interval: 50,
})
watcher.on("change", () => {
server.update(filepath)
})
watcher.on("error", (err) => {
console.log(err)
})
let newserver = server.fileServer(filepath)
newserver.listen(PORT)