-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_install.cljs
49 lines (38 loc) · 1.18 KB
/
post_install.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(ns post-install
(:require ["dashify$default" :as dashify]
["fs" :refer [readFileSync writeFileSync mkdirSync rmSync]]
[cljs.pprint :refer [pprint]]
[clojure.string :as str]))
(defn file->str
[filename]
(str (readFileSync filename)))
(def project-name
(->> (file->str "app.json")
(.parse js/JSON)
(.-name)
dashify))
(def build-edn
(let [new-edn (-> (file->str "build.edn")
read-string
(assoc :main (symbol (str project-name ".core"))))]
(-> (with-out-str (pprint new-edn))
(str/replace "," "\n"))))
(writeFileSync "build.edn" build-edn)
(def core-cljs
(-> (file->str "src/project_name/core.cljs")
(str/replace "project-name" project-name)))
(def folder-name
(str "src/" (str/replace project-name "-" "_")))
(mkdirSync folder-name)
(writeFileSync
(str folder-name "/core.cljs")
core-cljs)
(rmSync "src/project_name" #js {:recursive true})
(def package-json
(-> (readFileSync "package.json")
str
js/JSON.parse
js->clj
(update "scripts" dissoc "postinstall")
clj->js))
(writeFileSync "package.json" (js/JSON.stringify package-json nil 2))