Fork me on GitHub
#cljsrn
<
2024-08-06
>
hadils19:08:24

Thanks @joshmiller. I wrote a babashka script to do the same thing:

#!/usr/bin/env bb

(ns preprocess
  (:require [ :as io]
            [clojure.string :as str]))

(defn preprocess-file [file-path]
  (println file-path)
  (let [content (slurp file-path)
        preprocessed-content #_(str/replace content #"(\b[a-zA-Z_]\w*)!(\w*\b)" "$1_$2")
        (str/replace content "!$" "_$")]
    (spit file-path preprocessed-content)))

(defn preprocess-dir [dir-path]
  (let [dir (io/file dir-path)]
    (doseq [file (.listFiles dir)]
      (if (.isFile file)
        (let [file-name (.getName file)]
          (when (str/ends-with? file-name ".js")
            (preprocess-file (.getPath file))))
        (preprocess-dir (.getPath file))))))
 
(defn -main [& args]
  (println args)
  (let [target-dir (ffirst args)]
    (println target-dir)
    (preprocess-dir target-dir)))

(when (first *command-line-args*)
  (-main *command-line-args*))
this would be run after the compilation phase, as you have done. Your solution is simpler, though.

👍 1
joshmiller19:08:20

I don’t want to take too much credit, I made ChatGPT tell me how to use find/sed

hadils19:08:15

That’s what it’s for! Take the credit.👍