Skip to content

Commit

Permalink
Prepare 0.2.19 (#429)
Browse files Browse the repository at this point in the history
* Added 'check' to the clj-poly API.
* Added 'check', 'test', and 'test-all' to the clj-poly API.
* Added support for :config-filename in workspace.edn.
* Added note that you should use more unique prefixes if they are exposed outside the workspace.
* Make "lib names" for bricks in projects, globally unique. The reason is that we build the clj-poly library out of it, and that we want to avoid name clashes for people that use the library.
* Removed the examples where we can use c/b/p/w instead of component/base/project/workspace.
* Show a warning that the short form "create c", "create b", "create p", and "create w" are deprecated.
* Remove the :: examples + print deprecation message if used.
* Updated polylith overview image (in production systems in the cljdoc).
  • Loading branch information
tengstrand authored Feb 3, 2024
1 parent 15cd173 commit 748fb9a
Show file tree
Hide file tree
Showing 72 changed files with 666 additions and 495 deletions.
6 changes: 3 additions & 3 deletions bases/poly-cli/src/polylith/clj/core/poly_cli/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
It reads the input from the incoming arguments and delegates to the 'command' component,
that reads the workspace in the read-workspace function in its core namespace:
(-> user-input
ws-clj/workspace-from-disk
ws/enrich-workspace
change/with-changes)
(ws-clj/workspace-from-disk)
(ws/enrich-workspace)
(change/with-changes))
- The first step ws-clj/workspace-from-disk reads the workspace from disk (or file if 'ws-file'
is given).
Expand Down
17 changes: 11 additions & 6 deletions components/api/src/polylith/clj/core/api/core.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns ^:no-doc polylith.clj.core.api.core
(:require [clojure.string :as str]
[polylith.clj.core.change.interface :as change]
[polylith.clj.core.check.interface :as check]
[polylith.clj.core.user-input.interface :as user-input]
[polylith.clj.core.workspace.interface :as ws]
[polylith.clj.core.workspace-clj.interface :as ws-clj]
Expand All @@ -10,9 +11,9 @@
(let [since-then (str "since:" (or since "stable"))
user-input (user-input/extract-arguments ["ws" since-then "skip:development"])
workspace (-> user-input
ws-clj/workspace-from-disk
ws/enrich-workspace
change/with-changes)]
(ws-clj/workspace-from-disk)
(ws/enrich-workspace)
(change/with-changes))]
(-> workspace :changes :changed-or-affected-projects)))

(defn key->str [key]
Expand All @@ -29,9 +30,13 @@
["ws" since-str (str "get:" (str/join ":" keys-str))])
user-input (user-input/extract-arguments args)
workspace (-> user-input
ws-clj/workspace-from-disk
ws/enrich-workspace
change/with-changes)]
(ws-clj/workspace-from-disk)
(ws/enrich-workspace)
(change/with-changes))]
(if (empty? keys-str)
workspace
(ws-explorer/extract workspace keys-str))))

(defn check [since]
(-> (workspace since [])
(check/check)))
41 changes: 35 additions & 6 deletions components/api/src/polylith/clj/core/api/interface.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
All other code that is not part of the public API, is used at your own risk,
and may change in a breaking way between `clj-poly` versions."
(:require [polylith.clj.core.api.core :as core]
[polylith.clj.core.api.test :as test]
[polylith.clj.core.version.interface :as version])
(:gen-class))

Expand All @@ -54,7 +55,8 @@
```
When a new version of the [clj-poly](https://clojars.org/polylith/clj-poly) library is released to Clojars,
any of the three APIs may change version, but the ambition is to never break `:api` and `:test-runner`.
any of the three APIs may change version, but the ambition is to never break `:api` and `:test-runner`
if we make major changes to the workspace structure.
With `:ws` it's different, and we know that the workspace structure will change over time, so pay extra
attention every time you bump `clj-poly` and have a look at the [versions](https://cljdoc.org/d/polylith/clj-poly/CURRENT/doc/versions) page,
Expand All @@ -74,9 +76,35 @@
:test-runner version/test-runner-api-version
:ws version/workspace-version})

(defn check
"Returns true if no error messages + a vector of error messages.
```clojure
{:ok? true
:error-messages []}
```"
[since]
(core/check since))

(defn test
"Runs all tests since the given stable point in time (since).
Additional arguments can be given, e.g.:
```clojure
(test \"stable\" \":all\" \"project:myproject\"
```"
[since & args]
(test/test since args))

(defn test-all
"Runs all tests since the given stable point in time (since), e.g.:
```clojure
(test-all \"stable\"
```"
[since]
(test/test since [":all"]))

(defn projects-to-deploy
"This function returns the projects that have changed (directly or indirectly) since the
_last stable point in time_, and is primarily used to know which projects to build and deploy.
"Returns the projects that have changed (directly or indirectly) since the _last stable point in time_,
and is primarily used to know which projects to build and deploy.
If called with:
```clojure
Expand Down Expand Up @@ -113,14 +141,15 @@
(workspace nil \"settings\" \"interface-ns\")
```
Passing in `since` is only needed if we access things under the `:changes` top key.
Passing in `since` is only needed if we access things under the `:changes` top key
or `:bricks-to-test` and `:projects-to-test` under `:projects`.
Avoid using things under `:configs`, if they can be found in e.g. `:settings`,
`:components`, `:bases`, `:projects`, or elsewhere.
Note that since version `0.2.18` we only publish `clj-poly` to Clojars and not the old `clj-api`."
[stable-point & keys]
(core/workspace stable-point keys))
[since & keys]
(core/workspace since keys))

(comment
(projects-to-deploy nil)
Expand Down
28 changes: 28 additions & 0 deletions components/api/src/polylith/clj/core/api/test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(ns ^:no-doc polylith.clj.core.api.test
(:require [polylith.clj.core.change.interface :as change]
[polylith.clj.core.common.interface :as common]
[polylith.clj.core.test-runner-orchestrator.interface :as test-runner-orchestrator]
[polylith.clj.core.user-input.interface :as user-input]
[polylith.clj.core.workspace-clj.interface :as ws-clj]
[polylith.clj.core.workspace.interface :as ws]))

(defn run-tests [user-input]
(-> user-input
(ws-clj/workspace-from-disk)
(ws/enrich-workspace)
(change/with-changes)
(test-runner-orchestrator/run false "dark"))
{:ok? true})

(defn print-argument-error [message]
(println message)
{:ok? false})

(defn test [since args]
(let [cmd-args (concat ["test" (str "since:" since)] args)
user-input (user-input/extract-arguments cmd-args)
unnamed-args (:unnamed-args user-input)
{:keys [ok? message]} (common/validate-args unnamed-args "test project:dev")]
(if ok?
(run-tests user-input)
(print-argument-error message))))
4 changes: 4 additions & 0 deletions components/check/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:paths ["src"]
:deps {}
:aliases {:test {:extra-paths []
:extra-deps {}}}}
15 changes: 15 additions & 0 deletions components/check/src/polylith/clj/core/check/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns ^:no-doc polylith.clj.core.check.core
(:require [polylith.clj.core.util.interface.color :as color]
[polylith.clj.core.validator.interface :as validator]))

(defn check [{:keys [messages]}]
(let [error-messages (validator/error-messages messages)
ok? (empty? error-messages)]
{:ok? ok?
:error-messages error-messages}))

(defn print-check [{:keys [messages] :as workspace} color-mode]
(let [error-messages (validator/error-messages messages)]
(if (empty? error-messages)
(println (color/ok color-mode "OK"))
(validator/print-messages workspace))))
8 changes: 8 additions & 0 deletions components/check/src/polylith/clj/core/check/interface.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns ^:no-doc polylith.clj.core.check.interface
(:require [polylith.clj.core.check.core :as core]))

(defn check [workspace]
(core/check workspace))

(defn print-check [workspace color-mode]
(core/print-check workspace color-mode))
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
(let [ent (common/entity->short entity)]
(if (= "create" cmd)
(cond
(nil? ent) [false " The first argument after 'create' is expected to be any of: w, p, b, c, workspace, project, base, component."]
(nil? ent) [false " The first argument after 'create' is expected to be any of: base, component, project, workspace."]
(and (base-or-comp? ent)
(contains-char? name ".")) [false " The . character is not allowed in brick names."]
(and (base-or-comp? ent)
Expand All @@ -43,6 +43,6 @@
(and (workspace? ent)
(-> workspace git-repo? not)))) [false (str " A name must be given, e.g.: create " ent " name:" (ent->name ent))]
(and (workspace? ent)
(str/blank? top-ns)) [false (str " A top namespace must be given, e.g.: create " ent " name:" (ent->name ent) " top-ns:com.my-company")]
(str/blank? top-ns)) [false (str " A top namespace must be given, e.g.: create " (common/entity->long ent) " name:" (ent->name ent) " top-ns:com.my-company")]
:else [true])
[true])))
22 changes: 10 additions & 12 deletions components/command/src/polylith/clj/core/command/core.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns ^:no-doc polylith.clj.core.command.core
(:require [clojure.string :as str]
[polylith.clj.core.change.interface :as change]
[polylith.clj.core.check.interface :as check]
[polylith.clj.core.command.cmd-validator.core :as cmd-validator]
[polylith.clj.core.command.create :as create]
[polylith.clj.core.command.dependencies :as dependencies]
Expand All @@ -18,19 +19,13 @@
[polylith.clj.core.shell.interface :as shell]
[polylith.clj.core.tap.interface :as tap]
[polylith.clj.core.util.interface.color :as color]
[polylith.clj.core.validator.interface :as validator]
[polylith.clj.core.version.interface :as ver]
[polylith.clj.core.workspace-clj.interface :as ws-clj]
[polylith.clj.core.workspace.interface :as workspace]
[polylith.clj.core.ws-file.interface :as ws-file]
[polylith.clj.core.ws-explorer.interface :as ws-explorer])
(:refer-clojure :exclude [test]))

(defn check [{:keys [messages] :as workspace} color-mode]
(if (empty? messages)
(println (color/ok color-mode "OK"))
(validator/print-messages workspace)))

(defn diff [workspace]
(doseq [file (-> workspace :changes :changed-files)]
(println file)))
Expand Down Expand Up @@ -86,26 +81,29 @@
(lib/update-libs! workspace)
(lib/print-lib-table workspace)))

(defn execute [{:keys [cmd args alias name top-ns branch help is-local more page ws is-tap is-git-add is-github is-commit is-all is-update is-show-brick is-show-workspace is-show-project is-verbose is-fake-poly get out interface selected-bricks selected-projects unnamed-args ws-file] :as user-input}]
(defn print-deprecation-message [color-mode]
(println (str " The use of :: is " (color/error color-mode "deprecated") " and support for it will probably be dropped in the future. "
"Please contact the Polylith team if you think it's important to keep!")))

(defn execute [{:keys [cmd args alias name top-ns branch help is-local more page ws is-tap is-git-add is-github is-commit is-all is-update is-show-brick is-show-workspace is-show-project is-verbose is-fake-poly is-search-for-ws-dir get out interface selected-bricks selected-projects unnamed-args ws-file] :as user-input}]
(let [color-mode (common/color-mode user-input)
ws-dir (config-reader/workspace-dir user-input)
workspace-fn (workspace-reader-fn)
workspace (workspace-fn user-input ws-file)
[cmd user-input] (with-shell cmd user-input)]
(tap> {:execute cmd
:is-local is-local
:branch branch})
(user-config/create-user-config-if-not-exists)
(when is-tap (tap/execute "open"))
(when is-search-for-ws-dir (print-deprecation-message color-mode))
(let [brick-name (first selected-bricks)
project-name (first selected-projects)
toolsdeps1? (common/toolsdeps1? workspace)
test-result (atom true)
config-filename (or (-> workspace :settings :config-filename) "config.edn")
[ok? message] (cmd-validator/validate workspace user-input color-mode)]
(if ok?
(case cmd
"check" (check workspace color-mode)
"create" (create/create ws-dir workspace args name alias top-ns interface branch is-git-add is-commit color-mode)
"check" (check/print-check workspace color-mode)
"create" (create/create ws-dir workspace args name alias top-ns interface branch is-git-add is-commit config-filename color-mode)
"deps" (dependencies/deps workspace project-name brick-name unnamed-args)
"doc" (doc/open-doc branch is-local is-github help more page ws unnamed-args)
"diff" (diff workspace)
Expand Down
15 changes: 13 additions & 2 deletions components/command/src/polylith/clj/core/command/create.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
(ns ^:no-doc polylith.clj.core.command.create
(:require [polylith.clj.core.common.interface :as common]
[polylith.clj.core.util.interface.color :as color]
[polylith.clj.core.creator.interface :as creator]))

(defn print-error-message [entity-short color-mode]
(println (str " The short form 'create " entity-short "' is " (color/error color-mode "deprecated") " and support for it will be dropped. "
"Please use 'create " (common/entity->long entity-short) "' instead.")))

(defn create [current-dir workspace
[_ entity] name alias top-ns interface branch git-add? commit? color-mode]
[_ entity] name alias top-ns interface branch git-add? commit? config-filename color-mode]
(let [ent (common/entity->short entity)
git-add (if (-> git-add? nil? not)
git-add?
(-> workspace :settings :vcs :auto-add))]
(if (contains? #{"b" "c" "p" "w"} entity)
(print-error-message entity color-mode))
(condp = ent
"w" (creator/create-workspace current-dir name top-ns branch commit?)
"p" (when (= :ok (creator/create-project workspace name alias git-add))
(creator/print-alias-message name alias color-mode))
(creator/print-alias-message name alias config-filename color-mode))
"b" (creator/create-base workspace name git-add)
"c" (creator/create-component workspace name interface git-add))))

(comment
(print-error-message "c" "dark")
#__)
9 changes: 9 additions & 0 deletions components/common/src/polylith/clj/core/common/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"base" "b"
"component" "c"})

(def entity->long {"w" "workspace"
"p" "project"
"b" "base"
"c" "component"
"workspace" "workspace"
"project" "project"
"base" "base"
"component" "component"})

(defn ns-to-path [namespace]
(-> namespace
(str/replace "." "/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[polylith.clj.core.version.interface :as version]))

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

(defn absolute-path [path entity-root-path]
(core/absolute-path path entity-root-path))
Expand Down
Loading

0 comments on commit 748fb9a

Please sign in to comment.