@devmed555/angular-clean-architecture-cli 0.0.2 → 0.0.3
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/README.md +425 -0
- package/bin/index.js +100 -2
- package/generators.json +19 -9
- package/package.json +1 -1
- package/src/generators/core/files/auth/auth.guard.ts.template +14 -0
- package/src/generators/core/files/auth/auth.service.ts.template +137 -0
- package/src/generators/core/files/auth/login.component.ts.template +165 -0
- package/src/generators/core/files/auth/signup.component.ts.template +171 -0
- package/src/generators/core/files/guard/__name__.guard.ts.template +6 -0
- package/src/generators/core/files/interceptor/__name__.interceptor.ts.template +6 -0
- package/src/generators/core/files/language-selector/language-selector.component.ts.template +82 -0
- package/src/generators/core/files/menu/__name__.component.html.template +14 -0
- package/src/generators/core/files/menu/__name__.component.scss.template +66 -0
- package/src/generators/core/files/menu/__name__.component.ts.template +24 -0
- package/src/generators/core/files/navbar/__name__.component.html.template +45 -0
- package/src/generators/core/files/navbar/__name__.component.scss.template +134 -0
- package/src/generators/core/files/navbar/__name__.component.ts.template +38 -0
- package/src/generators/core/files/service/__name__.service.ts.template +26 -0
- package/src/generators/core/files/theme-selector/theme-selector.component.ts.template +49 -0
- package/src/generators/core/files/translate/translate.pipe.ts.template +15 -0
- package/src/generators/core/files/translate/translate.service.ts.template +24 -0
- package/src/generators/core/generator.d.ts +7 -0
- package/src/generators/core/generator.js +49 -0
- package/src/generators/core/generator.js.map +1 -0
- package/src/generators/core/schema.json +34 -0
- package/src/generators/feature/blueprint.schema.json +34 -0
- package/src/generators/feature/files/application/store.ts.template +135 -0
- package/src/generators/feature/files/domain/model.ts.template +9 -0
- package/src/generators/{clean-feature → feature}/files/infrastructure/service.ts.template +5 -5
- package/src/generators/feature/files/ui/__singularName__.component.html.template +109 -0
- package/src/generators/feature/files/ui/__singularName__.component.scss.template +162 -0
- package/src/generators/feature/files/ui/__singularName__.component.ts.template +131 -0
- package/src/generators/feature/files/ui/_theme.scss.template +35 -0
- package/src/generators/feature/files/ui/form/form.component.ts.template +122 -0
- package/src/generators/feature/generator.d.ts +4 -0
- package/src/generators/feature/generator.js +209 -0
- package/src/generators/feature/generator.js.map +1 -0
- package/src/generators/feature/schema.d.ts +5 -0
- package/src/generators/{clean-feature → feature}/schema.json +25 -21
- package/src/generators/shared/files/ui/__name__.component.ts.template +57 -0
- package/src/generators/shared/files/util/__name__.ts.template +7 -0
- package/src/generators/shared/generator.d.ts +7 -0
- package/src/generators/shared/generator.js +31 -0
- package/src/generators/shared/generator.js.map +1 -0
- package/src/generators/shared/schema.json +23 -0
- package/src/index.js +1 -0
- package/src/utils/string-utils.d.ts +16 -0
- package/src/utils/string-utils.js +33 -0
- package/src/utils/string-utils.js.map +1 -0
- package/src/generators/clean-feature/files/application/store.ts.template +0 -6
- package/src/generators/clean-feature/files/domain/model.ts.template +0 -4
- package/src/generators/clean-feature/files/ui/component.ts.template +0 -44
- package/src/generators/clean-feature/generator.d.ts +0 -4
- package/src/generators/clean-feature/generator.js +0 -89
- package/src/generators/clean-feature/generator.js.map +0 -1
- package/src/generators/clean-feature/schema.d.ts +0 -4
package/README.md
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
# Angular Clean Architecture CLI
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@devmed555/angular-clean-architecture-cli)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
> 🚀 Scaffold Angular features following Clean Architecture principles with NgRx SignalStore.
|
|
7
|
+
|
|
8
|
+
A powerful CLI that generates production-ready Angular features structured into **Domain**, **Infrastructure**, **Application**, and **UI** layers — keeping your codebase maintainable, testable, and scalable.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 📦 Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Global installation (recommended)
|
|
16
|
+
npm install -g @devmed555/angular-clean-architecture-cli
|
|
17
|
+
|
|
18
|
+
# Verify installation
|
|
19
|
+
aca --version
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Prerequisites
|
|
23
|
+
|
|
24
|
+
- **Node.js** v18+
|
|
25
|
+
- **Angular** 16+ project
|
|
26
|
+
- **@ngrx/signals** installed:
|
|
27
|
+
```bash
|
|
28
|
+
npm install @ngrx/signals
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## ⚡ Quick Start
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Generate all features from feature-schema.json
|
|
37
|
+
aca g feature
|
|
38
|
+
|
|
39
|
+
# Generate a single feature with attributes
|
|
40
|
+
aca g feature product --attributes="name:string,price:number"
|
|
41
|
+
|
|
42
|
+
# Generate ALL core assets (auth, navbar, menu, theme, etc.)
|
|
43
|
+
aca g core
|
|
44
|
+
|
|
45
|
+
# Generate ALL shared components (button, card, input, etc.)
|
|
46
|
+
aca g shared
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 🛠️ Generators
|
|
52
|
+
|
|
53
|
+
| Generator | Command | Description |
|
|
54
|
+
| ----------- | --------------- | ----------------------------------------------- |
|
|
55
|
+
| **Feature** | `aca g feature` | Complete Clean Architecture feature (4 layers) |
|
|
56
|
+
| **Core** | `aca g core` | Core system assets (auth, guards, interceptors) |
|
|
57
|
+
| **Shared** | `aca g shared` | Shared UI components & utilities |
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 📁 Feature Generator
|
|
62
|
+
|
|
63
|
+
Creates a complete Clean Architecture feature with 4 layers:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
features/<name>/
|
|
67
|
+
├── domain/model.ts # Business entities & interfaces
|
|
68
|
+
├── infrastructure/service.ts # HTTP service with CRUD operations
|
|
69
|
+
├── application/store.ts # NgRx SignalStore state management
|
|
70
|
+
└── ui/component.ts # Standalone Angular component
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Usage
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Interactive mode
|
|
77
|
+
aca g feature
|
|
78
|
+
|
|
79
|
+
# With name argument
|
|
80
|
+
aca g feature product
|
|
81
|
+
|
|
82
|
+
# With inline attributes
|
|
83
|
+
aca g feature product --attributes="name:string,price:number,inStock:boolean"
|
|
84
|
+
|
|
85
|
+
# From blueprint file
|
|
86
|
+
aca g feature --blueprint=./my-feature.json
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Options
|
|
90
|
+
|
|
91
|
+
| Option | Description | Example |
|
|
92
|
+
| -------------- | ------------------------------ | ------------------------------------------ |
|
|
93
|
+
| `--attributes` | Define model properties inline | `--attributes="title:string,views:number"` |
|
|
94
|
+
| `--blueprint` | Use a JSON blueprint file | `--blueprint=./order.json` |
|
|
95
|
+
|
|
96
|
+
### Supported Types
|
|
97
|
+
|
|
98
|
+
| Type | Description |
|
|
99
|
+
| --------- | --------------------------------------- |
|
|
100
|
+
| `string` | Text data |
|
|
101
|
+
| `number` | Numeric values |
|
|
102
|
+
| `boolean` | True/false values |
|
|
103
|
+
| `Date` | Date/time values |
|
|
104
|
+
| `any` | Flexible type (use sparingly) |
|
|
105
|
+
| `Type[]` | Arrays (e.g., `string[]`, `CartItem[]`) |
|
|
106
|
+
|
|
107
|
+
### Interactive Mode Example
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
$ aca g feature
|
|
111
|
+
|
|
112
|
+
? What is the name of the feature (singular)? product
|
|
113
|
+
Let's add some attributes (property fields).
|
|
114
|
+
? Enter attribute name (or press enter to finish): name
|
|
115
|
+
? Select type: string
|
|
116
|
+
? Enter attribute name (or press enter to finish): price
|
|
117
|
+
? Select type: number
|
|
118
|
+
? Enter attribute name (or press enter to finish): [Press Enter]
|
|
119
|
+
|
|
120
|
+
✓ Generated feature "product" in src/app/features/products
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 🔧 Core Generator
|
|
126
|
+
|
|
127
|
+
Creates core system assets like authentication, guards, and interceptors.
|
|
128
|
+
|
|
129
|
+
**Running without arguments generates ALL core assets automatically:**
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# Generate ALL core assets (recommended)
|
|
133
|
+
aca g core
|
|
134
|
+
|
|
135
|
+
# Output:
|
|
136
|
+
# 🚀 Generating ALL core assets: navbar, menu, theme-selector, language-selector, translate, auth...
|
|
137
|
+
# ✓ Generated core navbar in apps/sandbox/src/app/core/navbar
|
|
138
|
+
# ✓ Generated core menu in apps/sandbox/src/app/core/menu
|
|
139
|
+
# ...
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Generated Assets
|
|
143
|
+
|
|
144
|
+
| Asset | Description |
|
|
145
|
+
| ------------------- | ---------------------------------------- |
|
|
146
|
+
| `navbar` | Top navigation bar |
|
|
147
|
+
| `menu` | Side navigation menu |
|
|
148
|
+
| `theme-selector` | Dark/light theme toggle |
|
|
149
|
+
| `language-selector` | Language switcher component |
|
|
150
|
+
| `translate` | i18n translation setup |
|
|
151
|
+
| `auth` | Authentication service with login/logout |
|
|
152
|
+
|
|
153
|
+
### Generate Specific Asset
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Generate only a specific asset
|
|
157
|
+
aca g core --type=navbar
|
|
158
|
+
aca g core --type=auth
|
|
159
|
+
aca g core --type=guard
|
|
160
|
+
aca g core --type=interceptor
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## 🎨 Shared Generator
|
|
166
|
+
|
|
167
|
+
Creates shared reusable components and utilities.
|
|
168
|
+
|
|
169
|
+
**Running without arguments generates ALL shared UI components automatically:**
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# Generate ALL shared UI components (recommended)
|
|
173
|
+
aca g shared
|
|
174
|
+
|
|
175
|
+
# Output:
|
|
176
|
+
# 🚀 Generating standard shared UI components: button, card, input, icon, loader, confirm-dialog...
|
|
177
|
+
# ✓ Generated shared ui "button" in apps/sandbox/src/app/shared/ui/button
|
|
178
|
+
# ✓ Generated shared ui "card" in apps/sandbox/src/app/shared/ui/card
|
|
179
|
+
# ...
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Generated Components
|
|
183
|
+
|
|
184
|
+
| Component | Description |
|
|
185
|
+
| ---------------- | ----------------------------- |
|
|
186
|
+
| `button` | Reusable button component |
|
|
187
|
+
| `card` | Card container component |
|
|
188
|
+
| `input` | Form input component |
|
|
189
|
+
| `icon` | Icon wrapper component |
|
|
190
|
+
| `loader` | Loading spinner component |
|
|
191
|
+
| `confirm-dialog` | Confirmation dialog component |
|
|
192
|
+
|
|
193
|
+
### Generate Specific Component
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# Generate only a specific UI component
|
|
197
|
+
aca g shared myButton --type=ui
|
|
198
|
+
|
|
199
|
+
# Generate a utility module
|
|
200
|
+
aca g shared format --type=util
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 📋 Blueprint Mode
|
|
206
|
+
|
|
207
|
+
For complex features with multiple related models, use a JSON blueprint file.
|
|
208
|
+
|
|
209
|
+
### Blueprint Schema
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"name": "order",
|
|
214
|
+
"models": [
|
|
215
|
+
{
|
|
216
|
+
"name": "Order",
|
|
217
|
+
"attributes": [
|
|
218
|
+
{ "name": "customerId", "type": "string" },
|
|
219
|
+
{ "name": "total", "type": "number" },
|
|
220
|
+
{ "name": "status", "type": "string" }
|
|
221
|
+
]
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"name": "OrderItem",
|
|
225
|
+
"attributes": [
|
|
226
|
+
{ "name": "orderId", "type": "string" },
|
|
227
|
+
{ "name": "productId", "type": "string" },
|
|
228
|
+
{ "name": "quantity", "type": "number" }
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Generate from Blueprint
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
aca g feature --blueprint=./order-blueprint.json
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Example: E-Commerce Blueprint
|
|
242
|
+
|
|
243
|
+
```json
|
|
244
|
+
{
|
|
245
|
+
"name": "ecommerce",
|
|
246
|
+
"models": [
|
|
247
|
+
{
|
|
248
|
+
"name": "Product",
|
|
249
|
+
"attributes": [
|
|
250
|
+
{ "name": "name", "type": "string" },
|
|
251
|
+
{ "name": "price", "type": "number" },
|
|
252
|
+
{ "name": "stock", "type": "number" },
|
|
253
|
+
{ "name": "imageUrl", "type": "string" }
|
|
254
|
+
]
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"name": "Cart",
|
|
258
|
+
"attributes": [
|
|
259
|
+
{ "name": "userId", "type": "string" },
|
|
260
|
+
{ "name": "items", "type": "CartItem[]" },
|
|
261
|
+
{ "name": "total", "type": "number" }
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## 📂 Feature Schema (Batch Generation)
|
|
271
|
+
|
|
272
|
+
The CLI automatically stores feature definitions in `feature-schema.json`. When you run `aca g feature` without arguments, it can batch-generate all features defined in this schema.
|
|
273
|
+
|
|
274
|
+
### Schema Format
|
|
275
|
+
|
|
276
|
+
```json
|
|
277
|
+
{
|
|
278
|
+
"version": "1.0",
|
|
279
|
+
"lastUpdated": "2026-01-04T20:11:51.889Z",
|
|
280
|
+
"features": {
|
|
281
|
+
"product": {
|
|
282
|
+
"name": "product",
|
|
283
|
+
"attributes": [
|
|
284
|
+
{ "name": "name", "type": "string" },
|
|
285
|
+
{ "name": "price", "type": "number" }
|
|
286
|
+
]
|
|
287
|
+
},
|
|
288
|
+
"book": {
|
|
289
|
+
"name": "book",
|
|
290
|
+
"attributes": [
|
|
291
|
+
{ "name": "title", "type": "string" },
|
|
292
|
+
{ "name": "author", "type": "string" }
|
|
293
|
+
]
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Batch Generation
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
# Running without a name triggers batch generation from feature-schema.json
|
|
303
|
+
aca g feature
|
|
304
|
+
|
|
305
|
+
# Output:
|
|
306
|
+
# 🚀 Found 4 features in feature-schema.json. Generating...
|
|
307
|
+
# ✓ Generated feature "product" in src/app/features/products
|
|
308
|
+
# ✓ Generated feature "book" in src/app/features/books
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## 🏛️ Architecture Overview
|
|
314
|
+
|
|
315
|
+
Generated features follow **Clean Architecture** (Hexagonal Architecture) principles:
|
|
316
|
+
|
|
317
|
+
```
|
|
318
|
+
┌─────────────────────────────────────────────────────────┐
|
|
319
|
+
│ UI Layer │
|
|
320
|
+
│ (Components, Templates, Styles) │
|
|
321
|
+
├─────────────────────────────────────────────────────────┤
|
|
322
|
+
│ Application Layer │
|
|
323
|
+
│ (NgRx SignalStore, Selectors) │
|
|
324
|
+
├─────────────────────────────────────────────────────────┤
|
|
325
|
+
│ Infrastructure Layer │
|
|
326
|
+
│ (HTTP Services, API Clients) │
|
|
327
|
+
├─────────────────────────────────────────────────────────┤
|
|
328
|
+
│ Domain Layer │
|
|
329
|
+
│ (Interfaces, Types, Business Rules) │
|
|
330
|
+
└─────────────────────────────────────────────────────────┘
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Dependency Flow
|
|
334
|
+
|
|
335
|
+
```
|
|
336
|
+
UI → Application → Infrastructure → Domain
|
|
337
|
+
↓
|
|
338
|
+
External APIs
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
- **Domain**: Pure TypeScript, zero dependencies
|
|
342
|
+
- **Infrastructure**: Depends on Domain
|
|
343
|
+
- **Application**: Depends on Infrastructure + Domain
|
|
344
|
+
- **UI**: Depends on Application
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## 💡 Best Practices
|
|
349
|
+
|
|
350
|
+
### ✅ Feature Naming
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
# Good (singular, kebab-case)
|
|
354
|
+
aca g feature product
|
|
355
|
+
aca g feature user-profile
|
|
356
|
+
aca g feature order-item
|
|
357
|
+
|
|
358
|
+
# Avoid
|
|
359
|
+
aca g feature products # Will become "productss"
|
|
360
|
+
aca g feature UserProfile # Use kebab-case
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### ✅ Attribute Types
|
|
364
|
+
|
|
365
|
+
```bash
|
|
366
|
+
# Use appropriate TypeScript types
|
|
367
|
+
--attributes="name:string,age:number,isActive:boolean,createdAt:Date,tags:string[]"
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### ✅ Blueprint Organization
|
|
371
|
+
|
|
372
|
+
```
|
|
373
|
+
project-root/
|
|
374
|
+
├── blueprints/
|
|
375
|
+
│ ├── user.json
|
|
376
|
+
│ ├── product.json
|
|
377
|
+
│ └── order.json
|
|
378
|
+
└── src/
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
383
|
+
## 🔗 Nx Workspace Integration
|
|
384
|
+
|
|
385
|
+
When using within an Nx monorepo:
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
# Generate feature using Nx
|
|
389
|
+
nx g cli:feature product
|
|
390
|
+
|
|
391
|
+
# Generate core assets
|
|
392
|
+
nx g cli:core app --type=navbar
|
|
393
|
+
|
|
394
|
+
# Generate shared components
|
|
395
|
+
nx g cli:shared button --type=ui
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## 📚 Resources
|
|
401
|
+
|
|
402
|
+
- [Architecture Documentation](https://github.com/MohamedBouattour/angular-clean-architecture/blob/main/ARCHITECTURE.md)
|
|
403
|
+
- [Examples & Scenarios](./EXAMPLES.md)
|
|
404
|
+
- [Roadmap](https://github.com/MohamedBouattour/angular-clean-architecture/blob/main/ROADMAP.md)
|
|
405
|
+
- [GitHub Issues](https://github.com/MohamedBouattour/angular-clean-architecture/issues)
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## 🤝 Contributing
|
|
410
|
+
|
|
411
|
+
1. Fork the repository
|
|
412
|
+
2. Create your feature branch: `git checkout -b feature/amazing-feature`
|
|
413
|
+
3. Commit your changes: `git commit -m 'Add amazing feature'`
|
|
414
|
+
4. Push to the branch: `git push origin feature/amazing-feature`
|
|
415
|
+
5. Open a Pull Request
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
## 📝 License
|
|
420
|
+
|
|
421
|
+
MIT © [Mohamed Bouattour](https://github.com/MohamedBouattour)
|
|
422
|
+
|
|
423
|
+
---
|
|
424
|
+
|
|
425
|
+
**Built with ❤️ for the Angular community**
|
package/bin/index.js
CHANGED
|
@@ -1,4 +1,102 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
const { spawn } = require('child_process');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
|
|
8
|
+
function findWorkspaceRoot(dir) {
|
|
9
|
+
if (fs.existsSync(path.join(dir, 'nx.json')) || fs.existsSync(path.join(dir, 'package.json'))) {
|
|
10
|
+
if (fs.existsSync(path.join(dir, 'nx.json'))) {
|
|
11
|
+
return dir;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const parent = path.dirname(dir);
|
|
15
|
+
if (parent === dir) return null;
|
|
16
|
+
return findWorkspaceRoot(parent);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const root = findWorkspaceRoot(process.cwd());
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Executes an Nx generator command
|
|
23
|
+
* @param {string} generator - The generator name (e.g., 'feature', 'core', 'shared')
|
|
24
|
+
* @param {string[]} remainingArgs - Additional arguments to pass
|
|
25
|
+
*/
|
|
26
|
+
function runGenerator(generator, remainingArgs) {
|
|
27
|
+
const nxArgs = ['g', `cli:${generator}`];
|
|
28
|
+
|
|
29
|
+
remainingArgs.forEach(arg => {
|
|
30
|
+
nxArgs.push(arg);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
console.log(`Executing: npx nx ${nxArgs.join(' ')}`);
|
|
34
|
+
|
|
35
|
+
const child = spawn('npx', ['nx', ...nxArgs], {
|
|
36
|
+
stdio: 'inherit',
|
|
37
|
+
shell: true,
|
|
38
|
+
cwd: root || process.cwd(),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
child.on('exit', (code) => {
|
|
42
|
+
process.exit(code || 0);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Parse commands
|
|
47
|
+
if (args[0] === 'generate' || args[0] === 'g') {
|
|
48
|
+
const generatorType = args[1];
|
|
49
|
+
const remainingArgs = args.slice(2);
|
|
50
|
+
|
|
51
|
+
// Parse name from positional argument
|
|
52
|
+
const nxArgs = [];
|
|
53
|
+
if (remainingArgs[0] && !remainingArgs[0].startsWith('-')) {
|
|
54
|
+
nxArgs.push(`--name=${remainingArgs[0]}`);
|
|
55
|
+
remainingArgs.shift();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Pass through all other flags
|
|
59
|
+
remainingArgs.forEach(arg => nxArgs.push(arg));
|
|
60
|
+
|
|
61
|
+
switch (generatorType) {
|
|
62
|
+
case 'feature':
|
|
63
|
+
case 'f':
|
|
64
|
+
runGenerator('feature', nxArgs);
|
|
65
|
+
break;
|
|
66
|
+
case 'core':
|
|
67
|
+
case 'c':
|
|
68
|
+
runGenerator('core', nxArgs);
|
|
69
|
+
break;
|
|
70
|
+
case 'shared':
|
|
71
|
+
case 's':
|
|
72
|
+
runGenerator('shared', nxArgs);
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
console.log('\x1b[31m%s\x1b[0m', `Unknown generator: ${generatorType}`);
|
|
76
|
+
console.log('Available generators: feature (f), core (c), shared (s)');
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
console.log('\x1b[36m%s\x1b[0m', 'Angular Clean Architecture CLI');
|
|
81
|
+
console.log('');
|
|
82
|
+
console.log('Usage:');
|
|
83
|
+
console.log(' aca generate <generator> [name] [options]');
|
|
84
|
+
console.log(' aca g <generator> [name] [options]');
|
|
85
|
+
console.log('');
|
|
86
|
+
console.log('Generators:');
|
|
87
|
+
console.log(' feature (f) Generate a Clean Architecture feature');
|
|
88
|
+
console.log(' core (c) Generate a core asset (auth, guard, interceptor, etc.)');
|
|
89
|
+
console.log(' shared (s) Generate a shared component or utility');
|
|
90
|
+
console.log('');
|
|
91
|
+
console.log('Examples:');
|
|
92
|
+
console.log(' aca g feature products --attributes="name:string,price:number"');
|
|
93
|
+
console.log(' aca g core auth-service --type=service');
|
|
94
|
+
console.log(' aca g core app --type=navbar');
|
|
95
|
+
console.log(' aca g shared button --type=ui');
|
|
96
|
+
console.log('');
|
|
97
|
+
console.log('Run without options for interactive mode:');
|
|
98
|
+
console.log(' aca g feature');
|
|
99
|
+
console.log(' aca g core');
|
|
100
|
+
process.exit(0);
|
|
101
|
+
}
|
|
2
102
|
|
|
3
|
-
console.log("ACA CLI installed successfully!");
|
|
4
|
-
console.log("To use the generator, run: nx g @devmed555/angular-clean-architecture-cli:clean-feature");
|
package/generators.json
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
{
|
|
2
|
-
"generators": {
|
|
3
|
-
"
|
|
4
|
-
"factory": "./src/generators/
|
|
5
|
-
"schema": "./src/generators/
|
|
6
|
-
"description": "
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
{
|
|
2
|
+
"generators": {
|
|
3
|
+
"feature": {
|
|
4
|
+
"factory": "./src/generators/feature/generator",
|
|
5
|
+
"schema": "./src/generators/feature/schema.json",
|
|
6
|
+
"description": "Generate a Clean Architecture feature with domain, infrastructure, application, and UI layers"
|
|
7
|
+
},
|
|
8
|
+
"shared": {
|
|
9
|
+
"factory": "./src/generators/shared/generator",
|
|
10
|
+
"schema": "./src/generators/shared/schema.json",
|
|
11
|
+
"description": "Generate a shared UI component or utility"
|
|
12
|
+
},
|
|
13
|
+
"core": {
|
|
14
|
+
"factory": "./src/generators/core/generator",
|
|
15
|
+
"schema": "./src/generators/core/schema.json",
|
|
16
|
+
"description": "Generate a core system asset (Auth, Guard, Interceptor, Service)"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { inject } from '@angular/core';
|
|
2
|
+
import { Router } from '@angular/router';
|
|
3
|
+
import { AuthService } from './auth.service';
|
|
4
|
+
|
|
5
|
+
export const authGuard = () => {
|
|
6
|
+
const authService = inject(AuthService);
|
|
7
|
+
const router = inject(Router);
|
|
8
|
+
|
|
9
|
+
if (authService.isAuthenticated()) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return router.parseUrl('/login');
|
|
14
|
+
};
|