Skip to content

Commit

Permalink
Add ClojureScript support
Browse files Browse the repository at this point in the history
  • Loading branch information
furkan3ayraktar committed Dec 26, 2024
1 parent 7bf0581 commit 6ca059f
Show file tree
Hide file tree
Showing 24 changed files with 161 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@
(require '~ns-symbol)
(clojure.test/run-tests '~ns-symbol))))

(defn- clj-namespace? [{:keys [file-path]}]
(or (str/ends-with? file-path ".clj")
(str/ends-with? file-path ".cljc")))

(defn brick-test-namespaces [bricks test-brick-names]
(let [brick-name->namespaces (into {} (map (juxt :name #(-> % :namespaces :test))) bricks)]
(into []
(comp (mapcat brick-name->namespaces)
(map :namespace))
test-brick-names)))
(let [brick-name->namespaces (->> bricks
(map (juxt :name #(-> % :namespaces :test)))
(into {}))]
(->> test-brick-names
(mapcat brick-name->namespaces)
(filter clj-namespace?)
(map :namespace)
(into []))))

(defn project-test-namespaces [project-name projects-to-test namespaces]
(when (contains? (set projects-to-test) project-name)
(mapv :namespace (:test namespaces))))
(->> (:test namespaces)
(filter clj-namespace?)
(map :namespace)
(into []))))

(defn components-msg [component-names color-mode]
(when (seq component-names)
Expand Down
11 changes: 5 additions & 6 deletions components/common/src/polylith/clj/core/common/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
[polylith.clj.core.util.interface :as util]
[polylith.clj.core.user-config.interface :as user-config]))

(def cljs? false)

(def entity->short {"w" "w"
"p" "p"
"b" "b"
Expand Down Expand Up @@ -67,11 +65,12 @@
(defn hidden-file? [path]
(str/starts-with? (path->filename path) "."))

(defn filter-clojure-paths [paths]
(defn filter-clojure-paths [ws-dialects paths]
(filterv #(and
(or (str/ends-with? % ".clj")
(and cljs? (str/ends-with? % ".cljs"))
(str/ends-with? % ".cljc"))
(or (str/ends-with? % ".cljc")
(str/ends-with? % ".clj")
(and (contains? ws-dialects "cljs")
(str/ends-with? % ".cljs")))
;; E.g. temporary emacs files might give problems
(not (hidden-file? %)))
paths))
Expand Down
6 changes: 2 additions & 4 deletions components/common/src/polylith/clj/core/common/interface.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
[polylith.clj.core.common.validate-args :as validate-args]
[polylith.clj.core.version.interface :as version]))

(def cljs? core/cljs?)

(def entity->short core/entity->short)
(def entity->long core/entity->long)

Expand Down Expand Up @@ -43,8 +41,8 @@
(defn extract-namespace [suffixed-top-ns ns-to-extract]
(ns-extractor/extract suffixed-top-ns ns-to-extract))

(defn filter-clojure-paths [paths]
(core/filter-clojure-paths paths))
(defn filter-clojure-paths [ws-dialects paths]
(core/filter-clojure-paths ws-dialects paths))

(defn find-base [base-name bases]
(core/find-base base-name bases))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@
(dirs-with-deps-file ws-dir "project")))

(defn read-development-deps-config-file [ws-dir ws-type]
(let [deps-filename (str ws-dir "/deps.edn")]
(let [{:keys [config error]} (deps-reader/read-deps-file deps-filename "deps.edn")]
(if error
{:error error}
(let [message (validator/validate-project-dev-config ws-type config "./deps.edn")]
(if message
{:error message}
{:deps config
:is-dev true
:name "development"
:type "project"
:project-name "development"
:project-dir (str ws-dir "/development")
:project-config-dir ws-dir}))))))
(let [deps-filename (str ws-dir "/deps.edn")
{:keys [config error]} (deps-reader/read-deps-file deps-filename "deps.edn")]
(if error
{:error error}
(let [message (validator/validate-project-dev-config ws-type config "./deps.edn")]
(if message
{:error message}
{:deps config
:is-dev true
:name "development"
:type "project"
:project-name "development"
:project-dir (str ws-dir "/development")
:project-config-dir ws-dir})))))

(defn clean-project-configs [configs]
(mapv #(dissoc %
Expand All @@ -99,12 +99,12 @@
(filter-config-files)))

(defn read-workspace-config-file [ws-dir]
(let [filename-path (str ws-dir "/workspace.edn")]
(let [{:keys [config error]} (deps-reader/read-deps-file filename-path "workspace.edn")]
(if error
{:error error}
(let [message (validator/validate-workspace-config config)]
(if message
{:error (str "Error in ./workspace.edn: " message)
:config config}
{:config config}))))))
(let [filename-path (str ws-dir "/workspace.edn")
{:keys [config error]} (deps-reader/read-deps-file filename-path "workspace.edn")]
(if error
{:error error}
(let [message (validator/validate-workspace-config config)]
(if message
{:error (str "Error in ./workspace.edn: " message)
:config config}
{:config config})))))
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
new-paths
[new-paths]))))

(defn substitute-alias [sources alias->path]
(defn substitute-alias
"If the incoming vector of sources are strings, e.g. ['src' 'resources'] then do nothing,
but if it is an alias, e.g. [:src-paths :resources-paths], then return the substituted values
taken from the alias->path map."
[sources alias->path]
(vec (mapcat #(substitute-if-alias % alias->path)
sources)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[polylith.clj.core.config-reader.ws-root :as ws-root]))

(defn file-exists?
[filename _]
"The second argument is used for test purposes."
[filename _]
(check-file/file-exists? filename))

(defn clean-project-configs [configs]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{:top-namespace "{{top-ns}}"
:interface-ns "interface"
:default-profile-name "default"
:dialects #{"clj"}
:compact-views #{}
:vcs {:name "git"
:auto-add false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
(is (= ["{:top-namespace \"se.example\""
" :interface-ns \"interface\""
" :default-profile-name \"default\""
" :dialects #{\"clj\"}"
" :compact-views #{}"
" :vcs {:name \"git\""
" :auto-add false}"
Expand Down
14 changes: 14 additions & 0 deletions components/util/src/polylith/clj/core/util/interface/dialects.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(ns ^:no-doc polylith.clj.core.util.interface.dialects)

(def valid-dialects #{"clj" "cljs"})

(defn valid-dialect? [dialect]
(contains? valid-dialects dialect))

(defn clean-dialects [dialects]
(let [valid-dialects (if (coll? dialects)
(->> dialects (filter valid-dialect?) (into #{}))
#{})]
(if (empty? valid-dialects)
#{"clj"}
valid-dialects)))
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
[:or project-test-config-schema
vector?]]]) ;; legacy

(def dialect
[:enum "clj" "cljs"])

(def dialects-schema
[:or
[:vector {:min 1} dialect]
[:set {:min 1} dialect]])

(def workspace-schema
[:map
[:vcs {:optional true} [:or string? map?]]
Expand All @@ -69,7 +77,8 @@
[:tag-patterns {:optional true} map?]
[:projects {:optional true}
[:map-of :string project-settings-schema]]
[:test {:optional true} test-runner-config-schema]])
[:test {:optional true} test-runner-config-schema]
[:dialects {:optional true} dialects-schema]])

(defn validate-workspace-config [config]
(-> workspace-schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
[polylith.clj.core.workspace.fromdisk.namespaces-from-disk :as ns-from-disk]
[polylith.clj.core.workspace.fromdisk.non-top-namespace :as non-top-ns]))

(defn read-base [ws-dir ws-type user-home top-namespace ns-to-lib top-src-dir interface-ns brick->settings config]
(defn read-base [ws-dir ws-type ws-dialects user-home top-namespace ns-to-lib top-src-dir interface-ns brick->settings config]
(let [deps-config (:deps config)
base-name (:name config)
base-dir (str ws-dir "/bases/" base-name)
base-src-dirs (brick-dirs/top-src-dirs base-dir top-src-dir deps-config)
base-test-dirs (brick-dirs/top-test-dirs base-dir top-src-dir deps-config)
suffixed-top-ns (common/suffix-ns-with-dot top-namespace)
namespaces (ns-from-disk/namespaces-from-disk ws-dir base-src-dirs base-test-dirs suffixed-top-ns interface-ns)
namespaces (ns-from-disk/namespaces-from-disk ws-dir ws-dialects base-src-dirs base-test-dirs suffixed-top-ns interface-ns)
entity-root-path (str "bases/" base-name)
lib-deps (lib/brick-lib-deps ws-dir ws-type deps-config top-namespace ns-to-lib namespaces entity-root-path user-home)
source-paths (config/source-paths deps-config)
Expand All @@ -32,6 +32,6 @@
:lib-deps lib-deps)))

(defn read-bases
[ws-dir ws-type user-home top-namespace ns-to-lib top-src-dir interface-ns base-dep-configs brick->settings]
(vec (sort-by :name (map #(read-base ws-dir ws-type user-home top-namespace ns-to-lib top-src-dir interface-ns brick->settings %)
[ws-dir ws-type ws-dialects user-home top-namespace ns-to-lib top-src-dir interface-ns base-dep-configs brick->settings]
(vec (sort-by :name (map #(read-base ws-dir ws-type ws-dialects user-home top-namespace ns-to-lib top-src-dir interface-ns brick->settings %)
base-dep-configs))))
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@
[polylith.clj.core.workspace.fromdisk.namespaces-from-disk :as ns-from-disk]
[polylith.clj.core.workspace.fromdisk.interface-defs-from-disk :as defs-from-disk]))

(defn read-component [ws-dir ws-type user-home top-namespace ns-to-lib top-src-dir interface-ns brick->settings config]
(defn read-component [ws-dir ws-type ws-dialects user-home top-namespace ns-to-lib top-src-dir interface-ns brick->settings config]
(let [deps-config (:deps config)
component-name (:name config)
component-dir (str ws-dir "/components/" component-name)
component-top-src-dirs (brick-dirs/top-src-dirs component-dir top-src-dir deps-config)
component-top-test-dirs (brick-dirs/top-test-dirs component-dir top-src-dir deps-config)
interface-path-name (first (mapcat file/directories component-top-src-dirs))
interface-name (common/path-to-ns interface-path-name)
src-dirs (mapv #(str % interface-path-name)
component-top-src-dirs)
suffixed-top-ns (common/suffix-ns-with-dot top-namespace)
namespaces (ns-from-disk/namespaces-from-disk ws-dir component-top-src-dirs component-top-test-dirs suffixed-top-ns interface-ns)
definitions (defs-from-disk/defs-from-disk src-dirs interface-ns)
namespaces (ns-from-disk/namespaces-from-disk ws-dir ws-dialects component-top-src-dirs component-top-test-dirs suffixed-top-ns interface-ns)
definitions (defs-from-disk/defs-from-disk ws-dir top-namespace interface-name (:src namespaces) interface-ns)
entity-root-path (str "components/" component-name)
lib-deps (lib/brick-lib-deps ws-dir ws-type deps-config top-namespace ns-to-lib namespaces entity-root-path user-home)
paths (brick-paths/source-paths component-dir deps-config)
Expand All @@ -41,6 +39,6 @@
:interface (util/ordered-map :name interface-name
:definitions definitions))))

(defn read-components [ws-dir ws-type user-home top-namespace ns-to-lib top-src-dir interface-ns component-dep-configs brick->settings]
(vec (sort-by :name (map #(read-component ws-dir ws-type user-home top-namespace ns-to-lib top-src-dir interface-ns brick->settings %)
(defn read-components [ws-dir ws-type ws-dialects user-home top-namespace ns-to-lib top-src-dir interface-ns component-dep-configs brick->settings]
(vec (sort-by :name (map #(read-component ws-dir ws-type ws-dialects user-home top-namespace ns-to-lib top-src-dir interface-ns brick->settings %)
component-dep-configs))))
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
[polylith.clj.core.config-reader.interface :as config-reader]
[polylith.clj.core.file.interface :as file]
[polylith.clj.core.git.interface :as git]
[polylith.clj.core.path-finder.interface :as path-finder]
[polylith.clj.core.user-config.interface :as user-config]
[polylith.clj.core.user-input.interface :as user-input]
[polylith.clj.core.util.interface :as util]
[polylith.clj.core.util.interface.color :as color]
[polylith.clj.core.user-config.interface :as user-config]
[polylith.clj.core.util.interface.dialects :as dialects]
[polylith.clj.core.version.interface :as version]
[polylith.clj.core.path-finder.interface :as path-finder]
[polylith.clj.core.workspace.fromdisk.bases-from-disk :as bases-from-disk]
[polylith.clj.core.workspace.fromdisk.components-from-disk :as components-from-disk]
[polylith.clj.core.workspace.fromdisk.profile :as profile]
[polylith.clj.core.workspace.fromdisk.projects-from-disk :as projects-from-disk]
[polylith.clj.core.workspace.fromdisk.tag-pattern :as tag-pattern]
[polylith.clj.core.workspace.fromdisk.ws-config :as ws-config]
[polylith.clj.core.workspace.fromdisk.ws-reader :as ws-reader]
[polylith.clj.core.workspace.fromdisk.bases-from-disk :as bases-from-disk]
[polylith.clj.core.workspace.fromdisk.projects-from-disk :as projects-from-disk]
[polylith.clj.core.workspace.fromdisk.components-from-disk :as components-from-disk]))
[polylith.clj.core.workspace.fromdisk.ws-reader :as ws-reader]))

(def no-git-repo "NO-GIT-REPO")

Expand Down Expand Up @@ -98,7 +99,7 @@
aliases
user-input
color-mode]
(let [{:keys [vcs top-namespace interface-ns default-profile-name tag-patterns release-tag-pattern stable-tag-pattern ns-to-lib compact-views test bricks]
(let [{:keys [vcs top-namespace interface-ns default-profile-name dialects tag-patterns release-tag-pattern stable-tag-pattern ns-to-lib compact-views test bricks]
:or {vcs {:name "git", :auto-add false}
compact-views {}
default-profile-name "default"
Expand All @@ -108,18 +109,19 @@
empty-character (user-config/empty-character)
m2-dir (user-config/m2-dir)
user-home (user-config/home-dir)
ws-dialects (dialects/clean-dialects dialects)
thousand-separator (user-config/thousand-separator)
user-config-filename (user-config/file-path)
project->settings (:projects ws-config)
ns-to-lib-str (stringify ws-type (or ns-to-lib {}))
[component-configs component-errors] (config-reader/read-brick-config-file ws-dir ws-type "component")
components (components-from-disk/read-components ws-dir ws-type user-home top-namespace ns-to-lib-str top-src-dir interface-ns component-configs bricks)
components (components-from-disk/read-components ws-dir ws-type ws-dialects user-home top-namespace ns-to-lib-str top-src-dir interface-ns component-configs bricks)
[base-configs base-errors] (config-reader/read-brick-config-file ws-dir ws-type "base")
bases (bases-from-disk/read-bases ws-dir ws-type user-home top-namespace ns-to-lib-str top-src-dir interface-ns base-configs bricks)
bases (bases-from-disk/read-bases ws-dir ws-type ws-dialects user-home top-namespace ns-to-lib-str top-src-dir interface-ns base-configs bricks)
name->brick (into {} (comp cat (map (juxt :name identity))) [components bases])
suffixed-top-ns (common/suffix-ns-with-dot top-namespace)
[project-configs project-errors] (config-reader/read-project-config-file ws-dir ws-type)
projects (projects-from-disk/read-projects ws-dir name->brick project->settings user-input user-home suffixed-top-ns interface-ns project-configs)
projects (projects-from-disk/read-projects ws-dir ws-dialects name->brick project->settings user-input user-home suffixed-top-ns interface-ns project-configs)
profiles (profile/profiles ws-dir default-profile-name aliases name->brick user-home)
ws-local-dir (->ws-local-dir ws-dir)
paths (path-finder/paths ws-dir projects profiles)
Expand Down Expand Up @@ -171,7 +173,7 @@
(defn workspace-type [ws-dir ws-config-file deps-config-file]
(if (config-reader/file-exists? ws-config-file :workspace)
:toolsdeps2
(if (config-reader/file-exists? deps-config-file :development)
(when (config-reader/file-exists? deps-config-file :development)
(let [{:keys [deps]} (config-reader/read-development-deps-config-file ws-dir :toolsdeps1)]
(when (:polylith deps)
:toolsdeps1)))))
Expand All @@ -197,7 +199,6 @@
:else (toolsdeps-ws-from-disk ws-name ws-type ws-dir ws-config aliases user-input color-mode))))))

(comment
(require '[polylith.clj.core.user-input.interface :as user-input])
(def user-input (user-input/extract-arguments ["info" "ws-dir:../sandbox/slask/fresh"]))
(def workspace (workspace-from-disk user-input))
(workspace-from-disk user-input)
Expand Down
Loading

0 comments on commit 6ca059f

Please sign in to comment.