@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,68 @@
1
+ import {
2
+ SchematicTestRunner,
3
+ UnitTestTree,
4
+ } from '@angular-devkit/schematics/testing';
5
+ import * as path from 'path';
6
+ import { LibraryOptions } from './library.schema';
7
+
8
+ describe('Library 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: LibraryOptions = {
15
+ name: 'project',
16
+ prefix: 'app',
17
+ };
18
+ const tree: UnitTestTree = runner.runSchematic('library', options);
19
+ const files: string[] = tree.files;
20
+ expect(files).toEqual([
21
+ '/libs/project/.gitignore',
22
+ '/libs/project/package.json',
23
+ '/libs/project/tsconfig.lib.json',
24
+ '/libs/project/tslint.json',
25
+ '/libs/project/src/index.ts',
26
+ '/libs/project/src/project.module.ts',
27
+ '/libs/project/src/project.service.spec.ts',
28
+ '/libs/project/src/project.service.ts',
29
+ ]);
30
+ });
31
+ it('should manage name to dasherize', () => {
32
+ const options: LibraryOptions = {
33
+ name: 'awesomeProject',
34
+ prefix: 'app',
35
+ };
36
+ const tree: UnitTestTree = runner.runSchematic('library', options);
37
+ const files: string[] = tree.files;
38
+ expect(files).toEqual([
39
+ '/libs/awesome-project/.gitignore',
40
+ '/libs/awesome-project/package.json',
41
+ '/libs/awesome-project/tsconfig.lib.json',
42
+ '/libs/awesome-project/tslint.json',
43
+ '/libs/awesome-project/src/index.ts',
44
+ '/libs/awesome-project/src/awesome-project.module.ts',
45
+ '/libs/awesome-project/src/awesome-project.service.spec.ts',
46
+ '/libs/awesome-project/src/awesome-project.service.ts',
47
+ ]);
48
+ });
49
+ it('should manage javascript files', () => {
50
+ const options: LibraryOptions = {
51
+ name: 'project',
52
+ language: 'js',
53
+ prefix: 'app',
54
+ };
55
+ const tree: UnitTestTree = runner.runSchematic('library', options);
56
+ const files: string[] = tree.files;
57
+ expect(files).toEqual([
58
+ '/libs/project/.babelrc',
59
+ '/libs/project/.gitignore',
60
+ '/libs/project/jsconfig.json',
61
+ '/libs/project/package.json',
62
+ '/libs/project/src/index.js',
63
+ '/libs/project/src/project.module.js',
64
+ '/libs/project/src/project.service.js',
65
+ '/libs/project/src/project.service.spec.js',
66
+ ]);
67
+ });
68
+ });
@@ -0,0 +1,158 @@
1
+ import {
2
+ join,
3
+ normalize,
4
+ parseJson,
5
+ Path,
6
+ strings,
7
+ } from '@angular-devkit/core';
8
+ import {
9
+ apply,
10
+ branchAndMerge,
11
+ chain,
12
+ mergeWith,
13
+ move,
14
+ Rule,
15
+ SchematicsException,
16
+ Source,
17
+ template,
18
+ Tree,
19
+ url,
20
+ } from '@angular-devkit/schematics';
21
+ import { DEFAULT_LANGUAGE, DEFAULT_LIB_PATH } from '../defaults';
22
+ import { LibraryOptions } from './library.schema';
23
+
24
+ type UpdateJsonFn<T> = (obj: T) => T | void;
25
+ interface TsConfigPartialType {
26
+ compilerOptions: {
27
+ baseUrl: string;
28
+ paths: {
29
+ [key: string]: string[];
30
+ };
31
+ };
32
+ }
33
+
34
+ export function main(options: LibraryOptions): Rule {
35
+ options = transform(options);
36
+ return chain([
37
+ updateTsConfig(options.name, options.prefix, options.path),
38
+ addLibraryToCliOptions(options.path, options.name),
39
+ branchAndMerge(mergeWith(generate(options))),
40
+ ]);
41
+ }
42
+
43
+ function transform(options: LibraryOptions): LibraryOptions {
44
+ const target: LibraryOptions = Object.assign({}, options);
45
+ const defaultSourceRoot =
46
+ options.rootDir !== undefined ? options.rootDir : DEFAULT_LIB_PATH;
47
+
48
+ if (!target.name) {
49
+ throw new SchematicsException('Option (name) is required.');
50
+ }
51
+ target.language = !!target.language ? target.language : DEFAULT_LANGUAGE;
52
+ target.name = strings.dasherize(target.name);
53
+ target.path =
54
+ target.path !== undefined
55
+ ? join(normalize(defaultSourceRoot), target.path)
56
+ : normalize(defaultSourceRoot);
57
+
58
+ target.prefix = target.prefix || '@app';
59
+ return target;
60
+ }
61
+
62
+ function updateJsonFile<T>(
63
+ host: Tree,
64
+ path: string,
65
+ callback: UpdateJsonFn<T>,
66
+ ): Tree {
67
+ const source = host.read(path);
68
+ if (source) {
69
+ const sourceText = source.toString('utf-8');
70
+ const json = parseJson(sourceText);
71
+ callback((json as {}) as T);
72
+ host.overwrite(path, JSON.stringify(json, null, 2));
73
+ }
74
+
75
+ return host;
76
+ }
77
+
78
+ function updateTsConfig(
79
+ packageName: string,
80
+ packagePrefix: string,
81
+ root: string,
82
+ ) {
83
+ return (host: Tree) => {
84
+ if (!host.exists('tsconfig.json')) {
85
+ return host;
86
+ }
87
+ const distRoot = join(root as Path, packageName, 'src');
88
+ const packageKey = packagePrefix
89
+ ? packagePrefix + '/' + packageName
90
+ : packageName;
91
+
92
+ return updateJsonFile(
93
+ host,
94
+ 'tsconfig.json',
95
+ (tsconfig: TsConfigPartialType) => {
96
+ if (!tsconfig.compilerOptions) {
97
+ tsconfig.compilerOptions = {} as any;
98
+ }
99
+ if (!tsconfig.compilerOptions.baseUrl) {
100
+ tsconfig.compilerOptions.baseUrl = './';
101
+ }
102
+ if (!tsconfig.compilerOptions.paths) {
103
+ tsconfig.compilerOptions.paths = {};
104
+ }
105
+ if (!tsconfig.compilerOptions.paths[packageKey]) {
106
+ tsconfig.compilerOptions.paths[packageKey] = [];
107
+ }
108
+ tsconfig.compilerOptions.paths[packageKey].push(distRoot);
109
+
110
+ const deepPackagePath = packageKey + '/*';
111
+ if (!tsconfig.compilerOptions.paths[deepPackagePath]) {
112
+ tsconfig.compilerOptions.paths[deepPackagePath] = [];
113
+ }
114
+ tsconfig.compilerOptions.paths[deepPackagePath].push(distRoot + '/*');
115
+ },
116
+ );
117
+ };
118
+ }
119
+
120
+ function addLibraryToCliOptions(
121
+ projectRoot: string,
122
+ projectName: string,
123
+ ): Rule {
124
+ const project = {
125
+ root: join(projectRoot as Path, projectName),
126
+ sourceRoot: join(projectRoot as Path, projectName, 'src'),
127
+ };
128
+ return (host: Tree) => {
129
+ const nestCliFileExists = host.exists('nest-cli.json');
130
+ const nestFileExists = host.exists('nest.json');
131
+
132
+ if (!nestCliFileExists && !nestFileExists) {
133
+ return host;
134
+ }
135
+ return updateJsonFile(
136
+ host,
137
+ nestCliFileExists ? 'nest-cli.json' : 'nest.json',
138
+ (optionsFile: Record<string, any>) => {
139
+ if (!optionsFile.projects) {
140
+ optionsFile.projects = {} as any;
141
+ }
142
+ optionsFile.projects[projectName] = project;
143
+ },
144
+ );
145
+ };
146
+ }
147
+
148
+ function generate(options: LibraryOptions): Source {
149
+ const path = join(options.path as Path, options.name);
150
+
151
+ return apply(url(join('./files' as Path, options.language)), [
152
+ template({
153
+ ...strings,
154
+ ...options,
155
+ }),
156
+ move(path),
157
+ ]);
158
+ }
@@ -0,0 +1,24 @@
1
+ import { Path } from '@angular-devkit/core';
2
+
3
+ export interface LibraryOptions {
4
+ /**
5
+ * Nest library name.
6
+ */
7
+ name: string;
8
+ /**
9
+ * Prefix (scope)
10
+ */
11
+ prefix?: string;
12
+ /**
13
+ * Application language.
14
+ */
15
+ language?: string;
16
+ /**
17
+ * The path to create the library.
18
+ */
19
+ path?: string | Path;
20
+ /**
21
+ * The libraries root directory
22
+ */
23
+ rootDir?: string | Path;
24
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "id": "SchematicsNestLibrary",
4
+ "title": "Nest Library Options Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The name of the library.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use for the library?"
15
+ },
16
+ "prefix": {
17
+ "type": "string",
18
+ "description": "The prefix of the library.",
19
+ "x-prompt": "What prefix would you like to use for the library (default: @app)?"
20
+ },
21
+ "language": {
22
+ "type": "string",
23
+ "description": "Nest library language."
24
+ },
25
+ "path": {
26
+ "type": "string",
27
+ "format": "path",
28
+ "description": "The path to create the library."
29
+ },
30
+ "rootDir": {
31
+ "type": "string",
32
+ "format": "path",
33
+ "description": "The libraries root directory."
34
+ }
35
+ },
36
+ "required": ["name", "prefix"]
37
+ }
@@ -0,0 +1,4 @@
1
+ import { Module } from '@rxdi/core';
2
+
3
+ @Module({})
4
+ export class <%= classify(name) %>Module {}
@@ -0,0 +1,4 @@
1
+ import { Module } from '@rxdi/core';
2
+
3
+ @Module({})
4
+ export class <%= classify(name) %>Module {}
@@ -10,10 +10,10 @@ const source_root_helpers_1 = require("../../utils/source-root.helpers");
10
10
  function main(options) {
11
11
  options = transform(options);
12
12
  return (tree, context) => {
13
- return schematics_1.branchAndMerge(schematics_1.chain([
14
- source_root_helpers_1.mergeSourceRoot(options),
13
+ return (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
14
+ (0, source_root_helpers_1.mergeSourceRoot)(options),
15
15
  addDeclarationToModule(options),
16
- schematics_1.mergeWith(generate(options)),
16
+ (0, schematics_1.mergeWith)(generate(options)),
17
17
  ]))(tree, context);
18
18
  };
19
19
  }
@@ -24,14 +24,14 @@ function transform(source) {
24
24
  target.type = 'module';
25
25
  const location = new name_parser_1.NameParser().parse(target);
26
26
  target.name = core_1.strings.dasherize(location.name);
27
- target.path = core_1.join(core_1.strings.dasherize(location.path), target.name);
27
+ target.path = (0, core_1.join)(core_1.strings.dasherize(location.path), target.name);
28
28
  target.language = target.language !== undefined ? target.language : 'ts';
29
29
  return target;
30
30
  }
31
31
  function generate(options) {
32
- return (context) => schematics_1.apply(schematics_1.url(core_1.join('./files', options.language)), [
33
- schematics_1.template(Object.assign(Object.assign({}, core_1.strings), options)),
34
- schematics_1.move(options.path),
32
+ return (context) => (0, schematics_1.apply)((0, schematics_1.url)((0, core_1.join)('./files', options.language)), [
33
+ (0, schematics_1.template)(Object.assign(Object.assign({}, core_1.strings), options)),
34
+ (0, schematics_1.move)(options.path),
35
35
  ])(context);
36
36
  }
37
37
  function addDeclarationToModule(options) {
@@ -0,0 +1,165 @@
1
+ import { normalize } from '@angular-devkit/core';
2
+ import {
3
+ SchematicTestRunner,
4
+ UnitTestTree,
5
+ } from '@angular-devkit/schematics/testing';
6
+ import * as path from 'path';
7
+ import { ApplicationOptions } from '../application/application.schema';
8
+ import { ModuleOptions } from './module.schema';
9
+
10
+ describe('Module Factory', () => {
11
+ const runner: SchematicTestRunner = new SchematicTestRunner(
12
+ '.',
13
+ path.join(process.cwd(), 'src/collection.json'),
14
+ );
15
+ it('should manage name only', () => {
16
+ const options: ModuleOptions = {
17
+ name: 'foo',
18
+ skipImport: true,
19
+ };
20
+ const tree: UnitTestTree = runner.runSchematic('module', options);
21
+ const files: string[] = tree.files;
22
+ expect(
23
+ files.find(filename => filename === '/foo/foo.module.ts'),
24
+ ).not.toBeUndefined();
25
+ expect(tree.readContent('/foo/foo.module.ts')).toEqual(
26
+ "import { Module } from '@nestjs/common';\n" +
27
+ '\n' +
28
+ '@Module({})\n' +
29
+ 'export class FooModule {}\n',
30
+ );
31
+ });
32
+ it('should manage name as a path', () => {
33
+ const options: ModuleOptions = {
34
+ name: 'bar/foo',
35
+ skipImport: true,
36
+ };
37
+ const tree: UnitTestTree = runner.runSchematic('module', options);
38
+ const files: string[] = tree.files;
39
+ expect(
40
+ files.find(filename => filename === '/bar/foo/foo.module.ts'),
41
+ ).not.toBeUndefined();
42
+ expect(tree.readContent('/bar/foo/foo.module.ts')).toEqual(
43
+ "import { Module } from '@nestjs/common';\n" +
44
+ '\n' +
45
+ '@Module({})\n' +
46
+ 'export class FooModule {}\n',
47
+ );
48
+ });
49
+ it('should manage name and path', () => {
50
+ const options: ModuleOptions = {
51
+ name: 'foo',
52
+ path: 'bar',
53
+ skipImport: true,
54
+ };
55
+ const tree: UnitTestTree = runner.runSchematic('module', options);
56
+ const files: string[] = tree.files;
57
+ expect(
58
+ files.find(filename => filename === '/bar/foo/foo.module.ts'),
59
+ ).not.toBeUndefined();
60
+ expect(tree.readContent('/bar/foo/foo.module.ts')).toEqual(
61
+ "import { Module } from '@nestjs/common';\n" +
62
+ '\n' +
63
+ '@Module({})\n' +
64
+ 'export class FooModule {}\n',
65
+ );
66
+ });
67
+ it('should manage name to dasherize', () => {
68
+ const options: ModuleOptions = {
69
+ name: 'fooBar',
70
+ skipImport: true,
71
+ };
72
+ const tree: UnitTestTree = runner.runSchematic('module', options);
73
+ const files: string[] = tree.files;
74
+ expect(
75
+ files.find(filename => filename === '/foo-bar/foo-bar.module.ts'),
76
+ ).not.toBeUndefined();
77
+ expect(tree.readContent('/foo-bar/foo-bar.module.ts')).toEqual(
78
+ "import { Module } from '@nestjs/common';\n" +
79
+ '\n' +
80
+ '@Module({})\n' +
81
+ 'export class FooBarModule {}\n',
82
+ );
83
+ });
84
+ it('should manage path to dasherize', () => {
85
+ const options: ModuleOptions = {
86
+ name: 'barBaz/foo',
87
+ skipImport: true,
88
+ };
89
+ const tree: UnitTestTree = runner.runSchematic('module', options);
90
+ const files: string[] = tree.files;
91
+ expect(
92
+ files.find(filename => filename === '/bar-baz/foo/foo.module.ts'),
93
+ ).not.toBeUndefined();
94
+ expect(tree.readContent('/bar-baz/foo/foo.module.ts')).toEqual(
95
+ "import { Module } from '@nestjs/common';\n" +
96
+ '\n' +
97
+ '@Module({})\n' +
98
+ 'export class FooModule {}\n',
99
+ );
100
+ });
101
+ it('should manage javascript file', () => {
102
+ const options: ModuleOptions = {
103
+ name: 'foo',
104
+ skipImport: true,
105
+ language: 'js',
106
+ };
107
+ const tree: UnitTestTree = runner.runSchematic('module', options);
108
+ const files: string[] = tree.files;
109
+ expect(
110
+ files.find(filename => filename === '/foo/foo.module.js'),
111
+ ).not.toBeUndefined();
112
+ expect(tree.readContent('/foo/foo.module.js')).toEqual(
113
+ "import { Module } from '@nestjs/common';\n" +
114
+ '\n' +
115
+ '@Module({})\n' +
116
+ 'export class FooModule {}\n',
117
+ );
118
+ });
119
+ it('should manage declaration in app module', () => {
120
+ const app: ApplicationOptions = {
121
+ name: '',
122
+ };
123
+ let tree: UnitTestTree = runner.runSchematic('application', app);
124
+ const options: ModuleOptions = {
125
+ name: 'foo',
126
+ };
127
+ tree = runner.runSchematic('module', options, tree);
128
+ expect(tree.readContent(normalize('/src/app.module.ts'))).toEqual(
129
+ "import { Module } from '@nestjs/common';\n" +
130
+ "import { AppController } from './app.controller';\n" +
131
+ "import { AppService } from './app.service';\n" +
132
+ "import { FooModule } from './foo/foo.module';\n" +
133
+ '\n' +
134
+ '@Module({\n' +
135
+ ' imports: [FooModule],\n' +
136
+ ' controllers: [AppController],\n' +
137
+ ' providers: [AppService],\n' +
138
+ '})\n' +
139
+ 'export class AppModule {}\n',
140
+ );
141
+ });
142
+ it('should manage declaration in bar module', () => {
143
+ const app: ApplicationOptions = {
144
+ name: '',
145
+ };
146
+ let tree: UnitTestTree = runner.runSchematic('application', app);
147
+ const module: ModuleOptions = {
148
+ name: 'bar',
149
+ };
150
+ tree = runner.runSchematic('module', module, tree);
151
+ const options: ModuleOptions = {
152
+ name: 'bar/foo',
153
+ };
154
+ tree = runner.runSchematic('module', options, tree);
155
+ expect(tree.readContent(normalize('/src/bar/bar.module.ts'))).toEqual(
156
+ "import { Module } from '@nestjs/common';\n" +
157
+ "import { FooModule } from './foo/foo.module';\n" +
158
+ '\n' +
159
+ '@Module({\n' +
160
+ ' imports: [FooModule]\n' +
161
+ '})\n' +
162
+ 'export class BarModule {}\n',
163
+ );
164
+ });
165
+ });
@@ -0,0 +1,79 @@
1
+ import { join, Path, strings } from '@angular-devkit/core';
2
+ import {
3
+ apply,
4
+ branchAndMerge,
5
+ chain,
6
+ mergeWith,
7
+ move,
8
+ Rule,
9
+ SchematicContext,
10
+ template,
11
+ Tree,
12
+ url,
13
+ } from '@angular-devkit/schematics';
14
+ import {
15
+ DeclarationOptions,
16
+ ModuleDeclarator,
17
+ } from '../../utils/module.declarator';
18
+ import { ModuleFinder } from '../../utils/module.finder';
19
+ import { Location, NameParser } from '../../utils/name.parser';
20
+ import { mergeSourceRoot } from '../../utils/source-root.helpers';
21
+ import { ModuleOptions } from './module.schema';
22
+
23
+ export function main(options: ModuleOptions): Rule {
24
+ options = transform(options);
25
+ return (tree: Tree, context: SchematicContext) => {
26
+ return branchAndMerge(
27
+ chain([
28
+ mergeSourceRoot(options),
29
+ addDeclarationToModule(options),
30
+ mergeWith(generate(options)),
31
+ ]),
32
+ )(tree, context);
33
+ };
34
+ }
35
+
36
+ function transform(source: ModuleOptions): ModuleOptions {
37
+ const target: ModuleOptions = Object.assign({}, source);
38
+ target.metadata = 'imports';
39
+ target.type = 'module';
40
+
41
+ const location: Location = new NameParser().parse(target);
42
+ target.name = strings.dasherize(location.name);
43
+ target.path = join(strings.dasherize(location.path) as Path, target.name);
44
+ target.language = target.language !== undefined ? target.language : 'ts';
45
+ return target;
46
+ }
47
+
48
+ function generate(options: ModuleOptions) {
49
+ return (context: SchematicContext) =>
50
+ apply(url(join('./files' as Path, options.language)), [
51
+ template({
52
+ ...strings,
53
+ ...options,
54
+ }),
55
+ move(options.path),
56
+ ])(context);
57
+ }
58
+
59
+ function addDeclarationToModule(options: ModuleOptions): Rule {
60
+ return (tree: Tree) => {
61
+ if (options.skipImport !== undefined && options.skipImport) {
62
+ return tree;
63
+ }
64
+ options.module = new ModuleFinder(tree).find({
65
+ name: options.name,
66
+ path: options.path as Path,
67
+ });
68
+ if (!options.module) {
69
+ return tree;
70
+ }
71
+ const content = tree.read(options.module).toString();
72
+ const declarator: ModuleDeclarator = new ModuleDeclarator();
73
+ tree.overwrite(
74
+ options.module,
75
+ declarator.declare(content, options as DeclarationOptions),
76
+ );
77
+ return tree;
78
+ };
79
+ }
@@ -0,0 +1,36 @@
1
+ import { Path } from '@angular-devkit/core';
2
+
3
+ export interface ModuleOptions {
4
+ /**
5
+ * The name of the module.
6
+ */
7
+ name: string;
8
+ /**
9
+ * The path to create the module.
10
+ */
11
+ path?: string;
12
+ /**
13
+ * The path to insert the module declaration.
14
+ */
15
+ module?: Path;
16
+ /**
17
+ * Directive to insert declaration in module.
18
+ */
19
+ skipImport?: boolean;
20
+ /**
21
+ * Metadata name affected by declaration insertion.
22
+ */
23
+ metadata?: string;
24
+ /**
25
+ * Nest element type name
26
+ */
27
+ type?: string;
28
+ /**
29
+ * Application language.
30
+ */
31
+ language?: string;
32
+ /**
33
+ * The source root path
34
+ */
35
+ sourceRoot?: string;
36
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "id": "SchematicsNestModule",
4
+ "title": "Nest Module Options Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The name of the module.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use for the module?"
15
+ },
16
+ "path": {
17
+ "type": "string",
18
+ "format": "path",
19
+ "description": "The path to create the module."
20
+ },
21
+ "module": {
22
+ "type": "string",
23
+ "format": "path",
24
+ "description": "The path to import the module."
25
+ },
26
+ "language": {
27
+ "type": "string",
28
+ "description": "Nest module language (ts/js)."
29
+ },
30
+ "sourceRoot": {
31
+ "type": "string",
32
+ "description": "Nest module source root directory."
33
+ },
34
+ "skipImport": {
35
+ "description": "Flag to skip the module import.",
36
+ "default": false
37
+ }
38
+ },
39
+ "required": ["name"]
40
+ }
@@ -0,0 +1,8 @@
1
+ import { Injectable } from '@rxdi/core';
2
+
3
+ @Injectable()
4
+ export class <%= classify(name) %>Pipe {
5
+ transform(value) {
6
+ return value;
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ import { <%= classify(name) %>Pipe } from './<%= name %>.pipe';
2
+
3
+ describe('<%= classify(name) %>Pipe', () => {
4
+ it('should be defined', () => {
5
+ expect(new <%= classify(name) %>Pipe()).toBeDefined();
6
+ });
7
+ });
@@ -0,0 +1,7 @@
1
+ import { <%= classify(name) %>Pipe } from './<%= name %>.pipe';
2
+
3
+ describe('<%= classify(name) %>Pipe', () => {
4
+ it('should be defined', () => {
5
+ expect(new <%= classify(name) %>Pipe()).toBeDefined();
6
+ });
7
+ });