@tech4good/angular-schematics 0.0.2 → 13.0.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.
- package/README.md +46 -46
- package/package.json +27 -27
- package/src/collection.json +25 -25
- package/src/component/index.d.ts +2 -2
- package/src/component/index.js +102 -102
- package/src/component/index.js.map +1 -1
- package/src/component/index_spec.d.ts +1 -1
- package/src/component/index_spec.js +22 -22
- package/src/component/schema.json +33 -29
- package/src/container/index.d.ts +2 -2
- package/src/container/index.js +282 -282
- package/src/container/index.js.map +1 -1
- package/src/container/index_spec.d.ts +1 -1
- package/src/container/index_spec.js +22 -22
- package/src/container/schema.json +28 -24
- package/src/entity/index.d.ts +2 -2
- package/src/entity/index.js +524 -524
- package/src/entity/index.js.map +1 -1
- package/src/entity/index_spec.d.ts +1 -1
- package/src/entity/index_spec.js +22 -22
- package/src/entity/schema.json +23 -19
- package/src/module/index.d.ts +2 -2
- package/src/module/index.js +87 -87
- package/src/module/index.js.map +1 -1
- package/src/module/index_spec.d.ts +1 -1
- package/src/module/index_spec.js +22 -22
- package/src/module/schema.json +23 -19
- package/src/shared/camelcase-formatter.d.ts +1 -1
- package/src/shared/camelcase-formatter.js +18 -18
- package/src/shared/statements-adder.d.ts +5 -5
- package/src/shared/statements-adder.js +31 -31
- package/tsconfig.json +34 -34
package/src/container/index.js
CHANGED
|
@@ -1,283 +1,283 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.container = void 0;
|
|
4
|
-
const camelcase_formatter_1 = require("../shared/camelcase-formatter");
|
|
5
|
-
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 container(_options) {
|
|
10
|
-
return (tree, _context) => {
|
|
11
|
-
const { name, module } = _options;
|
|
12
|
-
const camelName = camelcase_formatter_1.CamelCaseFormatter(name, false);
|
|
13
|
-
const ActionsFile = `import { Action } from '@ngrx/store';
|
|
14
|
-
|
|
15
|
-
export enum ${camelName}ActionTypes {
|
|
16
|
-
LOAD_DATA = '[${camelName}] load data',
|
|
17
|
-
CLEANUP = '[${camelName}] cleanup',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Action for loading required DB data. */
|
|
21
|
-
export class LoadData implements Action {
|
|
22
|
-
readonly type = ${camelName}ActionTypes.LOAD_DATA;
|
|
23
|
-
|
|
24
|
-
constructor(public payload: {
|
|
25
|
-
containerId: string,
|
|
26
|
-
}) { }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Action for cleaning up loading subscriptions. */
|
|
30
|
-
export class Cleanup implements Action {
|
|
31
|
-
readonly type = ${camelName}ActionTypes.CLEANUP;
|
|
32
|
-
constructor(public payload: {
|
|
33
|
-
containerId: string,
|
|
34
|
-
}) { }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type ${camelName}Actions =
|
|
38
|
-
LoadData |
|
|
39
|
-
Cleanup;
|
|
40
|
-
`;
|
|
41
|
-
const EffectsFile = `import { Injectable } from '@angular/core';
|
|
42
|
-
import { Action } from '@ngrx/store';
|
|
43
|
-
import { Actions, createEffect, Effect, ofType } from '@ngrx/effects';
|
|
44
|
-
|
|
45
|
-
import { of, Observable } from 'rxjs';
|
|
46
|
-
import { mergeMap, tap, map } from 'rxjs/operators';
|
|
47
|
-
|
|
48
|
-
import { select, Store } from '@ngrx/store';
|
|
49
|
-
import * as fromStore from '../../../core/store/app.reducer';
|
|
50
|
-
import { FirebaseService } from '../../../core/firebase/firebase.service';
|
|
51
|
-
import { EffectsHelpers } from '../../../core/store/effects.helpers';
|
|
52
|
-
import { ${camelName}State } from './${name}.state';
|
|
53
|
-
|
|
54
|
-
import { ActionFlow, RouterNavigate, LoadAction, Unsubscribe } from '../../../core/store/app.actions';
|
|
55
|
-
import { ${camelName}ActionTypes, Cleanup, LoadData } from './${name}.actions';
|
|
56
|
-
|
|
57
|
-
@Injectable()
|
|
58
|
-
export class ${camelName}Effects {
|
|
59
|
-
|
|
60
|
-
/** Load data from Firebase. */
|
|
61
|
-
loadData$: Observable<Action> = createEffect(
|
|
62
|
-
() => this.actions$.pipe(
|
|
63
|
-
ofType<LoadData>(${camelName}ActionTypes.LOAD_DATA),
|
|
64
|
-
mergeMap((action: LoadData) => {
|
|
65
|
-
|
|
66
|
-
const loadId = action.payload.containerId;
|
|
67
|
-
|
|
68
|
-
return [
|
|
69
|
-
];
|
|
70
|
-
}),
|
|
71
|
-
),
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
/** Unsubscribe connections from Firebase. */
|
|
75
|
-
cleanup$: Observable<Action> = createEffect(
|
|
76
|
-
() => this.actions$.pipe(
|
|
77
|
-
ofType<Cleanup>(${camelName}ActionTypes.CLEANUP),
|
|
78
|
-
map((action: Cleanup) => new Unsubscribe(action.payload.containerId)),
|
|
79
|
-
),
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
constructor(
|
|
83
|
-
private actions$: Actions,
|
|
84
|
-
private store: Store<fromStore.State>,
|
|
85
|
-
private state: ${camelName}State,
|
|
86
|
-
private db: FirebaseService,
|
|
87
|
-
private eh: EffectsHelpers,
|
|
88
|
-
) {}
|
|
89
|
-
}
|
|
90
|
-
`;
|
|
91
|
-
const SelectorsFile = `import { Injectable } from '@angular/core';
|
|
92
|
-
import { Store, select } from '@ngrx/store';
|
|
93
|
-
import * as fromStore from '../../../core/store/app.reducer';
|
|
94
|
-
import { EntitySelectorService } from '../../../core/store/app.selectors';
|
|
95
|
-
|
|
96
|
-
import { Observable, of, combineLatest } from 'rxjs';
|
|
97
|
-
import { bufferTime, distinctUntilChanged, shareReplay, mergeMap, filter, switchMap, map } from 'rxjs/operators';
|
|
98
|
-
|
|
99
|
-
@Injectable({
|
|
100
|
-
providedIn: 'root',
|
|
101
|
-
})
|
|
102
|
-
export class ${camelName}Selectors {
|
|
103
|
-
|
|
104
|
-
constructor(
|
|
105
|
-
private slRx: EntitySelectorService,
|
|
106
|
-
) { }
|
|
107
|
-
|
|
108
|
-
cleanup(cId: string) {
|
|
109
|
-
this.slRx.release(cId);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
`;
|
|
113
|
-
const StateFile = `import { Injectable } from '@angular/core';
|
|
114
|
-
|
|
115
|
-
import { BehaviorSubject } from 'rxjs';
|
|
116
|
-
|
|
117
|
-
@Injectable({
|
|
118
|
-
providedIn: 'root',
|
|
119
|
-
})
|
|
120
|
-
export class ${camelName}State {
|
|
121
|
-
|
|
122
|
-
// --------------- LOCAL UI STATE ----------------------
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
constructor(
|
|
126
|
-
) { }
|
|
127
|
-
}
|
|
128
|
-
`;
|
|
129
|
-
const AnimationsFile = `import { trigger, group, query, animateChild, state, style, animate, transition } from '@angular/animations';
|
|
130
|
-
|
|
131
|
-
export const ${camelName}Animations = [
|
|
132
|
-
];
|
|
133
|
-
`;
|
|
134
|
-
const HTMLFile = `<div class="${name}-container">
|
|
135
|
-
${name} works!
|
|
136
|
-
</div>`;
|
|
137
|
-
const CSSFile = `.${name}-container {
|
|
138
|
-
}`;
|
|
139
|
-
const SpecFile = `import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
140
|
-
|
|
141
|
-
import { ${camelName}Component } from './${name}.component';
|
|
142
|
-
|
|
143
|
-
describe('${camelName}Component', () => {
|
|
144
|
-
let component: ${camelName}Component;
|
|
145
|
-
let fixture: ComponentFixture<${camelName}Component>;
|
|
146
|
-
|
|
147
|
-
beforeEach(waitForAsync(() => {
|
|
148
|
-
TestBed.configureTestingModule({
|
|
149
|
-
declarations: [ ${camelName}Component ],
|
|
150
|
-
})
|
|
151
|
-
.compileComponents();
|
|
152
|
-
}));
|
|
153
|
-
|
|
154
|
-
beforeEach(() => {
|
|
155
|
-
fixture = TestBed.createComponent(${camelName}Component);
|
|
156
|
-
component = fixture.componentInstance;
|
|
157
|
-
fixture.detectChanges();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('should create', () => {
|
|
161
|
-
expect(component).toBeTruthy();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
`;
|
|
165
|
-
const ComponentFile = `import { Component, OnInit, OnDestroy, ChangeDetectionStrategy } from '@angular/core';
|
|
166
|
-
import { ${camelName}Animations } from './${name}.animations';
|
|
167
|
-
import { ParamMap, ActivatedRoute } from '@angular/router';
|
|
168
|
-
import { Store, select } from '@ngrx/store';
|
|
169
|
-
import * as fromStore from '../../core/store/app.reducer';
|
|
170
|
-
import * as fromAuth from '../../core/store/auth/auth.reducer';
|
|
171
|
-
import { FirebaseService } from '../../core/firebase/firebase.service';
|
|
172
|
-
import { Observable, Subject, BehaviorSubject, combineLatest } from 'rxjs';
|
|
173
|
-
import { withLatestFrom, take, takeUntil } from 'rxjs/operators';
|
|
174
|
-
|
|
175
|
-
import { ${camelName}State } from './+state/${name}.state';
|
|
176
|
-
import { ${camelName}Selectors } from './+state/${name}.selectors';
|
|
177
|
-
|
|
178
|
-
import { LoadData, Cleanup } from './+state/${name}.actions';
|
|
179
|
-
import { RouterNavigate } from '../../core/store/app.actions';
|
|
180
|
-
|
|
181
|
-
import { User } from '../../core/store/user/user.model';
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
@Component({
|
|
185
|
-
selector: 'app-${name}',
|
|
186
|
-
templateUrl: './${name}.component.html',
|
|
187
|
-
styleUrls: ['./${name}.component.scss'],
|
|
188
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
189
|
-
animations: ${camelName}Animations,
|
|
190
|
-
})
|
|
191
|
-
export class ${camelName}Component implements OnInit, OnDestroy {
|
|
192
|
-
|
|
193
|
-
// --------------- ROUTE PARAMS & CURRENT USER ---------
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// --------------- LOCAL UI STATE ----------------------
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
// --------------- DB ENTITY DATA ----------------------
|
|
200
|
-
|
|
201
|
-
/** Container id for selectors and loading. */
|
|
202
|
-
containerId: string = this.db.createId();
|
|
203
|
-
|
|
204
|
-
// --------------- DATA BINDING STREAMS ----------------
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// --------------- EVENT BINDING STREAMS ---------------
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
// --------------- OTHER -------------------------------
|
|
211
|
-
|
|
212
|
-
/** Unsubscribe observable for subscriptions. */
|
|
213
|
-
unsubscribe$: Subject<void> = new Subject();
|
|
214
|
-
|
|
215
|
-
constructor(
|
|
216
|
-
private state: ${camelName}State,
|
|
217
|
-
private route: ActivatedRoute,
|
|
218
|
-
private selectors: ${camelName}Selectors,
|
|
219
|
-
private store: Store<fromStore.State>,
|
|
220
|
-
private db: FirebaseService,
|
|
221
|
-
) {
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
ngOnInit() {
|
|
225
|
-
|
|
226
|
-
// --------------- EVENT HANDLING ----------------------
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
// --------------- LOAD DATA ---------------------------
|
|
230
|
-
|
|
231
|
-
// Once everything is set up, load the data for the role.
|
|
232
|
-
this.store.dispatch( new LoadData({
|
|
233
|
-
containerId: this.containerId,
|
|
234
|
-
}) );
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
ngOnDestroy() {
|
|
238
|
-
// Unsubscribe subscriptions.
|
|
239
|
-
this.unsubscribe$.next();
|
|
240
|
-
this.unsubscribe$.complete();
|
|
241
|
-
|
|
242
|
-
// Unsubscribe from firebase connection from load and free up memoized selector values.
|
|
243
|
-
this.store.dispatch( new Cleanup({
|
|
244
|
-
containerId: this.containerId,
|
|
245
|
-
}) );
|
|
246
|
-
this.selectors.cleanup(this.containerId);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
`;
|
|
250
|
-
const ModuleRoutingFile = `${module}-routing.module.ts`;
|
|
251
|
-
const ModuleFile = `${module}.module.ts`;
|
|
252
|
-
const filePath = `./src/app/${module}/${ModuleRoutingFile}`;
|
|
253
|
-
const labels = ['// Containers', 'const routes: Routes = ['];
|
|
254
|
-
const statements = [`import { ${camelName}Component } from './${name}/${name}.component';`, ` { path: '${name}', component: ${camelName}Component }`];
|
|
255
|
-
statements_adder_1.AddStatements(filePath, labels, statements, tree);
|
|
256
|
-
const filePath2 = `./src/app/${module}/${ModuleFile}`;
|
|
257
|
-
const labels2 = ['// Containers', 'EffectsModule.forFeature([', '// Containers'];
|
|
258
|
-
const statements2 = [`import { ${camelName}Component } from './${name}/${name}.component';\nimport { ${camelName}Effects } from './${name}/+state/${name}.effects';`, ` ${camelName}Effects,`, ` ${camelName}Component,`];
|
|
259
|
-
statements_adder_1.AddStatements(filePath2, labels2, statements2, tree);
|
|
260
|
-
// create directories before adding files
|
|
261
|
-
const dir = `./src/app/${module}/${name}`;
|
|
262
|
-
if (!fs.existsSync(dir)) {
|
|
263
|
-
fs.mkdirSync(dir);
|
|
264
|
-
}
|
|
265
|
-
const statePath = `${dir}/+state`;
|
|
266
|
-
if (!fs.existsSync(statePath)) {
|
|
267
|
-
fs.mkdirSync(statePath);
|
|
268
|
-
}
|
|
269
|
-
tree.create(`${statePath}/${name}.actions.ts`, ActionsFile);
|
|
270
|
-
tree.create(`${statePath}/${name}.effects.ts`, EffectsFile);
|
|
271
|
-
tree.create(`${statePath}/${name}.model.ts`, '');
|
|
272
|
-
tree.create(`${statePath}/${name}.selectors.ts`, SelectorsFile);
|
|
273
|
-
tree.create(`${statePath}/${name}.state.ts`, StateFile);
|
|
274
|
-
tree.create(`${dir}/${name}.animations.ts`, AnimationsFile);
|
|
275
|
-
tree.create(`${dir}/${name}.component.html`, HTMLFile);
|
|
276
|
-
tree.create(`${dir}/${name}.component.scss`, CSSFile);
|
|
277
|
-
tree.create(`${dir}/${name}.component.spec.ts`, SpecFile);
|
|
278
|
-
tree.create(`${dir}/${name}.component.ts`, ComponentFile);
|
|
279
|
-
return tree;
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
exports.container = container;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.container = void 0;
|
|
4
|
+
const camelcase_formatter_1 = require("../shared/camelcase-formatter");
|
|
5
|
+
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 container(_options) {
|
|
10
|
+
return (tree, _context) => {
|
|
11
|
+
const { name, module, description } = _options;
|
|
12
|
+
const camelName = (0, camelcase_formatter_1.CamelCaseFormatter)(name, false);
|
|
13
|
+
const ActionsFile = `import { Action } from '@ngrx/store';
|
|
14
|
+
|
|
15
|
+
export enum ${camelName}ActionTypes {
|
|
16
|
+
LOAD_DATA = '[${camelName}] load data',
|
|
17
|
+
CLEANUP = '[${camelName}] cleanup',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Action for loading required DB data. */
|
|
21
|
+
export class LoadData implements Action {
|
|
22
|
+
readonly type = ${camelName}ActionTypes.LOAD_DATA;
|
|
23
|
+
|
|
24
|
+
constructor(public payload: {
|
|
25
|
+
containerId: string,
|
|
26
|
+
}) { }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Action for cleaning up loading subscriptions. */
|
|
30
|
+
export class Cleanup implements Action {
|
|
31
|
+
readonly type = ${camelName}ActionTypes.CLEANUP;
|
|
32
|
+
constructor(public payload: {
|
|
33
|
+
containerId: string,
|
|
34
|
+
}) { }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type ${camelName}Actions =
|
|
38
|
+
LoadData |
|
|
39
|
+
Cleanup;
|
|
40
|
+
`;
|
|
41
|
+
const EffectsFile = `import { Injectable } from '@angular/core';
|
|
42
|
+
import { Action } from '@ngrx/store';
|
|
43
|
+
import { Actions, createEffect, Effect, ofType } from '@ngrx/effects';
|
|
44
|
+
|
|
45
|
+
import { of, Observable } from 'rxjs';
|
|
46
|
+
import { mergeMap, tap, map } from 'rxjs/operators';
|
|
47
|
+
|
|
48
|
+
import { select, Store } from '@ngrx/store';
|
|
49
|
+
import * as fromStore from '../../../core/store/app.reducer';
|
|
50
|
+
import { FirebaseService } from '../../../core/firebase/firebase.service';
|
|
51
|
+
import { EffectsHelpers } from '../../../core/store/effects.helpers';
|
|
52
|
+
import { ${camelName}State } from './${name}.state';
|
|
53
|
+
|
|
54
|
+
import { ActionFlow, RouterNavigate, LoadAction, Unsubscribe } from '../../../core/store/app.actions';
|
|
55
|
+
import { ${camelName}ActionTypes, Cleanup, LoadData } from './${name}.actions';
|
|
56
|
+
|
|
57
|
+
@Injectable()
|
|
58
|
+
export class ${camelName}Effects {
|
|
59
|
+
|
|
60
|
+
/** Load data from Firebase. */
|
|
61
|
+
loadData$: Observable<Action> = createEffect(
|
|
62
|
+
() => this.actions$.pipe(
|
|
63
|
+
ofType<LoadData>(${camelName}ActionTypes.LOAD_DATA),
|
|
64
|
+
mergeMap((action: LoadData) => {
|
|
65
|
+
|
|
66
|
+
const loadId = action.payload.containerId;
|
|
67
|
+
|
|
68
|
+
return [
|
|
69
|
+
];
|
|
70
|
+
}),
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
/** Unsubscribe connections from Firebase. */
|
|
75
|
+
cleanup$: Observable<Action> = createEffect(
|
|
76
|
+
() => this.actions$.pipe(
|
|
77
|
+
ofType<Cleanup>(${camelName}ActionTypes.CLEANUP),
|
|
78
|
+
map((action: Cleanup) => new Unsubscribe(action.payload.containerId)),
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
constructor(
|
|
83
|
+
private actions$: Actions,
|
|
84
|
+
private store: Store<fromStore.State>,
|
|
85
|
+
private state: ${camelName}State,
|
|
86
|
+
private db: FirebaseService,
|
|
87
|
+
private eh: EffectsHelpers,
|
|
88
|
+
) {}
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
const SelectorsFile = `import { Injectable } from '@angular/core';
|
|
92
|
+
import { Store, select } from '@ngrx/store';
|
|
93
|
+
import * as fromStore from '../../../core/store/app.reducer';
|
|
94
|
+
import { EntitySelectorService } from '../../../core/store/app.selectors';
|
|
95
|
+
|
|
96
|
+
import { Observable, of, combineLatest } from 'rxjs';
|
|
97
|
+
import { bufferTime, distinctUntilChanged, shareReplay, mergeMap, filter, switchMap, map } from 'rxjs/operators';
|
|
98
|
+
|
|
99
|
+
@Injectable({
|
|
100
|
+
providedIn: 'root',
|
|
101
|
+
})
|
|
102
|
+
export class ${camelName}Selectors {
|
|
103
|
+
|
|
104
|
+
constructor(
|
|
105
|
+
private slRx: EntitySelectorService,
|
|
106
|
+
) { }
|
|
107
|
+
|
|
108
|
+
cleanup(cId: string) {
|
|
109
|
+
this.slRx.release(cId);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
`;
|
|
113
|
+
const StateFile = `import { Injectable } from '@angular/core';
|
|
114
|
+
|
|
115
|
+
import { BehaviorSubject } from 'rxjs';
|
|
116
|
+
|
|
117
|
+
@Injectable({
|
|
118
|
+
providedIn: 'root',
|
|
119
|
+
})
|
|
120
|
+
export class ${camelName}State {
|
|
121
|
+
|
|
122
|
+
// --------------- LOCAL UI STATE ----------------------
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
constructor(
|
|
126
|
+
) { }
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
const AnimationsFile = `import { trigger, group, query, animateChild, state, style, animate, transition } from '@angular/animations';
|
|
130
|
+
|
|
131
|
+
export const ${camelName}Animations = [
|
|
132
|
+
];
|
|
133
|
+
`;
|
|
134
|
+
const HTMLFile = `<div class="${name}-container">
|
|
135
|
+
${name} works!
|
|
136
|
+
</div>`;
|
|
137
|
+
const CSSFile = `.${name}-container {
|
|
138
|
+
}`;
|
|
139
|
+
const SpecFile = `import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
140
|
+
|
|
141
|
+
import { ${camelName}Component } from './${name}.component';
|
|
142
|
+
|
|
143
|
+
describe('${camelName}Component', () => {
|
|
144
|
+
let component: ${camelName}Component;
|
|
145
|
+
let fixture: ComponentFixture<${camelName}Component>;
|
|
146
|
+
|
|
147
|
+
beforeEach(waitForAsync(() => {
|
|
148
|
+
TestBed.configureTestingModule({
|
|
149
|
+
declarations: [ ${camelName}Component ],
|
|
150
|
+
})
|
|
151
|
+
.compileComponents();
|
|
152
|
+
}));
|
|
153
|
+
|
|
154
|
+
beforeEach(() => {
|
|
155
|
+
fixture = TestBed.createComponent(${camelName}Component);
|
|
156
|
+
component = fixture.componentInstance;
|
|
157
|
+
fixture.detectChanges();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should create', () => {
|
|
161
|
+
expect(component).toBeTruthy();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
`;
|
|
165
|
+
const ComponentFile = `import { Component, OnInit, OnDestroy, ChangeDetectionStrategy } from '@angular/core';
|
|
166
|
+
import { ${camelName}Animations } from './${name}.animations';
|
|
167
|
+
import { ParamMap, ActivatedRoute } from '@angular/router';
|
|
168
|
+
import { Store, select } from '@ngrx/store';
|
|
169
|
+
import * as fromStore from '../../core/store/app.reducer';
|
|
170
|
+
import * as fromAuth from '../../core/store/auth/auth.reducer';
|
|
171
|
+
import { FirebaseService } from '../../core/firebase/firebase.service';
|
|
172
|
+
import { Observable, Subject, BehaviorSubject, combineLatest } from 'rxjs';
|
|
173
|
+
import { withLatestFrom, take, takeUntil } from 'rxjs/operators';
|
|
174
|
+
|
|
175
|
+
import { ${camelName}State } from './+state/${name}.state';
|
|
176
|
+
import { ${camelName}Selectors } from './+state/${name}.selectors';
|
|
177
|
+
|
|
178
|
+
import { LoadData, Cleanup } from './+state/${name}.actions';
|
|
179
|
+
import { RouterNavigate } from '../../core/store/app.actions';
|
|
180
|
+
|
|
181
|
+
import { User } from '../../core/store/user/user.model';
|
|
182
|
+
|
|
183
|
+
/** ${description} */
|
|
184
|
+
@Component({
|
|
185
|
+
selector: 'app-${name}',
|
|
186
|
+
templateUrl: './${name}.component.html',
|
|
187
|
+
styleUrls: ['./${name}.component.scss'],
|
|
188
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
189
|
+
animations: ${camelName}Animations,
|
|
190
|
+
})
|
|
191
|
+
export class ${camelName}Component implements OnInit, OnDestroy {
|
|
192
|
+
|
|
193
|
+
// --------------- ROUTE PARAMS & CURRENT USER ---------
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
// --------------- LOCAL UI STATE ----------------------
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
// --------------- DB ENTITY DATA ----------------------
|
|
200
|
+
|
|
201
|
+
/** Container id for selectors and loading. */
|
|
202
|
+
containerId: string = this.db.createId();
|
|
203
|
+
|
|
204
|
+
// --------------- DATA BINDING STREAMS ----------------
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
// --------------- EVENT BINDING STREAMS ---------------
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
// --------------- OTHER -------------------------------
|
|
211
|
+
|
|
212
|
+
/** Unsubscribe observable for subscriptions. */
|
|
213
|
+
unsubscribe$: Subject<void> = new Subject();
|
|
214
|
+
|
|
215
|
+
constructor(
|
|
216
|
+
private state: ${camelName}State,
|
|
217
|
+
private route: ActivatedRoute,
|
|
218
|
+
private selectors: ${camelName}Selectors,
|
|
219
|
+
private store: Store<fromStore.State>,
|
|
220
|
+
private db: FirebaseService,
|
|
221
|
+
) {
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
ngOnInit() {
|
|
225
|
+
|
|
226
|
+
// --------------- EVENT HANDLING ----------------------
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
// --------------- LOAD DATA ---------------------------
|
|
230
|
+
|
|
231
|
+
// Once everything is set up, load the data for the role.
|
|
232
|
+
this.store.dispatch( new LoadData({
|
|
233
|
+
containerId: this.containerId,
|
|
234
|
+
}) );
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
ngOnDestroy() {
|
|
238
|
+
// Unsubscribe subscriptions.
|
|
239
|
+
this.unsubscribe$.next();
|
|
240
|
+
this.unsubscribe$.complete();
|
|
241
|
+
|
|
242
|
+
// Unsubscribe from firebase connection from load and free up memoized selector values.
|
|
243
|
+
this.store.dispatch( new Cleanup({
|
|
244
|
+
containerId: this.containerId,
|
|
245
|
+
}) );
|
|
246
|
+
this.selectors.cleanup(this.containerId);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
`;
|
|
250
|
+
const ModuleRoutingFile = `${module}-routing.module.ts`;
|
|
251
|
+
const ModuleFile = `${module}.module.ts`;
|
|
252
|
+
const filePath = `./src/app/${module}/${ModuleRoutingFile}`;
|
|
253
|
+
const labels = ['// Containers', 'const routes: Routes = ['];
|
|
254
|
+
const statements = [`import { ${camelName}Component } from './${name}/${name}.component';`, ` { path: '${name}', component: ${camelName}Component }`];
|
|
255
|
+
(0, statements_adder_1.AddStatements)(filePath, labels, statements, tree);
|
|
256
|
+
const filePath2 = `./src/app/${module}/${ModuleFile}`;
|
|
257
|
+
const labels2 = ['// Containers', 'EffectsModule.forFeature([', '// Containers'];
|
|
258
|
+
const statements2 = [`import { ${camelName}Component } from './${name}/${name}.component';\nimport { ${camelName}Effects } from './${name}/+state/${name}.effects';`, ` ${camelName}Effects,`, ` ${camelName}Component,`];
|
|
259
|
+
(0, statements_adder_1.AddStatements)(filePath2, labels2, statements2, tree);
|
|
260
|
+
// create directories before adding files
|
|
261
|
+
const dir = `./src/app/${module}/${name}`;
|
|
262
|
+
if (!fs.existsSync(dir)) {
|
|
263
|
+
fs.mkdirSync(dir);
|
|
264
|
+
}
|
|
265
|
+
const statePath = `${dir}/+state`;
|
|
266
|
+
if (!fs.existsSync(statePath)) {
|
|
267
|
+
fs.mkdirSync(statePath);
|
|
268
|
+
}
|
|
269
|
+
tree.create(`${statePath}/${name}.actions.ts`, ActionsFile);
|
|
270
|
+
tree.create(`${statePath}/${name}.effects.ts`, EffectsFile);
|
|
271
|
+
tree.create(`${statePath}/${name}.model.ts`, '');
|
|
272
|
+
tree.create(`${statePath}/${name}.selectors.ts`, SelectorsFile);
|
|
273
|
+
tree.create(`${statePath}/${name}.state.ts`, StateFile);
|
|
274
|
+
tree.create(`${dir}/${name}.animations.ts`, AnimationsFile);
|
|
275
|
+
tree.create(`${dir}/${name}.component.html`, HTMLFile);
|
|
276
|
+
tree.create(`${dir}/${name}.component.scss`, CSSFile);
|
|
277
|
+
tree.create(`${dir}/${name}.component.spec.ts`, SpecFile);
|
|
278
|
+
tree.create(`${dir}/${name}.component.ts`, ComponentFile);
|
|
279
|
+
return tree;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
exports.container = container;
|
|
283
283
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAEA,uEAAmE;AACnE,iEAA2D;AAE3D,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,iGAAiG;AACjG,YAAY;AACZ,SAAgB,SAAS,CAAC,QAAa;IACrC,OAAO,CAAC,IAAU,EAAE,QAA0B,EAAE,EAAE;QAChD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAEA,uEAAmE;AACnE,iEAA2D;AAE3D,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,iGAAiG;AACjG,YAAY;AACZ,SAAgB,SAAS,CAAC,QAAa;IACrC,OAAO,CAAC,IAAU,EAAE,QAA0B,EAAE,EAAE;QAChD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;QAC/C,MAAM,SAAS,GAAG,IAAA,wCAAkB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AAE,WAAW,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,IAAI,IAAI,WAAW,EAAE,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,IAAI,IAAI,eAAe,EAAE,aAAa,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,IAAI,IAAI,WAAW,EAAE,SAAS,CAAC,CAAC;QACxD,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,IAAI,gBAAgB,EAAE,cAAc,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,IAAI,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,IAAI,iBAAiB,EAAE,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,IAAI,oBAAoB,EAAE,QAAQ,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,IAAI,eAAe,EAAE,aAAa,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AA9RD,8BA8RC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,23 +1,23 @@
|
|
|
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
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
13
|
-
const testing_1 = require("@angular-devkit/schematics/testing");
|
|
14
|
-
const path = require("path");
|
|
15
|
-
const collectionPath = path.join(__dirname, '../collection.json');
|
|
16
|
-
describe('container', () => {
|
|
17
|
-
it('works', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
|
|
19
|
-
const tree = yield runner.runSchematicAsync('container', {}, schematics_1.Tree.empty()).toPromise();
|
|
20
|
-
expect(tree.files).toEqual([]);
|
|
21
|
-
}));
|
|
22
|
-
});
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
13
|
+
const testing_1 = require("@angular-devkit/schematics/testing");
|
|
14
|
+
const path = require("path");
|
|
15
|
+
const collectionPath = path.join(__dirname, '../collection.json');
|
|
16
|
+
describe('container', () => {
|
|
17
|
+
it('works', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
|
|
19
|
+
const tree = yield runner.runSchematicAsync('container', {}, schematics_1.Tree.empty()).toPromise();
|
|
20
|
+
expect(tree.files).toEqual([]);
|
|
21
|
+
}));
|
|
22
|
+
});
|
|
23
23
|
//# sourceMappingURL=index_spec.js.map
|