tshex-cli 1.0.14 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +156 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tshex-cli",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "author": "https://github.com/virtualitems/",
5
5
  "description": "Typescript Hexagonal Architecture CLI",
6
6
  "type": "module",
package/readme.md CHANGED
@@ -4,15 +4,11 @@ This CLI will help you to generate a hexagonal architecture structure.
4
4
 
5
5
  # Why?
6
6
 
7
- Hexagonal architecture is a software design pattern that separates the internal domain of the application from the external dependencies.. This separation is achieved by dividing the application into layers. Each layer has a specific responsibility and interacts with the other layers in a specific way.
7
+ Hexagonal architecture is a software design pattern that separates the internal domain of the application from the external dependencies. This separation is achieved by dividing the application into layers. Each layer has a specific responsibility and interacts with the other layers in a specific way.
8
8
 
9
- Because what we are trying to achieve is a separation between the domain code and the installed dependencies, a Hexagonal Architecture Framework is a step in the opposite direction, as it couples the domain code with the framework. This is why we need a tool to help us to create the structure with our own codebase.
9
+ The goal is to separate the domain code from installed dependencies. A Hexagonal Architecture _framework_ would work against that goal, since it couples the domain code to the framework itself. That is why this CLI exists: it scaffolds the structure for you, using your own codebase instead of a framework.
10
10
 
11
- # Usage example
12
-
13
- https://github.com/virtualitems/tshex-cli
14
-
15
- # Note!!!
11
+ # Note
16
12
 
17
13
  This tool and its templates are in constant development, so be aware that some changes may occur and be careful when updating the tool.
18
14
 
@@ -20,57 +16,190 @@ If you have any suggestions or improvements, please let me know.
20
16
 
21
17
  https://github.com/virtualitems/tshex-cli/issues
22
18
 
23
- # Installation
19
+ # Getting started
20
+
21
+ `tshex` scaffolds folders and files for a hexagonal architecture project. It does not write business logic for you; it only generates the structure, so you can fill it in with your own code.
22
+
23
+ There are two things you can generate:
24
+
25
+ - A **library** (`--lib`): the shared foundation of a project. It contains the domain and application contracts (entities, value objects, services, etc.) that the rest of the code depends on.
26
+ - A **context** (`--ctx`): a specific business area (e.g. `users`, `billing`, `orders`). It contains the `domain/`, `application/`, and `adapters/` folders where you implement that area's logic.
27
+
28
+ A typical project has one library and one or more contexts inside it.
29
+
30
+ ## Install
31
+
32
+ Install the CLI globally:
24
33
 
25
34
  ```bash
26
35
  npm install -g tshex-cli
27
36
  ```
28
37
 
29
- # Usage
38
+ Check the installation:
39
+
40
+ ```bash
41
+ tshex --version
42
+ ```
43
+
44
+ Show the command options:
30
45
 
31
- > Remember to replace placeholders `<...>` with the actual data.
32
- >
46
+ ```bash
47
+ tshex --help
48
+ ```
33
49
 
34
- ## Getting started
50
+ ## Usage
35
51
 
36
52
  ```bash
37
- tshex --lib <library-name> --ctx <context-name>
53
+ tshex [--lib <name>] [--ctx <name>] [--dir <path>]
38
54
  ```
39
55
 
40
- ## Help
56
+ | Option | Purpose |
57
+ | -------------- | ------------------------------------------------------------------- |
58
+ | `--lib <name>` | Generate a library called `<name>`, based on `templates/lib`. |
59
+ | `--ctx <name>` | Generate a context called `<name>`, based on `templates/ctx`. |
60
+ | `--dir <path>` | Parent directory where the library/context will be created. Defaults to the current directory. |
61
+ | `--help` | Show the command options. |
62
+ | `--version` | Show the installed version. |
63
+
64
+ `--lib` and `--ctx` can be used together in a single command (see [Create a library and a context together](#create-a-library-and-a-context-together)). Running `tshex` without any options just prints the help text — it does not generate anything.
65
+
66
+ ## Create a library
67
+
68
+ Use this when you are starting a new project and need the shared contracts that the rest of your code will build on:
41
69
 
42
70
  ```bash
43
- tshex -h
71
+ tshex --lib core
72
+ ```
44
73
 
45
- tshex --help
74
+ This generates a `core/` folder in the current directory:
75
+
76
+ ```text
77
+ core/
78
+ ├── index.d.ts
79
+ ├── main.ts
80
+ └── shared/
81
+ ├── application/
82
+ │ ├── databases.ts
83
+ │ ├── events.ts
84
+ │ ├── http.ts
85
+ │ ├── loggers.ts
86
+ │ └── services.ts
87
+ └── domain/
88
+ ├── aggregates.ts
89
+ ├── entities.ts
90
+ ├── errors.ts
91
+ └── value-objects.ts
46
92
  ```
47
93
 
48
- ## Create a new library
94
+ What each file is for:
95
+
96
+ | File | Purpose |
97
+ | ------------------ | --------------------------------------------- |
98
+ | `index.d.ts` | Declare library types. |
99
+ | `main.ts` | Export the library API. |
100
+ | `entities.ts` | Define entity contracts. |
101
+ | `value-objects.ts` | Define value objects and validation. |
102
+ | `aggregates.ts` | Define aggregate contracts. |
103
+ | `errors.ts` | Define domain errors. |
104
+ | `services.ts` | Define application service contracts. |
105
+ | `databases.ts` | Define data manager and repository contracts. |
106
+ | `events.ts` | Define event contracts. |
107
+ | `http.ts` | Define HTTP response contracts. |
108
+ | `loggers.ts` | Define logger contracts. |
109
+
110
+ `main.ts` is generated with a placeholder `throw new Error('Not implemented yet')`, so the library fails loudly if you try to use it before filling it in. To start using it, open `main.ts`, remove that line, and export your own code, built on top of the shared contracts. For example:
111
+
112
+ ```ts
113
+ export { Entity } from './shared/domain/entities.js'
114
+ export { ValueObject, Email } from './shared/domain/value-objects.js'
115
+
116
+ class User extends Entity {
117
+ constructor(public readonly email: Email) {
118
+ super()
119
+ }
120
+ }
121
+ ```
122
+
123
+ ## Create a context
124
+
125
+ Use this to scaffold a specific business area, such as `users`, inside an existing library (or on its own):
49
126
 
50
127
  ```bash
51
- tshex --lib <name>
128
+ tshex --ctx users
129
+ ```
130
+
131
+ This generates a `users/` folder in the current directory:
132
+
133
+ ```text
134
+ users/
135
+ ├── adapters/
136
+ ├── application/
137
+ ├── domain/
138
+ └── index.ts
52
139
  ```
53
140
 
54
- ## Create a new context
141
+ What each part is for:
142
+
143
+ | Path | Purpose |
144
+ | -------------- | ---------------------------------------------------------------- |
145
+ | `domain/` | Entities, value objects, aggregates, and domain errors. |
146
+ | `application/` | Use cases, services, DTOs, and contracts. |
147
+ | `adapters/` | Database, HTTP, event, file, and service implementations. |
148
+ | `index.ts` | Export or compose the context's public API. |
149
+
150
+ ## Choose the destination folder
151
+
152
+ By default, `tshex` creates files in your current directory. Use `--dir` to choose a different parent directory instead.
153
+
154
+ Create a library inside `./src`:
55
155
 
56
156
  ```bash
57
- tshex --ctx <name>
157
+ tshex --lib core --dir ./src
58
158
  ```
59
159
 
60
- ## Create a new class
160
+ This generates the library at:
161
+
162
+ ```text
163
+ ./src/core
164
+ ```
165
+
166
+ Create a context inside that library:
61
167
 
62
168
  ```bash
63
- tshex --cls <name>
169
+ tshex --ctx users --dir ./src/core
170
+ ```
171
+
172
+ This generates the context at:
173
+
174
+ ```text
175
+ ./src/core/users
64
176
  ```
65
177
 
66
- ## Create a new react functional component
178
+ You can also use an absolute path:
67
179
 
68
180
  ```bash
69
- tshex --rfc <name>
181
+ tshex --ctx users --dir /workspace/project/src
70
182
  ```
71
183
 
72
- ## Set the directory to create the new items
184
+ ## Create a library and a context together
185
+
186
+ You can generate both in a single command. `tshex` creates the library first, then creates the context inside it:
73
187
 
74
188
  ```bash
75
- tshex --lib <lib-name> --ctx <ctx-name> --dir <path>
76
- ```
189
+ tshex --dir ./src --lib core --ctx users
190
+ ```
191
+
192
+ Result:
193
+
194
+ ```text
195
+ src/
196
+ └── core/
197
+ ├── index.d.ts
198
+ ├── main.ts
199
+ ├── shared/
200
+ └── users/
201
+ ├── adapters/
202
+ ├── application/
203
+ ├── domain/
204
+ └── index.ts
205
+ ```