@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.
Files changed (224) hide show
  1. package/lib/application/application.factory.js +4 -4
  2. package/lib/application/application.factory.test.ts +88 -0
  3. package/lib/application/application.factory.ts +54 -0
  4. package/lib/application/application.schema.d.ts +34 -0
  5. package/lib/application/files/js/.babelrc +4 -0
  6. package/lib/application/files/js/.prettierrc +4 -0
  7. package/lib/application/files/js/README.md +37 -0
  8. package/lib/application/files/js/index.js +3 -0
  9. package/lib/application/files/js/jsconfig.json +9 -0
  10. package/lib/application/files/js/nest-cli.json +5 -0
  11. package/lib/application/files/js/nodemon.json +6 -0
  12. package/lib/application/files/js/package.json +46 -0
  13. package/lib/application/files/js/test/app.e2e-spec.js +23 -0
  14. package/lib/application/files/js/test/jest-e2e.json +5 -0
  15. package/lib/application/files/ts/.prettierrc +4 -0
  16. package/lib/application/files/ts/README.md +75 -0
  17. package/lib/application/files/ts/nest-cli.json +5 -0
  18. package/lib/application/files/ts/nodemon-debug.json +6 -0
  19. package/lib/application/files/ts/nodemon.json +6 -0
  20. package/lib/application/files/ts/package.json +58 -0
  21. package/lib/application/files/ts/test/app.e2e-spec.ts +23 -0
  22. package/lib/application/files/ts/test/jest-e2e.json +9 -0
  23. package/lib/application/files/ts/tsconfig.build.json +4 -0
  24. package/lib/application/schema.json +49 -0
  25. package/lib/class/class.factory.js +6 -6
  26. package/lib/class/class.factory.test.ts +100 -0
  27. package/lib/class/class.factory.ts +54 -0
  28. package/lib/class/class.schema.d.ts +28 -0
  29. package/lib/class/files/js/__name__.js +1 -0
  30. package/lib/class/files/js/__name__.spec.js +7 -0
  31. package/lib/class/files/ts/__name__.spec.ts +7 -0
  32. package/lib/class/files/ts/__name__.ts +1 -0
  33. package/lib/class/schema.json +39 -0
  34. package/lib/client-app/angular/angular.factory.js +9 -9
  35. package/lib/client-app/angular/angular.factory.ts +139 -0
  36. package/lib/client-app/angular/angular.schema.d.ts +32 -0
  37. package/lib/client-app/angular/files/angular.constants.ts +4 -0
  38. package/lib/client-app/angular/files/angular.module.ts +41 -0
  39. package/lib/client-app/angular/files/angular.providers.ts +27 -0
  40. package/lib/client-app/angular/files/angular.utils.ts +19 -0
  41. package/lib/client-app/angular/files/interfaces/angular-options.interface.ts +87 -0
  42. package/lib/client-app/angular/files/loaders/abstract.loader.ts +16 -0
  43. package/lib/client-app/angular/files/loaders/express.loader.ts +25 -0
  44. package/lib/client-app/angular/files/loaders/fastify.loader.ts +34 -0
  45. package/lib/client-app/angular/files/loaders/noop.loader.ts +12 -0
  46. package/lib/client-app/angular/schema.json +24 -0
  47. package/lib/component/component.factory.js +8 -8
  48. package/lib/component/component.factory.test.ts +191 -0
  49. package/lib/component/component.factory.ts +91 -0
  50. package/lib/component/component.schema.d.ts +44 -0
  51. package/lib/component/files/js/__name__.component.js +56 -0
  52. package/lib/component/files/js/__name__.component.spec.js +31 -0
  53. package/lib/component/files/ts/__name__.component.spec.ts +31 -0
  54. package/lib/component/files/ts/__name__.component.ts +56 -0
  55. package/lib/component/schema.json +47 -0
  56. package/lib/configuration/configuration.factory.js +4 -4
  57. package/lib/configuration/configuration.factory.test.ts +60 -0
  58. package/lib/configuration/configuration.factory.ts +35 -0
  59. package/lib/configuration/configuration.schema.d.ts +18 -0
  60. package/lib/configuration/files/js/nest-cli.json +5 -0
  61. package/lib/configuration/files/ts/nest-cli.json +5 -0
  62. package/lib/controller/controller.factory.js +8 -8
  63. package/lib/controller/controller.factory.test.ts +191 -0
  64. package/lib/controller/controller.factory.ts +91 -0
  65. package/lib/controller/controller.schema.d.ts +44 -0
  66. package/lib/controller/files/js/__name__.controller.js +24 -0
  67. package/lib/controller/files/js/__name__.controller.spec.js +61 -0
  68. package/lib/controller/files/ts/__name__.controller.spec.ts +61 -0
  69. package/lib/controller/files/ts/__name__.controller.ts +24 -0
  70. package/lib/controller/schema.json +47 -0
  71. package/lib/decorator/decorator.factory.js +5 -5
  72. package/lib/decorator/decorator.factory.test.ts +111 -0
  73. package/lib/decorator/decorator.factory.ts +48 -0
  74. package/lib/decorator/decorator.schema.d.ts +24 -0
  75. package/lib/decorator/files/js/__name__.decorator.js +3 -0
  76. package/lib/decorator/files/ts/__name__.decorator.ts +3 -0
  77. package/lib/decorator/schema.json +35 -0
  78. package/lib/defaults.ts +6 -0
  79. package/lib/effect/effect.factory.js +9 -9
  80. package/lib/effect/effect.factory.test.ts +190 -0
  81. package/lib/effect/effect.factory.ts +91 -0
  82. package/lib/effect/effect.schema.d.ts +44 -0
  83. package/lib/effect/files/js/__name__.effect.js +11 -0
  84. package/lib/effect/files/js/__name__.effect.spec.js +17 -0
  85. package/lib/effect/files/ts/__name__.effect.spec.ts +17 -0
  86. package/lib/effect/files/ts/__name__.effect.ts +11 -0
  87. package/lib/effect/schema.json +39 -0
  88. package/lib/filter/files/js/__name__.filter.js +6 -0
  89. package/lib/filter/files/js/__name__.filter.spec.js +7 -0
  90. package/lib/filter/files/ts/__name__.filter.spec.ts +7 -0
  91. package/lib/filter/files/ts/__name__.filter.ts +6 -0
  92. package/lib/filter/filter.factory.js +6 -6
  93. package/lib/filter/filter.factory.test.ts +147 -0
  94. package/lib/filter/filter.factory.ts +51 -0
  95. package/lib/filter/filter.schema.d.ts +28 -0
  96. package/lib/filter/schema.json +39 -0
  97. package/lib/gateway/files/js/__name__.gateway.js +9 -0
  98. package/lib/gateway/files/js/__name__.gateway.spec.js +18 -0
  99. package/lib/gateway/files/ts/__name__.gateway.spec.ts +18 -0
  100. package/lib/gateway/files/ts/__name__.gateway.ts +9 -0
  101. package/lib/gateway/gateway.factory.js +8 -8
  102. package/lib/gateway/gateway.factory.test.ts +147 -0
  103. package/lib/gateway/gateway.factory.ts +92 -0
  104. package/lib/gateway/gateway.schema.d.ts +36 -0
  105. package/lib/gateway/schema.json +39 -0
  106. package/lib/guard/files/js/__name__.guard.js +17 -0
  107. package/lib/guard/files/js/__name__.guard.spec.js +7 -0
  108. package/lib/guard/files/ts/__name__.guard.spec.ts +7 -0
  109. package/lib/guard/files/ts/__name__.guard.ts +17 -0
  110. package/lib/guard/guard.factory.js +6 -6
  111. package/lib/guard/guard.factory.test.ts +156 -0
  112. package/lib/guard/guard.factory.ts +51 -0
  113. package/lib/guard/guard.schema.d.ts +28 -0
  114. package/lib/guard/schema.json +39 -0
  115. package/lib/interceptor/files/js/__name__.interceptor.js +18 -0
  116. package/lib/interceptor/files/js/__name__.interceptor.spec.js +7 -0
  117. package/lib/interceptor/files/ts/__name__.interceptor.spec.ts +7 -0
  118. package/lib/interceptor/files/ts/__name__.interceptor.ts +19 -0
  119. package/lib/interceptor/interceptor.factory.js +6 -6
  120. package/lib/interceptor/interceptor.factory.test.ts +146 -0
  121. package/lib/interceptor/interceptor.factory.ts +51 -0
  122. package/lib/interceptor/interceptor.schema.d.ts +28 -0
  123. package/lib/interceptor/schema.json +39 -0
  124. package/lib/interface/files/__name__.interface.ts +1 -0
  125. package/lib/interface/interface.factory.js +5 -5
  126. package/lib/interface/interface.factory.test.ts +84 -0
  127. package/lib/interface/interface.factory.ts +47 -0
  128. package/lib/interface/interface.schema.d.ts +20 -0
  129. package/lib/interface/schema.json +31 -0
  130. package/lib/library/files/js/.babelrc +4 -0
  131. package/lib/library/files/js/jsconfig.json +9 -0
  132. package/lib/library/files/js/package.json +8 -0
  133. package/lib/library/files/js/src/__name__.module.js +8 -0
  134. package/lib/library/files/js/src/__name__.service.js +4 -0
  135. package/lib/library/files/js/src/__name__.service.spec.js +18 -0
  136. package/lib/library/files/js/src/index.js +2 -0
  137. package/lib/library/files/ts/package.json +8 -0
  138. package/lib/library/files/ts/src/__name__.module.ts +8 -0
  139. package/lib/library/files/ts/src/__name__.service.spec.ts +18 -0
  140. package/lib/library/files/ts/src/__name__.service.ts +4 -0
  141. package/lib/library/files/ts/src/index.ts +2 -0
  142. package/lib/library/files/ts/tsconfig.lib.json +5 -0
  143. package/lib/library/library.factory.js +12 -12
  144. package/lib/library/library.factory.test.ts +68 -0
  145. package/lib/library/library.factory.ts +158 -0
  146. package/lib/library/library.schema.d.ts +24 -0
  147. package/lib/library/schema.json +37 -0
  148. package/lib/module/files/js/__name__.module.js +4 -0
  149. package/lib/module/files/ts/__name__.module.ts +4 -0
  150. package/lib/module/module.factory.js +7 -7
  151. package/lib/module/module.factory.test.ts +165 -0
  152. package/lib/module/module.factory.ts +79 -0
  153. package/lib/module/module.schema.d.ts +36 -0
  154. package/lib/module/schema.json +40 -0
  155. package/lib/pipe/files/js/__name__.pipe.js +8 -0
  156. package/lib/pipe/files/js/__name__.pipe.spec.js +7 -0
  157. package/lib/pipe/files/ts/__name__.pipe.spec.ts +7 -0
  158. package/lib/pipe/files/ts/__name__.pipe.ts +8 -0
  159. package/lib/pipe/pipe.factory.js +6 -6
  160. package/lib/pipe/pipe.factory.test.ts +141 -0
  161. package/lib/pipe/pipe.factory.ts +51 -0
  162. package/lib/pipe/pipe.schema.d.ts +28 -0
  163. package/lib/pipe/schema.json +39 -0
  164. package/lib/plugin/files/js/__name__.plugin.js +28 -0
  165. package/lib/plugin/files/js/__name__.plugin.spec.js +7 -0
  166. package/lib/plugin/files/ts/__name__.plugin.spec.ts +7 -0
  167. package/lib/plugin/files/ts/__name__.plugin.ts +28 -0
  168. package/lib/plugin/plugin.factory.d.ts +2 -2
  169. package/lib/plugin/plugin.factory.js +1 -2
  170. package/lib/plugin/plugin.factory.test.ts +191 -0
  171. package/lib/plugin/plugin.factory.ts +91 -0
  172. package/lib/plugin/plugin.schema.d.ts +44 -0
  173. package/lib/plugin/schema.json +52 -0
  174. package/lib/provider/files/js/__name__.js +4 -0
  175. package/lib/provider/files/js/__name__.spec.js +17 -0
  176. package/lib/provider/files/ts/__name__.spec.ts +17 -0
  177. package/lib/provider/files/ts/__name__.ts +4 -0
  178. package/lib/provider/provider.factory.js +1 -2
  179. package/lib/provider/provider.factory.test.ts +151 -0
  180. package/lib/provider/provider.factory.ts +89 -0
  181. package/lib/provider/provider.schema.d.ts +44 -0
  182. package/lib/provider/schema.json +39 -0
  183. package/lib/resolver/files/js/__name__.resolver.js +4 -0
  184. package/lib/resolver/files/js/__name__.resolver.spec.js +18 -0
  185. package/lib/resolver/files/ts/__name__.resolver.spec.ts +18 -0
  186. package/lib/resolver/files/ts/__name__.resolver.ts +4 -0
  187. package/lib/resolver/resolver.factory.js +8 -8
  188. package/lib/resolver/resolver.factory.test.ts +117 -0
  189. package/lib/resolver/resolver.factory.ts +92 -0
  190. package/lib/resolver/resolver.schema.d.ts +36 -0
  191. package/lib/resolver/schema.json +39 -0
  192. package/lib/service/files/js/__name__.service.js +4 -0
  193. package/lib/service/files/js/__name__.service.spec.js +17 -0
  194. package/lib/service/files/ts/__name__.service.spec.ts +17 -0
  195. package/lib/service/files/ts/__name__.service.ts +4 -0
  196. package/lib/service/schema.json +39 -0
  197. package/lib/service/service.factory.js +9 -9
  198. package/lib/service/service.factory.test.ts +190 -0
  199. package/lib/service/service.factory.ts +91 -0
  200. package/lib/service/service.schema.d.ts +44 -0
  201. package/lib/type/files/js/__name__.type.js +10 -0
  202. package/lib/type/files/ts/__name__.type.ts +10 -0
  203. package/lib/type/schema.json +43 -0
  204. package/lib/type/type.factory.d.ts +1 -1
  205. package/lib/type/type.factory.js +1 -2
  206. package/lib/type/type.factory.test.ts +191 -0
  207. package/lib/type/type.factory.ts +91 -0
  208. package/lib/type/type.schema.d.ts +44 -0
  209. package/package.json +2 -2
  210. package/utils/metadata.manager.js +1 -1
  211. package/utils/metadata.manager.ts +219 -0
  212. package/utils/module-import.declarator.js +2 -2
  213. package/utils/module-import.declarator.ts +41 -0
  214. package/utils/module-metadata.declarator.ts +14 -0
  215. package/utils/module.declarator.js +2 -2
  216. package/utils/module.declarator.ts +41 -0
  217. package/utils/module.finder.js +1 -1
  218. package/utils/module.finder.ts +32 -0
  219. package/utils/name.parser.js +3 -3
  220. package/utils/name.parser.ts +29 -0
  221. package/utils/path.solver.js +2 -2
  222. package/utils/path.solver.ts +17 -0
  223. package/utils/source-root.helpers.js +2 -2
  224. package/utils/source-root.helpers.ts +30 -0
@@ -0,0 +1,92 @@
1
+ import { join, Path, strings } from '@angular-devkit/core';
2
+ import {
3
+ apply,
4
+ branchAndMerge,
5
+ chain,
6
+ filter,
7
+ mergeWith,
8
+ move,
9
+ noop,
10
+ Rule,
11
+ SchematicContext,
12
+ SchematicsException,
13
+ Source,
14
+ template,
15
+ Tree,
16
+ url,
17
+ } from '@angular-devkit/schematics';
18
+ import {
19
+ DeclarationOptions,
20
+ ModuleDeclarator,
21
+ } from '../../utils/module.declarator';
22
+ import { ModuleFinder } from '../../utils/module.finder';
23
+ import { Location, NameParser } from '../../utils/name.parser';
24
+ import { mergeSourceRoot } from '../../utils/source-root.helpers';
25
+ import { ProviderOptions } from '../provider/provider.schema';
26
+ import { GatewayOptions } from './gateway.schema';
27
+
28
+ export function main(options: GatewayOptions): Rule {
29
+ options = transform(options);
30
+ return (tree: Tree, context: SchematicContext) => {
31
+ return branchAndMerge(
32
+ chain([
33
+ mergeSourceRoot(options),
34
+ addDeclarationToModule(options),
35
+ mergeWith(generate(options)),
36
+ ]),
37
+ )(tree, context);
38
+ };
39
+ }
40
+
41
+ function transform(options: GatewayOptions): GatewayOptions {
42
+ const target: GatewayOptions = Object.assign({}, options);
43
+ if (!target.name) {
44
+ throw new SchematicsException('Option (name) is required.');
45
+ }
46
+ target.metadata = 'providers';
47
+ target.type = 'gateway';
48
+
49
+ const location: Location = new NameParser().parse(target);
50
+ target.name = strings.dasherize(location.name);
51
+ target.path = strings.dasherize(location.path);
52
+ target.language = target.language !== undefined ? target.language : 'ts';
53
+
54
+ target.path = target.flat
55
+ ? target.path
56
+ : join(target.path as Path, target.name);
57
+ return target;
58
+ }
59
+
60
+ function generate(options: GatewayOptions): Source {
61
+ return (context: SchematicContext) =>
62
+ apply(url(join('./files' as Path, options.language)), [
63
+ options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
64
+ template({
65
+ ...strings,
66
+ ...options,
67
+ }),
68
+ move(options.path),
69
+ ])(context);
70
+ }
71
+
72
+ function addDeclarationToModule(options: ProviderOptions): Rule {
73
+ return (tree: Tree) => {
74
+ if (options.skipImport !== undefined && options.skipImport) {
75
+ return tree;
76
+ }
77
+ options.module = new ModuleFinder(tree).find({
78
+ name: options.name,
79
+ path: options.path as Path,
80
+ });
81
+ if (!options.module) {
82
+ return tree;
83
+ }
84
+ const content = tree.read(options.module).toString();
85
+ const declarator: ModuleDeclarator = new ModuleDeclarator();
86
+ tree.overwrite(
87
+ options.module,
88
+ declarator.declare(content, options as DeclarationOptions),
89
+ );
90
+ return tree;
91
+ };
92
+ }
@@ -0,0 +1,36 @@
1
+ import { Path } from '@angular-devkit/core';
2
+
3
+ export interface GatewayOptions {
4
+ /**
5
+ * The name of the gateway.
6
+ */
7
+ name: string;
8
+ /**
9
+ * The path to create the gateway.
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
+ /**
29
+ * Metadata name affected by declaration insertion.
30
+ */
31
+ metadata?: string;
32
+ /**
33
+ * Nest element type name
34
+ */
35
+ type?: string;
36
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "id": "SchematicsNestGateway",
4
+ "title": "Nest Gateway Options Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The name of the gateway.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use for the gateway?"
15
+ },
16
+ "path": {
17
+ "type": "string",
18
+ "format": "path",
19
+ "description": "The path to create the gateway."
20
+ },
21
+ "language": {
22
+ "type": "string",
23
+ "description": "Nest gateway language (ts/js)."
24
+ },
25
+ "sourceRoot": {
26
+ "type": "string",
27
+ "description": "Nest gateway 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,17 @@
1
+ import { Injectable, CanActivateResolver, GenericGapiResolversType } from '@gapi/core';
2
+ import { Observable } from 'rxjs';
3
+
4
+ @Injectable()
5
+ export class <%= classify(name) %>Guard implements CanActivateResolver {
6
+ canActivate(
7
+ context,
8
+ payload,
9
+ descriptor: GenericGapiResolversType
10
+ ): boolean | Promise<boolean> | Observable<boolean> {
11
+ return new Observable(o => o.next(true));
12
+ return new Promise((r) => r(true));
13
+ return new Observable(o => o.next(false));
14
+ return new Promise((r) => r(false));
15
+ throw new Error('error');
16
+ }
17
+ }
@@ -0,0 +1,7 @@
1
+ import { <%= classify(name) %>Guard } from './<%= name %>.guard';
2
+
3
+ describe('<%= classify(name) %>Guard', () => {
4
+ it('should be defined', () => {
5
+ expect(new <%= classify(name) %>Guard()).toBeDefined();
6
+ });
7
+ });
@@ -0,0 +1,7 @@
1
+ import { <%= classify(name) %>Guard } from './<%= name %>.guard';
2
+
3
+ describe('<%= classify(name) %>Guard', () => {
4
+ it('should be defined', () => {
5
+ expect(new <%= classify(name) %>Guard()).toBeDefined();
6
+ });
7
+ });
@@ -0,0 +1,17 @@
1
+ import { Injectable, CanActivateResolver, GenericGapiResolversType } from '@gapi/core';
2
+ import { Observable } from 'rxjs';
3
+
4
+ @Injectable()
5
+ export class <%= classify(name) %>Guard implements CanActivateResolver {
6
+ canActivate(
7
+ context,
8
+ payload,
9
+ descriptor: GenericGapiResolversType
10
+ ): boolean | Promise<boolean> | Observable<boolean> {
11
+ return new Observable(o => o.next(true));
12
+ return new Promise((r) => r(true));
13
+ return new Observable(o => o.next(false));
14
+ return new Promise((r) => r(false));
15
+ throw new Error('error');
16
+ }
17
+ }
@@ -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) {
@@ -21,13 +21,13 @@ function transform(options) {
21
21
  target.language = target.language !== undefined ? target.language : 'ts';
22
22
  target.path = target.flat
23
23
  ? target.path
24
- : core_1.join(target.path, target.name);
24
+ : (0, core_1.join)(target.path, target.name);
25
25
  return target;
26
26
  }
27
27
  function generate(options) {
28
- return (context) => schematics_1.apply(schematics_1.url(core_1.join('./files', options.language)), [
29
- options.spec ? schematics_1.noop() : schematics_1.filter(path => !path.endsWith('.spec.ts')),
30
- schematics_1.template(Object.assign(Object.assign({}, core_1.strings), options)),
31
- schematics_1.move(options.path),
28
+ return (context) => (0, schematics_1.apply)((0, schematics_1.url)((0, core_1.join)('./files', options.language)), [
29
+ options.spec ? (0, schematics_1.noop)() : (0, schematics_1.filter)(path => !path.endsWith('.spec.ts')),
30
+ (0, schematics_1.template)(Object.assign(Object.assign({}, core_1.strings), options)),
31
+ (0, schematics_1.move)(options.path),
32
32
  ])(context);
33
33
  }
@@ -0,0 +1,156 @@
1
+ import {
2
+ SchematicTestRunner,
3
+ UnitTestTree,
4
+ } from '@angular-devkit/schematics/testing';
5
+ import * as path from 'path';
6
+ import { GuardOptions } from './guard.schema';
7
+
8
+ describe('Guard 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: GuardOptions = {
16
+ name: 'foo',
17
+ };
18
+ const tree: UnitTestTree = runner.runSchematic('guard', options);
19
+ const files: string[] = tree.files;
20
+ expect(
21
+ files.find(filename => filename === '/foo.guard.ts'),
22
+ ).not.toBeUndefined();
23
+ expect(tree.readContent('/foo.guard.ts')).toEqual(
24
+ "import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';\n" +
25
+ "import { Observable } from 'rxjs';\n" +
26
+ '\n' +
27
+ '@Injectable()\n' +
28
+ 'export class FooGuard implements CanActivate {\n' +
29
+ ' canActivate(\n' +
30
+ ' context: ExecutionContext,\n' +
31
+ ' ): boolean | Promise<boolean> | Observable<boolean> {\n' +
32
+ ' return true;\n' +
33
+ ' }\n' +
34
+ '}\n',
35
+ );
36
+ });
37
+
38
+ it('should manage name has a path', () => {
39
+ const options: GuardOptions = {
40
+ name: 'bar/foo',
41
+ };
42
+ const tree: UnitTestTree = runner.runSchematic('guard', options);
43
+ const files: string[] = tree.files;
44
+ expect(
45
+ files.find(filename => filename === '/bar/foo.guard.ts'),
46
+ ).not.toBeUndefined();
47
+ expect(tree.readContent('/bar/foo.guard.ts')).toEqual(
48
+ "import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';\n" +
49
+ "import { Observable } from 'rxjs';\n" +
50
+ '\n' +
51
+ '@Injectable()\n' +
52
+ 'export class FooGuard implements CanActivate {\n' +
53
+ ' canActivate(\n' +
54
+ ' context: ExecutionContext,\n' +
55
+ ' ): boolean | Promise<boolean> | Observable<boolean> {\n' +
56
+ ' return true;\n' +
57
+ ' }\n' +
58
+ '}\n',
59
+ );
60
+ });
61
+
62
+ it('should manage name and path', () => {
63
+ const options: GuardOptions = {
64
+ name: 'foo',
65
+ path: 'baz',
66
+ };
67
+ const tree: UnitTestTree = runner.runSchematic('guard', options);
68
+ const files: string[] = tree.files;
69
+ expect(
70
+ files.find(filename => filename === '/baz/foo.guard.ts'),
71
+ ).not.toBeUndefined();
72
+ expect(tree.readContent('/baz/foo.guard.ts')).toEqual(
73
+ "import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';\n" +
74
+ "import { Observable } from 'rxjs';\n" +
75
+ '\n' +
76
+ '@Injectable()\n' +
77
+ 'export class FooGuard implements CanActivate {\n' +
78
+ ' canActivate(\n' +
79
+ ' context: ExecutionContext,\n' +
80
+ ' ): boolean | Promise<boolean> | Observable<boolean> {\n' +
81
+ ' return true;\n' +
82
+ ' }\n' +
83
+ '}\n',
84
+ );
85
+ });
86
+
87
+ it('should manage name to dasherize', () => {
88
+ const options: GuardOptions = {
89
+ name: 'fooBar',
90
+ };
91
+ const tree: UnitTestTree = runner.runSchematic('guard', options);
92
+ const files: string[] = tree.files;
93
+ expect(
94
+ files.find(filename => filename === '/foo-bar.guard.ts'),
95
+ ).not.toBeUndefined();
96
+ expect(tree.readContent('/foo-bar.guard.ts')).toEqual(
97
+ "import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';\n" +
98
+ "import { Observable } from 'rxjs';\n" +
99
+ '\n' +
100
+ '@Injectable()\n' +
101
+ 'export class FooBarGuard implements CanActivate {\n' +
102
+ ' canActivate(\n' +
103
+ ' context: ExecutionContext,\n' +
104
+ ' ): boolean | Promise<boolean> | Observable<boolean> {\n' +
105
+ ' return true;\n' +
106
+ ' }\n' +
107
+ '}\n',
108
+ );
109
+ });
110
+
111
+ it('should manage path to dasherize', () => {
112
+ const options: GuardOptions = {
113
+ name: 'barBaz/foo',
114
+ };
115
+ const tree: UnitTestTree = runner.runSchematic('guard', options);
116
+ const files: string[] = tree.files;
117
+ expect(
118
+ files.find(filename => filename === '/bar-baz/foo.guard.ts'),
119
+ ).not.toBeUndefined();
120
+ expect(tree.readContent('/bar-baz/foo.guard.ts')).toEqual(
121
+ "import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';\n" +
122
+ "import { Observable } from 'rxjs';\n" +
123
+ '\n' +
124
+ '@Injectable()\n' +
125
+ 'export class FooGuard implements CanActivate {\n' +
126
+ ' canActivate(\n' +
127
+ ' context: ExecutionContext,\n' +
128
+ ' ): boolean | Promise<boolean> | Observable<boolean> {\n' +
129
+ ' return true;\n' +
130
+ ' }\n' +
131
+ '}\n',
132
+ );
133
+ });
134
+
135
+ it('should manage javascript file', () => {
136
+ const options: GuardOptions = {
137
+ name: 'foo',
138
+ language: 'js',
139
+ };
140
+ const tree: UnitTestTree = runner.runSchematic('guard', options);
141
+ const files: string[] = tree.files;
142
+ expect(
143
+ files.find(filename => filename === '/foo.guard.js'),
144
+ ).not.toBeUndefined();
145
+ expect(tree.readContent('/foo.guard.js')).toEqual(
146
+ "import { Injectable } from '@nestjs/common';\n" +
147
+ '\n' +
148
+ '@Injectable()\n' +
149
+ 'export class FooGuard {\n' +
150
+ ' canActivate(context) {\n' +
151
+ ' return true;\n' +
152
+ ' }\n' +
153
+ '}\n',
154
+ );
155
+ });
156
+ });
@@ -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 { GuardOptions } from './guard.schema';
19
+
20
+ export function main(options: GuardOptions): Rule {
21
+ options = transform(options);
22
+ return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
23
+ }
24
+
25
+ function transform(options: GuardOptions): GuardOptions {
26
+ const target: GuardOptions = 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: GuardOptions): 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 GuardOptions {
4
+ /**
5
+ * The name of the guard.
6
+ */
7
+ name: string;
8
+ /**
9
+ * The path to create the guard.
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": "SchematicsNestGuard",
4
+ "title": "Nest Guard Options Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The name of the guard.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use for the guard?"
15
+ },
16
+ "path": {
17
+ "type": "string",
18
+ "format": "path",
19
+ "description": "The path to create the guard."
20
+ },
21
+ "language": {
22
+ "type": "string",
23
+ "description": "Nest guard language (ts/js)."
24
+ },
25
+ "sourceRoot": {
26
+ "type": "string",
27
+ "description": "Nest guard 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,18 @@
1
+ import { Injectable } from '@gapi/core';
2
+ import { tap } from 'rxjs/operators';
3
+
4
+ @Injectable()
5
+ export class <%= classify(name) %>Interceptor {
6
+ intercept(
7
+ chainable$,
8
+ context,
9
+ payload,
10
+ descriptor
11
+ ) {
12
+ console.log('Before...');
13
+ const now = Date.now();
14
+ return chainable$.pipe(
15
+ tap(() => console.log(`After... ${Date.now() - now}ms`)),
16
+ );
17
+ }
18
+ }
@@ -0,0 +1,7 @@
1
+ import { <%= classify(name) %>Interceptor } from './<%= name %>.interceptor';
2
+
3
+ describe('<%= classify(name) %>Interceptor', () => {
4
+ it('should be defined', () => {
5
+ expect(new <%= classify(name) %>Interceptor()).toBeDefined();
6
+ });
7
+ });
@@ -0,0 +1,7 @@
1
+ import { <%= classify(name) %>Interceptor } from './<%= name %>.interceptor';
2
+
3
+ describe('<%= classify(name) %>Interceptor', () => {
4
+ it('should be defined', () => {
5
+ expect(new <%= classify(name) %>Interceptor()).toBeDefined();
6
+ });
7
+ });
@@ -0,0 +1,19 @@
1
+ import { InterceptResolver, Injectable, GenericGapiResolversType } from '@gapi/core';
2
+ import { Observable } from 'rxjs';
3
+ import { tap } from 'rxjs/operators';
4
+
5
+ @Injectable()
6
+ export class <%= classify(name) %>Interceptor implements InterceptResolver {
7
+ intercept(
8
+ chainable$: Observable<any>,
9
+ context,
10
+ payload,
11
+ descriptor: GenericGapiResolversType
12
+ ) {
13
+ console.log('Before...');
14
+ const now = Date.now();
15
+ return chainable$.pipe(
16
+ tap(() => console.log(`After... ${Date.now() - now}ms`)),
17
+ );
18
+ }
19
+ }
@@ -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) {
@@ -21,13 +21,13 @@ function transform(options) {
21
21
  target.language = target.language !== undefined ? target.language : 'ts';
22
22
  target.path = target.flat
23
23
  ? target.path
24
- : core_1.join(target.path, target.name);
24
+ : (0, core_1.join)(target.path, target.name);
25
25
  return target;
26
26
  }
27
27
  function generate(options) {
28
- return (context) => schematics_1.apply(schematics_1.url(core_1.join('./files', options.language)), [
29
- options.spec ? schematics_1.noop() : schematics_1.filter(path => !path.endsWith('.spec.ts')),
30
- schematics_1.template(Object.assign(Object.assign({}, core_1.strings), options)),
31
- schematics_1.move(options.path),
28
+ return (context) => (0, schematics_1.apply)((0, schematics_1.url)((0, core_1.join)('./files', options.language)), [
29
+ options.spec ? (0, schematics_1.noop)() : (0, schematics_1.filter)(path => !path.endsWith('.spec.ts')),
30
+ (0, schematics_1.template)(Object.assign(Object.assign({}, core_1.strings), options)),
31
+ (0, schematics_1.move)(options.path),
32
32
  ])(context);
33
33
  }