Skip to content

Instantly share code, notes, and snippets.

@ajchemist
Last active January 26, 2022 15:03
Show Gist options
  • Save ajchemist/c6a170afee5305c9211d4b3f9ce7282f to your computer and use it in GitHub Desktop.
Save ajchemist/c6a170afee5305c9211d4b3f9ce7282f to your computer and use it in GitHub Desktop.
(ns build
(:require
[clojure.java.io :as jio]
[clojure.string :as str]
[buddy.core.codecs :as codecs]
[buddy.core.hash :as hash]
))
(set! *warn-on-reflection* true)
(defn module-hash-name
[module]
(subs (str/upper-case (codecs/bytes->hex (hash/md5 (jio/input-stream module)))) 0 8))
(defn rename-file
[a b]
(.renameTo (jio/file a) (jio/file b)))
(defn rename-module-filename
[f]
{:pre [(.isFile (jio/file f))]
:post [(.isFile (jio/file %))]}
(let [file (jio/file f)
parent (.getParent file)
name (.getName file)
idx (str/last-index-of name ".")
target (jio/file parent (str (subs name 0 idx) "." (module-hash-name file) (subs name idx)))]
(rename-file file target)
target))
(comment
(rename-module-filename "/tmp/out.css")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment