mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
🎉 Add prefetch builtin templates script
This commit is contained in:
parent
6981d92b11
commit
53d7c4332d
2 changed files with 43 additions and 2 deletions
|
@ -17,5 +17,6 @@ cp scripts/manage.template.sh target/dist/manage.sh;
|
|||
chmod +x target/dist/run.sh;
|
||||
chmod +x target/dist/manage.sh;
|
||||
|
||||
|
||||
|
||||
# Prefetch
|
||||
bb ./scripts/prefetch-templates.clj resources/app/onboarding.edn builtin-templates/
|
||||
cp -r builtin-templates target/dist/
|
||||
|
|
40
backend/scripts/prefetch-templates.clj
Executable file
40
backend/scripts/prefetch-templates.clj
Executable file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env bb
|
||||
|
||||
(require '[babashka.curl :as curl]
|
||||
'[babashka.fs :as fs])
|
||||
|
||||
(defn download-if-needed!
|
||||
[dest data]
|
||||
(doseq [{:keys [id file-uri] :as item} data]
|
||||
(let [file (fs/file dest id)
|
||||
rsp (curl/get file-uri {:as :stream})]
|
||||
|
||||
(when (not= 200 (:status rsp))
|
||||
(println (format "unable to download %s (uri: %s)" id file-uri))
|
||||
(System/exit -1))
|
||||
|
||||
(when-not (fs/exists? (str file))
|
||||
(println (format "=> downloading %s" id))
|
||||
(with-open [output (io/output-stream file)]
|
||||
(io/copy (:body rsp) output))))))
|
||||
|
||||
(defn read-defs-file
|
||||
[path]
|
||||
(with-open [content (io/reader path)]
|
||||
(edn/read-string (slurp content))))
|
||||
|
||||
(let [[path dest] *command-line-args*]
|
||||
(when (or (nil? path)
|
||||
(nil? dest))
|
||||
(println "invalid arguments")
|
||||
(System/exit -1))
|
||||
|
||||
(when-not (fs/exists? path)
|
||||
(println (format "file %s does not exists" path))
|
||||
(System/exit -1))
|
||||
|
||||
(when-not (fs/exists? dest)
|
||||
(fs/create-dirs dest))
|
||||
|
||||
(let [data (read-defs-file path)]
|
||||
(download-if-needed! dest data)))
|
Loading…
Add table
Reference in a new issue