-
-
Save ishideo/e04943475e53cae9c6feff784994a2fa to your computer and use it in GitHub Desktop.
babashka command to watch a folder for changes to .zig-files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
(if *command-line-args* | |
(def in (str (first *command-line-args*))) | |
(do | |
(println "Which bin to run?") | |
(def in (str *input*)))) | |
(println "Watching" "*.zig" "->" (str "./" in)) | |
(require '[babashka.pods :as pods]) | |
(pods/load-pod "pod-babashka-filewatcher") | |
(require '[pod.babashka.filewatcher :as fw]) | |
(def chan (fw/watch "." {:delay-ms 0})) | |
(require '[clojure.core.async :as async]) | |
(loop [] | |
(let [res (async/<!! chan)] | |
#_(prn res) | |
(when (and (#{"write" "create"} (:type res)) | |
(str/ends-with? (:path res) ".zig")) | |
(println (str "\n>> Compiling " (:path res) "...")) | |
(let [{:keys [out err]} (shell/sh "zig" "build-exe" (str in ".zig"))] | |
(when (seq out) | |
(println out)) | |
(when (seq err) | |
(println err))) | |
(let [{:keys [out err]} (shell/sh (str "./" in))] | |
(when (seq out) | |
(println out)) | |
(when (seq err) | |
(println err)))) | |
(recur))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment