@rxdi/schematics 0.7.124 → 0.7.128
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/lib/application/application.factory.js +4 -4
- package/lib/application/application.factory.test.ts +88 -0
- package/lib/application/application.factory.ts +54 -0
- package/lib/application/application.schema.d.ts +34 -0
- package/lib/application/files/js/.babelrc +4 -0
- package/lib/application/files/js/.prettierrc +4 -0
- package/lib/application/files/js/README.md +37 -0
- package/lib/application/files/js/index.js +3 -0
- package/lib/application/files/js/jsconfig.json +9 -0
- package/lib/application/files/js/nest-cli.json +5 -0
- package/lib/application/files/js/nodemon.json +6 -0
- package/lib/application/files/js/package.json +46 -0
- package/lib/application/files/js/test/app.e2e-spec.js +23 -0
- package/lib/application/files/js/test/jest-e2e.json +5 -0
- package/lib/application/files/ts/.prettierrc +4 -0
- package/lib/application/files/ts/README.md +75 -0
- package/lib/application/files/ts/nest-cli.json +5 -0
- package/lib/application/files/ts/nodemon-debug.json +6 -0
- package/lib/application/files/ts/nodemon.json +6 -0
- package/lib/application/files/ts/package.json +58 -0
- package/lib/application/files/ts/test/app.e2e-spec.ts +23 -0
- package/lib/application/files/ts/test/jest-e2e.json +9 -0
- package/lib/application/files/ts/tsconfig.build.json +4 -0
- package/lib/application/schema.json +49 -0
- package/lib/class/class.factory.js +6 -6
- package/lib/class/class.factory.test.ts +100 -0
- package/lib/class/class.factory.ts +54 -0
- package/lib/class/class.schema.d.ts +28 -0
- package/lib/class/files/js/__name__.js +1 -0
- package/lib/class/files/js/__name__.spec.js +7 -0
- package/lib/class/files/ts/__name__.spec.ts +7 -0
- package/lib/class/files/ts/__name__.ts +1 -0
- package/lib/class/schema.json +39 -0
- package/lib/client-app/angular/angular.factory.js +9 -9
- package/lib/client-app/angular/angular.factory.ts +139 -0
- package/lib/client-app/angular/angular.schema.d.ts +32 -0
- package/lib/client-app/angular/files/angular.constants.ts +4 -0
- package/lib/client-app/angular/files/angular.module.ts +41 -0
- package/lib/client-app/angular/files/angular.providers.ts +27 -0
- package/lib/client-app/angular/files/angular.utils.ts +19 -0
- package/lib/client-app/angular/files/interfaces/angular-options.interface.ts +87 -0
- package/lib/client-app/angular/files/loaders/abstract.loader.ts +16 -0
- package/lib/client-app/angular/files/loaders/express.loader.ts +25 -0
- package/lib/client-app/angular/files/loaders/fastify.loader.ts +34 -0
- package/lib/client-app/angular/files/loaders/noop.loader.ts +12 -0
- package/lib/client-app/angular/schema.json +24 -0
- package/lib/component/component.factory.js +8 -8
- package/lib/component/component.factory.test.ts +191 -0
- package/lib/component/component.factory.ts +91 -0
- package/lib/component/component.schema.d.ts +44 -0
- package/lib/component/files/js/__name__.component.js +56 -0
- package/lib/component/files/js/__name__.component.spec.js +31 -0
- package/lib/component/files/ts/__name__.component.spec.ts +31 -0
- package/lib/component/files/ts/__name__.component.ts +56 -0
- package/lib/component/schema.json +47 -0
- package/lib/configuration/configuration.factory.js +4 -4
- package/lib/configuration/configuration.factory.test.ts +60 -0
- package/lib/configuration/configuration.factory.ts +35 -0
- package/lib/configuration/configuration.schema.d.ts +18 -0
- package/lib/configuration/files/js/nest-cli.json +5 -0
- package/lib/configuration/files/ts/nest-cli.json +5 -0
- package/lib/controller/controller.factory.js +8 -8
- package/lib/controller/controller.factory.test.ts +191 -0
- package/lib/controller/controller.factory.ts +91 -0
- package/lib/controller/controller.schema.d.ts +44 -0
- package/lib/controller/files/js/__name__.controller.js +24 -0
- package/lib/controller/files/js/__name__.controller.spec.js +61 -0
- package/lib/controller/files/ts/__name__.controller.spec.ts +61 -0
- package/lib/controller/files/ts/__name__.controller.ts +24 -0
- package/lib/controller/schema.json +47 -0
- package/lib/decorator/decorator.factory.js +5 -5
- package/lib/decorator/decorator.factory.test.ts +111 -0
- package/lib/decorator/decorator.factory.ts +48 -0
- package/lib/decorator/decorator.schema.d.ts +24 -0
- package/lib/decorator/files/js/__name__.decorator.js +3 -0
- package/lib/decorator/files/ts/__name__.decorator.ts +3 -0
- package/lib/decorator/schema.json +35 -0
- package/lib/defaults.ts +6 -0
- package/lib/effect/effect.factory.js +9 -9
- package/lib/effect/effect.factory.test.ts +190 -0
- package/lib/effect/effect.factory.ts +91 -0
- package/lib/effect/effect.schema.d.ts +44 -0
- package/lib/effect/files/js/__name__.effect.js +11 -0
- package/lib/effect/files/js/__name__.effect.spec.js +17 -0
- package/lib/effect/files/ts/__name__.effect.spec.ts +17 -0
- package/lib/effect/files/ts/__name__.effect.ts +11 -0
- package/lib/effect/schema.json +39 -0
- package/lib/filter/files/js/__name__.filter.js +6 -0
- package/lib/filter/files/js/__name__.filter.spec.js +7 -0
- package/lib/filter/files/ts/__name__.filter.spec.ts +7 -0
- package/lib/filter/files/ts/__name__.filter.ts +6 -0
- package/lib/filter/filter.factory.js +6 -6
- package/lib/filter/filter.factory.test.ts +147 -0
- package/lib/filter/filter.factory.ts +51 -0
- package/lib/filter/filter.schema.d.ts +28 -0
- package/lib/filter/schema.json +39 -0
- package/lib/gateway/files/js/__name__.gateway.js +9 -0
- package/lib/gateway/files/js/__name__.gateway.spec.js +18 -0
- package/lib/gateway/files/ts/__name__.gateway.spec.ts +18 -0
- package/lib/gateway/files/ts/__name__.gateway.ts +9 -0
- package/lib/gateway/gateway.factory.js +8 -8
- package/lib/gateway/gateway.factory.test.ts +147 -0
- package/lib/gateway/gateway.factory.ts +92 -0
- package/lib/gateway/gateway.schema.d.ts +36 -0
- package/lib/gateway/schema.json +39 -0
- package/lib/guard/files/js/__name__.guard.js +17 -0
- package/lib/guard/files/js/__name__.guard.spec.js +7 -0
- package/lib/guard/files/ts/__name__.guard.spec.ts +7 -0
- package/lib/guard/files/ts/__name__.guard.ts +17 -0
- package/lib/guard/guard.factory.js +6 -6
- package/lib/guard/guard.factory.test.ts +156 -0
- package/lib/guard/guard.factory.ts +51 -0
- package/lib/guard/guard.schema.d.ts +28 -0
- package/lib/guard/schema.json +39 -0
- package/lib/interceptor/files/js/__name__.interceptor.js +18 -0
- package/lib/interceptor/files/js/__name__.interceptor.spec.js +7 -0
- package/lib/interceptor/files/ts/__name__.interceptor.spec.ts +7 -0
- package/lib/interceptor/files/ts/__name__.interceptor.ts +19 -0
- package/lib/interceptor/interceptor.factory.js +6 -6
- package/lib/interceptor/interceptor.factory.test.ts +146 -0
- package/lib/interceptor/interceptor.factory.ts +51 -0
- package/lib/interceptor/interceptor.schema.d.ts +28 -0
- package/lib/interceptor/schema.json +39 -0
- package/lib/interface/files/__name__.interface.ts +1 -0
- package/lib/interface/interface.factory.js +5 -5
- package/lib/interface/interface.factory.test.ts +84 -0
- package/lib/interface/interface.factory.ts +47 -0
- package/lib/interface/interface.schema.d.ts +20 -0
- package/lib/interface/schema.json +31 -0
- package/lib/library/files/js/.babelrc +4 -0
- package/lib/library/files/js/jsconfig.json +9 -0
- package/lib/library/files/js/package.json +8 -0
- package/lib/library/files/js/src/__name__.module.js +8 -0
- package/lib/library/files/js/src/__name__.service.js +4 -0
- package/lib/library/files/js/src/__name__.service.spec.js +18 -0
- package/lib/library/files/js/src/index.js +2 -0
- package/lib/library/files/ts/package.json +8 -0
- package/lib/library/files/ts/src/__name__.module.ts +8 -0
- package/lib/library/files/ts/src/__name__.service.spec.ts +18 -0
- package/lib/library/files/ts/src/__name__.service.ts +4 -0
- package/lib/library/files/ts/src/index.ts +2 -0
- package/lib/library/files/ts/tsconfig.lib.json +5 -0
- package/lib/library/library.factory.js +12 -12
- package/lib/library/library.factory.test.ts +68 -0
- package/lib/library/library.factory.ts +158 -0
- package/lib/library/library.schema.d.ts +24 -0
- package/lib/library/schema.json +37 -0
- package/lib/module/files/js/__name__.module.js +4 -0
- package/lib/module/files/ts/__name__.module.ts +4 -0
- package/lib/module/module.factory.js +7 -7
- package/lib/module/module.factory.test.ts +165 -0
- package/lib/module/module.factory.ts +79 -0
- package/lib/module/module.schema.d.ts +36 -0
- package/lib/module/schema.json +40 -0
- package/lib/pipe/files/js/__name__.pipe.js +8 -0
- package/lib/pipe/files/js/__name__.pipe.spec.js +7 -0
- package/lib/pipe/files/ts/__name__.pipe.spec.ts +7 -0
- package/lib/pipe/files/ts/__name__.pipe.ts +8 -0
- package/lib/pipe/pipe.factory.js +6 -6
- package/lib/pipe/pipe.factory.test.ts +141 -0
- package/lib/pipe/pipe.factory.ts +51 -0
- package/lib/pipe/pipe.schema.d.ts +28 -0
- package/lib/pipe/schema.json +39 -0
- package/lib/plugin/files/js/__name__.plugin.js +28 -0
- package/lib/plugin/files/js/__name__.plugin.spec.js +7 -0
- package/lib/plugin/files/ts/__name__.plugin.spec.ts +7 -0
- package/lib/plugin/files/ts/__name__.plugin.ts +28 -0
- package/lib/plugin/plugin.factory.d.ts +2 -2
- package/lib/plugin/plugin.factory.js +1 -2
- package/lib/plugin/plugin.factory.test.ts +191 -0
- package/lib/plugin/plugin.factory.ts +91 -0
- package/lib/plugin/plugin.schema.d.ts +44 -0
- package/lib/plugin/schema.json +52 -0
- package/lib/provider/files/js/__name__.js +4 -0
- package/lib/provider/files/js/__name__.spec.js +17 -0
- package/lib/provider/files/ts/__name__.spec.ts +17 -0
- package/lib/provider/files/ts/__name__.ts +4 -0
- package/lib/provider/provider.factory.js +1 -2
- package/lib/provider/provider.factory.test.ts +151 -0
- package/lib/provider/provider.factory.ts +89 -0
- package/lib/provider/provider.schema.d.ts +44 -0
- package/lib/provider/schema.json +39 -0
- package/lib/resolver/files/js/__name__.resolver.js +4 -0
- package/lib/resolver/files/js/__name__.resolver.spec.js +18 -0
- package/lib/resolver/files/ts/__name__.resolver.spec.ts +18 -0
- package/lib/resolver/files/ts/__name__.resolver.ts +4 -0
- package/lib/resolver/resolver.factory.js +8 -8
- package/lib/resolver/resolver.factory.test.ts +117 -0
- package/lib/resolver/resolver.factory.ts +92 -0
- package/lib/resolver/resolver.schema.d.ts +36 -0
- package/lib/resolver/schema.json +39 -0
- package/lib/service/files/js/__name__.service.js +4 -0
- package/lib/service/files/js/__name__.service.spec.js +17 -0
- package/lib/service/files/ts/__name__.service.spec.ts +17 -0
- package/lib/service/files/ts/__name__.service.ts +4 -0
- package/lib/service/schema.json +39 -0
- package/lib/service/service.factory.js +9 -9
- package/lib/service/service.factory.test.ts +190 -0
- package/lib/service/service.factory.ts +91 -0
- package/lib/service/service.schema.d.ts +44 -0
- package/lib/type/files/js/__name__.type.js +10 -0
- package/lib/type/files/ts/__name__.type.ts +10 -0
- package/lib/type/schema.json +43 -0
- package/lib/type/type.factory.d.ts +1 -1
- package/lib/type/type.factory.js +1 -2
- package/lib/type/type.factory.test.ts +191 -0
- package/lib/type/type.factory.ts +91 -0
- package/lib/type/type.schema.d.ts +44 -0
- package/package.json +2 -2
- package/utils/metadata.manager.js +1 -1
- package/utils/metadata.manager.ts +219 -0
- package/utils/module-import.declarator.js +2 -2
- package/utils/module-import.declarator.ts +41 -0
- package/utils/module-metadata.declarator.ts +14 -0
- package/utils/module.declarator.js +2 -2
- package/utils/module.declarator.ts +41 -0
- package/utils/module.finder.js +1 -1
- package/utils/module.finder.ts +32 -0
- package/utils/name.parser.js +3 -3
- package/utils/name.parser.ts +29 -0
- package/utils/path.solver.js +2 -2
- package/utils/path.solver.ts +17 -0
- package/utils/source-root.helpers.js +2 -2
- package/utils/source-root.helpers.ts +30 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SchematicTestRunner,
|
|
3
|
+
UnitTestTree,
|
|
4
|
+
} from '@angular-devkit/schematics/testing';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { InterceptorOptions } from './interceptor.schema';
|
|
7
|
+
|
|
8
|
+
describe('Interceptor Factory', () => {
|
|
9
|
+
const runner: SchematicTestRunner = new SchematicTestRunner(
|
|
10
|
+
'.',
|
|
11
|
+
path.join(process.cwd(), 'src/collection.json'),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
it('should manage name only', () => {
|
|
15
|
+
const options: InterceptorOptions = {
|
|
16
|
+
name: 'foo',
|
|
17
|
+
};
|
|
18
|
+
const tree: UnitTestTree = runner.runSchematic('interceptor', options);
|
|
19
|
+
const files: string[] = tree.files;
|
|
20
|
+
expect(
|
|
21
|
+
files.find(filename => filename === '/foo.interceptor.ts'),
|
|
22
|
+
).toBeDefined();
|
|
23
|
+
expect(tree.readContent('/foo.interceptor.ts')).toEqual(
|
|
24
|
+
"import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';\n" +
|
|
25
|
+
"import { Observable } from 'rxjs';\n" +
|
|
26
|
+
'\n' +
|
|
27
|
+
'@Injectable()\n' +
|
|
28
|
+
'export class FooInterceptor implements NestInterceptor {\n' +
|
|
29
|
+
' intercept(context: ExecutionContext, next: CallHandler): Observable<any> {\n' +
|
|
30
|
+
' return next.handle();\n' +
|
|
31
|
+
' }\n' +
|
|
32
|
+
'}\n',
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should manage name as a path', () => {
|
|
37
|
+
const options: InterceptorOptions = {
|
|
38
|
+
name: 'bar/foo',
|
|
39
|
+
};
|
|
40
|
+
const tree: UnitTestTree = runner.runSchematic('interceptor', options);
|
|
41
|
+
const files: string[] = tree.files;
|
|
42
|
+
expect(
|
|
43
|
+
files.find(filename => filename === '/bar/foo.interceptor.ts'),
|
|
44
|
+
).toBeDefined();
|
|
45
|
+
expect(tree.readContent('/bar/foo.interceptor.ts')).toEqual(
|
|
46
|
+
"import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';\n" +
|
|
47
|
+
"import { Observable } from 'rxjs';\n" +
|
|
48
|
+
'\n' +
|
|
49
|
+
'@Injectable()\n' +
|
|
50
|
+
'export class FooInterceptor implements NestInterceptor {\n' +
|
|
51
|
+
' intercept(context: ExecutionContext, next: CallHandler): Observable<any> {\n' +
|
|
52
|
+
' return next.handle();\n' +
|
|
53
|
+
' }\n' +
|
|
54
|
+
'}\n',
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should manage name and path', () => {
|
|
59
|
+
const options: InterceptorOptions = {
|
|
60
|
+
name: 'foo',
|
|
61
|
+
path: 'baz',
|
|
62
|
+
};
|
|
63
|
+
const tree: UnitTestTree = runner.runSchematic('interceptor', options);
|
|
64
|
+
const files: string[] = tree.files;
|
|
65
|
+
expect(
|
|
66
|
+
files.find(filename => filename === '/baz/foo.interceptor.ts'),
|
|
67
|
+
).toBeDefined();
|
|
68
|
+
expect(tree.readContent('/baz/foo.interceptor.ts')).toEqual(
|
|
69
|
+
"import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';\n" +
|
|
70
|
+
"import { Observable } from 'rxjs';\n" +
|
|
71
|
+
'\n' +
|
|
72
|
+
'@Injectable()\n' +
|
|
73
|
+
'export class FooInterceptor implements NestInterceptor {\n' +
|
|
74
|
+
' intercept(context: ExecutionContext, next: CallHandler): Observable<any> {\n' +
|
|
75
|
+
' return next.handle();\n' +
|
|
76
|
+
' }\n' +
|
|
77
|
+
'}\n',
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should manage name to dasherize', () => {
|
|
82
|
+
const options: InterceptorOptions = {
|
|
83
|
+
name: 'fooBar',
|
|
84
|
+
};
|
|
85
|
+
const tree: UnitTestTree = runner.runSchematic('interceptor', options);
|
|
86
|
+
const files: string[] = tree.files;
|
|
87
|
+
expect(
|
|
88
|
+
files.find(filename => filename === '/foo-bar.interceptor.ts'),
|
|
89
|
+
).toBeDefined();
|
|
90
|
+
expect(tree.readContent('/foo-bar.interceptor.ts')).toEqual(
|
|
91
|
+
"import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';\n" +
|
|
92
|
+
"import { Observable } from 'rxjs';\n" +
|
|
93
|
+
'\n' +
|
|
94
|
+
'@Injectable()\n' +
|
|
95
|
+
'export class FooBarInterceptor implements NestInterceptor {\n' +
|
|
96
|
+
' intercept(context: ExecutionContext, next: CallHandler): Observable<any> {\n' +
|
|
97
|
+
' return next.handle();\n' +
|
|
98
|
+
' }\n' +
|
|
99
|
+
'}\n',
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should manage path to dasherize', () => {
|
|
104
|
+
const options: InterceptorOptions = {
|
|
105
|
+
name: 'barBaz/foo',
|
|
106
|
+
};
|
|
107
|
+
const tree: UnitTestTree = runner.runSchematic('interceptor', options);
|
|
108
|
+
const files: string[] = tree.files;
|
|
109
|
+
expect(
|
|
110
|
+
files.find(filename => filename === '/bar-baz/foo.interceptor.ts'),
|
|
111
|
+
).toBeDefined();
|
|
112
|
+
expect(tree.readContent('/bar-baz/foo.interceptor.ts')).toEqual(
|
|
113
|
+
"import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';\n" +
|
|
114
|
+
"import { Observable } from 'rxjs';\n" +
|
|
115
|
+
'\n' +
|
|
116
|
+
'@Injectable()\n' +
|
|
117
|
+
'export class FooInterceptor implements NestInterceptor {\n' +
|
|
118
|
+
' intercept(context: ExecutionContext, next: CallHandler): Observable<any> {\n' +
|
|
119
|
+
' return next.handle();\n' +
|
|
120
|
+
' }\n' +
|
|
121
|
+
'}\n',
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should manage javascript file', () => {
|
|
126
|
+
const options: InterceptorOptions = {
|
|
127
|
+
name: 'foo',
|
|
128
|
+
language: 'js',
|
|
129
|
+
};
|
|
130
|
+
const tree: UnitTestTree = runner.runSchematic('interceptor', options);
|
|
131
|
+
const files: string[] = tree.files;
|
|
132
|
+
expect(
|
|
133
|
+
files.find(filename => filename === '/foo.interceptor.js'),
|
|
134
|
+
).toBeDefined();
|
|
135
|
+
expect(tree.readContent('/foo.interceptor.js')).toEqual(
|
|
136
|
+
"import { Injectable } from '@nestjs/common';\n" +
|
|
137
|
+
'\n' +
|
|
138
|
+
'@Injectable()\n' +
|
|
139
|
+
'export class FooInterceptor {\n' +
|
|
140
|
+
' intercept(context, next) {\n' +
|
|
141
|
+
' return next.handle();\n' +
|
|
142
|
+
' }\n' +
|
|
143
|
+
'}\n',
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { join, Path, strings } from '@angular-devkit/core';
|
|
2
|
+
import {
|
|
3
|
+
apply,
|
|
4
|
+
chain,
|
|
5
|
+
filter,
|
|
6
|
+
mergeWith,
|
|
7
|
+
move,
|
|
8
|
+
noop,
|
|
9
|
+
Rule,
|
|
10
|
+
SchematicContext,
|
|
11
|
+
SchematicsException,
|
|
12
|
+
Source,
|
|
13
|
+
template,
|
|
14
|
+
url,
|
|
15
|
+
} from '@angular-devkit/schematics';
|
|
16
|
+
import { Location, NameParser } from '../../utils/name.parser';
|
|
17
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers';
|
|
18
|
+
import { InterceptorOptions } from './interceptor.schema';
|
|
19
|
+
|
|
20
|
+
export function main(options: InterceptorOptions): Rule {
|
|
21
|
+
options = transform(options);
|
|
22
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function transform(options: InterceptorOptions): InterceptorOptions {
|
|
26
|
+
const target: InterceptorOptions = Object.assign({}, options);
|
|
27
|
+
if (!target.name) {
|
|
28
|
+
throw new SchematicsException('Option (name) is required.');
|
|
29
|
+
}
|
|
30
|
+
const location: Location = new NameParser().parse(target);
|
|
31
|
+
target.name = strings.dasherize(location.name);
|
|
32
|
+
target.path = strings.dasherize(location.path);
|
|
33
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
34
|
+
|
|
35
|
+
target.path = target.flat
|
|
36
|
+
? target.path
|
|
37
|
+
: join(target.path as Path, target.name);
|
|
38
|
+
return target;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function generate(options: InterceptorOptions): Source {
|
|
42
|
+
return (context: SchematicContext) =>
|
|
43
|
+
apply(url(join('./files' as Path, options.language)), [
|
|
44
|
+
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
|
|
45
|
+
template({
|
|
46
|
+
...strings,
|
|
47
|
+
...options,
|
|
48
|
+
}),
|
|
49
|
+
move(options.path),
|
|
50
|
+
])(context);
|
|
51
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Path } from '@angular-devkit/core';
|
|
2
|
+
|
|
3
|
+
export interface InterceptorOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The name of the interceptor.
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* The path to create the interceptor.
|
|
10
|
+
*/
|
|
11
|
+
path?: string | Path;
|
|
12
|
+
/**
|
|
13
|
+
* Application language.
|
|
14
|
+
*/
|
|
15
|
+
language?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The source root path
|
|
18
|
+
*/
|
|
19
|
+
sourceRoot?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Specifies if a spec file is generated.
|
|
22
|
+
*/
|
|
23
|
+
spec?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Flag to indicate if a directory is created.
|
|
26
|
+
*/
|
|
27
|
+
flat?: boolean;
|
|
28
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"id": "SchematicsNestInterceptor",
|
|
4
|
+
"title": "Nest Interceptor Options Schema",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "The name of the interceptor.",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "argv",
|
|
12
|
+
"index": 0
|
|
13
|
+
},
|
|
14
|
+
"x-prompt": "What name would you like to use for the interceptor?"
|
|
15
|
+
},
|
|
16
|
+
"path": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"format": "path",
|
|
19
|
+
"description": "The path to create the interceptor."
|
|
20
|
+
},
|
|
21
|
+
"language": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Nest interceptor language (ts/js)."
|
|
24
|
+
},
|
|
25
|
+
"sourceRoot": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "Nest interceptor source root directory."
|
|
28
|
+
},
|
|
29
|
+
"flat": {
|
|
30
|
+
"default": true,
|
|
31
|
+
"description": "Flag to indicate if a directory is created."
|
|
32
|
+
},
|
|
33
|
+
"spec": {
|
|
34
|
+
"default": true,
|
|
35
|
+
"description": "Specifies if a spec file is generated."
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"required": ["name"]
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export interface <%= classify(name) %> {}
|
|
@@ -7,7 +7,7 @@ const name_parser_1 = require("../../utils/name.parser");
|
|
|
7
7
|
const source_root_helpers_1 = require("../../utils/source-root.helpers");
|
|
8
8
|
function main(options) {
|
|
9
9
|
options = transform(options);
|
|
10
|
-
return schematics_1.chain([source_root_helpers_1.mergeSourceRoot(options), schematics_1.mergeWith(generate(options))]);
|
|
10
|
+
return (0, schematics_1.chain)([(0, source_root_helpers_1.mergeSourceRoot)(options), (0, schematics_1.mergeWith)(generate(options))]);
|
|
11
11
|
}
|
|
12
12
|
exports.main = main;
|
|
13
13
|
function transform(options) {
|
|
@@ -20,12 +20,12 @@ function transform(options) {
|
|
|
20
20
|
target.path = core_1.strings.dasherize(location.path);
|
|
21
21
|
target.path = target.flat
|
|
22
22
|
? target.path
|
|
23
|
-
: core_1.join(target.path, target.name);
|
|
23
|
+
: (0, core_1.join)(target.path, target.name);
|
|
24
24
|
return target;
|
|
25
25
|
}
|
|
26
26
|
function generate(options) {
|
|
27
|
-
return (context) => schematics_1.apply(schematics_1.url('./files'), [
|
|
28
|
-
schematics_1.template(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
29
|
-
schematics_1.move(options.path),
|
|
27
|
+
return (context) => (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
28
|
+
(0, schematics_1.template)(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
29
|
+
(0, schematics_1.move)(options.path),
|
|
30
30
|
])(context);
|
|
31
31
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SchematicTestRunner,
|
|
3
|
+
UnitTestTree,
|
|
4
|
+
} from '@angular-devkit/schematics/testing';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { InterfaceOptions } from './interface.schema';
|
|
7
|
+
|
|
8
|
+
describe('Interface Factory', () => {
|
|
9
|
+
const runner: SchematicTestRunner = new SchematicTestRunner(
|
|
10
|
+
'.',
|
|
11
|
+
path.join(process.cwd(), 'src/collection.json'),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
it('should manage name only', () => {
|
|
15
|
+
const options: InterfaceOptions = {
|
|
16
|
+
name: 'foo',
|
|
17
|
+
};
|
|
18
|
+
const tree: UnitTestTree = runner.runSchematic('interface', options);
|
|
19
|
+
const files: string[] = tree.files;
|
|
20
|
+
expect(
|
|
21
|
+
files.find(filename => filename === '/foo.interface.ts'),
|
|
22
|
+
).toBeDefined();
|
|
23
|
+
expect(tree.readContent('/foo.interface.ts')).toEqual(
|
|
24
|
+
'export interface Foo {}\n',
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should manage name as a path', () => {
|
|
29
|
+
const options: InterfaceOptions = {
|
|
30
|
+
name: 'bar/foo',
|
|
31
|
+
};
|
|
32
|
+
const tree: UnitTestTree = runner.runSchematic('interface', options);
|
|
33
|
+
const files: string[] = tree.files;
|
|
34
|
+
expect(
|
|
35
|
+
files.find(filename => filename === '/bar/foo.interface.ts'),
|
|
36
|
+
).toBeDefined();
|
|
37
|
+
expect(tree.readContent('/bar/foo.interface.ts')).toEqual(
|
|
38
|
+
'export interface Foo {}\n',
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should manage name and path', () => {
|
|
43
|
+
const options: InterfaceOptions = {
|
|
44
|
+
name: 'foo',
|
|
45
|
+
path: 'baz',
|
|
46
|
+
};
|
|
47
|
+
const tree: UnitTestTree = runner.runSchematic('interface', options);
|
|
48
|
+
const files: string[] = tree.files;
|
|
49
|
+
expect(
|
|
50
|
+
files.find(filename => filename === '/baz/foo.interface.ts'),
|
|
51
|
+
).toBeDefined();
|
|
52
|
+
expect(tree.readContent('/baz/foo.interface.ts')).toEqual(
|
|
53
|
+
'export interface Foo {}\n',
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should manage name to dasherize', () => {
|
|
58
|
+
const options: InterfaceOptions = {
|
|
59
|
+
name: 'fooBar',
|
|
60
|
+
};
|
|
61
|
+
const tree: UnitTestTree = runner.runSchematic('interface', options);
|
|
62
|
+
const files: string[] = tree.files;
|
|
63
|
+
expect(
|
|
64
|
+
files.find(filename => filename === '/foo-bar.interface.ts'),
|
|
65
|
+
).toBeDefined();
|
|
66
|
+
expect(tree.readContent('/foo-bar.interface.ts')).toEqual(
|
|
67
|
+
'export interface FooBar {}\n',
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should manage path to dasherize', () => {
|
|
72
|
+
const options: InterfaceOptions = {
|
|
73
|
+
name: 'barBaz/foo',
|
|
74
|
+
};
|
|
75
|
+
const tree: UnitTestTree = runner.runSchematic('interface', options);
|
|
76
|
+
const files: string[] = tree.files;
|
|
77
|
+
expect(
|
|
78
|
+
files.find(filename => filename === '/bar-baz/foo.interface.ts'),
|
|
79
|
+
).toBeDefined();
|
|
80
|
+
expect(tree.readContent('/bar-baz/foo.interface.ts')).toEqual(
|
|
81
|
+
'export interface Foo {}\n',
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { join, Path, strings } from '@angular-devkit/core';
|
|
2
|
+
import {
|
|
3
|
+
apply,
|
|
4
|
+
chain,
|
|
5
|
+
mergeWith,
|
|
6
|
+
move,
|
|
7
|
+
Rule,
|
|
8
|
+
SchematicContext,
|
|
9
|
+
SchematicsException,
|
|
10
|
+
Source,
|
|
11
|
+
template,
|
|
12
|
+
url,
|
|
13
|
+
} from '@angular-devkit/schematics';
|
|
14
|
+
import { Location, NameParser } from '../../utils/name.parser';
|
|
15
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers';
|
|
16
|
+
import { InterfaceOptions } from './interface.schema';
|
|
17
|
+
|
|
18
|
+
export function main(options: InterfaceOptions): Rule {
|
|
19
|
+
options = transform(options);
|
|
20
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function transform(options: InterfaceOptions): InterfaceOptions {
|
|
24
|
+
const target: InterfaceOptions = Object.assign({}, options);
|
|
25
|
+
if (!target.name) {
|
|
26
|
+
throw new SchematicsException('Option (name) is required.');
|
|
27
|
+
}
|
|
28
|
+
const location: Location = new NameParser().parse(target);
|
|
29
|
+
target.name = strings.dasherize(location.name);
|
|
30
|
+
target.path = strings.dasherize(location.path);
|
|
31
|
+
|
|
32
|
+
target.path = target.flat
|
|
33
|
+
? target.path
|
|
34
|
+
: join(target.path as Path, target.name);
|
|
35
|
+
return target;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function generate(options: InterfaceOptions): Source {
|
|
39
|
+
return (context: SchematicContext) =>
|
|
40
|
+
apply(url('./files'), [
|
|
41
|
+
template({
|
|
42
|
+
...strings,
|
|
43
|
+
...options,
|
|
44
|
+
}),
|
|
45
|
+
move(options.path),
|
|
46
|
+
])(context);
|
|
47
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Path } from '@angular-devkit/core';
|
|
2
|
+
|
|
3
|
+
export interface InterfaceOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The name of the interface.
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* The path to create the interface.
|
|
10
|
+
*/
|
|
11
|
+
path?: string | Path;
|
|
12
|
+
/**
|
|
13
|
+
* The source root path
|
|
14
|
+
*/
|
|
15
|
+
sourceRoot?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Flag to indicate if a directory is created.
|
|
18
|
+
*/
|
|
19
|
+
flat?: boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"id": "SchematicsNestInterface",
|
|
4
|
+
"title": "Nest Interface Options Schema",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "The name of the interface.",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "argv",
|
|
12
|
+
"index": 0
|
|
13
|
+
},
|
|
14
|
+
"x-prompt": "What name would you like to use for the interface?"
|
|
15
|
+
},
|
|
16
|
+
"path": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"format": "path",
|
|
19
|
+
"description": "The path to create the interface."
|
|
20
|
+
},
|
|
21
|
+
"sourceRoot": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Nest interface source root directory."
|
|
24
|
+
},
|
|
25
|
+
"flat": {
|
|
26
|
+
"default": true,
|
|
27
|
+
"description": "Flag to indicate if a directory is created."
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"required": ["name"]
|
|
31
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Test } from '@nestjs/testing';
|
|
2
|
+
import { <%= classify(name) %>Service } from './<%= name %>.service';
|
|
3
|
+
|
|
4
|
+
describe('<%= classify(name) %>Service', () => {
|
|
5
|
+
let service;
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
const module = await Test.createTestingModule({
|
|
9
|
+
providers: [<%= classify(name) %>Service],
|
|
10
|
+
}).compile();
|
|
11
|
+
|
|
12
|
+
service = module.get(<%= classify(name) %>Service);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should be defined', () => {
|
|
16
|
+
expect(service).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { <%= classify(name) %>Service } from './<%= name %>.service';
|
|
3
|
+
|
|
4
|
+
describe('<%= classify(name) %>Service', () => {
|
|
5
|
+
let service: <%= classify(name) %>Service;
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
9
|
+
providers: [<%= classify(name) %>Service],
|
|
10
|
+
}).compile();
|
|
11
|
+
|
|
12
|
+
service = module.get<<%= classify(name) %>Service>(<%= classify(name) %>Service);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should be defined', () => {
|
|
16
|
+
expect(service).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -6,10 +6,10 @@ const schematics_1 = require("@angular-devkit/schematics");
|
|
|
6
6
|
const defaults_1 = require("../defaults");
|
|
7
7
|
function main(options) {
|
|
8
8
|
options = transform(options);
|
|
9
|
-
return schematics_1.chain([
|
|
9
|
+
return (0, schematics_1.chain)([
|
|
10
10
|
updateTsConfig(options.name, options.prefix, options.path),
|
|
11
11
|
addLibraryToCliOptions(options.path, options.name),
|
|
12
|
-
schematics_1.branchAndMerge(schematics_1.mergeWith(generate(options))),
|
|
12
|
+
(0, schematics_1.branchAndMerge)((0, schematics_1.mergeWith)(generate(options))),
|
|
13
13
|
]);
|
|
14
14
|
}
|
|
15
15
|
exports.main = main;
|
|
@@ -23,8 +23,8 @@ function transform(options) {
|
|
|
23
23
|
target.name = core_1.strings.dasherize(target.name);
|
|
24
24
|
target.path =
|
|
25
25
|
target.path !== undefined
|
|
26
|
-
? core_1.join(core_1.normalize(defaultSourceRoot), target.path)
|
|
27
|
-
: core_1.normalize(defaultSourceRoot);
|
|
26
|
+
? (0, core_1.join)((0, core_1.normalize)(defaultSourceRoot), target.path)
|
|
27
|
+
: (0, core_1.normalize)(defaultSourceRoot);
|
|
28
28
|
target.prefix = target.prefix || '@app';
|
|
29
29
|
return target;
|
|
30
30
|
}
|
|
@@ -32,7 +32,7 @@ function updateJsonFile(host, path, callback) {
|
|
|
32
32
|
const source = host.read(path);
|
|
33
33
|
if (source) {
|
|
34
34
|
const sourceText = source.toString('utf-8');
|
|
35
|
-
const json = core_1.parseJson(sourceText);
|
|
35
|
+
const json = (0, core_1.parseJson)(sourceText);
|
|
36
36
|
callback(json);
|
|
37
37
|
host.overwrite(path, JSON.stringify(json, null, 2));
|
|
38
38
|
}
|
|
@@ -43,7 +43,7 @@ function updateTsConfig(packageName, packagePrefix, root) {
|
|
|
43
43
|
if (!host.exists('tsconfig.json')) {
|
|
44
44
|
return host;
|
|
45
45
|
}
|
|
46
|
-
const distRoot = core_1.join(root, packageName, 'src');
|
|
46
|
+
const distRoot = (0, core_1.join)(root, packageName, 'src');
|
|
47
47
|
const packageKey = packagePrefix
|
|
48
48
|
? packagePrefix + '/' + packageName
|
|
49
49
|
: packageName;
|
|
@@ -71,8 +71,8 @@ function updateTsConfig(packageName, packagePrefix, root) {
|
|
|
71
71
|
}
|
|
72
72
|
function addLibraryToCliOptions(projectRoot, projectName) {
|
|
73
73
|
const project = {
|
|
74
|
-
root: core_1.join(projectRoot, projectName),
|
|
75
|
-
sourceRoot: core_1.join(projectRoot, projectName, 'src'),
|
|
74
|
+
root: (0, core_1.join)(projectRoot, projectName),
|
|
75
|
+
sourceRoot: (0, core_1.join)(projectRoot, projectName, 'src'),
|
|
76
76
|
};
|
|
77
77
|
return (host) => {
|
|
78
78
|
const nestCliFileExists = host.exists('nest-cli.json');
|
|
@@ -89,9 +89,9 @@ function addLibraryToCliOptions(projectRoot, projectName) {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
function generate(options) {
|
|
92
|
-
const path = core_1.join(options.path, options.name);
|
|
93
|
-
return schematics_1.apply(schematics_1.url(core_1.join('./files', options.language)), [
|
|
94
|
-
schematics_1.template(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
95
|
-
schematics_1.move(path),
|
|
92
|
+
const path = (0, core_1.join)(options.path, options.name);
|
|
93
|
+
return (0, schematics_1.apply)((0, schematics_1.url)((0, core_1.join)('./files', options.language)), [
|
|
94
|
+
(0, schematics_1.template)(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
95
|
+
(0, schematics_1.move)(path),
|
|
96
96
|
]);
|
|
97
97
|
}
|