Last active
January 26, 2022 15:03
-
-
Save ajchemist/c6a170afee5305c9211d4b3f9ce7282f to your computer and use it in GitHub Desktop.
This file contains 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
(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