Skip to content

Commit

Permalink
Delete a base and a system (#40)
Browse files Browse the repository at this point in the history
- Added support for deleting a system
- Added support for deleting a base
- Added a link for slack channel to readme

Co-authored-by: Joakim Tengstrand <[email protected]>
  • Loading branch information
furkan3ayraktar and tengstrand authored May 9, 2020
1 parent 2e9e8a5 commit da2b6cb
Show file tree
Hide file tree
Showing 10 changed files with 626 additions and 22 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject polylith/lein-polylith "0.2.2"
(defproject polylith/lein-polylith "0.2.3"
:description "Polylith - a component based architecture, by Joakim Tengstrand."
:url "https://github.com/tengstrand/lein-polylith"
:license {:name "Eclipse Public License",
Expand Down
33 changes: 27 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ $ lein polylith
```

```
Polylith 0.2.2 (2019-02-14) - https://github.com/tengstrand/lein-polylith
Polylith 0.2.3 (2020-05-09) - https://github.com/tengstrand/lein-polylith

lein polylith CMD [ARGS] - where CMD [ARGS] are:

Expand All @@ -1503,7 +1503,7 @@ $ lein polylith
changes E P [A] Lists changed components, bases or systems.
compile P [A] [S] Compiles changed components, bases and systems.
create X N [F] Creates a component, system or workspace.
delete c N Deletes a component.
delete X N [B] Deletes a component, base or system.
deps [A] Lists dependencies.
diff P [A] [F] Lists all changes since a specific point in time.
help [C] Show this help or help for specified command.
Expand Down Expand Up @@ -1535,6 +1535,9 @@ $ lein polylith
lein polylith create w myworkspace com.my.company
lein polylith create w myworkspace com.my.company -git
lein polylith delete c mycomponent
lein polylith delete b mybase
lein polylith delete s mysystem
lein polylith delete s mysystem mybase
lein polylith deps
lein polylith deps +c
lein polylith deps +f
Expand Down Expand Up @@ -1748,13 +1751,31 @@ Possible problems could for example be that an unsolvable interface declaration

### delete
```
Deletes a component and its interface if no other components use it.
Deletes a component and its interface if no other components use it:

lein polylith delete c NAME
NAME = component to delete
lein polylith delete c[omponent] NAME
NAME = Component name
--------------------------------------------------------
Deletes a base:

lein polylith delete b[ase] NAME
NAME = Base name.
--------------------------------------------------------
Deletes a system (and its base if given):

lein polylith delete s[ystem] NAME [BASE]
NAME = System name.
BASE = Base name.

example:
lein polylith delete c mycomponent
lein polylith delete component mycomponent
lein polylith delete b mybase
lein polylith create base mybase
lein polylith delete s mysystem
lein polylith delete system mysystem
lein polylith delete s mysystem mybase
lein polylith delete system mysystem mybase
```

### deps
Expand Down Expand Up @@ -2012,7 +2033,7 @@ Feel free to contact me:<br><br>
Twitter: @jtengstrand<br>
Email: joakim[dot]tengstrand[at]gmail[dot]com

You can also get in touch with us in the [Polylith forum](https://polylith.freeflarum.com).
You can also get in touch with us in the [Polylith forum](https://polylith.freeflarum.com) or on [Slack](https://clojurians.slack.com/archives/C013B7MQHJQ).

## License

Expand Down
2 changes: 1 addition & 1 deletion src/leiningen/polylith/cmd/create/workspace.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"- The [Polylith Tool documentation](https://github.com/tengstrand/lein-polylith)"
"- The [RealWorld example app documentation](https://github.com/furkan3ayraktar/clojure-polylith-realworld-example-app)"
""
"You can also get in touch with the Polylith Team via our [forum](https://polylith.freeflarum.com)."
"You can also get in touch with the Polylith Team via our [forum](https://polylith.freeflarum.com) or on [Slack](https://clojurians.slack.com/archives/C013B7MQHJQ)."
""
(str "<h1>" name "</h1>")
""
Expand Down
34 changes: 27 additions & 7 deletions src/leiningen/polylith/cmd/delete.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
(ns leiningen.polylith.cmd.delete
(:require [leiningen.polylith.cmd.delete.component :as delete-component]
[leiningen.polylith.cmd.delete.base :as delete-base]
[leiningen.polylith.cmd.delete.system :as delete-system]
[leiningen.polylith.cmd.shared :as shared]))

(defn validate [ws-path cmd component]
(let [components (shared/all-components ws-path)]
(defn validate [ws-path type entity entity2]
(let [components (shared/all-components ws-path)
bases (shared/all-bases ws-path)
systems (shared/all-systems ws-path)]
(cond
(not (shared/component? cmd)) [false "Illegal first argument."]
(not (contains? components component)) [false (str "Component '" component "' does not exist.")]
(not (or (shared/component? type)
(shared/base? type)
(shared/system? type))) [false "Illegal first argument."]
(and (shared/component? type)
(not (contains? components entity))) [false (str "Component '" entity "' does not exist.")]
(and (shared/base? type)
(not (contains? bases entity))) [false (str "Base '" entity "' does not exist.")]
(and (shared/system? type)
(not (contains? systems entity))) [false (str "System '" entity "' does not exist.")]
(and (shared/system? type)
(-> entity2 nil? not)
(not (contains? bases entity2))) [false (str "Base '" entity2 "' does not exist.")]
:else [true])))

(defn execute [ws-path top-dir [cmd component]]
(let [[ok? message] (validate ws-path cmd component)]
(defn execute [ws-path top-dir [type entity entity2]]
(let [[ok? message] (validate ws-path type entity entity2)]
(if ok?
(delete-component/delete ws-path top-dir component)
(do
(when (shared/component? type)
(delete-component/delete ws-path top-dir entity))
(when (shared/base? type)
(delete-base/delete ws-path top-dir entity))
(when (shared/system? type)
(delete-system/delete ws-path top-dir entity entity2)))
(println message))))
24 changes: 24 additions & 0 deletions src/leiningen/polylith/cmd/delete/base.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(ns leiningen.polylith.cmd.delete.base
(:require [leiningen.polylith.cmd.shared :as shared]
[leiningen.polylith.file :as file]))

(defn delete-from-environment [base ns-dir dev-path]
(file/delete-dir (str dev-path "/docs/" base "-readme.md"))
(file/delete-dir (str dev-path "/project-files/bases/" base "-project.clj"))
(file/delete-dir (str dev-path "/resources/" base))
(file/delete-dir (str dev-path "/src/" ns-dir))
(file/delete-dir (str dev-path "/test/" ns-dir)))

(defn delete [ws-path top-dir base]
(let [base-dir (str ws-path "/bases/" base)
base-ns-dir (shared/full-dir-name top-dir base)
dev-dirs (file/directory-names (str ws-path "/environments"))
system-dirs (file/directory-names (str ws-path "/systems"))
env-path (str ws-path "/environments/")
ns-dir (shared/full-dir-name top-dir base)]
(file/delete-dir base-dir)
(doseq [sys-dir system-dirs]
(file/delete-file! (str ws-path "/systems/" sys-dir "/src/" base-ns-dir))
(file/delete-file! (str ws-path "/systems/" sys-dir "/resources/" base)))
(doseq [dev-dir dev-dirs]
(delete-from-environment base ns-dir (str env-path dev-dir)))))
21 changes: 21 additions & 0 deletions src/leiningen/polylith/cmd/delete/system.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns leiningen.polylith.cmd.delete.system
(:require [leiningen.polylith.cmd.shared :as shared]
[leiningen.polylith.file :as file]
[leiningen.polylith.cmd.delete.base :as delete-base]))

(defn delete-from-environment [system ns-dir dev-path]
(file/delete-dir (str dev-path "/docs/" system "-readme.md"))
(file/delete-dir (str dev-path "/project-files/systems/" system "-project.clj"))
(file/delete-dir (str dev-path "/src/" ns-dir))
(file/delete-dir (str dev-path "/test/" ns-dir)))

(defn delete [ws-path top-dir system base]
(let [system-dir (str ws-path "/systems/" system)
dev-dirs (file/directory-names (str ws-path "/environments"))
env-path (str ws-path "/environments/")
ns-dir (shared/full-dir-name top-dir system)]
(when base
(delete-base/delete ws-path top-dir base))
(file/delete-dir system-dir)
(doseq [dev-dir dev-dirs]
(delete-from-environment system ns-dir (str env-path dev-dir)))))
5 changes: 4 additions & 1 deletion src/leiningen/polylith/cmd/help.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
(println " changes E P [A] Lists changed components, bases or systems.")
(println " compile P [A] [S] Compiles changed components, bases and systems.")
(println " create X N [F] Creates a component, system or workspace.")
(println " delete c N Deletes a component.")
(println " delete X N [B] Deletes a component, base or system.")
(println " deps [A] Lists dependencies.")
(println " diff P [A] [F] Lists all changes since a specific point in time.")
;(println " doc [T] Generates system documentation.")
Expand Down Expand Up @@ -70,6 +70,9 @@
(println " lein polylith create w myworkspace com.my.company")
(println " lein polylith create w myworkspace com.my.company -git")
(println " lein polylith delete c mycomponent")
(println " lein polylith delete b mybase")
(println " lein polylith delete s mysystem")
(println " lein polylith delete s mysystem mybase")
(println " lein polylith deps")
(println " lein polylith deps +c")
(println " lein polylith deps +f")
Expand Down
26 changes: 22 additions & 4 deletions src/leiningen/polylith/cmd/help/delete.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
(ns leiningen.polylith.cmd.help.delete)

(defn help []
(println " Deletes a component and its interface if no other components use it.")
(println " Deletes a component and its interface if no other components use it:")
(println)
(println " lein polylith delete c NAME")
(println " NAME = component to delete")
(println " lein polylith delete c[omponent] NAME")
(println " NAME = Component name")
(println " --------------------------------------------------------")
(println " Deletes a base:")
(println)
(println " lein polylith delete b[ase] NAME")
(println " NAME = Base name.")
(println " --------------------------------------------------------")
(println " Deletes a system (and its base if given):")
(println)
(println " lein polylith delete s[ystem] NAME [BASE]")
(println " NAME = System name.")
(println " BASE = Base name.")
(println)
(println " example:")
(println " lein polylith delete c mycomponent"))
(println " lein polylith delete c mycomponent")
(println " lein polylith delete component mycomponent")
(println " lein polylith delete b mybase")
(println " lein polylith create base mybase")
(println " lein polylith delete s mysystem")
(println " lein polylith delete system mysystem")
(println " lein polylith delete s mysystem mybase")
(println " lein polylith delete system mysystem mybase"))
4 changes: 2 additions & 2 deletions src/leiningen/polylith/version.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns leiningen.polylith.version)

(def version "0.2.2")
(def date "2019-02-14")
(def version "0.2.3")
(def date "2020-05-09")
Loading

0 comments on commit da2b6cb

Please sign in to comment.