tshex-cli 1.0.13 → 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.
- package/LICENSE +21 -21
- package/build/main.js +21 -46
- package/package.json +50 -52
- package/readme.md +205 -76
- package/source/main.ts +84 -145
- package/templates/ctx/index.ts +9 -9
- package/templates/lib/index.d.ts +1 -1
- package/templates/lib/main.ts +5 -5
- package/templates/lib/shared/application/databases.ts +81 -0
- package/templates/lib/shared/application/events.ts +121 -0
- package/templates/lib/shared/application/{Response.ts → http.ts} +48 -52
- package/templates/{cls.example → lib/shared/application/loggers.ts} +50 -50
- package/templates/lib/shared/application/{Service.ts → services.ts} +43 -47
- package/templates/lib/shared/domain/{Aggregate.ts → aggregates.ts} +44 -48
- package/templates/lib/shared/domain/{Entity.ts → entities.ts} +46 -50
- package/templates/lib/shared/{application/DataTransferObject.ts → domain/errors.ts} +46 -46
- package/templates/lib/shared/domain/value-objects.ts +194 -0
- package/templates/ctx/ports/.gitkeep +0 -0
- package/templates/lib/shared/adapters/.gitkeep +0 -0
- package/templates/lib/shared/application/Logger.ts +0 -54
- package/templates/lib/shared/application/data/DataManager.ts +0 -50
- package/templates/lib/shared/application/data/Repository.ts +0 -55
- package/templates/lib/shared/application/errors/.gitkeep +0 -0
- package/templates/lib/shared/application/events/Event.ts +0 -56
- package/templates/lib/shared/application/events/EventDispatcher.ts +0 -55
- package/templates/lib/shared/application/events/EventHandler.ts +0 -50
- package/templates/lib/shared/constants/.gitkeep +0 -0
- package/templates/lib/shared/domain/errors/ValueError.ts +0 -69
- package/templates/lib/shared/domain/utils/.gitkeep +0 -0
- package/templates/lib/shared/domain/value-objects/BooleanValueObject.ts +0 -87
- package/templates/lib/shared/domain/value-objects/DateValueObject.ts +0 -100
- package/templates/lib/shared/domain/value-objects/EmailValueObject.ts +0 -89
- package/templates/lib/shared/domain/value-objects/NullableBooleanValueObject.ts +0 -87
- package/templates/lib/shared/domain/value-objects/NumericValueObject.ts +0 -136
- package/templates/lib/shared/domain/value-objects/StringValueObject.ts +0 -87
- package/templates/lib/shared/domain/value-objects/SymbolValueObject.ts +0 -82
- package/templates/lib/shared/domain/value-objects/ValueObject.ts +0 -57
- package/templates/rfc.example +0 -42
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 virtualitems
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 virtualitems
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/build/main.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program } from 'commander';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
.version(packageJson.version)
|
|
9
|
-
.option('--lib <name>', 'creates a new library with it\'s shared directory')
|
|
10
|
-
.option('--ctx <name>', 'creates a new context')
|
|
11
|
-
.option('--cls <name>', 'creates a new class')
|
|
12
|
-
.option('--rfc <name>', 'creates a new react functional component')
|
|
13
|
-
.option('--dir <path>', 'sets the directory to create the new item')
|
|
14
|
-
.parse(process.argv);
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
function readPackageJson() {
|
|
6
|
+
return JSON.parse(fs.readFileSync(path.join(import.meta.dirname, '..', 'package.json'), 'utf-8'));
|
|
7
|
+
}
|
|
15
8
|
function executeCreateLib(templatesDir, libraryDir) {
|
|
16
9
|
try {
|
|
17
10
|
fs.cpSync(path.join(templatesDir, 'lib'), libraryDir, {
|
|
18
11
|
recursive: true,
|
|
19
|
-
filter:
|
|
12
|
+
filter: (src) => !src.endsWith('.gitkeep')
|
|
20
13
|
});
|
|
21
14
|
console.log('Library created successfully');
|
|
22
15
|
}
|
|
@@ -28,7 +21,7 @@ function executeCreateContext(templatesDir, contextDir) {
|
|
|
28
21
|
try {
|
|
29
22
|
fs.cpSync(path.join(templatesDir, 'ctx'), contextDir, {
|
|
30
23
|
recursive: true,
|
|
31
|
-
filter:
|
|
24
|
+
filter: (src) => !src.endsWith('.gitkeep')
|
|
32
25
|
});
|
|
33
26
|
console.log('Context created successfully');
|
|
34
27
|
}
|
|
@@ -36,29 +29,10 @@ function executeCreateContext(templatesDir, contextDir) {
|
|
|
36
29
|
console.error(err);
|
|
37
30
|
}
|
|
38
31
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
console.error(err);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function executeCreateReactFunctionalComponent(templatesDir, classDir) {
|
|
49
|
-
try {
|
|
50
|
-
fs.cpSync(path.join(templatesDir, 'rfc.example'), classDir, {});
|
|
51
|
-
console.log('React component created successfully');
|
|
52
|
-
}
|
|
53
|
-
catch (err) {
|
|
54
|
-
console.error(err);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
(function () {
|
|
58
|
-
var _a;
|
|
59
|
-
var templatesDir = path.join(import.meta.dirname, '..', 'templates');
|
|
60
|
-
var options = program.opts();
|
|
61
|
-
var targetDir = path.resolve((_a = options.dir) !== null && _a !== void 0 ? _a : process.cwd());
|
|
32
|
+
function main(program) {
|
|
33
|
+
const templatesDir = path.join(import.meta.dirname, '..', 'templates');
|
|
34
|
+
const options = program.opts();
|
|
35
|
+
let targetDir = path.resolve(options.dir ?? process.cwd());
|
|
62
36
|
if (Object.keys(options).length === 0) {
|
|
63
37
|
program.help();
|
|
64
38
|
return;
|
|
@@ -74,12 +48,13 @@ function executeCreateReactFunctionalComponent(templatesDir, classDir) {
|
|
|
74
48
|
targetDir = path.join(targetDir, options.ctx);
|
|
75
49
|
executeCreateContext(templatesDir, targetDir);
|
|
76
50
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
51
|
+
}
|
|
52
|
+
const packageJson = readPackageJson();
|
|
53
|
+
program
|
|
54
|
+
.name('tshex')
|
|
55
|
+
.version(packageJson.version)
|
|
56
|
+
.option('--lib <name>', "creates a new library with it's shared directory")
|
|
57
|
+
.option('--ctx <name>', 'creates a new context')
|
|
58
|
+
.option('--dir <path>', 'sets the directory to create the new item')
|
|
59
|
+
.parse(process.argv);
|
|
60
|
+
main(program);
|
package/package.json
CHANGED
|
@@ -1,52 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tshex-cli",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"author": "https://github.com/virtualitems/",
|
|
5
|
-
"description": "Typescript Hexagonal Architecture CLI",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "./build/main.js",
|
|
8
|
-
"keywords": [
|
|
9
|
-
"architecture",
|
|
10
|
-
"clean-architecture",
|
|
11
|
-
"clean",
|
|
12
|
-
"cli",
|
|
13
|
-
"ddd",
|
|
14
|
-
"design-patterns",
|
|
15
|
-
"design",
|
|
16
|
-
"domain-driven-design",
|
|
17
|
-
"hexagonal",
|
|
18
|
-
"pattern",
|
|
19
|
-
"software-architecture",
|
|
20
|
-
"tshex",
|
|
21
|
-
"tshex-cli",
|
|
22
|
-
"typescript",
|
|
23
|
-
"virtualitems"
|
|
24
|
-
],
|
|
25
|
-
"homepage": "https://github.com/virtualitems/tshex-cli",
|
|
26
|
-
"bugs": {
|
|
27
|
-
"url": "https://github.com/virtualitems/tshex-cli/issues"
|
|
28
|
-
},
|
|
29
|
-
"files": [
|
|
30
|
-
"./build",
|
|
31
|
-
"./source",
|
|
32
|
-
"./templates"
|
|
33
|
-
],
|
|
34
|
-
"types": "./source/index.d.ts",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "tshex-cli",
|
|
3
|
+
"version": "1.0.15",
|
|
4
|
+
"author": "https://github.com/virtualitems/",
|
|
5
|
+
"description": "Typescript Hexagonal Architecture CLI",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./build/main.js",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"architecture",
|
|
10
|
+
"clean-architecture",
|
|
11
|
+
"clean",
|
|
12
|
+
"cli",
|
|
13
|
+
"ddd",
|
|
14
|
+
"design-patterns",
|
|
15
|
+
"design",
|
|
16
|
+
"domain-driven-design",
|
|
17
|
+
"hexagonal",
|
|
18
|
+
"pattern",
|
|
19
|
+
"software-architecture",
|
|
20
|
+
"tshex",
|
|
21
|
+
"tshex-cli",
|
|
22
|
+
"typescript",
|
|
23
|
+
"virtualitems"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://github.com/virtualitems/tshex-cli",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/virtualitems/tshex-cli/issues"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"./build",
|
|
31
|
+
"./source",
|
|
32
|
+
"./templates"
|
|
33
|
+
],
|
|
34
|
+
"types": "./source/index.d.ts",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^22.5.4",
|
|
37
|
+
"typescript": "^5.4.5"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"commander": "^12.1.0"
|
|
41
|
+
},
|
|
42
|
+
"bin": {
|
|
43
|
+
"tshex": "./build/main.js"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"examples": "tsc -p examples",
|
|
47
|
+
"build": "tsc",
|
|
48
|
+
"dev": "tsc -w"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,76 +1,205 @@
|
|
|
1
|
-
# Hexagonal Architecture CLI
|
|
2
|
-
|
|
3
|
-
This CLI will help you to generate a hexagonal architecture structure.
|
|
4
|
-
|
|
5
|
-
# Why?
|
|
6
|
-
|
|
7
|
-
Hexagonal architecture is a software design pattern that separates the internal domain of the application from the external dependencies
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
#
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
## Create a
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
```
|
|
1
|
+
# Hexagonal Architecture CLI
|
|
2
|
+
|
|
3
|
+
This CLI will help you to generate a hexagonal architecture structure.
|
|
4
|
+
|
|
5
|
+
# Why?
|
|
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.
|
|
8
|
+
|
|
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
|
+
|
|
11
|
+
# Note
|
|
12
|
+
|
|
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.
|
|
14
|
+
|
|
15
|
+
If you have any suggestions or improvements, please let me know.
|
|
16
|
+
|
|
17
|
+
https://github.com/virtualitems/tshex-cli/issues
|
|
18
|
+
|
|
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:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install -g tshex-cli
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Check the installation:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
tshex --version
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Show the command options:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
tshex --help
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
tshex [--lib <name>] [--ctx <name>] [--dir <path>]
|
|
54
|
+
```
|
|
55
|
+
|
|
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:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
tshex --lib core
|
|
72
|
+
```
|
|
73
|
+
|
|
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
|
|
92
|
+
```
|
|
93
|
+
|
|
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):
|
|
126
|
+
|
|
127
|
+
```bash
|
|
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
|
|
139
|
+
```
|
|
140
|
+
|
|
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`:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
tshex --lib core --dir ./src
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
This generates the library at:
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
./src/core
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Create a context inside that library:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
tshex --ctx users --dir ./src/core
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
This generates the context at:
|
|
173
|
+
|
|
174
|
+
```text
|
|
175
|
+
./src/core/users
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
You can also use an absolute path:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
tshex --ctx users --dir /workspace/project/src
|
|
182
|
+
```
|
|
183
|
+
|
|
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:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
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
|
+
```
|