Skip to content

Commit

Permalink
adding new functions related to storage file; bump 0.1.1-a2
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Dec 13, 2018
1 parent b5b8c0c commit 64bca2a
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 202 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ Cumulo Util (WIP)
[![Clojars Project](https://img.shields.io/clojars/v/cumulo/util.svg)](https://clojars.org/cumulo/util)

```edn
[cumulo/util "0.1.0-a2"]
[cumulo/util "0.1.1-a2"]
```

```clojure
(cumulo-util.core/find-first "x" ["x" "y"])
(cumulo-util.core/get-env! x) ; reading process.env[x]

(cumulo-util.file/write-mildly! "a.text" "content")
(cumulo-util.file/get-backup-path!)
(cumulo-util.file/merge-local-edn! {} "a.edn" (fn [found?] (println found?)))
```

### License
Expand Down
178 changes: 178 additions & 0 deletions calcit.edn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion meyvn.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{:pom {:group-id "cumulo",
:artifact-id "util",
:version "0.1.0",
:version "0.1.1-a2",
:name "Util functions for Cumulo projects"}
:packaging {:jar {:enabled true
:remote-repository {:id "clojars"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Cumulo Workflow",
"main": "index.js",
"scripts": {
"watch": "shadow-cljs watch app",
"watch": "shadow-cljs watch app"
},
"repository": {
"type": "git",
Expand All @@ -14,7 +14,7 @@
"license": "MIT",
"dependencies": {},
"devDependencies": {
"shadow-cljs": "^2.7.8",
"shadow-cljs": "^2.7.9",
"source-map-support": "^0.5.9",
"ws": "^6.1.2"
}
Expand Down
21 changes: 20 additions & 1 deletion src/cumulo_util/file.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@

(ns cumulo-util.file (:require ["path" :as path] ["fs" :as fs] ["child_process" :as cp]))
(ns cumulo-util.file
(:require ["path" :as path]
["fs" :as fs]
["child_process" :as cp]
[cljs.reader :refer [read-string]]))

(defn get-backup-path! []
(let [now (js/Date.)]
(path/join
js/__dirname
"backups"
(str (inc (.getMonth now)))
(str (.getDate now) "-snapshot.edn"))))

(defn merge-local-edn! [x0 filepath handler]
(merge
x0
(let [found? (fs/existsSync filepath)]
(if (fn? handler) (handler found?))
(if found? (read-string (fs/readFileSync filepath "utf8")) nil))))

(defn write-mildly! [file-path content]
(let [do-write! (fn []
Expand Down

0 comments on commit 64bca2a

Please sign in to comment.