Skip to content

Commit

Permalink
Merge pull request #4 from hephaistox/feat/mati/compilation
Browse files Browse the repository at this point in the history
Update compilation and configuration
  • Loading branch information
Kaspazza authored Jan 1, 2024
2 parents cc32c56 + cc72412 commit 0757346
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 63 deletions.
2 changes: 1 addition & 1 deletion bb.edn
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -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"}}
Expand Down
6 changes: 3 additions & 3 deletions docs/code/stats.md
Original file line number Diff line number Diff line change
@@ -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
* clj-test-nb-lines - 1985
* clj-total-nb-lines - 6801
* ratio-in-pct - 41.21
39 changes: 1 addition & 38 deletions src/clj/automaton_core/adapters/deps_edn.clj
Original file line number Diff line number Diff line change
@@ -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 {...}}
Expand Down Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions src/clj/automaton_core/adapters/files.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/clj/automaton_core/repl/portal.clj
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion src/clj/automaton_core/storage/component.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
67 changes: 59 additions & 8 deletions src/cljc/automaton_core/configuration/simple_files.cljc
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
(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]))

#?(:cljs (def ^:private nodejs? (exists? js/require)))

#?(: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."
Expand All @@ -32,15 +69,29 @@
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."
[]
#?(:clj (->> config-file
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))

Expand Down
2 changes: 1 addition & 1 deletion src/cljc/automaton_core/utils/keyword.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/cljs/automaton_core/log/be_log.clj

This file was deleted.

3 changes: 2 additions & 1 deletion test/clj/automaton_core/adapters/edn_utils_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/cljc/automaton_core/adapters/re_test.cljc
Original file line number Diff line number Diff line change
@@ -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])))

Expand Down
5 changes: 3 additions & 2 deletions version.edn
Original file line number Diff line number Diff line change
@@ -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"}
:minor-version 25
:version "0.0.25"}

0 comments on commit 0757346

Please sign in to comment.