Watch
This commit is contained in:
@@ -10,5 +10,6 @@ pkgs.mkShell {
|
||||
buildInputs = with pkgs; buildInputs ++ [
|
||||
nim
|
||||
nimlsp
|
||||
fswatch
|
||||
];
|
||||
}
|
||||
|
||||
54
src/js/watch.nim
Normal file
54
src/js/watch.nim
Normal file
@@ -0,0 +1,54 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user