This commit is contained in:
Florian Schroedl
2022-05-04 17:00:00 +02:00
parent 8b21ffc334
commit 20c183910d
2 changed files with 55 additions and 0 deletions

View File

@@ -10,5 +10,6 @@ pkgs.mkShell {
buildInputs = with pkgs; buildInputs ++ [
nim
nimlsp
fswatch
];
}

54
src/js/watch.nim Normal file
View 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()