poly
Search…
Base
A base is similar to a component except for two things:
  • It doesn't have an interface.
  • It exposes a public API to the outside world.
The lack of an interface makes bases less composable compared to components. This is okay because they serve a different purpose which is to be a bridge between the real world and the components the base delegates to. This gives us the modularity and structure we need to build simple and understandable services and tools.
Let's create the cli base to see how it works, by executing the create base command:
1
poly create base name:cli
Copied!
Our workspace should now look like this:
1
example
2
├── bases
3
│ └── cli
4
│ ├── deps.edn
5
│ ├── resources
6
│ │ └── cli
7
│ ├── src
8
│ │ └── se
9
│ │ └── example
10
│ │ └── cli
11
│ │ └── core.clj
12
│ └── test
13
│ └── se
14
│ └── example
15
│ └── cli
16
│ └── core_test.clj
17
├── components
18
│ └── user
19
│ ├── deps.edn
20
│ ├── resources
21
│ │ └── user
22
│ ├── src
23
│ │ └── se
24
│ │ └── example
25
│ │ └── user
26
│ │ ├── core.clj
27
│ │ └── interface.clj
28
│ └── test
29
│ └── se
30
│ └── example
31
│ └── user
32
│ └── interface_test.clj
33
├── deps.edn
34
├── development
35
│ └── src
36
│ └── dev
37
│ └── lisa.clj
38
├── logo.png
39
├── projects
40
├── readme.md
41
└── workspace.edn
Copied!
Now we need to update ./deps.edn with our newly created base:
1
:aliases {:dev {:extra-paths ["development/src"
2
"components/user/src"
3
"components/user/resources"
4
"bases/cli/src"
5
"bases/cli/resources"]
6
:extra-deps {org.clojure/clojure {:mvn/version "1.10.1"}
7
org.clojure/tools.deps.alpha {:mvn/version "0.12.1003"}}}
8
9
:test {:extra-paths ["components/user/test"
10
"bases/cli/test"]}
Copied!
...and add some code to it:
1
(ns se.example.cli.core
2
(:require [se.example.user.interface :as user])
3
(:gen-class))
4
5
(defn -main [& args]
6
(println (user/hello (first args)))
7
(System/exit 0))
Copied!
Here we added the -main function that will later be called from the command line. The (:gen-class) statement tells the compiler to generate a Java class for us when the code is compiled.
A deps.edn file was also created with this content:
1
{:paths ["src" "resources"]
2
:deps {}
3
:aliases {:test {:extra-paths ["test"]
4
:extra-deps {}}}}
Copied!
This config file is identical to the user config file, and will soon be needed when we create a project that includes it.
The next thing we want to do is to build an artifact that will turn the code into something useful, a command-line tool. To do that, we need to start by creating a project.
Last modified 1mo ago
Copy link