@nx/nest 0.0.0-pr-22179-271588f

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 (119) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/generators.json +103 -0
  4. package/index.d.ts +18 -0
  5. package/index.js +39 -0
  6. package/migrations.json +76 -0
  7. package/package.json +46 -0
  8. package/src/generators/application/application.d.ts +5 -0
  9. package/src/generators/application/application.js +38 -0
  10. package/src/generators/application/files/app/app.controller.spec.ts__tmpl__ +22 -0
  11. package/src/generators/application/files/app/app.controller.ts__tmpl__ +13 -0
  12. package/src/generators/application/files/app/app.module.ts__tmpl__ +11 -0
  13. package/src/generators/application/files/app/app.service.spec.ts__tmpl__ +21 -0
  14. package/src/generators/application/files/app/app.service.ts__tmpl__ +8 -0
  15. package/src/generators/application/files/main.ts__tmpl__ +20 -0
  16. package/src/generators/application/lib/create-files.d.ts +3 -0
  17. package/src/generators/application/lib/create-files.js +12 -0
  18. package/src/generators/application/lib/index.d.ts +3 -0
  19. package/src/generators/application/lib/index.js +6 -0
  20. package/src/generators/application/lib/normalize-options.d.ts +5 -0
  21. package/src/generators/application/lib/normalize-options.js +53 -0
  22. package/src/generators/application/lib/update-tsconfig.d.ts +3 -0
  23. package/src/generators/application/lib/update-tsconfig.js +22 -0
  24. package/src/generators/application/schema.d.ts +25 -0
  25. package/src/generators/application/schema.json +86 -0
  26. package/src/generators/class/class.d.ts +6 -0
  27. package/src/generators/class/class.js +25 -0
  28. package/src/generators/class/schema.json +63 -0
  29. package/src/generators/controller/controller.d.ts +9 -0
  30. package/src/generators/controller/controller.js +27 -0
  31. package/src/generators/controller/schema.json +72 -0
  32. package/src/generators/decorator/decorator.d.ts +6 -0
  33. package/src/generators/decorator/decorator.js +24 -0
  34. package/src/generators/decorator/schema.json +57 -0
  35. package/src/generators/filter/filter.d.ts +6 -0
  36. package/src/generators/filter/filter.js +25 -0
  37. package/src/generators/filter/schema.json +63 -0
  38. package/src/generators/gateway/gateway.d.ts +6 -0
  39. package/src/generators/gateway/gateway.js +25 -0
  40. package/src/generators/gateway/schema.json +63 -0
  41. package/src/generators/guard/guard.d.ts +6 -0
  42. package/src/generators/guard/guard.js +25 -0
  43. package/src/generators/guard/schema.json +63 -0
  44. package/src/generators/init/init.d.ts +4 -0
  45. package/src/generators/init/init.js +17 -0
  46. package/src/generators/init/lib/add-dependencies.d.ts +3 -0
  47. package/src/generators/init/lib/add-dependencies.js +12 -0
  48. package/src/generators/init/lib/index.d.ts +1 -0
  49. package/src/generators/init/lib/index.js +4 -0
  50. package/src/generators/init/schema.d.ts +7 -0
  51. package/src/generators/init/schema.json +28 -0
  52. package/src/generators/interceptor/interceptor.d.ts +6 -0
  53. package/src/generators/interceptor/interceptor.js +25 -0
  54. package/src/generators/interceptor/schema.json +63 -0
  55. package/src/generators/interface/interface.d.ts +6 -0
  56. package/src/generators/interface/interface.js +17 -0
  57. package/src/generators/interface/schema.json +52 -0
  58. package/src/generators/library/files/common/src/lib/__fileName__.module.ts__tmpl__ +11 -0
  59. package/src/generators/library/files/controller/src/lib/__fileName__.controller.spec.ts__tmpl__ +20 -0
  60. package/src/generators/library/files/controller/src/lib/__fileName__.controller.ts__tmpl__ +7 -0
  61. package/src/generators/library/files/service/src/lib/__fileName__.service.spec.ts__tmpl__ +18 -0
  62. package/src/generators/library/files/service/src/lib/__fileName__.service.ts__tmpl__ +4 -0
  63. package/src/generators/library/lib/add-exports-to-barrel.d.ts +3 -0
  64. package/src/generators/library/lib/add-exports-to-barrel.js +25 -0
  65. package/src/generators/library/lib/add-project.d.ts +3 -0
  66. package/src/generators/library/lib/add-project.js +23 -0
  67. package/src/generators/library/lib/create-files.d.ts +3 -0
  68. package/src/generators/library/lib/create-files.js +27 -0
  69. package/src/generators/library/lib/delete-files.d.ts +3 -0
  70. package/src/generators/library/lib/delete-files.js +14 -0
  71. package/src/generators/library/lib/index.d.ts +6 -0
  72. package/src/generators/library/lib/index.js +9 -0
  73. package/src/generators/library/lib/normalize-options.d.ts +5 -0
  74. package/src/generators/library/lib/normalize-options.js +68 -0
  75. package/src/generators/library/lib/update-tsconfig.d.ts +3 -0
  76. package/src/generators/library/lib/update-tsconfig.js +22 -0
  77. package/src/generators/library/library.d.ts +5 -0
  78. package/src/generators/library/library.js +40 -0
  79. package/src/generators/library/schema.d.ts +46 -0
  80. package/src/generators/library/schema.json +147 -0
  81. package/src/generators/middleware/middleware.d.ts +6 -0
  82. package/src/generators/middleware/middleware.js +25 -0
  83. package/src/generators/middleware/schema.json +63 -0
  84. package/src/generators/module/module.d.ts +9 -0
  85. package/src/generators/module/module.js +26 -0
  86. package/src/generators/module/schema.json +67 -0
  87. package/src/generators/pipe/pipe.d.ts +6 -0
  88. package/src/generators/pipe/pipe.js +25 -0
  89. package/src/generators/pipe/schema.json +63 -0
  90. package/src/generators/provider/provider.d.ts +6 -0
  91. package/src/generators/provider/provider.js +25 -0
  92. package/src/generators/provider/schema.json +63 -0
  93. package/src/generators/resolver/resolver.d.ts +6 -0
  94. package/src/generators/resolver/resolver.js +25 -0
  95. package/src/generators/resolver/schema.json +58 -0
  96. package/src/generators/resource/resource.d.ts +6 -0
  97. package/src/generators/resource/resource.js +25 -0
  98. package/src/generators/resource/schema.json +107 -0
  99. package/src/generators/service/schema.json +63 -0
  100. package/src/generators/service/service.d.ts +6 -0
  101. package/src/generators/service/service.js +25 -0
  102. package/src/generators/utils/index.d.ts +3 -0
  103. package/src/generators/utils/index.js +6 -0
  104. package/src/generators/utils/normalize-options.d.ts +4 -0
  105. package/src/generators/utils/normalize-options.js +28 -0
  106. package/src/generators/utils/run-nest-schematic.d.ts +3 -0
  107. package/src/generators/utils/run-nest-schematic.js +15 -0
  108. package/src/generators/utils/testing.d.ts +2 -0
  109. package/src/generators/utils/testing.js +16 -0
  110. package/src/generators/utils/types.d.ts +40 -0
  111. package/src/generators/utils/types.js +2 -0
  112. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  113. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  114. package/src/migrations/update-16-4-0-cache-manager/nestjs-10-updates.d.ts +5 -0
  115. package/src/migrations/update-16-4-0-cache-manager/nestjs-10-updates.js +81 -0
  116. package/src/utils/ensure-dependencies.d.ts +2 -0
  117. package/src/utils/ensure-dependencies.js +18 -0
  118. package/src/utils/versions.d.ts +6 -0
  119. package/src/utils/versions.js +9 -0
@@ -0,0 +1,63 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxNestGuardGenerator",
4
+ "title": "Nest Guard Options Schema",
5
+ "description": "Nest Guard Options Schema.",
6
+ "cli": "nx",
7
+ "type": "object",
8
+ "properties": {
9
+ "name": {
10
+ "description": "The name of the guard.",
11
+ "type": "string",
12
+ "$default": {
13
+ "$source": "argv",
14
+ "index": 0
15
+ },
16
+ "x-prompt": "What name would you like to use?"
17
+ },
18
+ "nameAndDirectoryFormat": {
19
+ "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
20
+ "type": "string",
21
+ "enum": ["as-provided", "derived"]
22
+ },
23
+ "project": {
24
+ "description": "The Nest project to target.",
25
+ "type": "string",
26
+ "$default": {
27
+ "$source": "projectName"
28
+ },
29
+ "alias": "p",
30
+ "x-deprecated": "Provide The `directory` option instead and use the `as-provided` format. the project will be determined from the directory provided. it will be removed in nx v19."
31
+ },
32
+ "directory": {
33
+ "description": "Directory where the generated files are placed. when `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. otherwise, it will be relative to the workspace root.",
34
+ "type": "string",
35
+ "aliases": ["dir", "path"]
36
+ },
37
+ "skipFormat": {
38
+ "description": "Skip formatting files.",
39
+ "type": "boolean",
40
+ "default": false,
41
+ "x-priority": "internal"
42
+ },
43
+ "unitTestRunner": {
44
+ "description": "Test runner to use for unit tests.",
45
+ "type": "string",
46
+ "enum": ["jest", "none"],
47
+ "default": "jest"
48
+ },
49
+ "flat": {
50
+ "description": "Flag to indicate if a directory is created.",
51
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v19.",
52
+ "type": "boolean",
53
+ "default": true
54
+ },
55
+ "language": {
56
+ "description": "Nest guard language.",
57
+ "type": "string",
58
+ "enum": ["js", "ts"]
59
+ }
60
+ },
61
+ "additionalProperties": false,
62
+ "required": ["name"]
63
+ }
@@ -0,0 +1,4 @@
1
+ import type { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import type { InitGeneratorOptions } from './schema';
3
+ export declare function initGenerator(tree: Tree, options: InitGeneratorOptions): Promise<GeneratorCallback>;
4
+ export default initGenerator;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const lib_1 = require("./lib");
6
+ async function initGenerator(tree, options) {
7
+ let installPackagesTask = () => { };
8
+ if (!options.skipPackageJson) {
9
+ installPackagesTask = (0, lib_1.addDependencies)(tree, options);
10
+ }
11
+ if (!options.skipFormat) {
12
+ await (0, devkit_1.formatFiles)(tree);
13
+ }
14
+ return installPackagesTask;
15
+ }
16
+ exports.initGenerator = initGenerator;
17
+ exports.default = initGenerator;
@@ -0,0 +1,3 @@
1
+ import type { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { InitGeneratorOptions } from '../schema';
3
+ export declare function addDependencies(tree: Tree, options: InitGeneratorOptions): GeneratorCallback;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addDependencies = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../../utils/versions");
6
+ function addDependencies(tree, options) {
7
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
8
+ '@nestjs/schematics': versions_1.nestJsSchematicsVersion,
9
+ '@nx/nest': versions_1.nxVersion,
10
+ }, undefined, options.keepExistingVersions);
11
+ }
12
+ exports.addDependencies = addDependencies;
@@ -0,0 +1 @@
1
+ export * from './add-dependencies';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./add-dependencies"), exports);
@@ -0,0 +1,7 @@
1
+ import { UnitTestRunner } from '../utils';
2
+
3
+ export interface InitGeneratorOptions {
4
+ skipFormat?: boolean;
5
+ skipPackageJson?: boolean;
6
+ keepExistingVersions?: boolean;
7
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxNestInitGenerator",
4
+ "title": "Init Nest Plugin",
5
+ "description": "Init Nest Plugin.",
6
+ "cli": "nx",
7
+ "type": "object",
8
+ "properties": {
9
+ "skipFormat": {
10
+ "description": "Skip formatting files.",
11
+ "type": "boolean",
12
+ "default": false
13
+ },
14
+ "skipPackageJson": {
15
+ "description": "Do not add dependencies to `package.json`.",
16
+ "type": "boolean",
17
+ "default": false,
18
+ "x-priority": "internal"
19
+ },
20
+ "keepExistingVersions": {
21
+ "type": "boolean",
22
+ "x-priority": "internal",
23
+ "description": "Keep existing dependencies versions",
24
+ "default": false
25
+ }
26
+ },
27
+ "required": []
28
+ }
@@ -0,0 +1,6 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { NestGeneratorWithLanguageOption, NestGeneratorWithTestOption } from '../utils';
3
+ export type InterceptorGeneratorOptions = NestGeneratorWithLanguageOption & NestGeneratorWithTestOption;
4
+ export declare function interceptorGenerator(tree: Tree, rawOptions: InterceptorGeneratorOptions): Promise<void>;
5
+ export declare function interceptorGeneratorInternal(tree: Tree, rawOptions: InterceptorGeneratorOptions): Promise<any>;
6
+ export default interceptorGenerator;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interceptorGeneratorInternal = exports.interceptorGenerator = void 0;
4
+ const utils_1 = require("../utils");
5
+ async function interceptorGenerator(tree, rawOptions) {
6
+ await interceptorGeneratorInternal(tree, {
7
+ nameAndDirectoryFormat: 'derived',
8
+ ...rawOptions,
9
+ });
10
+ }
11
+ exports.interceptorGenerator = interceptorGenerator;
12
+ async function interceptorGeneratorInternal(tree, rawOptions) {
13
+ const options = await normalizeInterceptorOptions(tree, rawOptions);
14
+ return (0, utils_1.runNestSchematic)(tree, 'interceptor', options);
15
+ }
16
+ exports.interceptorGeneratorInternal = interceptorGeneratorInternal;
17
+ exports.default = interceptorGenerator;
18
+ async function normalizeInterceptorOptions(tree, options) {
19
+ const normalizedOptions = await (0, utils_1.normalizeOptions)(tree, 'interceptor', '@nx/nest:interceptor', options);
20
+ return {
21
+ ...normalizedOptions,
22
+ language: options.language,
23
+ spec: (0, utils_1.unitTestRunnerToSpec)(options.unitTestRunner),
24
+ };
25
+ }
@@ -0,0 +1,63 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxNestInterceptorGenerator",
4
+ "title": "Nest Interceptor Options Schema",
5
+ "description": "Nest Interceptor Options Schema.",
6
+ "cli": "nx",
7
+ "type": "object",
8
+ "properties": {
9
+ "name": {
10
+ "description": "The name of the interceptor.",
11
+ "type": "string",
12
+ "$default": {
13
+ "$source": "argv",
14
+ "index": 0
15
+ },
16
+ "x-prompt": "What name would you like to use?"
17
+ },
18
+ "nameAndDirectoryFormat": {
19
+ "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
20
+ "type": "string",
21
+ "enum": ["as-provided", "derived"]
22
+ },
23
+ "project": {
24
+ "description": "The Nest project to target.",
25
+ "type": "string",
26
+ "$default": {
27
+ "$source": "projectName"
28
+ },
29
+ "alias": "p",
30
+ "x-deprecated": "Provide The `directory` option instead and use the `as-provided` format. the project will be determined from the directory provided. it will be removed in nx v19."
31
+ },
32
+ "directory": {
33
+ "description": "Directory where the generated files are placed. when `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. otherwise, it will be relative to the workspace root.",
34
+ "type": "string",
35
+ "aliases": ["dir", "path"]
36
+ },
37
+ "skipFormat": {
38
+ "description": "Skip formatting files.",
39
+ "type": "boolean",
40
+ "default": false,
41
+ "x-priority": "internal"
42
+ },
43
+ "unitTestRunner": {
44
+ "description": "Test runner to use for unit tests.",
45
+ "type": "string",
46
+ "enum": ["jest", "none"],
47
+ "default": "jest"
48
+ },
49
+ "flat": {
50
+ "description": "Flag to indicate if a directory is created.",
51
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v19.",
52
+ "type": "boolean",
53
+ "default": true
54
+ },
55
+ "language": {
56
+ "description": "Nest interceptor language.",
57
+ "type": "string",
58
+ "enum": ["js", "ts"]
59
+ }
60
+ },
61
+ "additionalProperties": false,
62
+ "required": ["name"]
63
+ }
@@ -0,0 +1,6 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { NestGeneratorOptions } from '../utils';
3
+ export type InterfaceGeneratorOptions = NestGeneratorOptions;
4
+ export declare function interfaceGenerator(tree: Tree, rawOptions: InterfaceGeneratorOptions): Promise<void>;
5
+ export declare function interfaceGeneratorInternal(tree: Tree, rawOptions: InterfaceGeneratorOptions): Promise<any>;
6
+ export default interfaceGenerator;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interfaceGeneratorInternal = exports.interfaceGenerator = void 0;
4
+ const utils_1 = require("../utils");
5
+ async function interfaceGenerator(tree, rawOptions) {
6
+ await interfaceGeneratorInternal(tree, {
7
+ nameAndDirectoryFormat: 'derived',
8
+ ...rawOptions,
9
+ });
10
+ }
11
+ exports.interfaceGenerator = interfaceGenerator;
12
+ async function interfaceGeneratorInternal(tree, rawOptions) {
13
+ const options = await (0, utils_1.normalizeOptions)(tree, 'interface', '@nx/nest:interface', rawOptions);
14
+ return (0, utils_1.runNestSchematic)(tree, 'interface', options);
15
+ }
16
+ exports.interfaceGeneratorInternal = interfaceGeneratorInternal;
17
+ exports.default = interfaceGenerator;
@@ -0,0 +1,52 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxNestInterfaceGenerator",
4
+ "title": "Nest Interface Options Schema",
5
+ "description": "Nest Interface Options Schema.",
6
+ "cli": "nx",
7
+ "type": "object",
8
+ "properties": {
9
+ "name": {
10
+ "description": "The name of the interface.",
11
+ "type": "string",
12
+ "$default": {
13
+ "$source": "argv",
14
+ "index": 0
15
+ },
16
+ "x-prompt": "What name would you like to use?"
17
+ },
18
+ "nameAndDirectoryFormat": {
19
+ "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
20
+ "type": "string",
21
+ "enum": ["as-provided", "derived"]
22
+ },
23
+ "project": {
24
+ "description": "The Nest project to target.",
25
+ "type": "string",
26
+ "$default": {
27
+ "$source": "projectName"
28
+ },
29
+ "alias": "p",
30
+ "x-deprecated": "Provide The `directory` option instead and use the `as-provided` format. the project will be determined from the directory provided. it will be removed in nx v19."
31
+ },
32
+ "directory": {
33
+ "description": "Directory where the generated files are placed. when `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. otherwise, it will be relative to the workspace root.",
34
+ "type": "string",
35
+ "aliases": ["dir", "path"]
36
+ },
37
+ "skipFormat": {
38
+ "description": "Skip formatting files.",
39
+ "type": "boolean",
40
+ "default": false,
41
+ "x-priority": "internal"
42
+ },
43
+ "flat": {
44
+ "description": "Flag to indicate if a directory is created.",
45
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v19.",
46
+ "type": "boolean",
47
+ "default": true
48
+ }
49
+ },
50
+ "additionalProperties": false,
51
+ "required": ["name"]
52
+ }
@@ -0,0 +1,11 @@
1
+ import { Module<% if(global) { %>, Global<% } %> } from '@nestjs/common';<% if(controller) { %>
2
+ import { <%= className %>Controller } from './<%= fileName %>.controller';<% } %><% if(service) { %>
3
+ import { <%= className %>Service } from './<%= fileName %>.service';<% } %>
4
+ <% if(global) { %>
5
+ @Global()<% } %>
6
+ @Module({
7
+ controllers: [<% if(controller) { %><%= className %>Controller<% } %>],
8
+ providers: [<% if(service) { %><%= className %>Service<% } %>],
9
+ exports: [<% if(service) { %><%= className %>Service<% } %>],
10
+ })
11
+ export class <%= className %>Module {}
@@ -0,0 +1,20 @@
1
+ import { Test } from '@nestjs/testing';
2
+ import { <%= className %>Controller } from './<%= fileName %>.controller';<% if(service) { %>
3
+ import { <%= className %>Service } from './<%= fileName %>.service';<% } %>
4
+
5
+ describe('<%= className %>Controller', () => {
6
+ let controller: <%= className %>Controller;
7
+
8
+ beforeEach(async () => {
9
+ const module = await Test.createTestingModule({
10
+ providers: [<% if(service) { %><%= className %>Service<% } %>],
11
+ controllers: [<%= className %>Controller]
12
+ }).compile();
13
+
14
+ controller = module.get(<%= className %>Controller);
15
+ });
16
+
17
+ it('should be defined', () => {
18
+ expect(controller).toBeTruthy();
19
+ });
20
+ })
@@ -0,0 +1,7 @@
1
+ import { Controller } from '@nestjs/common';<% if(service) { %>
2
+ import { <%= className %>Service } from './<%= fileName %>.service';<% } %>
3
+
4
+ @Controller('<%= fileName %>')
5
+ export class <%= className %>Controller {<% if(service) { %>
6
+ constructor(private <%= propertyName %>Service: <%= className %>Service) {}
7
+ <% } %>}
@@ -0,0 +1,18 @@
1
+ import { Test } from '@nestjs/testing';
2
+ import { <%= className %>Service } from './<%= fileName %>.service';
3
+
4
+ describe('<%= className %>Service', () => {
5
+ let service: <%= className %>Service;
6
+
7
+ beforeEach(async () => {
8
+ const module = await Test.createTestingModule({
9
+ providers: [<%= className %>Service]
10
+ }).compile();
11
+
12
+ service = module.get(<%= className %>Service);
13
+ });
14
+
15
+ it('should be defined', () => {
16
+ expect(service).toBeTruthy();
17
+ });
18
+ })
@@ -0,0 +1,4 @@
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ @Injectable()
4
+ export class <%= className %>Service {}
@@ -0,0 +1,3 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { NormalizedOptions } from '../schema';
3
+ export declare function addExportsToBarrelFile(tree: Tree, options: NormalizedOptions): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addExportsToBarrelFile = void 0;
4
+ const js_1 = require("@nx/js");
5
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
6
+ let tsModule;
7
+ function addExportsToBarrelFile(tree, options) {
8
+ if (!tsModule) {
9
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
10
+ }
11
+ const indexPath = `${options.projectRoot}/src/index.ts`;
12
+ const indexContent = tree.read(indexPath, 'utf-8');
13
+ let sourceFile = tsModule.createSourceFile(indexPath, indexContent, tsModule.ScriptTarget.Latest, true);
14
+ // find the export in the source file
15
+ const exportStatement = sourceFile.statements.find((statement) => tsModule.isExportDeclaration(statement));
16
+ sourceFile = (0, js_1.removeChange)(tree, sourceFile, indexPath, 0, exportStatement.getFullText());
17
+ sourceFile = (0, js_1.addGlobal)(tree, sourceFile, indexPath, `export * from './lib/${options.fileName}.module';`);
18
+ if (options.service) {
19
+ sourceFile = (0, js_1.addGlobal)(tree, sourceFile, indexPath, `export * from './lib/${options.fileName}.service';`);
20
+ }
21
+ if (options.controller) {
22
+ sourceFile = (0, js_1.addGlobal)(tree, sourceFile, indexPath, `export * from './lib/${options.fileName}.controller';`);
23
+ }
24
+ }
25
+ exports.addExportsToBarrelFile = addExportsToBarrelFile;
@@ -0,0 +1,3 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { NormalizedOptions } from '../schema';
3
+ export declare function addProject(tree: Tree, options: NormalizedOptions): void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addProject = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function addProject(tree, options) {
6
+ if (!options.publishable && !options.buildable) {
7
+ return;
8
+ }
9
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
10
+ project.targets.build = {
11
+ executor: '@nx/js:tsc',
12
+ outputs: ['{options.outputPath}'],
13
+ options: {
14
+ outputPath: `dist/${options.projectRoot}`,
15
+ tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
16
+ packageJson: `${options.projectRoot}/package.json`,
17
+ main: `${options.projectRoot}/src/index.ts`,
18
+ assets: [`${options.projectRoot}/*.md`],
19
+ },
20
+ };
21
+ (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
22
+ }
23
+ exports.addProject = addProject;
@@ -0,0 +1,3 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { NormalizedOptions } from '../schema';
3
+ export declare function createFiles(tree: Tree, options: NormalizedOptions): void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFiles = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function createFiles(tree, options) {
6
+ const substitutions = {
7
+ ...options,
8
+ ...(0, devkit_1.names)(options.projectName),
9
+ tmpl: '',
10
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
11
+ fileName: options.fileName,
12
+ };
13
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '..', 'files', 'common'), options.projectRoot, substitutions);
14
+ if (options.controller) {
15
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '..', 'files', 'controller'), options.projectRoot, substitutions);
16
+ if (options.unitTestRunner === 'none') {
17
+ tree.delete((0, devkit_1.joinPathFragments)(options.projectRoot, 'src', 'lib', `${substitutions.fileName}.controller.spec.ts`));
18
+ }
19
+ }
20
+ if (options.service) {
21
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '..', 'files', 'service'), options.projectRoot, substitutions);
22
+ if (options.unitTestRunner === 'none') {
23
+ tree.delete((0, devkit_1.joinPathFragments)(options.projectRoot, 'src', 'lib', `${substitutions.fileName}.service.spec.ts`));
24
+ }
25
+ }
26
+ }
27
+ exports.createFiles = createFiles;
@@ -0,0 +1,3 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { NormalizedOptions } from '../schema';
3
+ export declare function deleteFiles(tree: Tree, options: NormalizedOptions): void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteFiles = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function deleteFiles(tree, options) {
6
+ tree.delete((0, devkit_1.joinPathFragments)(options.projectRoot, 'src', 'lib', `${options.fileName}.ts`));
7
+ if (options.unitTestRunner !== 'none') {
8
+ tree.delete((0, devkit_1.joinPathFragments)(options.projectRoot, 'src', 'lib', `${options.fileName}.spec.ts`));
9
+ }
10
+ if (!options.buildable && !options.publishable) {
11
+ tree.delete((0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'));
12
+ }
13
+ }
14
+ exports.deleteFiles = deleteFiles;
@@ -0,0 +1,6 @@
1
+ export * from './add-exports-to-barrel';
2
+ export * from './add-project';
3
+ export * from './create-files';
4
+ export * from './delete-files';
5
+ export * from './normalize-options';
6
+ export * from './update-tsconfig';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./add-exports-to-barrel"), exports);
5
+ tslib_1.__exportStar(require("./add-project"), exports);
6
+ tslib_1.__exportStar(require("./create-files"), exports);
7
+ tslib_1.__exportStar(require("./delete-files"), exports);
8
+ tslib_1.__exportStar(require("./normalize-options"), exports);
9
+ tslib_1.__exportStar(require("./update-tsconfig"), exports);
@@ -0,0 +1,5 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import type { LibraryGeneratorSchema as JsLibraryGeneratorSchema } from '@nx/js/src/utils/schema';
3
+ import type { LibraryGeneratorOptions, NormalizedOptions } from '../schema';
4
+ export declare function normalizeOptions(tree: Tree, options: LibraryGeneratorOptions): Promise<NormalizedOptions>;
5
+ export declare function toJsLibraryGeneratorOptions(options: LibraryGeneratorOptions): JsLibraryGeneratorSchema;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toJsLibraryGeneratorOptions = exports.normalizeOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ const get_npm_scope_1 = require("@nx/js/src/utils/package-json/get-npm-scope");
7
+ const eslint_1 = require("@nx/eslint");
8
+ async function normalizeOptions(tree, options) {
9
+ const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
10
+ name: options.name,
11
+ projectType: 'library',
12
+ directory: options.directory,
13
+ importPath: options.importPath,
14
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
15
+ callingGenerator: '@nx/nest:library',
16
+ });
17
+ const nxJson = (0, devkit_1.readNxJson)(tree);
18
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
19
+ nxJson.useInferencePlugins !== false;
20
+ options.addPlugin ??= addPlugin;
21
+ const fileName = options.simpleName
22
+ ? projectNames.projectSimpleName
23
+ : projectNames.projectFileName;
24
+ const parsedTags = options.tags
25
+ ? options.tags.split(',').map((s) => s.trim())
26
+ : [];
27
+ const normalized = {
28
+ ...options,
29
+ strict: options.strict ?? true,
30
+ controller: options.controller ?? false,
31
+ fileName,
32
+ global: options.global ?? false,
33
+ linter: options.linter ?? eslint_1.Linter.EsLint,
34
+ parsedTags,
35
+ prefix: (0, get_npm_scope_1.getNpmScope)(tree), // we could also allow customizing this
36
+ projectName,
37
+ projectRoot,
38
+ importPath,
39
+ service: options.service ?? false,
40
+ target: options.target ?? 'es6',
41
+ testEnvironment: options.testEnvironment ?? 'node',
42
+ unitTestRunner: options.unitTestRunner ?? 'jest',
43
+ };
44
+ return normalized;
45
+ }
46
+ exports.normalizeOptions = normalizeOptions;
47
+ function toJsLibraryGeneratorOptions(options) {
48
+ return {
49
+ name: options.name,
50
+ bundler: options?.buildable ? 'tsc' : 'none',
51
+ directory: options.directory,
52
+ importPath: options.importPath,
53
+ linter: options.linter,
54
+ publishable: options.publishable,
55
+ skipFormat: true,
56
+ skipTsConfig: options.skipTsConfig,
57
+ skipPackageJson: options.skipPackageJson,
58
+ strict: options.strict,
59
+ tags: options.tags,
60
+ testEnvironment: options.testEnvironment,
61
+ unitTestRunner: options.unitTestRunner,
62
+ config: options.standaloneConfig ? 'project' : 'workspace',
63
+ setParserOptionsProject: options.setParserOptionsProject,
64
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
65
+ addPlugin: options.addPlugin,
66
+ };
67
+ }
68
+ exports.toJsLibraryGeneratorOptions = toJsLibraryGeneratorOptions;
@@ -0,0 +1,3 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { NormalizedOptions } from '../schema';
3
+ export declare function updateTsConfig(tree: Tree, options: NormalizedOptions): void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateTsConfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function updateTsConfig(tree, options) {
6
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
7
+ return (0, devkit_1.updateJson)(tree, `${project.root}/tsconfig.lib.json`, (json) => {
8
+ json.compilerOptions.target = options.target;
9
+ if (options.strict) {
10
+ json.compilerOptions = {
11
+ ...json.compilerOptions,
12
+ strictNullChecks: true,
13
+ noImplicitAny: true,
14
+ strictBindCallApply: true,
15
+ forceConsistentCasingInFileNames: true,
16
+ noFallthroughCasesInSwitch: true,
17
+ };
18
+ }
19
+ return json;
20
+ });
21
+ }
22
+ exports.updateTsConfig = updateTsConfig;
@@ -0,0 +1,5 @@
1
+ import type { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import type { LibraryGeneratorOptions } from './schema';
3
+ export declare function libraryGenerator(tree: Tree, rawOptions: LibraryGeneratorOptions): Promise<GeneratorCallback>;
4
+ export declare function libraryGeneratorInternal(tree: Tree, rawOptions: LibraryGeneratorOptions): Promise<GeneratorCallback>;
5
+ export default libraryGenerator;