|
145 | 145 |
|
146 | 146 | (defn -transform [?schema options] (m/walk ?schema -walk options)) |
147 | 147 |
|
| 148 | +#?(:clj |
| 149 | + (defn -file-in-kondo-dir [options & paths] |
| 150 | + (apply io/file (into (get options :clj-kondo-dir-path []) paths)))) |
| 151 | + |
| 152 | +(defn -types-dir-name |
| 153 | + "Creates a directory name such as `malli-types-cljs` or `malli-types-clj`." |
| 154 | + [key] |
| 155 | + (str "malli-types-" (name key))) |
| 156 | + |
| 157 | +(defn -config-file-path [key options] |
| 158 | + (-file-in-kondo-dir options ".clj-kondo" "imports" "metosin" (-types-dir-name key) "config.edn")) |
| 159 | + |
148 | 160 | ;; |
149 | 161 | ;; public api |
150 | 162 | ;; |
151 | 163 |
|
| 164 | +(defn clean! |
| 165 | + "Cleans existing configurations from .clj-kondo directory" |
| 166 | + ([options] |
| 167 | + (clean! :clj options)) |
| 168 | + ([key options] |
| 169 | + (.delete (-config-file-path key options)) |
| 170 | + ;; These are remnants from old locations where malli used to store the configuration files |
| 171 | + (.delete (-file-in-kondo-dir options ".clj-kondo" "metosin" (-types-dir-name key) "config.edn")) |
| 172 | + (.delete (-file-in-kondo-dir options ".clj-kondo" "configs" "malli" "config.edn")))) |
| 173 | + |
152 | 174 | (defn transform |
153 | 175 | ([?schema] |
154 | 176 | (transform ?schema nil)) |
|
164 | 186 | ([config key] |
165 | 187 | (save! config key nil)) |
166 | 188 | ([config key options] |
167 | | - (let [cfg-file (apply io/file (conj |
168 | | - (get options :clj-kondo-dir-path []) |
169 | | - ;; Creates a file like malli-types-cljs or malli-types-clj. |
170 | | - ".clj-kondo" "imports" "metosin" (str "malli-types-" (name key)) "config.edn"))] |
171 | | - ;; delete the old files if they exist (does not throw) |
172 | | - (.delete (apply io/file (conj |
173 | | - (get options :clj-kondo-dir-path []) |
174 | | - ".clj-kondo" "metosin" (str "malli-types-" (name key)) "config.edn"))) |
175 | | - (.delete (apply io/file (conj |
176 | | - (get options :clj-kondo-dir-path []) |
177 | | - ".clj-kondo" "configs" "malli" "config.edn"))) |
| 189 | + (let [cfg-file (-config-file-path key options)] |
178 | 190 | (io/make-parents cfg-file) |
179 | 191 | (spit cfg-file (with-out-str (fipp/pprint config {:width 120}))) |
180 | 192 | config)))) |
|
0 commit comments