diff --git a/bb.edn b/bb.edn index 9baab3a3..b5a647b9 100644 --- a/bb.edn +++ b/bb.edn @@ -1,4 +1,4 @@ -{:deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.9"}} +{:deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.70"}} :paths [] :tasks {:requires [[automaton-build-app.tasks.launcher.bb-entrypoint :as build-task-bb-entrypoint] [babashka.process :as babahska-process]] heph-task {:doc "Launch an Hephaistox task" diff --git a/deps.edn b/deps.edn index 45756bc0..1fce99b6 100644 --- a/deps.edn +++ b/deps.edn @@ -1,5 +1,5 @@ -{:aliases {:bb-deps {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.9"}}} - :build {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.9"}}} +{:aliases {:bb-deps {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.70"}}} + :build {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.70"}}} :cljs-deps {:extra-deps {binaryage/devtools {:mvn/version "1.0.7"} cider/cider-nrepl {:mvn/version "0.30.0"} thheller/shadow-cljs {:mvn/version "2.26.2"}} diff --git a/docs/code/stats.md b/docs/code/stats.md index e9b05a18..751adf78 100644 --- a/docs/code/stats.md +++ b/docs/code/stats.md @@ -1,4 +1,4 @@ # That statistics counts number of line of code -* clj-test-nb-lines - 992 -* clj-total-nb-lines - 3406 -* ratio-in-pct - 41.09 \ No newline at end of file +* clj-test-nb-lines - 1985 +* clj-total-nb-lines - 6801 +* ratio-in-pct - 41.21 \ No newline at end of file diff --git a/src/clj/automaton_core/adapters/deps_edn.clj b/src/clj/automaton_core/adapters/deps_edn.clj index 6c260bb9..aa4f0e3a 100644 --- a/src/clj/automaton_core/adapters/deps_edn.clj +++ b/src/clj/automaton_core/adapters/deps_edn.clj @@ -1,41 +1,12 @@ (ns automaton-core.adapters.deps-edn "Proxy to deps.edn file" (:require [automaton-core.adapters.edn-utils :as edn-utils] - [automaton-core.adapters.files :as files] - [automaton-core.log :as core-log])) + [automaton-core.adapters.files :as files])) (def deps-edn "deps.edn") -(defn get-deps-filename - "Get the deps-file of the application - Params: - * `app-dir` is where the application is stored" - [app-dir] - (files/create-file-path app-dir deps-edn)) - (defn load-deps "Load the current project `deps.edn` files" [] (edn-utils/read-edn deps-edn)) -(defn load-deps-edn - "Load the deps.edn file of the app, passed as a parameter, - Params: - * `app-dir` the directory of the app, where `deps.edn` is stored - Returns nil if the file does not exists or is malformed" - [app-dir] - (let [deps-filename (get-deps-filename app-dir)] (when (files/is-existing-file? deps-filename) (edn-utils/read-edn deps-filename)))) - -(defn update-commit-id - "Update the `deps-edn` with the `commit-id` for the dependency `as-lib` - Params: - * `as-lib` is the symbol for the library to update - * `commit-id` is the sha of the commit - * `deps-edn` is the content of the file" - [as-lib commit-id deps-edn] - (if-let [old-commit-id (get-in deps-edn [:deps as-lib :sha])] - (if (= commit-id old-commit-id) - (do (core-log/trace "Skip update as it already uptodate") deps-edn) - (do (core-log/trace "Change commit from `" old-commit-id "` to `" commit-id "`") (assoc-in deps-edn [:deps as-lib :sha] commit-id))) - (do (core-log/trace "Skip as it does not use lib `%s:%s`") deps-edn))) - (defn extract-paths "Extracts the `:paths` and `:extra-paths` from a given `deps.edn` e.g. {:run {...}} @@ -97,14 +68,6 @@ keys vec)) -(defn spit-deps-edn - "Spit `content` in the filename path - Params: - * `app-dir` - * `content`" - ([app-dir content header] (edn-utils/spit-edn (get-deps-filename app-dir) content header)) - ([app-dir content] (spit-deps-edn app-dir content nil))) - (defn update-dep-local-root "Update the local root directories in a dependency map (of one lib) After the update, the local root path will be relative and starting from `base-dir` diff --git a/src/clj/automaton_core/adapters/files.clj b/src/clj/automaton_core/adapters/files.clj index f4e143fb..ca9e1328 100644 --- a/src/clj/automaton_core/adapters/files.clj +++ b/src/clj/automaton_core/adapters/files.clj @@ -319,6 +319,7 @@ (defn file-name "Return the file name without the path" [path] (fs/file-name path)) (defn relativize + "Turn the `path` into a relative directory starting from `root-dir`" [path root-dir] (let [path (-> path remove-trailing-separator diff --git a/src/clj/automaton_core/repl/portal.clj b/src/clj/automaton_core/repl/portal.clj index 94b554f6..0ee26c53 100644 --- a/src/clj/automaton_core/repl/portal.clj +++ b/src/clj/automaton_core/repl/portal.clj @@ -1,10 +1,10 @@ #_{:heph-ignore {:forbidden-words ["tap>"]}} (ns automaton-core.repl.portal - (:require [automaton-core.configuration :as core-conf] + (:require [automaton-core.configuration :as conf] [portal.api :as p] [portal.client.jvm :as p-client])) -(def default-port (core-conf/read-param [:dev :portal-port])) +(def default-port (conf/read-param [:dev :portal-port])) (def submit #'p/submit) @@ -15,7 +15,7 @@ Params: * `port` (optional) defaults to def `default-port`, it is a port on which portal app can be found." ([] (client-connect default-port)) - ([port] (core-conf/read-param [:app-name]) (add-tap (client-submit port)) (tap> "Client connected"))) + ([port] (conf/read-param [:app-name]) (add-tap (client-submit port)) (tap> "Client connected"))) (defn portal-connect "Regular portal add-tap fn proxy." [] (add-tap #'submit)) diff --git a/src/clj/automaton_core/storage/component.clj b/src/clj/automaton_core/storage/component.clj index 58ddf274..4cba45e6 100644 --- a/src/clj/automaton_core/storage/component.clj +++ b/src/clj/automaton_core/storage/component.clj @@ -11,7 +11,7 @@ [] (try (core-log/info "Starting storage component") (let [dc (datomic/make-datomic-client datomic-schema/all-schema) - db-uri (conf/read-param [:storage :datomic :url]) + db-uri (or (conf/read-param [:storage :datomic :url]) (conf/read-param [:storage-datomic-url])) _db-uri-valid? (when-not db-uri (throw (ex-info "Database uri was not found." {}))) conn (storage/connection dc db-uri) access (datomic/make-datomic-access)] diff --git a/src/cljc/automaton_core/adapters/re.cljc b/src/cljc/automaton_core/adapters/regexp.cljc similarity index 97% rename from src/cljc/automaton_core/adapters/re.cljc rename to src/cljc/automaton_core/adapters/regexp.cljc index fae60b21..55d406fc 100644 --- a/src/cljc/automaton_core/adapters/re.cljc +++ b/src/cljc/automaton_core/adapters/regexp.cljc @@ -1,4 +1,4 @@ -(ns automaton-core.adapters.re +(ns automaton-core.adapters.regexp "Adapter to regular expressions Seamless access to regular expressions between cljs and clj Managing both back and frontend to have a seamless experience" diff --git a/src/cljc/automaton_core/configuration/simple_files.cljc b/src/cljc/automaton_core/configuration/simple_files.cljc index cce9d37b..120dab74 100644 --- a/src/cljc/automaton_core/configuration/simple_files.cljc +++ b/src/cljc/automaton_core/configuration/simple_files.cljc @@ -1,10 +1,9 @@ (ns automaton-core.configuration.simple-files "Namespace for simple configuration based on local file. Just like in core configuration, we are not using log nor outside dependencies to comply with the configuration requirements." - (:require #?(:clj [clojure.edn :as edn] - :cljs [cljs.reader :as edn]) - #?@(:clj [[clojure.java.io :as io] [automaton-core.adapters.java-properties :as java-properties] - [automaton-core.utils.map :as utils-map]]) + (:require #?@(:clj [[clojure.edn :as edn] [clojure.java.io :as io] [automaton-core.adapters.java-properties :as java-properties]] + :cljs [[cljs.reader :as edn] [goog.object :as obj]]) + [automaton-core.utils.map :as utils-map] [automaton-core.configuration.protocol :as core-conf-prot] [automaton-core.utils.keyword :as utils-keyword])) @@ -12,10 +11,48 @@ #?(:cljs (def ^:private fs (when nodejs? (js/require "fs")))) +#?(:cljs (def ^:private process (when nodejs? (js/require "process")))) + +(defn parse-number + [^String v] + (try #?(:clj (Long/parseLong v) + :cljs (parse-long v)) + #?(:clj (catch NumberFormatException _ (BigInteger. v))) + (catch #?(:clj Exception + :cljs js/Error) + _ + v))) + +(defn str->value + "ENV vars and system properties are strings. str->value will convert: + the numbers to longs, the alphanumeric values to strings, and will use Clojure reader for the rest + in case reader can't read OR it reads a symbol, the value will be returned as is (a string)" + [v] + (cond (re-matches #"[0-9]+" v) (parse-number v) + (re-matches #"^(true|false)$" v) #?(:clj (Boolean/parseBoolean v) + :cljs (parse-boolean v)) + (re-matches #"\w+" v) v + :else (try (let [parsed (edn/read-string v)] (if (symbol? parsed) v parsed)) + (catch #?(:clj Exception + :cljs js/Error) + _ + v)))) + +(defn read-system-env + [] + (->> #?(:clj (System/getenv) + :cljs (zipmap (obj/getKeys (.-env process)) (obj/getValues (.-env process)))) + (map (fn [[k v]] [(utils-keyword/keywordize k) (str->value v)])) + (into {}))) + (defn slurp-file [f] - #?(:clj (when-let [f (io/file f)] (when (.exists f) (slurp f))) - :cljs (when ^js (.existsSync fs f) (str ^js (.readFileSync fs f))))) + (try #?(:clj (when-let [file (or (io/resource f) (io/file f))] (slurp file)) + :cljs (when ^js (.existsSync fs f) (str ^js (.readFileSync fs f)))) + (catch #?(:clj Exception + :cljs js/Error) + _ + (println (str "Reading file" f " failed"))))) (defn read-config-file "Reads config file, on purpose fn defined here to keep dependencies as small as possible." @@ -32,6 +69,17 @@ java-properties/get-java-property java-properties/split-property-value))) +(defn- warn-on-overwrite + [ms] + (doseq [[k kvs] (group-by key (apply concat ms)) + :let [vs (map val kvs)] + :when (and (next kvs) (not= (first vs) (last vs)))] + (println "WARNING: configuration keys are duplicated" + {:k k + :vs vs}))) + +(defn merge-configs [& m] (warn-on-overwrite m) (apply utils-map/deep-merge m)) + (defn read-config "Reads configuration, currently it's based on config.edn file. On js part, if nodejs is not available to get the configuration from file. If used with js, config-js-reference variable is expected to be set publicly." [] @@ -39,8 +87,11 @@ property->config-files (mapv read-config-file) (filterv some?) - (apply utils-map/deep-merge)) - :cljs (when nodejs? (read-config-file config-file)))) + (apply merge-configs (read-system-env))) + :cljs (if nodejs? + (->> (read-config-file config-file) + (merge-configs (read-system-env))) + {}))) (def ^{:doc "A map of configuration variables."} conf (memoize read-config)) diff --git a/src/cljc/automaton_core/utils/keyword.cljc b/src/cljc/automaton_core/utils/keyword.cljc index 7d960ed3..b3527236 100644 --- a/src/cljc/automaton_core/utils/keyword.cljc +++ b/src/cljc/automaton_core/utils/keyword.cljc @@ -2,7 +2,7 @@ "Utility functions for keywords." (:require [clojure.string :as str])) -(defn- keywordize +(defn keywordize "Change string to appropriate clojure keyword" [s] (-> (str/lower-case s) diff --git a/src/cljs/automaton_core/log/be_log.clj b/src/cljs/automaton_core/log/be_log.clj deleted file mode 100644 index bf38ee30..00000000 --- a/src/cljs/automaton_core/log/be_log.clj +++ /dev/null @@ -1 +0,0 @@ -(ns automaton-core.log.be-log "This namespace is here just to make the shadow-cljs compiler happy in `automaton-core.log`") diff --git a/test/clj/automaton_core/adapters/edn_utils_test.clj b/test/clj/automaton_core/adapters/edn_utils_test.clj index 41aa61f9..cb3a8570 100644 --- a/test/clj/automaton_core/adapters/edn_utils_test.clj +++ b/test/clj/automaton_core/adapters/edn_utils_test.clj @@ -32,7 +32,8 @@ (is (= {10 20} (sut/read-edn tmp-file))) (sut/spit-edn tmp-file {15 25}) (is (= {15 25} (sut/read-edn tmp-file))) - (sut/spit-edn tmp-file {5 5} "Header")))) + (sut/spit-edn tmp-file {5 5} ";;Header") + (is (= {5 5} (sut/read-edn tmp-file)))))) (deftest update-edn-content-test (testing "Update the edn" diff --git a/test/cljc/automaton_core/adapters/re_test.cljc b/test/cljc/automaton_core/adapters/re_test.cljc index 768a2947..67e86ebf 100644 --- a/test/cljc/automaton_core/adapters/re_test.cljc +++ b/test/cljc/automaton_core/adapters/re_test.cljc @@ -1,5 +1,5 @@ (ns automaton-core.adapters.re-test - (:require [automaton-core.adapters.re :as sut] + (:require [automaton-core.adapters.regexp :as sut] #?(:clj [clojure.test :refer [deftest is testing]] :cljs [cljs.test :refer [deftest is testing] :include-macros true]))) diff --git a/version.edn b/version.edn index 13c0a7ae..19a174bb 100644 --- a/version.edn +++ b/version.edn @@ -1,3 +1,4 @@ +;;Last generated version, note a failed push consume a number {:major-version "0.0.-1" - :minor-version 21 - :version "0.0.21"} \ No newline at end of file + :minor-version 25 + :version "0.0.25"} \ No newline at end of file