@barcidev/ngx-autogen 0.1.71 β 0.1.72
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 +339 -302
- package/README_ES.md +385 -0
- package/package.json +3 -1
- package/src/angular/component/index.js +136 -8
- package/src/angular/component/schema.json +20 -0
- package/src/angular/component/types/types.d.ts +4 -0
- package/src/ngrx/store/files/state/store/__name@dasherize__.store.ts.template +7 -8
- package/src/ngrx/store/index.js +19 -22
- package/README.es.md +0 -352
- package/src/angular/component/files/__name@dasherize__.component.css.template +0 -0
- package/src/angular/component/files/__name@dasherize__.component.html.template +0 -20
- package/src/angular/component/files/__name@dasherize__.component.spec.ts.template +0 -25
- package/src/angular/component/files/__name@dasherize__.component.ts.template +0 -17
package/README.md
CHANGED
|
@@ -1,352 +1,389 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./logo.png" alt="ngx-autogen logo" width="120">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="./ngx_autogen_banner_1777684797010.png" alt="ngx-autogen banner" width="100%">
|
|
7
|
+
</p>
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="README.md">πΊπΈ English</a> | <a href="README_ES.md">πͺπΈ EspaΓ±ol</a>
|
|
11
|
+
</p>
|
|
7
12
|
|
|
8
|
-
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.npmjs.com/package/@barcidev/ngx-autogen"><img src="https://img.shields.io/npm/v/@barcidev/ngx-autogen?style=for-the-badge&color=007acc&labelColor=010101" alt="npm version"></a>
|
|
15
|
+
<a href="https://github.com/jpalacio09/ngx-autogen/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@barcidev/ngx-autogen?style=for-the-badge&color=green&labelColor=010101" alt="license"></a>
|
|
16
|
+
<img src="https://img.shields.io/badge/Angular-17%2B-DD0031?style=for-the-badge&logo=angular&labelColor=010101" alt="Angular 17+">
|
|
17
|
+
<img src="https://img.shields.io/badge/NgRx%20Signals-17%2B-BA2BD2?style=for-the-badge&logo=ngrx&labelColor=010101" alt="NgRx Signals 17+">
|
|
18
|
+
</p>
|
|
9
19
|
|
|
10
|
-
|
|
20
|
+
<p align="center">
|
|
21
|
+
<b>β‘ Angular schematics that scaffold complete NgRx Signal Store entities, Transloco i18n scopes, and standalone components in seconds. β‘</b>
|
|
22
|
+
</p>
|
|
11
23
|
|
|
12
|
-
|
|
24
|
+
---
|
|
13
25
|
|
|
14
|
-
##
|
|
26
|
+
## π Table of Contents
|
|
15
27
|
|
|
16
|
-
|
|
28
|
+
- [Overview](#overview)
|
|
29
|
+
- [Requirements](#requirements)
|
|
30
|
+
- [Installation](#installation)
|
|
31
|
+
- [Via ng add (recommended)](#via-ng-add-recommended)
|
|
32
|
+
- [Via npm](#via-npm)
|
|
33
|
+
- [Runtime Exports](#runtime-exports)
|
|
34
|
+
- [Schematics Reference](#schematics-reference)
|
|
35
|
+
- [ng-add](#ng-add)
|
|
36
|
+
- [app-store](#app-store)
|
|
37
|
+
- [app-i18n](#app-i18n)
|
|
38
|
+
- [app-component](#app-component)
|
|
39
|
+
- [License](#license)
|
|
17
40
|
|
|
18
|
-
|
|
19
|
-
- Scaffolding for advanced components.
|
|
41
|
+
---
|
|
20
42
|
|
|
21
|
-
##
|
|
43
|
+
## π Overview
|
|
22
44
|
|
|
23
|
-
|
|
45
|
+
`@barcidev/ngx-autogen` is a collection of Angular schematics designed to eliminate repetitive scaffolding when building enterprise Angular applications. It generates production-ready code for three core concerns:
|
|
46
|
+
|
|
47
|
+
- **NgRx Signal Store** (`app-store`) - Full CRUD signal store with entity management, pagination state, status tracking, and an accompanying service and model layer. Built on `@ngrx/signals` and `@ngrx/signals/entities`.
|
|
48
|
+
- **Transloco i18n** (`app-i18n`) - Scoped translation files with typed Transloco integration via `@barcidev/typed-transloco`, automatic provider registration, and global type map updates.
|
|
49
|
+
- **Angular Component** (`app-component`) - Standalone component generation via `@schematics/angular` with optional automatic store and i18n wiring.
|
|
50
|
+
|
|
51
|
+
The library also ships runtime utilities under `@barcidev/ngx-autogen/entity` that provide reusable NgRx Signal Store features: `withEntityStatus`, `withPagination`, and typed model helpers.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## π Requirements
|
|
56
|
+
|
|
57
|
+
| Dependency | Minimum Version |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `@angular/core` | `>=17.0.0` |
|
|
60
|
+
| `@angular/common` | `>=17.0.0` |
|
|
61
|
+
| `@angular/forms` | `>=17.0.0` |
|
|
62
|
+
| `@ngrx/signals` | `>=17.0.0` |
|
|
63
|
+
| Node.js | `>=16.0.0` |
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## π Installation
|
|
68
|
+
|
|
69
|
+
### Via ng add (recommended)
|
|
24
70
|
|
|
25
71
|
```bash
|
|
26
|
-
ng add ngx-autogen
|
|
72
|
+
ng add @barcidev/ngx-autogen
|
|
27
73
|
```
|
|
28
74
|
|
|
29
|
-
|
|
75
|
+
This command performs the following actions automatically:
|
|
30
76
|
|
|
31
|
-
|
|
77
|
+
1. **Moves the library to `devDependencies`** - If installed as a production dependency, it is relocated to `devDependencies` in `package.json`.
|
|
78
|
+
2. **Registers the schematic collection** - Adds `@barcidev/ngx-autogen` to `cli.schematicCollections` in `angular.json`, enabling short-form aliases like `ng g app-store`.
|
|
79
|
+
3. **Stores global configuration** - Saves the selected default language (`lang`) under `schematics["@barcidev/ngx-autogen:all"]` in `angular.json` so all schematics inherit it.
|
|
32
80
|
|
|
33
|
-
|
|
81
|
+
**Prompt:**
|
|
34
82
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- `grouped` (optional): if true, the files will be grouped into subfolders `models`, `services`, and `store`.
|
|
83
|
+
| Prompt | Default |
|
|
84
|
+
|---|---|
|
|
85
|
+
| What is the default language for the application (en, es)? | `en` |
|
|
39
86
|
|
|
40
|
-
|
|
87
|
+
### Via npm
|
|
41
88
|
|
|
42
89
|
```bash
|
|
43
|
-
|
|
90
|
+
npm install @barcidev/ngx-autogen --save-dev
|
|
44
91
|
```
|
|
45
92
|
|
|
46
|
-
|
|
93
|
+
> [!NOTE]
|
|
94
|
+
> When installing via npm, you must manually register the collection in `angular.json` and use the fully qualified schematic name (e.g., `ng generate @barcidev/ngx-autogen:app-store`).
|
|
47
95
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
βββ user.model.ts
|
|
61
|
-
βββ user.store.ts
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
The `index.ts` file will export everything necessary so that the store can be imported and used anywhere in the application.
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## π οΈ Runtime Exports
|
|
99
|
+
|
|
100
|
+
The library exports reusable NgRx Signal Store features under the `@barcidev/ngx-autogen/entity` entry point:
|
|
101
|
+
|
|
102
|
+
| Export | Description |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `withEntityStatus()` | Signal Store feature that adds loading, error, and selection state tracking for entities. |
|
|
105
|
+
| `withPagination()` | Signal Store feature that adds pagination state (page, size, total). |
|
|
106
|
+
| `RequestConfig<TPayload, TResponse>` | Generic type for store method configurations with `payload`, `onSuccess`, and `onError` callbacks. |
|
|
107
|
+
| `FormGroupType<T>` | Utility type that maps an interface to its Angular `FormGroup` control types. |
|
|
65
108
|
|
|
66
109
|
```typescript
|
|
67
|
-
|
|
68
|
-
export * from './user/user.model';
|
|
69
|
-
export * from './user/user.service';
|
|
70
|
-
export * from './user/user.store';
|
|
110
|
+
import { withEntityStatus, withPagination, RequestConfig, FormGroupType } from '@barcidev/ngx-autogen/entity';
|
|
71
111
|
```
|
|
72
112
|
|
|
73
|
-
|
|
113
|
+
---
|
|
74
114
|
|
|
75
|
-
|
|
115
|
+
## π Schematics Reference
|
|
76
116
|
|
|
77
|
-
|
|
78
|
-
import { HttpErrorResponse } from '@angular/common/http';
|
|
79
|
-
import { FormControl } from '@angular/forms';
|
|
117
|
+
### `ng-add`
|
|
80
118
|
|
|
81
|
-
|
|
82
|
-
[K in keyof T]: FormControl<T[K]>;
|
|
83
|
-
};
|
|
119
|
+
**Description**: Ng add schematic for ngx-autogen. Configures the workspace for using all library schematics.
|
|
84
120
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
payload: T;
|
|
89
|
-
}
|
|
121
|
+
**Usage**
|
|
122
|
+
```bash
|
|
123
|
+
ng add @barcidev/ngx-autogen
|
|
90
124
|
```
|
|
91
125
|
|
|
92
|
-
|
|
126
|
+
**Options**
|
|
93
127
|
|
|
94
|
-
|
|
95
|
-
|
|
128
|
+
| Option | Type | Default | Required | Description |
|
|
129
|
+
|---|---|---|---|---|
|
|
130
|
+
| `lang` | `string` | `en` | No | The default language for the application (`en`, `es`). |
|
|
96
131
|
|
|
97
|
-
|
|
98
|
-
}
|
|
132
|
+
---
|
|
99
133
|
|
|
100
|
-
|
|
134
|
+
### `app-store`
|
|
101
135
|
|
|
102
|
-
|
|
103
|
-
cod: number;
|
|
104
|
-
}
|
|
136
|
+
> Alias: `ng g app-store` (when collection is registered via `ng add`)
|
|
105
137
|
|
|
106
|
-
|
|
138
|
+
**Description**: Adds NgRx Store to the Angular application with signal support. Generates a complete CRUD signal store, service, and model layer for a given entity.
|
|
107
139
|
|
|
108
|
-
|
|
140
|
+
**Usage**
|
|
141
|
+
```bash
|
|
142
|
+
# Short form (requires ng add):
|
|
143
|
+
ng g app-store --name product
|
|
144
|
+
|
|
145
|
+
# Full form:
|
|
146
|
+
ng generate @barcidev/ngx-autogen:app-store --name product
|
|
109
147
|
```
|
|
110
148
|
|
|
111
|
-
|
|
149
|
+
**Options**
|
|
112
150
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
151
|
+
| Option | Type | Default | Required | Description |
|
|
152
|
+
|---|---|---|---|---|
|
|
153
|
+
| `name` | `string` | - | **Yes** | Name of the entity. Used to derive all class names, file names, and store methods. |
|
|
154
|
+
| `path` | `string` | *(cwd)* | No | Destination path. Defaults to the current working directory relative to `src/`. |
|
|
155
|
+
| `grouped` | `boolean` | `false` | No | Whether the files should be grouped in `models/` and `services/` subfolders. |
|
|
156
|
+
| `pk` | `string` | `id` | No | The name of the default Primary Key (e.g., `id`, `cod`, `uuid`). |
|
|
157
|
+
| `lang` | `string` | *(global)* | No | The default language for the application (`en`, `es`). Inherited from `ng add` config. |
|
|
158
|
+
| `isProvideInRoot` | `boolean` | `false` | No | Whether the store and service should use `providedIn: 'root'`. |
|
|
159
|
+
|
|
160
|
+
**What it generates**
|
|
161
|
+
|
|
162
|
+
For a given entity name, this schematic creates:
|
|
163
|
+
|
|
164
|
+
- `<name>.store.ts` - NgRx Signal Store with full CRUD methods (`add`, `load`, `update`, `remove`, `select`), entity config, computed selectors, and `onInit` hook.
|
|
165
|
+
- `<name>.service.ts` - Injectable service with stub methods for `add$`, `get$` (pluralized), `update$`, and `remove$`.
|
|
166
|
+
- `<name>.model.ts` - TypeScript interfaces: `Add<Name>`, `<Name>Dto`, `Update<Name>`, `Add<Name>Form`, and `<Name>Request`.
|
|
167
|
+
- `state/index.ts` - Barrel file with re-exports (created or updated).
|
|
168
|
+
|
|
169
|
+
It also:
|
|
170
|
+
- Installs `@ngrx/signals` if not already present (matching Angular major version).
|
|
171
|
+
- Configures `@shared-state/*` path alias in `tsconfig.app.json`.
|
|
172
|
+
- Saves `pk` and `lang` defaults in `angular.json`.
|
|
173
|
+
|
|
174
|
+
**Examples**
|
|
175
|
+
|
|
176
|
+
**Minimal - Entity with defaults:**
|
|
177
|
+
```bash
|
|
178
|
+
ng g app-store --name product
|
|
179
|
+
```
|
|
180
|
+
```
|
|
181
|
+
src/app/state/
|
|
182
|
+
index.ts
|
|
183
|
+
product/
|
|
184
|
+
product.model.ts
|
|
185
|
+
product.service.ts
|
|
186
|
+
product.store.ts
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Grouped layout with custom PK:**
|
|
190
|
+
```bash
|
|
191
|
+
ng g app-store --name invoice --grouped --pk cod
|
|
192
|
+
```
|
|
193
|
+
```
|
|
194
|
+
src/app/state/
|
|
195
|
+
index.ts
|
|
196
|
+
invoice/
|
|
197
|
+
models/
|
|
198
|
+
invoice.model.ts
|
|
199
|
+
services/
|
|
200
|
+
invoice.service.ts
|
|
201
|
+
invoice.store.ts
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Provided in root with Spanish pluralization:**
|
|
205
|
+
```bash
|
|
206
|
+
ng g app-store --name usuario --isProvideInRoot --lang es
|
|
207
|
+
```
|
|
208
|
+
```
|
|
209
|
+
src/app/state/
|
|
210
|
+
index.ts
|
|
211
|
+
usuario/
|
|
212
|
+
usuario.model.ts # interfaces with pk: id
|
|
213
|
+
usuario.service.ts # @Injectable({ providedIn: 'root' })
|
|
214
|
+
usuario.store.ts # signalStore({ providedIn: 'root' }, ...) - methods use "Usuarios" (Spanish plural)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
121
218
|
|
|
122
|
-
|
|
123
|
-
providedIn: 'root'
|
|
124
|
-
})
|
|
125
|
-
export class UserService {
|
|
219
|
+
### `app-i18n`
|
|
126
220
|
|
|
127
|
-
|
|
128
|
-
return of(0);
|
|
129
|
-
}
|
|
221
|
+
> Alias: `ng g app-i18n` (when collection is registered via `ng add`)
|
|
130
222
|
|
|
131
|
-
|
|
132
|
-
return of(true);
|
|
133
|
-
}
|
|
223
|
+
**Description**: Adds Transloco to the Angular application. Generates a scoped i18n translation file and wires it into the target component.
|
|
134
224
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
225
|
+
**Usage**
|
|
226
|
+
```bash
|
|
227
|
+
# Short form:
|
|
228
|
+
ng g app-i18n --name dashboard
|
|
138
229
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
}
|
|
230
|
+
# Full form:
|
|
231
|
+
ng generate @barcidev/ngx-autogen:app-i18n --name dashboard
|
|
143
232
|
```
|
|
144
233
|
|
|
145
|
-
|
|
234
|
+
**Options**
|
|
146
235
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}),
|
|
302
|
-
switchMap(({ onError, onSuccess, payload }) => {
|
|
303
|
-
return userService.updateUser$(entity).pipe(
|
|
304
|
-
tap((response) => {
|
|
305
|
-
if (response) {
|
|
306
|
-
const idsUpdating = store.status.idsUpdating() || [];
|
|
307
|
-
patchState(store, updateEntity({ changes: payload, id: payload.cod }, config), (state) => ({
|
|
308
|
-
status: {
|
|
309
|
-
...state.status,
|
|
310
|
-
_updateLoading: false,
|
|
311
|
-
error: null,
|
|
312
|
-
idsUpdating: idsUpdating.filter((idUpdating) => idUpdating !== payload.cod)
|
|
313
|
-
}
|
|
314
|
-
}));
|
|
315
|
-
if (onSuccess) {
|
|
316
|
-
onSuccess(response);
|
|
317
|
-
}
|
|
318
|
-
} else {
|
|
319
|
-
throw new Error('');
|
|
320
|
-
}
|
|
321
|
-
}),
|
|
322
|
-
catchError(() => {
|
|
323
|
-
const idsUpdating = store.status.idsUpdating() || [];
|
|
324
|
-
patchState(store, (state) => ({
|
|
325
|
-
status: {
|
|
326
|
-
...state.status,
|
|
327
|
-
_updateLoading: false,
|
|
328
|
-
error: new Error('Error al actualizar user'),
|
|
329
|
-
idsUpdating: idsUpdating.filter((idUpdating) => idUpdating !== payload.cod)
|
|
330
|
-
}
|
|
331
|
-
}));
|
|
332
|
-
if (onError) {
|
|
333
|
-
onError();
|
|
334
|
-
}
|
|
335
|
-
return EMPTY;
|
|
336
|
-
})
|
|
337
|
-
);
|
|
338
|
-
})
|
|
339
|
-
)
|
|
340
|
-
),
|
|
341
|
-
})),
|
|
342
|
-
withHooks({
|
|
343
|
-
onInit: (store) => {
|
|
344
|
-
store.loadUsers();
|
|
345
|
-
},
|
|
346
|
-
})
|
|
347
|
-
);
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
## π License
|
|
351
|
-
|
|
352
|
-
This project is under the [MIT](LICENSE) license.
|
|
236
|
+
| Option | Type | Default | Required | Description |
|
|
237
|
+
|---|---|---|---|---|
|
|
238
|
+
| `name` | `string` | *(auto-detected)* | No | Name of the component. Auto-detected from the `.component.ts` file in the current directory if not provided. |
|
|
239
|
+
| `path` | `string` | *(cwd)* | No | Destination path. Defaults to the current working directory relative to `src/`. |
|
|
240
|
+
| `lang` | `string` | *(global)* | No | Language for pluralization (`en` for English, `es` for Spanish). |
|
|
241
|
+
|
|
242
|
+
**What it generates**
|
|
243
|
+
|
|
244
|
+
- `<name>.i18n.ts` - Translation scope file with `en-US` and `es-CO` objects registered via `TranslocoUtils.createScopeConfig`.
|
|
245
|
+
|
|
246
|
+
It also:
|
|
247
|
+
- Runs `@barcidev/typed-transloco:ng-add` if Transloco is not yet configured in the project.
|
|
248
|
+
- Adds `provideTranslocoScopeWrapper` to the component's `providers` array.
|
|
249
|
+
- Adds `AppTypedTranslocoDirective` to the component's `imports` array.
|
|
250
|
+
- Updates the global `app.i18n.ts` type map with the new scope.
|
|
251
|
+
|
|
252
|
+
**Examples**
|
|
253
|
+
|
|
254
|
+
**Auto-detect component in current directory:**
|
|
255
|
+
```bash
|
|
256
|
+
cd src/app/features/dashboard
|
|
257
|
+
ng g app-i18n
|
|
258
|
+
```
|
|
259
|
+
```
|
|
260
|
+
src/app/features/dashboard/
|
|
261
|
+
dashboard.i18n.ts # new
|
|
262
|
+
dashboard.component.ts # updated with providers + imports
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Explicit name and path:**
|
|
266
|
+
```bash
|
|
267
|
+
ng g app-i18n --name settings --path src/app/features/settings
|
|
268
|
+
```
|
|
269
|
+
```
|
|
270
|
+
src/app/features/settings/
|
|
271
|
+
settings.i18n.ts
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
**With Spanish pluralization:**
|
|
275
|
+
```bash
|
|
276
|
+
ng g app-i18n --name usuario --lang es
|
|
277
|
+
```
|
|
278
|
+
```
|
|
279
|
+
src/app/features/usuario/
|
|
280
|
+
usuario.i18n.ts # scope key: "usuario", pluralization uses Spanish rules
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
### `app-component`
|
|
286
|
+
|
|
287
|
+
> Alias: `ng g app-component` (when collection is registered via `ng add`)
|
|
288
|
+
|
|
289
|
+
**Description**: Generates an Angular component with optional i18n and NgRx support. Delegates to `@schematics/angular:component` for base generation, then optionally chains `app-store` and `app-i18n` schematics.
|
|
290
|
+
|
|
291
|
+
**Usage**
|
|
292
|
+
```bash
|
|
293
|
+
# Short form:
|
|
294
|
+
ng g app-component --name product-list
|
|
295
|
+
|
|
296
|
+
# Full form:
|
|
297
|
+
ng generate @barcidev/ngx-autogen:app-component --name product-list
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**Options**
|
|
301
|
+
|
|
302
|
+
| Option | Type | Default | Required | Description |
|
|
303
|
+
|---|---|---|---|---|
|
|
304
|
+
| `name` | `string` | - | **Yes** | Name of the component. |
|
|
305
|
+
| `store` | `string` | - | No | Whether to create a store for the component. Enum: `Yes`, `No`. |
|
|
306
|
+
| `i18n` | `string` | - | No | Whether to create an i18n file for the component. Enum: `Yes`, `No`. |
|
|
307
|
+
| `pk` | `string` | `id` | No | The name of the default Primary Key. Only used when `store` is `Yes`. |
|
|
308
|
+
| `isProvideInRoot` | `boolean` | `false` | No | Whether the store and service should be provided in root. Only used when `store` is `Yes`. |
|
|
309
|
+
| `path` | `string` | *(cwd)* | No | Destination path. |
|
|
310
|
+
| `lang` | `string` | *(global)* | No | Language for pluralization (`en`, `es`). |
|
|
311
|
+
| `style` | `string` | `css` | No | The file extension or preprocessor to use for style files. |
|
|
312
|
+
| `skipTests` | `boolean` | `false` | No | Do not create `spec.ts` test files. |
|
|
313
|
+
| `inlineStyle` | `boolean` | `false` | No | Include styles inline in the component `.ts` file. |
|
|
314
|
+
| `inlineTemplate` | `boolean` | `false` | No | Include template inline in the component `.ts` file. |
|
|
315
|
+
|
|
316
|
+
**Interactive prompts** (when `store` is `Yes`):
|
|
317
|
+
|
|
318
|
+
| Prompt | Default |
|
|
319
|
+
|---|---|
|
|
320
|
+
| What is the name of the entity store to create? | *(component name)* |
|
|
321
|
+
| What is the name of the default Primary Key? | `id` |
|
|
322
|
+
| Should the store and service be provided in root? | `No` |
|
|
323
|
+
|
|
324
|
+
**What it generates**
|
|
325
|
+
|
|
326
|
+
The base component is generated by the official `@schematics/angular:component` schematic with `standalone: true`. Depending on options:
|
|
327
|
+
|
|
328
|
+
- **With `store: Yes`**: Chains `app-store` schematic inside the component directory, injects the store into the component class, adds `JsonPipe` to imports, wires `data$` computed property, and configures `providers` with `provide<Name>Store()` (unless `isProvideInRoot` is true). Also updates the `.spec.ts` with store mock providers.
|
|
329
|
+
- **With `i18n: Yes`**: Chains `app-i18n` schematic inside the component directory.
|
|
330
|
+
|
|
331
|
+
**Examples**
|
|
332
|
+
|
|
333
|
+
**Minimal - Component only:**
|
|
334
|
+
```bash
|
|
335
|
+
ng g app-component --name dashboard --store No --i18n No
|
|
336
|
+
```
|
|
337
|
+
```
|
|
338
|
+
src/app/dashboard/
|
|
339
|
+
dashboard.component.ts
|
|
340
|
+
dashboard.component.html
|
|
341
|
+
dashboard.component.css
|
|
342
|
+
dashboard.component.spec.ts
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
**Component with store and i18n:**
|
|
346
|
+
```bash
|
|
347
|
+
ng g app-component --name product-list --store Yes --i18n Yes --style scss
|
|
348
|
+
```
|
|
349
|
+
```
|
|
350
|
+
src/app/product-list/
|
|
351
|
+
product-list.component.ts # injects ProductListStore, data$, JsonPipe, providers
|
|
352
|
+
product-list.component.html # <div *typedTransloco="let t; prefix:'productList'">
|
|
353
|
+
product-list.component.scss
|
|
354
|
+
product-list.component.spec.ts # TestBed configured with store mock
|
|
355
|
+
product-list.i18n.ts
|
|
356
|
+
state/
|
|
357
|
+
index.ts
|
|
358
|
+
product-list/
|
|
359
|
+
product-list.model.ts
|
|
360
|
+
product-list.service.ts
|
|
361
|
+
product-list.store.ts
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
**Component with custom entity store name and root provider:**
|
|
365
|
+
```bash
|
|
366
|
+
ng g app-component --name user-profile --store Yes --i18n No --pk uuid --isProvideInRoot
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
When prompted for the entity store name, enter `user` instead of the default `user-profile`:
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
src/app/user-profile/
|
|
373
|
+
user-profile.component.ts # injects UserStore (not UserProfileStore)
|
|
374
|
+
user-profile.component.html
|
|
375
|
+
user-profile.component.css
|
|
376
|
+
user-profile.component.spec.ts
|
|
377
|
+
state/
|
|
378
|
+
index.ts
|
|
379
|
+
user/
|
|
380
|
+
user.model.ts # pk field: uuid
|
|
381
|
+
user.service.ts # @Injectable({ providedIn: 'root' })
|
|
382
|
+
user.store.ts # signalStore({ providedIn: 'root' }, ...)
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## βοΈ License
|
|
388
|
+
|
|
389
|
+
[MIT](./LICENSE) - Jorge Palacio Barcinilla
|