@dawudesign/node-hexa-cli 0.1.3 → 0.1.5

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 ADDED
@@ -0,0 +1,45 @@
1
+ Proprietary License
2
+
3
+ Copyright (c) 2026 Dawudesign. All rights reserved.
4
+
5
+ TERMS AND CONDITIONS
6
+
7
+ 1. GRANT OF USE
8
+ A valid license purchased from the copyright holder grants the end user
9
+ the right to install and use this software solely for their own internal
10
+ purposes. No other rights are granted.
11
+
12
+ 2. RESTRICTIONS
13
+ You may NOT, without prior written permission from the copyright holder:
14
+ a. Copy, reproduce, or duplicate this software or any part thereof;
15
+ b. Distribute, publish, transmit, or otherwise make this software
16
+ available to any third party, whether for free or for a fee;
17
+ c. Sublicense, sell, resell, rent, lease, or lend this software;
18
+ d. Modify, adapt, translate, reverse-engineer, decompile, or create
19
+ derivative works based on this software;
20
+ e. Remove or alter any copyright notices or license terms contained
21
+ in this software.
22
+
23
+ 3. OWNERSHIP
24
+ This software and all copies thereof are proprietary to Dawud and
25
+ title thereto remains in Dawud. All rights reserved. Dawud is the
26
+ sole authorized distributor and seller of this software.
27
+
28
+ 4. NO WARRANTY
29
+ THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
32
+ NON-INFRINGEMENT.
33
+
34
+ 5. LIMITATION OF LIABILITY
35
+ IN NO EVENT SHALL DAWUD BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
36
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE,
37
+ ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE
38
+ OR OTHER DEALINGS IN THE SOFTWARE.
39
+
40
+ 6. TERMINATION
41
+ Any breach of these terms automatically terminates your right to use
42
+ this software. Upon termination, you must destroy all copies in your
43
+ possession.
44
+
45
+ For licensing inquiries, contact the copyright holder.
package/README.md ADDED
@@ -0,0 +1,287 @@
1
+ # @dawudesign/node-hexa-cli
2
+
3
+ > Scaffold and enforce **NestJS Hexagonal DDD** architecture from the command line.
4
+
5
+ **node-hexa** automates the repetitive parts of clean architecture in NestJS:
6
+
7
+ - **Scaffold** — generates a full bounded context with dependency injection pre-wired, in one command
8
+ - **Enforce** — statically analyzes your TypeScript source and reports architecture violations
9
+ - **Document** — exports a Mermaid diagram and architecture report as Markdown or SVG
10
+
11
+ ---
12
+
13
+ ## Requirements
14
+
15
+ - **Node.js ≥ 20**
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install -g @dawudesign/node-hexa-cli
23
+ ```
24
+
25
+ Verify:
26
+
27
+ ```bash
28
+ node-hexa --version
29
+ node-hexa --help
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Quickstart
35
+
36
+ ```bash
37
+ # 1. Create a new NestJS Hexagonal DDD project
38
+ node-hexa init my-app
39
+ cd my-app
40
+
41
+ # 2. Start the server
42
+ pnpm start:dev
43
+
44
+ # 3. Verify architecture is clean
45
+ node-hexa check .
46
+ # ✓ Architecture check passed
47
+ ```
48
+
49
+ ---
50
+
51
+ ## Commands
52
+
53
+ ### `init`
54
+
55
+ Creates a new NestJS project with the complete Hexagonal DDD structure.
56
+
57
+ ```bash
58
+ node-hexa init <name>
59
+ ```
60
+
61
+ ```bash
62
+ node-hexa init my-app
63
+ ```
64
+
65
+ Generates:
66
+
67
+ ```text
68
+ my-app/
69
+ ├── src/
70
+ │ ├── main.ts
71
+ │ ├── app.module.ts
72
+ │ └── contexts/
73
+ │ └── iam/
74
+ │ ├── iam.module.ts
75
+ │ ├── domain/
76
+ │ │ ├── entities/user.entity.ts
77
+ │ │ └── ports/user.repository.port.ts
78
+ │ ├── application/
79
+ │ │ └── use-cases/create-user.usecase.ts
80
+ │ └── infrastructure/
81
+ │ ├── http/user.controller.ts
82
+ │ └── persistence/in-memory-user.repository.ts
83
+ └── node-hexa.config.json
84
+ ```
85
+
86
+ ---
87
+
88
+ ### `generate context`
89
+
90
+ Generates a complete bounded context inside an existing NestJS project.
91
+
92
+ ```bash
93
+ node-hexa generate context <name>
94
+ ```
95
+
96
+ ```bash
97
+ cd my-app
98
+ node-hexa generate context orders
99
+ # ✓ Context 'orders' generated at src/contexts/orders/
100
+ # → Import OrdersModule in your AppModule to activate it.
101
+ ```
102
+
103
+ ---
104
+
105
+ ### `generate usecase`
106
+
107
+ Generates a use case with its DTO and Vitest spec inside an existing bounded context.
108
+
109
+ ```bash
110
+ node-hexa generate usecase <name> <context>
111
+ ```
112
+
113
+ ```bash
114
+ node-hexa generate usecase delete-user iam
115
+ # ✓ Use case 'delete-user' generated in context 'iam'
116
+ ```
117
+
118
+ Generated files:
119
+
120
+ ```text
121
+ src/contexts/iam/application/use-cases/
122
+ ├── delete-user.usecase.ts
123
+ ├── delete-user.dto.ts
124
+ └── delete-user.usecase.spec.ts
125
+ ```
126
+
127
+ ---
128
+
129
+ ### `generate aggregate`
130
+
131
+ Generates a full DDD aggregate (entity, value object, port, use case, in-memory repository, HTTP controller, NestJS module).
132
+
133
+ ```bash
134
+ node-hexa generate aggregate <name> <context>
135
+ ```
136
+
137
+ ```bash
138
+ node-hexa generate aggregate product catalog
139
+ # ✓ Aggregate 'product' generated in context 'catalog'
140
+ ```
141
+
142
+ ---
143
+
144
+ ### `check`
145
+
146
+ Checks architecture rules — exits `0` if clean, `1` if violations found. Designed for CI/CD.
147
+
148
+ ```bash
149
+ node-hexa check <path> [--watch]
150
+ ```
151
+
152
+ ```bash
153
+ # One-shot (CI)
154
+ node-hexa check .
155
+
156
+ # Watch mode (development)
157
+ node-hexa check . --watch
158
+ ```
159
+
160
+ Output:
161
+
162
+ ```text
163
+ ✓ Architecture check passed
164
+ ```
165
+
166
+ or:
167
+
168
+ ```text
169
+ ✗ Architecture violations detected
170
+
171
+ [CRITICAL] Domain must not depend on infrastructure → UserEntity
172
+ [HIGH] Application must not depend on infrastructure → CreateUserUseCase
173
+ ```
174
+
175
+ ---
176
+
177
+ ### `analyze`
178
+
179
+ Full analysis: layers, violations, bounded contexts, Mermaid diagram, and score.
180
+
181
+ ```bash
182
+ node-hexa analyze <path>
183
+ ```
184
+
185
+ ```bash
186
+ node-hexa analyze .
187
+ ```
188
+
189
+ ---
190
+
191
+ ### `list`
192
+
193
+ Lists all bounded contexts and their components.
194
+
195
+ ```bash
196
+ node-hexa list <path>
197
+ ```
198
+
199
+ ```bash
200
+ node-hexa list .
201
+ ```
202
+
203
+ Output:
204
+
205
+ ```text
206
+ Bounded Contexts (2)
207
+
208
+ IAM
209
+ Entities : user.entity
210
+ Ports : user.repository.port
211
+ Use Cases : create-user.usecase
212
+
213
+ CATALOG
214
+ Entities : product.entity
215
+ Ports : product.repository.port
216
+ Use Cases : create-product.usecase
217
+ ```
218
+
219
+ ---
220
+
221
+ ### `docs`
222
+
223
+ Generates an `architecture.md` at the project root with the Mermaid diagram, violations, and score.
224
+
225
+ ```bash
226
+ node-hexa docs <path>
227
+ ```
228
+
229
+ ```bash
230
+ node-hexa docs .
231
+ # Architecture documentation generated: ./architecture.md
232
+ ```
233
+
234
+ ---
235
+
236
+ ### `graph`
237
+
238
+ Generates an `architecture.svg` dependency graph (requires `@mermaid-js/mermaid-cli`).
239
+
240
+ ```bash
241
+ npm install -g @mermaid-js/mermaid-cli
242
+ node-hexa graph .
243
+ # Architecture graph generated: ./architecture.svg
244
+ ```
245
+
246
+ ---
247
+
248
+ ## Configuration
249
+
250
+ `node-hexa.config.json` at the project root (created by `init`, all keys optional):
251
+
252
+ ```json
253
+ {
254
+ "architecture": "hexagonal-ddd",
255
+ "strict": true,
256
+ "contextsDir": "src/contexts"
257
+ }
258
+ ```
259
+
260
+ | Key | Type | Default | Description |
261
+ | --- | --- | --- | --- |
262
+ | `architecture` | `string` | required | Architecture type — `hexagonal-ddd` |
263
+ | `strict` | `boolean` | `true` | `false` silences `MEDIUM` violations |
264
+ | `contextsDir` | `string` | `"src/contexts"` | Path to bounded contexts directory |
265
+
266
+ ---
267
+
268
+ ## Violation rules
269
+
270
+ | Violation | Severity | Score penalty |
271
+ | --- | --- | --- |
272
+ | Domain imports from infrastructure / adapter | `CRITICAL` | −25 pts |
273
+ | Domain imports from application | `CRITICAL` | −25 pts |
274
+ | Application imports from infrastructure / adapter | `HIGH` | −15 pts |
275
+ | Domain imports a framework (`@nestjs/*`, `prisma`, etc.) | `CRITICAL` | −25 pts |
276
+
277
+ Score = `100 − sum of penalties`, minimum 0.
278
+
279
+ ---
280
+
281
+ ## License
282
+
283
+ `activate` command required for production use:
284
+
285
+ ```bash
286
+ node-hexa activate <your-license-key>
287
+ ```
package/dist/index.js CHANGED
@@ -6,10 +6,10 @@ import { Command } from "commander";
6
6
 
7
7
  // src/license.ts
8
8
  import { createHmac, timingSafeEqual } from "crypto";
9
- import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
9
+ import { writeFileSync, mkdirSync } from "fs";
10
10
  import { homedir } from "os";
11
11
  import { join } from "path";
12
- var SIGNING_SECRET = "2dc6d0a8b5c755f95a2e9fbca8c8e6c45226763dc2040ae5335bc86f480337bb";
12
+ var SIGNING_SECRET = process.env["NODEHEXA_LICENSE_SECRET"] ?? "";
13
13
  var CONFIG_DIR = join(homedir(), ".config", "node-hexa");
14
14
  var LICENSE_FILE = join(CONFIG_DIR, "license");
15
15
  function parseLicenseKey(key) {
@@ -47,30 +47,11 @@ function activateLicense(key) {
47
47
  }
48
48
  mkdirSync(CONFIG_DIR, { recursive: true });
49
49
  writeFileSync(LICENSE_FILE, key.trim(), "utf8");
50
- console.log(`\u2713 License activated for ${parsed.email} (valid until: ${parsed.expiresAt})`);
50
+ console.log(
51
+ `\u2713 License activated for ${parsed.email} (valid until: ${parsed.expiresAt})`
52
+ );
51
53
  }
52
54
  function checkLicense() {
53
- if (!existsSync(LICENSE_FILE)) {
54
- console.error(
55
- "\u2717 No license found. Purchase a license at https://your-website.com and run:\n node-hexa activate <your-license-key>"
56
- );
57
- process.exit(1);
58
- }
59
- const key = readFileSync(LICENSE_FILE, "utf8").trim();
60
- const parsed = parseLicenseKey(key);
61
- if (!parsed) {
62
- console.error(
63
- "\u2717 License file is corrupted. Re-activate with:\n node-hexa activate <your-license-key>"
64
- );
65
- process.exit(1);
66
- }
67
- const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
68
- if (parsed.expiresAt !== "lifetime" && parsed.expiresAt < today) {
69
- console.error(
70
- `\u2717 Your license expired on ${parsed.expiresAt}. Renew at https://your-website.com`
71
- );
72
- process.exit(1);
73
- }
74
55
  }
75
56
 
76
57
  // ../../packages/parser/dist/index.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dawudesign/node-hexa-cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "CLI to scaffold and analyze NestJS Hexagonal DDD projects",
5
5
  "keywords": [
6
6
  "nestjs",
@@ -10,7 +10,7 @@
10
10
  "cli",
11
11
  "scaffold"
12
12
  ],
13
- "license": "UNLICENSED",
13
+ "license": "MIT",
14
14
  "type": "module",
15
15
  "engines": {
16
16
  "node": ">=20"