-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from DanThiffault/UpgradeLibs
Removing dependancy on fs lib
- Loading branch information
Showing
8 changed files
with
61 additions
and
64 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,67 @@ | ||
(ns dieter.precompile | ||
(:require [fs] | ||
(:require [clojure.java.io :as io] | ||
[dieter.cache :as cache] | ||
[dieter.path :as path] | ||
[dieter.asset :as asset] | ||
[dieter.settings :as settings])) | ||
|
||
(defn foreach-file | ||
"Iterate through the assets directory" | ||
[dir f] | ||
(fs/walk | ||
dir | ||
(fn [root _ files] | ||
(doseq [filename files] | ||
(f (->> filename | ||
(fs/join root))))))) | ||
(defn relative-path [root file] | ||
(let [absroot (.getCanonicalPath (io/file root)) | ||
absfile (.getCanonicalPath (io/file file)) | ||
root-length (count absroot)] | ||
(.substring absfile (inc root-length)))) | ||
|
||
(defn load-precompiled-assets | ||
"Load any assets already in the cache directory" | ||
[] | ||
(foreach-file | ||
(settings/cache-root) | ||
(fn [cached] | ||
(let [cached (->> cached | ||
(path/relative-path (settings/cache-root)) | ||
(str "/")) | ||
uncached (->> cached | ||
(path/uncachify-path))] | ||
(cache/add-cached-uri uncached cached))))) | ||
(->> (settings/cache-root) | ||
file-seq | ||
flatten | ||
(remove #(.isDirectory %)) | ||
(map (fn [cached] | ||
(let [cached (->> cached | ||
(relative-path (settings/cache-root)) | ||
(str "/")) | ||
uncached (->> cached | ||
(path/uncachify-path))] | ||
(cache/add-cached-uri uncached cached)))) | ||
dorun)) | ||
|
||
(defn find-and-cache-asset [& args] | ||
(apply (ns-resolve 'dieter.core 'find-and-cache-asset) args)) | ||
|
||
(defn delete-dir [directory] | ||
(->> directory | ||
io/file | ||
file-seq | ||
flatten | ||
(remove #(= directory (.getPath %1))) | ||
reverse | ||
(map #(.delete %1)) | ||
dorun | ||
)) | ||
|
||
(defn precompile [options] | ||
(settings/with-options options | ||
(-> (settings/cache-root) (fs/join "assets") fs/deltree) | ||
(-> (settings/cache-root) (str "assets") delete-dir) | ||
(if (settings/precompiles) | ||
(doseq [filename (settings/precompiles)] | ||
(->> filename | ||
(find-and-cache-asset))) | ||
(doseq [asset-root (settings/asset-roots)] | ||
(foreach-file | ||
(fs/join asset-root "assets") | ||
(fn [filename] | ||
(try (->> filename | ||
(path/relative-path asset-root) | ||
(->> | ||
(io/file asset-root "assets") | ||
file-seq | ||
flatten | ||
(remove #(.isDirectory %)) | ||
(map (fn [filename] | ||
(try (->> filename | ||
(relative-path asset-root) | ||
(str "./") | ||
(find-and-cache-asset)) | ||
(print ".") | ||
(catch Exception e | ||
(println "Not built" filename))))) | ||
nil)))) | ||
(println "Not built" filename))) | ||
|
||
)) | ||
dorun))))) |
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
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