55 lines
1.2 KiB
Nim
55 lines
1.2 KiB
Nim
import times, posix, strutils, os
|
|
import strformat
|
|
import times
|
|
import libfswatch
|
|
import std/[streams, osproc]
|
|
|
|
import libfswatch
|
|
import libfswatch/fswatch
|
|
|
|
let file = "/home/floscr/Code/Projects/org-parser/src/js/example/sandbox.nim"
|
|
|
|
var ps: seq[Process]
|
|
|
|
proc compile(path: string) =
|
|
echo "Compiling..."
|
|
let p = startProcess(
|
|
"nim",
|
|
args= [
|
|
"js",
|
|
"--verbosity:0",
|
|
"--hint[Processing]:off",
|
|
"--hint[XDeclaredButNotUsed]:off",
|
|
"--hint[DuplicateModuleImport]:off",
|
|
"--excessiveStackTrace:on",
|
|
"--warning[UnusedImport]:off",
|
|
path,
|
|
],
|
|
options = {poUsePath, poStdErrToStdOut}
|
|
)
|
|
ps.add(p)
|
|
discard p.waitForExit()
|
|
|
|
var line: string
|
|
while p.running() and p.outputStream.readLine(line):
|
|
echo line
|
|
|
|
echo "Compilation Finished"
|
|
p.close()
|
|
ps = @[]
|
|
|
|
proc monitorCallback(event: fsw_cevent, event_num: cuint) =
|
|
echo event_num
|
|
if event_num == 10:
|
|
echo &"""[{times.now().format("yyyy-MM-dd HH:MM:ss")}]: {event.path} was modified. Compiling..."""
|
|
for p in ps:
|
|
p.close()
|
|
ps = @[]
|
|
|
|
compile(file)
|
|
|
|
var mon = newMonitor()
|
|
mon.addPath(file)
|
|
mon.setCallback(monitorCallback)
|
|
mon.start()
|