@tech4good/angular-schematics 13.0.0 → 13.2.0

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 (64) hide show
  1. package/README.md +10 -10
  2. package/package.json +1 -1
  3. package/src/collection.json +9 -4
  4. package/src/component/files/__name@dasherize__/__name@dasherize__.animations.ts.template +4 -0
  5. package/src/component/files/__name@dasherize__/__name@dasherize__.component.html.template +3 -0
  6. package/src/component/files/__name@dasherize__/__name@dasherize__.component.scss.template +7 -0
  7. package/src/component/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +25 -0
  8. package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +30 -0
  9. package/src/component/index.d.ts +1 -1
  10. package/src/component/index.js +85 -94
  11. package/src/component/index.js.map +1 -1
  12. package/src/component/schema.json +27 -13
  13. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +27 -0
  14. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +47 -0
  15. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.model.ts.template +0 -0
  16. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.selectors.ts.template +20 -0
  17. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.state.ts.template +13 -0
  18. package/src/container/files/__name@dasherize__/__name@dasherize__.animations.ts.template +4 -0
  19. package/src/container/files/__name@dasherize__/__name@dasherize__.component.html.template +3 -0
  20. package/src/container/files/__name@dasherize__/__name@dasherize__.component.scss.template +5 -0
  21. package/src/container/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +25 -0
  22. package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +81 -0
  23. package/src/container/index.d.ts +1 -1
  24. package/src/container/index.js +106 -273
  25. package/src/container/index.js.map +1 -1
  26. package/src/container/schema.json +28 -9
  27. package/src/entity/files/__name@dasherize__/__name@dasherize__.actions.ts.template +270 -0
  28. package/src/entity/files/__name@dasherize__/__name@dasherize__.effects.ts.template +131 -0
  29. package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +7 -0
  30. package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.spec.ts.template +13 -0
  31. package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.ts.template +51 -0
  32. package/src/entity/files/__name@dasherize__/__name@dasherize__.service.ts.template +50 -0
  33. package/src/entity/index.d.ts +1 -1
  34. package/src/entity/index.js +105 -506
  35. package/src/entity/index.js.map +1 -1
  36. package/src/entity/schema.json +25 -6
  37. package/src/init/files/.eslintrc.json +120 -0
  38. package/src/init/files/.gitattributes +11 -0
  39. package/src/init/files/.github/workflows/angular-github-ci.yml.template +60 -0
  40. package/src/init/files/angular.json.template +132 -0
  41. package/src/init/files/package.json.template +60 -0
  42. package/src/init/files/src/app/app.component.html +3 -0
  43. package/src/init/files/src/app/app.component.scss +4 -0
  44. package/src/init/files/src/app/general/e404/e404.component.html +1 -0
  45. package/src/init/files/src/app/general/e404/e404.component.scss +0 -0
  46. package/src/init/files/src/app/general/login/login.component.html +11 -0
  47. package/src/init/files/src/app/general/login/login.component.scss +29 -0
  48. package/src/init/files/src/index.html.template +19 -0
  49. package/src/init/files/src/styles/_variables.scss +0 -0
  50. package/src/init/files/src/styles.scss +13 -0
  51. package/src/init/index.d.ts +2 -0
  52. package/src/init/index.js +50 -0
  53. package/src/init/index.js.map +1 -0
  54. package/src/init/schema.json +28 -0
  55. package/src/module/files/__name@dasherize__/__name@dasherize__-routing.module.ts.template +13 -0
  56. package/src/module/files/__name@dasherize__/__name@dasherize__.module.spec.ts.template +13 -0
  57. package/src/module/files/__name@dasherize__/__name@dasherize__.module.ts.template +24 -0
  58. package/src/module/index.d.ts +1 -1
  59. package/src/module/index.js +87 -78
  60. package/src/module/index.js.map +1 -1
  61. package/src/module/schema.json +21 -6
  62. package/src/shared/statements-adder.d.ts +3 -0
  63. package/src/shared/statements-adder.js +22 -1
  64. package/src/shared/statements-adder.js.map +1 -1
@@ -1,525 +1,124 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.entity = void 0;
4
- const camelcase_formatter_1 = require("../shared/camelcase-formatter");
13
+ const schematics_1 = require("@angular-devkit/schematics");
14
+ const change_1 = require("@schematics/angular/utility/change");
15
+ const find_module_1 = require("@schematics/angular/utility/find-module");
16
+ const parse_name_1 = require("@schematics/angular/utility/parse-name");
17
+ const workspace_1 = require("@schematics/angular/utility/workspace");
18
+ const core_1 = require("@angular-devkit/core");
5
19
  const statements_adder_1 = require("../shared/statements-adder");
6
- const fs = require('fs');
7
- // You don't have to export the function as default. You can also have more than one rule factory
8
- // per file.
9
- function entity(_options) {
10
- return (tree, _context) => {
11
- const { name, description } = _options;
12
- const camelName = (0, camelcase_formatter_1.CamelCaseFormatter)(name, false);
13
- const lowerCamelName = (0, camelcase_formatter_1.CamelCaseFormatter)(name, true);
14
- const ActionsFile = `import { Action } from '@ngrx/store';
15
- import { LoadAction } from '../app.actions';
16
- import { ${camelName} } from './${name}.model';
17
-
18
- export enum ${camelName}ActionTypes {
19
- LOAD = '[${camelName}] load ${lowerCamelName}',
20
- LOAD_SUCCESS = '[${camelName}] load ${lowerCamelName} success',
21
- LOAD_FAIL = '[${camelName}] load ${lowerCamelName} fail',
22
- ADD = '[${camelName}] add ${lowerCamelName}',
23
- ADD_SUCCESS = '[${camelName}] add ${lowerCamelName} success',
24
- ADD_FAIL = '[${camelName}] add ${lowerCamelName} fail',
25
- UPDATE = '[${camelName}] update ${lowerCamelName}',
26
- UPDATE_SUCCESS = '[${camelName}] update ${lowerCamelName} success',
27
- UPDATE_FAIL = '[${camelName}] update ${lowerCamelName} fail',
28
- UPSERT = '[${camelName}] upsert ${lowerCamelName}',
29
- UPSERT_SUCCESS = '[${camelName}] upsert ${lowerCamelName} success',
30
- UPSERT_FAIL = '[${camelName}] upsert ${lowerCamelName} fail',
31
- REMOVE = '[${camelName}] remove ${lowerCamelName}',
32
- REMOVE_SUCCESS = '[${camelName}] remove ${lowerCamelName} success',
33
- REMOVE_FAIL = '[${camelName}] remove ${lowerCamelName} fail',
34
- LOADED = '[${camelName}] loaded',
35
- ADDED = '[${camelName}] added',
36
- MODIFIED = '[${camelName}] modified',
37
- REMOVED = '[${camelName}] removed',
38
- }
39
-
40
- // See Firebase Docs for current constraints on valid queries
41
- export class Load${camelName} implements Action {
42
- readonly type = ${camelName}ActionTypes.LOAD;
43
- constructor(
44
- // property, comparator, value
45
- public queryParams: [string, string, any][],
46
- public queryOptions: {
47
- orderBy?: string | [string, string],
48
- limit?: number,
49
- startAt?: string,
50
- startAfter?: string,
51
- endAt?: string,
52
- endBefore?: string,
53
- },
54
- public correlationId: string,
55
- public followupActions?: (${lowerCamelName}: ${camelName}) => LoadAction[],
56
- ) {}
57
- }
58
-
59
- export class Load${camelName}Success implements Action {
60
- readonly type = ${camelName}ActionTypes.LOAD_SUCCESS;
61
- constructor(
62
- public queryParams: [string, string, any][],
63
- public queryOptions: {
64
- orderBy?: string | [string, string],
65
- limit?: number,
66
- startAt?: string,
67
- startAfter?: string,
68
- endAt?: string,
69
- endBefore?: string,
70
- },
71
- public correlationId: string,
72
- public followupActions?: (${lowerCamelName}: ${camelName}) => LoadAction[],
73
- ) {}
74
- }
75
-
76
- export class Load${camelName}Fail implements Action {
77
- readonly type = ${camelName}ActionTypes.LOAD_FAIL;
78
- constructor(
79
- public error: any,
80
- public correlationId?: string,
81
- ) {}
82
- }
83
-
84
- export class Add${camelName} implements Action {
85
- readonly type = ${camelName}ActionTypes.ADD;
86
- constructor(
87
- public ${lowerCamelName}: ${camelName},
88
- public correlationId?: string,
89
- ) {}
90
- }
91
-
92
- export class Add${camelName}Success implements Action {
93
- readonly type = ${camelName}ActionTypes.ADD_SUCCESS;
94
- constructor(
95
- public ${lowerCamelName}: ${camelName},
96
- public correlationId?: string,
97
- ) {}
98
- }
99
-
100
- export class Add${camelName}Fail implements Action {
101
- readonly type = ${camelName}ActionTypes.ADD_FAIL;
102
- constructor(
103
- public error: any,
104
- public correlationId?: string,
105
- ) {}
106
- }
107
-
108
- export class Update${camelName} implements Action {
109
- readonly type = ${camelName}ActionTypes.UPDATE;
110
- constructor(
111
- public __id: string,
112
- public changes: Partial<${camelName}>,
113
- public correlationId?: string,
114
- ) { }
115
- }
116
-
117
- export class Update${camelName}Success implements Action {
118
- readonly type = ${camelName}ActionTypes.UPDATE_SUCCESS;
119
- constructor(
120
- public __id: string,
121
- public changes: Partial<${camelName}>,
122
- public correlationId?: string,
123
- ) {}
124
- }
125
-
126
- export class Update${camelName}Fail implements Action {
127
- readonly type = ${camelName}ActionTypes.UPDATE_FAIL;
128
- constructor(
129
- public error: any,
130
- public correlationId?: string,
131
- ) {}
132
- }
133
-
134
- export class Upsert${camelName} implements Action {
135
- readonly type = ${camelName}ActionTypes.UPSERT;
136
- constructor(
137
- public ${lowerCamelName}: ${camelName},
138
- public correlationId?: string,
139
- ) {}
140
- }
141
-
142
- export class Upsert${camelName}Success implements Action {
143
- readonly type = ${camelName}ActionTypes.UPSERT_SUCCESS;
144
- constructor(
145
- public ${lowerCamelName}: ${camelName},
146
- public correlationId?: string,
147
- ) {}
148
- }
149
-
150
- export class Upsert${camelName}Fail implements Action {
151
- readonly type = ${camelName}ActionTypes.UPSERT_FAIL;
152
- constructor(
153
- public error: any,
154
- public correlationId?: string,
155
- ) {}
156
- }
157
-
158
- export class Remove${camelName} implements Action {
159
- readonly type = ${camelName}ActionTypes.REMOVE;
160
- constructor(
161
- public __id: string,
162
- public correlationId?: string,
163
- ) { }
164
- }
165
-
166
- export class Remove${camelName}Success implements Action {
167
- readonly type = ${camelName}ActionTypes.REMOVE_SUCCESS;
168
- constructor(
169
- public __id: string,
170
- public correlationId?: string,
171
- ) {}
172
- }
173
-
174
- export class Remove${camelName}Fail implements Action {
175
- readonly type = ${camelName}ActionTypes.REMOVE_FAIL;
176
- constructor(
177
- public error: any,
178
- public correlationId?: string,
179
- ) {}
180
- }
181
-
182
- export class Loaded${camelName} implements Action {
183
- readonly type = ${camelName}ActionTypes.LOADED;
184
- constructor(
185
- public payload: ${camelName}[],
186
- public correlationId?: string,
187
- ) {}
188
- }
189
-
190
- export class Added${camelName} implements Action {
191
- readonly type = ${camelName}ActionTypes.ADDED;
192
- constructor(
193
- public payload: ${camelName},
194
- public correlationId?: string,
195
- ) {}
196
- }
197
-
198
- export class Modified${camelName} implements Action {
199
- readonly type = ${camelName}ActionTypes.MODIFIED;
200
- constructor(
201
- public payload: ${camelName},
202
- public correlationId?: string,
203
- ) {}
204
- }
205
-
206
- export class Removed${camelName} implements Action {
207
- readonly type = ${camelName}ActionTypes.REMOVED;
208
- constructor(
209
- public payload: ${camelName},
210
- public correlationId?: string,
211
- ) {}
212
- }
213
-
214
- export type ${camelName}Actions =
215
- Load${camelName} |
216
- Load${camelName}Success |
217
- Load${camelName}Fail |
218
- Add${camelName} |
219
- Add${camelName}Success |
220
- Add${camelName}Fail |
221
- Update${camelName} |
222
- Update${camelName}Success |
223
- Update${camelName}Fail |
224
- Upsert${camelName} |
225
- Upsert${camelName}Success |
226
- Upsert${camelName}Fail |
227
- Remove${camelName} |
228
- Remove${camelName}Success |
229
- Remove${camelName}Fail |
230
- Loaded${camelName} |
231
- Added${camelName} |
232
- Modified${camelName} |
233
- Removed${camelName};`;
234
- const EffectsFile = `import { Injectable } from '@angular/core';
235
- import { Action } from '@ngrx/store';
236
- import { Actions, createEffect, Effect, ofType } from '@ngrx/effects';
237
- import { EMPTY, of, Observable, throwError, forkJoin, from, pipe, merge } from 'rxjs';
238
- import { switchMap, flatMap, mergeMap, map, catchError, tap, take } from 'rxjs/operators';
239
- import { FirebaseService } from '../../firebase/firebase.service';
240
- import { CachedLoadConnectionsService } from '../cached-load-connections.service';
241
-
242
- import { ${camelName} } from './${name}.model';
243
- import { ${camelName}ActionTypes, ${camelName}Actions,
244
- Load${camelName}, Load${camelName}Success, Load${camelName}Fail,
245
- Add${camelName}, Add${camelName}Success, Add${camelName}Fail,
246
- Update${camelName}, Update${camelName}Success, Update${camelName}Fail,
247
- Upsert${camelName}, Upsert${camelName}Success, Upsert${camelName}Fail,
248
- Remove${camelName}, Remove${camelName}Success, Remove${camelName}Fail } from './${name}.actions';
249
-
250
- @Injectable()
251
- export class ${camelName}Effects {
252
-
253
- /** Process the load action to create firebase connections. */
254
- load$: Observable<Action> = createEffect(
255
- () => this.actions$.pipe(
256
- ofType<Load${camelName}>(${camelName}ActionTypes.LOAD),
257
- mergeMap((action: Load${camelName}) => {
258
- const connection = this.clc.processLoadAction(action);
259
- return connection.loadStream.pipe(
260
- take(1),
261
- map(() => new Load${camelName}Success(action.queryParams, action.queryOptions, action.correlationId, action.followupActions)),
262
- catchError((error) => of(new Load${camelName}Fail(error, action.correlationId))),
263
- );
264
- }),
265
- ),
266
- );
267
-
268
- /** Process the add action to update database and initiate callbacks. */
269
- add$: Observable<Action> = createEffect(
270
- () => this.actions$.pipe(
271
- ofType<Add${camelName}>(${camelName}ActionTypes.ADD),
272
- mergeMap((action: Add${camelName}) => {
273
- return this.db.addEntity('${lowerCamelName}s', action.${lowerCamelName}).pipe(
274
- mergeMap(() => merge(
275
- of(new Add${camelName}Success(action.${lowerCamelName}, action.correlationId)),
276
- this.actionsOnAdd(action),
277
- )),
278
- catchError((error) => of(new Add${camelName}Fail(error, action.correlationId))),
279
- );
280
- }),
281
- ),
282
- );
283
-
284
- /** Process the update action to update database and initiate callbacks. */
285
- update$: Observable<Action> = createEffect(
286
- () => this.actions$.pipe(
287
- ofType<Update${camelName}>(${camelName}ActionTypes.UPDATE),
288
- mergeMap((action: Update${camelName}) => {
289
- return this.db.updateEntity('${lowerCamelName}s', action.__id, action.changes).pipe(
290
- mergeMap(() => merge(
291
- of(new Update${camelName}Success(action.__id, action.changes, action.correlationId)),
292
- this.actionsOnUpdate(action),
293
- )),
294
- catchError((error) => of(new Update${camelName}Fail(error, action.correlationId))),
295
- );
296
- }),
297
- ),
298
- );
299
-
300
- /** Process the upsert action to update database and initiate callbacks. */
301
- upsert$: Observable<Action> = createEffect(
302
- () => this.actions$.pipe(
303
- ofType<Upsert${camelName}>(${camelName}ActionTypes.UPSERT),
304
- mergeMap((action: Upsert${camelName}) => {
305
- return this.db.upsertEntity('${lowerCamelName}s', action.${lowerCamelName}).pipe(
306
- mergeMap((results) => merge(
307
- of(new Upsert${camelName}Success(action.${lowerCamelName}, action.correlationId)),
308
- results.type === 'add' ? this.actionsOnAdd(new Add${camelName}(action.${lowerCamelName}, action.correlationId)) : this.actionsOnUpdate(new Update${camelName}(action.${lowerCamelName}.__id, action.${lowerCamelName}, action.correlationId)),
309
- )),
310
- catchError((error) => of(new Upsert${camelName}Fail(error, action.correlationId))),
311
- );
312
- }),
313
- ),
314
- );
315
-
316
- /** Process the remove action to update database and initiate callbacks. */
317
- remove$: Observable<Action> = createEffect(
318
- () => this.actions$.pipe(
319
- ofType<Remove${camelName}>(${camelName}ActionTypes.REMOVE),
320
- mergeMap((action: Remove${camelName}) => {
321
- return this.db.removeEntity('${lowerCamelName}s', action.__id).pipe(
322
- mergeMap(() => merge(
323
- of(new Remove${camelName}Success(action.__id, action.correlationId)),
324
- this.actionsOnRemove(action),
325
- )),
326
- catchError((error) => of(new Remove${camelName}Fail(error, action.correlationId))),
327
- );
328
- }),
329
- ),
330
- );
331
-
332
- actionsOnAdd(action: Add${camelName}): Observable<Action> {
333
- return EMPTY;
334
- }
335
-
336
- actionsOnUpdate(action: Update${camelName}): Observable<Action> {
337
- return EMPTY;
338
- }
339
-
340
- actionsOnRemove(action: Remove${camelName}): Observable<Action> {
341
- return EMPTY;
342
- }
343
-
344
- constructor(
345
- private actions$: Actions,
346
- private db: FirebaseService,
347
- private clc: CachedLoadConnectionsService,
348
- ) {}
349
- }`;
350
- const ModelFile = `import { firestore } from 'firebase/app';
351
-
352
- /** ${description} */
353
- export interface ${camelName} {
354
- __id: string;
355
- _createdAt?: firestore.Timestamp;
356
- _updatedAt?: firestore.Timestamp;
357
- }`;
358
- const SpecFile = `import { reducer, initialState } from './${name}.reducer';
359
-
360
- describe('${camelName} Reducer', () => {
361
- describe('unknown action', () => {
362
- it('should return the initial state', () => {
363
- const action = {} as any;
364
-
365
- const result = reducer(initialState, action);
366
-
367
- expect(result).toBe(initialState);
368
- });
369
- });
370
- });`;
371
- const ReducerFile = `import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
372
- import { ${camelName} } from './${name}.model';
373
- import { ${camelName}Actions, ${camelName}ActionTypes } from './${name}.actions';
374
- import { createFeatureSelector } from '@ngrx/store';
375
-
376
- export interface State extends EntityState<${camelName}> {
377
- // additional entities state properties
378
- }
379
-
380
- export const adapter: EntityAdapter<${camelName}> = createEntityAdapter<${camelName}>({
381
- selectId: (${lowerCamelName}: ${camelName}) => ${lowerCamelName}.__id,
382
- sortComparer: false,
383
- });
384
-
385
- export const initialState: State = adapter.getInitialState({
386
- // additional entity state properties
387
- });
388
-
389
- export function reducer(
390
- state: State = initialState,
391
- action: ${camelName}Actions) {
392
-
393
- switch (action.type) {
394
-
395
- case ${camelName}ActionTypes.ADDED:
396
- return adapter.upsertOne(action.payload, state);
397
-
398
- case ${camelName}ActionTypes.LOADED:
399
- return adapter.upsertMany(action.payload, state);
400
-
401
- case ${camelName}ActionTypes.MODIFIED:
402
- return adapter.updateOne({
403
- id: action.payload.__id,
404
- changes: action.payload,
405
- }, state);
406
-
407
- case ${camelName}ActionTypes.REMOVED:
408
- return adapter.removeOne(action.payload.__id, state);
409
-
410
- default:
411
- return state;
412
- }
413
- }
414
-
415
- export const get${camelName}State = createFeatureSelector<State>('${lowerCamelName}');
416
-
417
- export const {
418
- selectIds,
419
- selectEntities,
420
- selectAll,
421
- selectTotal,
422
- } = adapter.getSelectors(get${camelName}State);`;
423
- const ServiceFile = `import { Injectable } from '@angular/core';
424
- import { Observable } from 'rxjs';
425
- import { CachedSelectorsService } from '../cached-selectors.service';
426
- import { FirebaseService } from '../../firebase/firebase.service';
427
- import { ${camelName} } from './${name}.model';
428
-
429
- @Injectable({
430
- providedIn: 'root',
431
- })
432
- export class ${camelName}Service {
433
-
434
- constructor(
435
- private cs: CachedSelectorsService,
436
- private db: FirebaseService,
437
- ) { }
438
-
439
- /** Select a ${lowerCamelName} from the store. */
440
- public select${camelName} = <T extends ${camelName}>(
441
- id: string,
442
- correlationId: string,
443
- childrenFn?: (e: ${camelName}) => { [index: string]: Observable<any> },
444
- ): Observable<T> => {
445
-
446
- return this.cs.selectEntityObj<${camelName}, T>('${lowerCamelName}', id, correlationId, childrenFn);
447
- }
448
-
449
- /** Select ${lowerCamelName}s from the store. */
450
- public select${camelName}s = <T extends ${camelName}>(
451
- queryParams: [string, string, any][],
452
- correlationId: string,
453
- childrenFn?: (e: ${camelName}) => { [index: string]: Observable<any> },
454
- ): Observable<Array<T>> => {
455
-
456
- return this.cs.selectEntityList<${camelName}, T>('${lowerCamelName}', queryParams, correlationId, childrenFn);
457
- }
458
-
459
- /** Get a ${lowerCamelName} directly from the database. */
460
- public get${camelName} = <T extends ${camelName}>(
461
- id: string,
462
- childrenFn?: (e: ${camelName}) => { [index: string]: Observable<any> },
463
- ): Observable<T> => {
464
-
465
- return this.db.queryObjOnce<${camelName}, T>('${lowerCamelName}s', id, childrenFn);
466
- }
467
-
468
- /** Get ${lowerCamelName}s directly from the database. */
469
- public get${camelName}s = <T extends ${camelName}>(
470
- queryParams: [string, string, any][],
471
- queryOptions?: { [index: string]: any },
472
- childrenFn?: (e: ${camelName}) => { [index: string]: Observable<any> },
473
- ): Observable<Array<T>> => {
474
-
475
- return this.db.queryListOnce<${camelName}, T>('${lowerCamelName}s', queryParams, queryOptions, childrenFn);
476
- }
477
- }`;
478
- (0, statements_adder_1.AddStatements)('src/app/core/core.module.ts', [
20
+ function addInserts(options) {
21
+ return (host, context) => {
22
+ const classifiedName = core_1.strings.classify(options.name);
23
+ const camelizedName = core_1.strings.camelize(options.name);
24
+ context.logger.info(`names: ${classifiedName}, ${camelizedName}`);
25
+ // Add core module changes
26
+ const coreModulePath = options.module;
27
+ const coreModuleText = (0, statements_adder_1.getSourceText)(host, coreModulePath);
28
+ context.logger.info(`modulePath: ${coreModulePath}`);
29
+ const entityEffectsPath = `/${options.path}/` +
30
+ core_1.strings.dasherize(options.name) + '/' +
31
+ core_1.strings.dasherize(options.name) + '.effects';
32
+ context.logger.info(`entityEffectsPath: ${entityEffectsPath}`);
33
+ const coreToEffectsPath = (0, find_module_1.buildRelativePath)(coreModulePath, entityEffectsPath);
34
+ context.logger.info(`coreToEffectsPath: ${coreToEffectsPath}`);
35
+ let insertChangesInCore = (0, statements_adder_1.simpleInsert)(coreModuleText, coreModulePath, [
479
36
  '// Entity Effects',
480
37
  '// Entity Effects'
481
38
  ], [
482
- `import { ${camelName}Effects } from './store/${name}/${name}.effects';`,
483
- ` ${camelName}Effects,`
484
- ], tree);
485
- (0, statements_adder_1.AddStatements)('src/app/core/firebase/firebase.mock.service.ts', [
486
- '// Entity Models',
487
- 'this.mockDBChanges = {'
488
- ], [
489
- `import { ${camelName} } from '../store/${name}/${name}.model';`,
490
- ` ${lowerCamelName}s: new BehaviorSubject<Array<{ type: string, result: ${camelName} }>>\n(this.mockDBService.getInitialDBStateChanges('${lowerCamelName}s')),`
491
- ], tree);
492
- (0, statements_adder_1.AddStatements)('src/app/core/store/app.reducer.ts', [
39
+ `import { ${classifiedName}Effects } from '${coreToEffectsPath}';`,
40
+ ` ${classifiedName}Effects,`
41
+ ]);
42
+ // Add app reducer changes
43
+ const appReducerPath = '//src/app/core/store/app.reducer.ts';
44
+ const appReducerText = (0, statements_adder_1.getSourceText)(host, appReducerPath);
45
+ context.logger.info(`appReducerPath: ${appReducerPath}`);
46
+ const entityReducerPath = `/${options.path}/` +
47
+ core_1.strings.dasherize(options.name) + '/' +
48
+ core_1.strings.dasherize(options.name) + '.reducer';
49
+ context.logger.info(`entityReducerPath: ${entityReducerPath}`);
50
+ const appToEntityReducerPath = (0, find_module_1.buildRelativePath)(appReducerPath, entityReducerPath);
51
+ let insertChangesInAppReducer = (0, statements_adder_1.simpleInsert)(appReducerText, appReducerPath, [
493
52
  '// Entity Reducers',
494
53
  '// Entity State',
495
54
  '// Entity Reducers'
496
55
  ], [
497
- `import * as from${camelName} from './${name}/${name}.reducer';`,
498
- ` ${lowerCamelName}: from${camelName}.State;`,
499
- ` ${lowerCamelName}: from${camelName}.reducer,`
500
- ], tree);
501
- (0, statements_adder_1.AddStatements)('src/app/core/store/app.selectors.ts', [
56
+ `import * as from${classifiedName} from '${appToEntityReducerPath}';`,
57
+ ` ${camelizedName}: from${classifiedName}.State;`,
58
+ ` ${camelizedName}: from${classifiedName}.reducer,`
59
+ ]);
60
+ // Add app selector changes
61
+ const appSelectorPath = '//src/app/core/store/app.selectors.ts';
62
+ const appSelectorText = (0, statements_adder_1.getSourceText)(host, appSelectorPath);
63
+ const entityServicePath = `/${options.path}/` +
64
+ core_1.strings.dasherize(options.name) + '/' +
65
+ core_1.strings.dasherize(options.name) + '.service';
66
+ const appToEntityServicePath = (0, find_module_1.buildRelativePath)(appSelectorPath, entityServicePath);
67
+ let insertChangesInAppSelector = (0, statements_adder_1.simpleInsert)(appSelectorText, appSelectorPath, [
502
68
  '// Entity Selectors',
503
69
  '// Entity Selectors',
504
70
  '// Entity Selectors'
505
71
  ], [
506
- `import { ${camelName}Service } from './${name}/${name}.service';`,
507
- ` private ${lowerCamelName}: ${camelName}Service,`,
508
- ` public get${camelName} = this.${lowerCamelName}.get${camelName};\n public get${camelName}s = this.${lowerCamelName}.get${camelName}s;\n public select${camelName} = this.${lowerCamelName}.select${camelName};\n public select${camelName}s = this.${lowerCamelName}.select${camelName}s;`
509
- ], tree);
510
- // create directories before adding files
511
- const dir = `./src/app/core/store/${name}`;
512
- if (!fs.existsSync(dir)) {
513
- fs.mkdirSync(dir);
514
- }
515
- tree.create(`${dir}/${name}.actions.ts`, ActionsFile);
516
- tree.create(`${dir}/${name}.effects.ts`, EffectsFile);
517
- tree.create(`${dir}/${name}.model.ts`, ModelFile);
518
- tree.create(`${dir}/${name}.reducer.spec.ts`, SpecFile);
519
- tree.create(`${dir}/${name}.reducer.ts`, ReducerFile);
520
- tree.create(`${dir}/${name}.service.ts`, ServiceFile);
521
- return tree;
72
+ `import { ${classifiedName}Service } from '${appToEntityServicePath}';`,
73
+ ` private ${camelizedName}: ${classifiedName}Service,`,
74
+ ` public get${classifiedName} = this.${camelizedName}.get${classifiedName};\n public get${classifiedName}s = this.${camelizedName}.get${classifiedName}s;\n public select${classifiedName} = this.${camelizedName}.select${classifiedName};\n public select${classifiedName}s = this.${camelizedName}.select${classifiedName}s;`
75
+ ]);
76
+ context.logger.info(`about to start committing`);
77
+ // For each of the files and corresponding set of changes, commit to the tree
78
+ [
79
+ [coreModulePath, insertChangesInCore],
80
+ [appReducerPath, insertChangesInAppReducer],
81
+ [appSelectorPath, insertChangesInAppSelector]
82
+ ].map(([filePath, insertChanges]) => {
83
+ const declarationRecorder = host.beginUpdate(filePath);
84
+ for (const change of insertChanges) {
85
+ if (change instanceof change_1.InsertChange) {
86
+ declarationRecorder.insertLeft(change.pos, change.toAdd);
87
+ }
88
+ }
89
+ host.commitUpdate(declarationRecorder);
90
+ });
91
+ return host;
522
92
  };
523
93
  }
94
+ function entity(options) {
95
+ return (tree, context) => __awaiter(this, void 0, void 0, function* () {
96
+ // Make sure the command is executed in the directory where the component should be generated
97
+ if (!options.inDirectory) {
98
+ context.logger.info("Please navigate to the directory where you want to generate the entity.");
99
+ return (0, schematics_1.noop)();
100
+ }
101
+ const workspace = yield (0, workspace_1.getWorkspace)(tree);
102
+ const project = workspace.projects.get(options.project);
103
+ if (!project) {
104
+ throw new schematics_1.SchematicsException(`Project "${options.project}" does not exist.`);
105
+ }
106
+ if (options.path === undefined) {
107
+ options.path = (0, workspace_1.buildDefaultPath)(project);
108
+ }
109
+ options.module = (0, find_module_1.findModuleFromOptions)(tree, options);
110
+ const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
111
+ options.name = parsedPath.name;
112
+ options.path = parsedPath.path;
113
+ const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
114
+ (0, schematics_1.applyTemplates)(Object.assign(Object.assign({}, core_1.strings), options)),
115
+ (0, schematics_1.move)(parsedPath.path),
116
+ ]);
117
+ return (0, schematics_1.chain)([
118
+ addInserts(options),
119
+ (0, schematics_1.mergeWith)(templateSource)
120
+ ]);
121
+ });
122
+ }
524
123
  exports.entity = entity;
525
124
  //# sourceMappingURL=index.js.map