@rxdi/schematics 0.7.189 → 0.7.191-nightly.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/lib/component/component.factory.js +1 -2
  2. package/lib/controller/controller.factory.js +1 -2
  3. package/lib/effect/effect.factory.js +2 -4
  4. package/lib/effect/effect.factory.ts +1 -2
  5. package/lib/guard/guard.factory.js +1 -2
  6. package/lib/interceptor/interceptor.factory.js +1 -2
  7. package/lib/module/module.factory.js +1 -2
  8. package/lib/service/service.factory.js +2 -4
  9. package/lib/service/service.factory.ts +1 -2
  10. package/package.json +8 -8
  11. package/utils/source-root.helpers.js +2 -3
  12. package/lib/application/application.factory.d.ts +0 -3
  13. package/lib/application/application.factory.js +0 -35
  14. package/lib/application/application.factory.test.ts +0 -88
  15. package/lib/application/application.factory.ts +0 -54
  16. package/lib/application/application.schema.d.ts +0 -34
  17. package/lib/application/files/js/.babelrc +0 -4
  18. package/lib/application/files/js/.prettierrc +0 -4
  19. package/lib/application/files/js/README.md +0 -37
  20. package/lib/application/files/js/index.js +0 -3
  21. package/lib/application/files/js/jsconfig.json +0 -9
  22. package/lib/application/files/js/nest-cli.json +0 -5
  23. package/lib/application/files/js/nodemon.json +0 -6
  24. package/lib/application/files/js/package.json +0 -46
  25. package/lib/application/files/js/test/app.e2e-spec.js +0 -23
  26. package/lib/application/files/js/test/jest-e2e.json +0 -5
  27. package/lib/application/files/ts/.prettierrc +0 -4
  28. package/lib/application/files/ts/README.md +0 -75
  29. package/lib/application/files/ts/nest-cli.json +0 -5
  30. package/lib/application/files/ts/nodemon-debug.json +0 -6
  31. package/lib/application/files/ts/nodemon.json +0 -6
  32. package/lib/application/files/ts/package.json +0 -58
  33. package/lib/application/files/ts/test/app.e2e-spec.ts +0 -23
  34. package/lib/application/files/ts/test/jest-e2e.json +0 -9
  35. package/lib/application/files/ts/tsconfig.build.json +0 -4
  36. package/lib/application/schema.json +0 -49
  37. package/lib/class/class.factory.d.ts +0 -3
  38. package/lib/class/class.factory.js +0 -35
  39. package/lib/class/class.factory.test.ts +0 -100
  40. package/lib/class/class.factory.ts +0 -54
  41. package/lib/class/class.schema.d.ts +0 -28
  42. package/lib/class/files/js/__name__.js +0 -1
  43. package/lib/class/files/js/__name__.spec.js +0 -7
  44. package/lib/class/files/ts/__name__.spec.ts +0 -7
  45. package/lib/class/files/ts/__name__.ts +0 -1
  46. package/lib/class/schema.json +0 -39
  47. package/lib/client-app/angular/angular.factory.d.ts +0 -3
  48. package/lib/client-app/angular/angular.factory.js +0 -97
  49. package/lib/client-app/angular/angular.factory.ts +0 -139
  50. package/lib/client-app/angular/angular.schema.d.ts +0 -32
  51. package/lib/client-app/angular/files/angular.constants.ts +0 -4
  52. package/lib/client-app/angular/files/angular.module.ts +0 -41
  53. package/lib/client-app/angular/files/angular.providers.ts +0 -27
  54. package/lib/client-app/angular/files/angular.utils.ts +0 -19
  55. package/lib/client-app/angular/files/interfaces/angular-options.interface.ts +0 -87
  56. package/lib/client-app/angular/files/loaders/abstract.loader.ts +0 -16
  57. package/lib/client-app/angular/files/loaders/express.loader.ts +0 -25
  58. package/lib/client-app/angular/files/loaders/fastify.loader.ts +0 -34
  59. package/lib/client-app/angular/files/loaders/noop.loader.ts +0 -12
  60. package/lib/client-app/angular/schema.json +0 -24
  61. package/lib/configuration/configuration.factory.d.ts +0 -3
  62. package/lib/configuration/configuration.factory.js +0 -24
  63. package/lib/configuration/configuration.factory.test.ts +0 -60
  64. package/lib/configuration/configuration.factory.ts +0 -35
  65. package/lib/configuration/configuration.schema.d.ts +0 -18
  66. package/lib/configuration/files/js/nest-cli.json +0 -5
  67. package/lib/configuration/files/ts/nest-cli.json +0 -5
  68. package/lib/decorator/decorator.factory.d.ts +0 -3
  69. package/lib/decorator/decorator.factory.js +0 -32
  70. package/lib/decorator/decorator.factory.test.ts +0 -111
  71. package/lib/decorator/decorator.factory.ts +0 -48
  72. package/lib/decorator/decorator.schema.d.ts +0 -24
  73. package/lib/decorator/files/js/__name__.decorator.js +0 -3
  74. package/lib/decorator/files/ts/__name__.decorator.ts +0 -3
  75. package/lib/decorator/schema.json +0 -35
  76. package/lib/filter/files/js/__name__.filter.js +0 -6
  77. package/lib/filter/files/js/__name__.filter.spec.js +0 -7
  78. package/lib/filter/files/ts/__name__.filter.spec.ts +0 -7
  79. package/lib/filter/files/ts/__name__.filter.ts +0 -6
  80. package/lib/filter/filter.factory.d.ts +0 -3
  81. package/lib/filter/filter.factory.js +0 -33
  82. package/lib/filter/filter.factory.test.ts +0 -147
  83. package/lib/filter/filter.factory.ts +0 -51
  84. package/lib/filter/filter.schema.d.ts +0 -28
  85. package/lib/filter/schema.json +0 -39
  86. package/lib/gateway/files/js/__name__.gateway.js +0 -9
  87. package/lib/gateway/files/js/__name__.gateway.spec.js +0 -18
  88. package/lib/gateway/files/ts/__name__.gateway.spec.ts +0 -18
  89. package/lib/gateway/files/ts/__name__.gateway.ts +0 -9
  90. package/lib/gateway/gateway.factory.d.ts +0 -3
  91. package/lib/gateway/gateway.factory.js +0 -61
  92. package/lib/gateway/gateway.factory.test.ts +0 -147
  93. package/lib/gateway/gateway.factory.ts +0 -92
  94. package/lib/gateway/gateway.schema.d.ts +0 -36
  95. package/lib/gateway/schema.json +0 -39
  96. package/lib/interface/files/__name__.interface.ts +0 -1
  97. package/lib/interface/interface.factory.d.ts +0 -3
  98. package/lib/interface/interface.factory.js +0 -31
  99. package/lib/interface/interface.factory.test.ts +0 -84
  100. package/lib/interface/interface.factory.ts +0 -47
  101. package/lib/interface/interface.schema.d.ts +0 -20
  102. package/lib/interface/schema.json +0 -31
  103. package/lib/library/files/js/.babelrc +0 -4
  104. package/lib/library/files/js/jsconfig.json +0 -9
  105. package/lib/library/files/js/package.json +0 -8
  106. package/lib/library/files/js/src/__name__.module.js +0 -8
  107. package/lib/library/files/js/src/__name__.service.js +0 -4
  108. package/lib/library/files/js/src/__name__.service.spec.js +0 -18
  109. package/lib/library/files/js/src/index.js +0 -2
  110. package/lib/library/files/ts/package.json +0 -8
  111. package/lib/library/files/ts/src/__name__.module.ts +0 -8
  112. package/lib/library/files/ts/src/__name__.service.spec.ts +0 -18
  113. package/lib/library/files/ts/src/__name__.service.ts +0 -4
  114. package/lib/library/files/ts/src/index.ts +0 -2
  115. package/lib/library/files/ts/tsconfig.lib.json +0 -5
  116. package/lib/library/library.factory.d.ts +0 -3
  117. package/lib/library/library.factory.js +0 -97
  118. package/lib/library/library.factory.test.ts +0 -68
  119. package/lib/library/library.factory.ts +0 -158
  120. package/lib/library/library.schema.d.ts +0 -24
  121. package/lib/library/schema.json +0 -37
  122. package/lib/pipe/files/js/__name__.pipe.js +0 -8
  123. package/lib/pipe/files/js/__name__.pipe.spec.js +0 -7
  124. package/lib/pipe/files/ts/__name__.pipe.spec.ts +0 -7
  125. package/lib/pipe/files/ts/__name__.pipe.ts +0 -8
  126. package/lib/pipe/pipe.factory.d.ts +0 -3
  127. package/lib/pipe/pipe.factory.js +0 -33
  128. package/lib/pipe/pipe.factory.test.ts +0 -141
  129. package/lib/pipe/pipe.factory.ts +0 -51
  130. package/lib/pipe/pipe.schema.d.ts +0 -28
  131. package/lib/pipe/schema.json +0 -39
  132. package/lib/resolver/files/js/__name__.resolver.js +0 -4
  133. package/lib/resolver/files/js/__name__.resolver.spec.js +0 -18
  134. package/lib/resolver/files/ts/__name__.resolver.spec.ts +0 -18
  135. package/lib/resolver/files/ts/__name__.resolver.ts +0 -4
  136. package/lib/resolver/resolver.factory.d.ts +0 -3
  137. package/lib/resolver/resolver.factory.js +0 -61
  138. package/lib/resolver/resolver.factory.test.ts +0 -117
  139. package/lib/resolver/resolver.factory.ts +0 -92
  140. package/lib/resolver/resolver.schema.d.ts +0 -36
  141. package/lib/resolver/schema.json +0 -39
@@ -1,111 +0,0 @@
1
- import {
2
- SchematicTestRunner,
3
- UnitTestTree,
4
- } from '@angular-devkit/schematics/testing';
5
- import * as path from 'path';
6
- import { DecoratorOptions } from './decorator.schema';
7
-
8
- describe('Decorator Factory', () => {
9
- const runner: SchematicTestRunner = new SchematicTestRunner(
10
- '.',
11
- path.join(process.cwd(), 'src/collection.json'),
12
- );
13
- it('should manage name only', () => {
14
- const options: DecoratorOptions = {
15
- name: 'foo',
16
- flat: false,
17
- };
18
- const tree: UnitTestTree = runner.runSchematic('decorator', options);
19
- const files: string[] = tree.files;
20
- expect(
21
- files.find(filename => filename === '/foo/foo.decorator.ts'),
22
- ).not.toBeUndefined();
23
- expect(tree.readContent('/foo/foo.decorator.ts')).toEqual(
24
- "import { ReflectMetadata } from '@nestjs/common';\n" +
25
- '\n' +
26
- "export const Foo = (...args: string[]) => ReflectMetadata('foo', args);\n",
27
- );
28
- });
29
- it('should manage name as a path', () => {
30
- const options: DecoratorOptions = {
31
- name: 'bar/foo',
32
- flat: false,
33
- };
34
- const tree: UnitTestTree = runner.runSchematic('decorator', options);
35
- const files: string[] = tree.files;
36
- expect(
37
- files.find(filename => filename === '/bar/foo/foo.decorator.ts'),
38
- ).not.toBeUndefined();
39
- expect(tree.readContent('/bar/foo/foo.decorator.ts')).toEqual(
40
- "import { ReflectMetadata } from '@nestjs/common';\n" +
41
- '\n' +
42
- "export const Foo = (...args: string[]) => ReflectMetadata('foo', args);\n",
43
- );
44
- });
45
- it('should manage name and path', () => {
46
- const options: DecoratorOptions = {
47
- name: 'foo',
48
- path: 'baz',
49
- flat: false,
50
- };
51
- const tree: UnitTestTree = runner.runSchematic('decorator', options);
52
- const files: string[] = tree.files;
53
- expect(
54
- files.find(filename => filename === '/baz/foo/foo.decorator.ts'),
55
- ).not.toBeUndefined();
56
- expect(tree.readContent('/baz/foo/foo.decorator.ts')).toEqual(
57
- "import { ReflectMetadata } from '@nestjs/common';\n" +
58
- '\n' +
59
- "export const Foo = (...args: string[]) => ReflectMetadata('foo', args);\n",
60
- );
61
- });
62
- it('should manage name to dasherize', () => {
63
- const options: DecoratorOptions = {
64
- name: 'fooBar',
65
- flat: false,
66
- };
67
- const tree: UnitTestTree = runner.runSchematic('decorator', options);
68
- const files: string[] = tree.files;
69
- expect(
70
- files.find(filename => filename === '/foo-bar/foo-bar.decorator.ts'),
71
- ).not.toBeUndefined();
72
- expect(tree.readContent('/foo-bar/foo-bar.decorator.ts')).toEqual(
73
- "import { ReflectMetadata } from '@nestjs/common';\n" +
74
- '\n' +
75
- "export const FooBar = (...args: string[]) => ReflectMetadata('foo-bar', args);\n",
76
- );
77
- });
78
- it('should manage path to dasherize', () => {
79
- const options: DecoratorOptions = {
80
- name: 'barBaz/foo',
81
- flat: false,
82
- };
83
- const tree: UnitTestTree = runner.runSchematic('decorator', options);
84
- const files: string[] = tree.files;
85
- expect(
86
- files.find(filename => filename === '/bar-baz/foo/foo.decorator.ts'),
87
- ).not.toBeUndefined();
88
- expect(tree.readContent('/bar-baz/foo/foo.decorator.ts')).toEqual(
89
- "import { ReflectMetadata } from '@nestjs/common';\n" +
90
- '\n' +
91
- "export const Foo = (...args: string[]) => ReflectMetadata('foo', args);\n",
92
- );
93
- });
94
- it('should manage javascript file', () => {
95
- const options: DecoratorOptions = {
96
- name: 'foo',
97
- language: 'js',
98
- flat: false,
99
- };
100
- const tree: UnitTestTree = runner.runSchematic('decorator', options);
101
- const files: string[] = tree.files;
102
- expect(
103
- files.find(filename => filename === '/foo/foo.decorator.js'),
104
- ).not.toBeUndefined();
105
- expect(tree.readContent('/foo/foo.decorator.js')).toEqual(
106
- "import { ReflectMetadata } from '@nestjs/common';\n" +
107
- '\n' +
108
- "export const Foo = (...args) => ReflectMetadata('foo', args);\n",
109
- );
110
- });
111
- });
@@ -1,48 +0,0 @@
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 { DecoratorOptions } from './decorator.schema';
17
-
18
- export function main(options: DecoratorOptions): Rule {
19
- options = transform(options);
20
- return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
21
- }
22
-
23
- function transform(options: DecoratorOptions): DecoratorOptions {
24
- const target: DecoratorOptions = 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
- target.language = target.language !== undefined ? target.language : 'ts';
32
-
33
- target.path = target.flat
34
- ? target.path
35
- : join(target.path as Path, target.name);
36
- return target;
37
- }
38
-
39
- function generate(options: DecoratorOptions): Source {
40
- return (context: SchematicContext) =>
41
- apply(url(join('./files' as Path, options.language)), [
42
- template({
43
- ...strings,
44
- ...options,
45
- }),
46
- move(options.path),
47
- ])(context);
48
- }
@@ -1,24 +0,0 @@
1
- import { Path } from '@angular-devkit/core';
2
-
3
- export interface DecoratorOptions {
4
- /**
5
- * The name of the decorator.
6
- */
7
- name: string;
8
- /**
9
- * The path to create the decorator.
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
- * Flag to indicate if a directory is created.
22
- */
23
- flat?: boolean;
24
- }
@@ -1,3 +0,0 @@
1
- import { ReflectMetadata } from '@nestjs/common';
2
-
3
- export const <%= classify(name) %> = (...args) => ReflectMetadata('<%= name %>', args);
@@ -1,3 +0,0 @@
1
- import { ReflectMetadata } from '@nestjs/common';
2
-
3
- export const <%= classify(name) %> = (...args: string[]) => ReflectMetadata('<%= name %>', args);
@@ -1,35 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/schema",
3
- "id": "SchematicsNestDecorator",
4
- "title": "Nest Decorator Options Schema",
5
- "type": "object",
6
- "properties": {
7
- "name": {
8
- "type": "string",
9
- "description": "The name of the decorator.",
10
- "$default": {
11
- "$source": "argv",
12
- "index": 0
13
- },
14
- "x-prompt": "What name would you like to use for the decorator?"
15
- },
16
- "path": {
17
- "type": "string",
18
- "format": "path",
19
- "description": "The path to create the decorator."
20
- },
21
- "language": {
22
- "type": "string",
23
- "description": "Nest decorator language (ts/js)."
24
- },
25
- "sourceRoot": {
26
- "type": "string",
27
- "description": "Nest decorator source root directory."
28
- },
29
- "flat": {
30
- "default": true,
31
- "description": "Flag to indicate if a directory is created."
32
- }
33
- },
34
- "required": ["name"]
35
- }
@@ -1,6 +0,0 @@
1
- import { Catch } from '@nestjs/common';
2
-
3
- @Catch()
4
- export class <%= classify(name) %>Filter {
5
- catch(exception, host) {}
6
- }
@@ -1,7 +0,0 @@
1
- import { <%= classify(name) %>Filter } from './<%= name %>.filter';
2
-
3
- describe('<%= classify(name) %>Filter', () => {
4
- it('should be defined', () => {
5
- expect(new <%= classify(name) %>Filter()).toBeDefined();
6
- });
7
- });
@@ -1,7 +0,0 @@
1
- import { <%= classify(name) %>Filter } from './<%= name %>.filter';
2
-
3
- describe('<%= classify(name) %>Filter', () => {
4
- it('should be defined', () => {
5
- expect(new <%= classify(name) %>Filter()).toBeDefined();
6
- });
7
- });
@@ -1,6 +0,0 @@
1
- import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';
2
-
3
- @Catch()
4
- export class <%= classify(name) %>Filter<T> implements ExceptionFilter {
5
- catch(exception: T, host: ArgumentsHost) {}
6
- }
@@ -1,3 +0,0 @@
1
- import { Rule } from '@angular-devkit/schematics';
2
- import { FilterOptions } from './filter.schema';
3
- export declare function main(options: FilterOptions): Rule;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
4
- const core_1 = require("@angular-devkit/core");
5
- const schematics_1 = require("@angular-devkit/schematics");
6
- const name_parser_1 = require("../../utils/name.parser");
7
- const source_root_helpers_1 = require("../../utils/source-root.helpers");
8
- function main(options) {
9
- options = transform(options);
10
- return (0, schematics_1.chain)([(0, source_root_helpers_1.mergeSourceRoot)(options), (0, schematics_1.mergeWith)(generate(options))]);
11
- }
12
- exports.main = main;
13
- function transform(options) {
14
- const target = Object.assign({}, options);
15
- if (!target.name) {
16
- throw new schematics_1.SchematicsException('Option (name) is required.');
17
- }
18
- const location = new name_parser_1.NameParser().parse(target);
19
- target.name = core_1.strings.dasherize(location.name);
20
- target.path = core_1.strings.dasherize(location.path);
21
- target.language = target.language !== undefined ? target.language : 'ts';
22
- target.path = target.flat
23
- ? target.path
24
- : (0, core_1.join)(target.path, target.name);
25
- return target;
26
- }
27
- function generate(options) {
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
- ])(context);
33
- }
@@ -1,147 +0,0 @@
1
- import {
2
- SchematicTestRunner,
3
- UnitTestTree,
4
- } from '@angular-devkit/schematics/testing';
5
- import * as path from 'path';
6
- import { FilterOptions } from './filter.schema';
7
-
8
- describe('Filter 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: FilterOptions = {
16
- name: 'foo',
17
- };
18
- const tree: UnitTestTree = runner.runSchematic('filter', options);
19
- const files: string[] = tree.files;
20
- expect(files.find(filename => filename === '/foo.filter.ts')).toBeDefined();
21
- expect(tree.readContent('/foo.filter.ts')).toEqual(
22
- "import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';\n" +
23
- '\n' +
24
- '@Catch()\n' +
25
- 'export class FooFilter<T> implements ExceptionFilter {\n' +
26
- ' catch(exception: T, host: ArgumentsHost) {}\n' +
27
- '}\n',
28
- );
29
- });
30
-
31
- it('should manage name has a path', () => {
32
- const options: FilterOptions = {
33
- name: 'bar/foo',
34
- };
35
- const tree: UnitTestTree = runner.runSchematic('filter', options);
36
- const files: string[] = tree.files;
37
- expect(
38
- files.find(filename => filename === '/bar/foo.filter.ts'),
39
- ).toBeDefined();
40
- expect(tree.readContent('/bar/foo.filter.ts')).toEqual(
41
- "import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';\n" +
42
- '\n' +
43
- '@Catch()\n' +
44
- 'export class FooFilter<T> implements ExceptionFilter {\n' +
45
- ' catch(exception: T, host: ArgumentsHost) {}\n' +
46
- '}\n',
47
- );
48
- });
49
-
50
- it('should manage name and path', () => {
51
- const options: FilterOptions = {
52
- name: 'foo',
53
- path: 'baz',
54
- };
55
- const tree: UnitTestTree = runner.runSchematic('filter', options);
56
- const files: string[] = tree.files;
57
- expect(
58
- files.find(filename => filename === '/baz/foo.filter.ts'),
59
- ).toBeDefined();
60
- expect(tree.readContent('/baz/foo.filter.ts')).toEqual(
61
- "import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';\n" +
62
- '\n' +
63
- '@Catch()\n' +
64
- 'export class FooFilter<T> implements ExceptionFilter {\n' +
65
- ' catch(exception: T, host: ArgumentsHost) {}\n' +
66
- '}\n',
67
- );
68
- });
69
-
70
- it('should manage name to dasherize', () => {
71
- const options: FilterOptions = {
72
- name: 'fooBar',
73
- };
74
- const tree: UnitTestTree = runner.runSchematic('filter', options);
75
- const files: string[] = tree.files;
76
- expect(
77
- files.find(filename => filename === '/foo-bar.filter.ts'),
78
- ).toBeDefined();
79
- expect(tree.readContent('/foo-bar.filter.ts')).toEqual(
80
- "import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';\n" +
81
- '\n' +
82
- '@Catch()\n' +
83
- 'export class FooBarFilter<T> implements ExceptionFilter {\n' +
84
- ' catch(exception: T, host: ArgumentsHost) {}\n' +
85
- '}\n',
86
- );
87
- });
88
-
89
- it('should manage path to dasherize', () => {
90
- const options: FilterOptions = {
91
- name: 'barBaz/foo',
92
- };
93
- const tree: UnitTestTree = runner.runSchematic('filter', options);
94
- const files: string[] = tree.files;
95
- expect(
96
- files.find(filename => filename === '/bar-baz/foo.filter.ts'),
97
- ).toBeDefined();
98
- expect(tree.readContent('/bar-baz/foo.filter.ts')).toEqual(
99
- "import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';\n" +
100
- '\n' +
101
- '@Catch()\n' +
102
- 'export class FooFilter<T> implements ExceptionFilter {\n' +
103
- ' catch(exception: T, host: ArgumentsHost) {}\n' +
104
- '}\n',
105
- );
106
- });
107
-
108
- it('should manage javascript file', () => {
109
- const options: FilterOptions = {
110
- name: 'foo',
111
- language: 'js',
112
- };
113
- const tree: UnitTestTree = runner.runSchematic('filter', options);
114
- const files: string[] = tree.files;
115
- expect(files.find(filename => filename === '/foo.filter.js')).toBeDefined();
116
- expect(tree.readContent('/foo.filter.js')).toEqual(
117
- "import { Catch } from '@nestjs/common';\n" +
118
- '\n' +
119
- '@Catch()\n' +
120
- 'export class FooFilter {\n' +
121
- ' catch(exception, host) {}\n' +
122
- '}\n',
123
- );
124
- });
125
-
126
- it('should add source root to path', () => {
127
- const options: FilterOptions = {
128
- name: 'foo',
129
- language: 'js',
130
- };
131
- let tree: UnitTestTree = runner.runSchematic('application', { name: '' });
132
- tree = runner.runSchematic('filter', options, tree);
133
-
134
- const files: string[] = tree.files;
135
- expect(
136
- files.find(filename => filename === '/src/foo.filter.js'),
137
- ).toBeDefined();
138
- expect(tree.readContent('/src/foo.filter.js')).toEqual(
139
- "import { Catch } from '@nestjs/common';\n" +
140
- '\n' +
141
- '@Catch()\n' +
142
- 'export class FooFilter {\n' +
143
- ' catch(exception, host) {}\n' +
144
- '}\n',
145
- );
146
- });
147
- });
@@ -1,51 +0,0 @@
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 { FilterOptions } from './filter.schema';
19
-
20
- export function main(options: FilterOptions): Rule {
21
- options = transform(options);
22
- return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
23
- }
24
-
25
- function transform(options: FilterOptions): FilterOptions {
26
- const target: FilterOptions = 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: FilterOptions): 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
- }
@@ -1,28 +0,0 @@
1
- import { Path } from '@angular-devkit/core';
2
-
3
- export interface FilterOptions {
4
- /**
5
- * The name of the filter.
6
- */
7
- name: string;
8
- /**
9
- * The path to create the filter.
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
- }
@@ -1,39 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/schema",
3
- "id": "SchematicsNestFilter",
4
- "title": "Nest Filter Options Schema",
5
- "type": "object",
6
- "properties": {
7
- "name": {
8
- "type": "string",
9
- "description": "The name of the filter.",
10
- "$default": {
11
- "$source": "argv",
12
- "index": 0
13
- },
14
- "x-prompt": "What name would you like to use for the filter?"
15
- },
16
- "path": {
17
- "type": "string",
18
- "format": "path",
19
- "description": "The path to create the filter."
20
- },
21
- "language": {
22
- "type": "string",
23
- "description": "Nest filter language (ts/js)."
24
- },
25
- "sourceRoot": {
26
- "type": "string",
27
- "description": "Nest filter 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
- }
@@ -1,9 +0,0 @@
1
- import { SubscribeMessage, WebSocketGateway } from '@nestjs/websockets';
2
-
3
- @WebSocketGateway()
4
- export class <%= classify(name) %>Gateway {
5
- @SubscribeMessage('message')
6
- handleMessage(client, payload) {
7
- return 'Hello world!';
8
- }
9
- }
@@ -1,18 +0,0 @@
1
- import { Test } from '@nestjs/testing';
2
- import { <%= classify(name) %>Gateway } from './<%= name %>.gateway';
3
-
4
- describe('<%= classify(name) %>Gateway', () => {
5
- let gateway;
6
-
7
- beforeEach(async () => {
8
- const module = await Test.createTestingModule({
9
- providers: [<%= classify(name) %>Gateway],
10
- }).compile();
11
-
12
- gateway = module.get(<%= classify(name) %>Gateway);
13
- });
14
-
15
- it('should be defined', () => {
16
- expect(gateway).toBeDefined();
17
- });
18
- });
@@ -1,18 +0,0 @@
1
- import { Test, TestingModule } from '@nestjs/testing';
2
- import { <%= classify(name) %>Gateway } from './<%= name %>.gateway';
3
-
4
- describe('<%= classify(name) %>Gateway', () => {
5
- let gateway: <%= classify(name) %>Gateway;
6
-
7
- beforeEach(async () => {
8
- const module: TestingModule = await Test.createTestingModule({
9
- providers: [<%= classify(name) %>Gateway],
10
- }).compile();
11
-
12
- gateway = module.get<<%= classify(name) %>Gateway>(<%= classify(name) %>Gateway);
13
- });
14
-
15
- it('should be defined', () => {
16
- expect(gateway).toBeDefined();
17
- });
18
- });
@@ -1,9 +0,0 @@
1
- import { SubscribeMessage, WebSocketGateway } from '@nestjs/websockets';
2
-
3
- @WebSocketGateway()
4
- export class <%= classify(name) %>Gateway {
5
- @SubscribeMessage('message')
6
- handleMessage(client: any, payload: any): string {
7
- return 'Hello world!';
8
- }
9
- }
@@ -1,3 +0,0 @@
1
- import { Rule } from '@angular-devkit/schematics';
2
- import { GatewayOptions } from './gateway.schema';
3
- export declare function main(options: GatewayOptions): Rule;