@nestjs/schematics 11.0.9 → 12.0.0-alpha.1

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 (101) hide show
  1. package/dist/lib/application/files/js/package.json +10 -10
  2. package/dist/lib/application/files/ts/package.json +3 -3
  3. package/dist/lib/application/files/ts/tsconfig.json +0 -1
  4. package/dist/lib/application/files/ts-esm/.prettierrc +4 -0
  5. package/dist/lib/application/files/ts-esm/README.md +98 -0
  6. package/dist/lib/application/files/ts-esm/eslint.config.mjs +34 -0
  7. package/dist/lib/application/files/ts-esm/nest-cli.json +8 -0
  8. package/dist/lib/application/files/ts-esm/package.json +50 -0
  9. package/dist/lib/application/files/ts-esm/src/app.controller.__specFileSuffix__.ts +22 -0
  10. package/dist/lib/application/files/ts-esm/src/app.controller.ts +12 -0
  11. package/dist/lib/application/files/ts-esm/src/app.module.ts +10 -0
  12. package/dist/lib/application/files/ts-esm/src/app.service.ts +8 -0
  13. package/dist/lib/application/files/ts-esm/src/main.ts +8 -0
  14. package/dist/lib/application/files/ts-esm/test/app.e2e-__specFileSuffix__.ts +25 -0
  15. package/dist/lib/application/files/ts-esm/tsconfig.build.json +4 -0
  16. package/dist/lib/application/files/ts-esm/tsconfig.json +24 -0
  17. package/dist/lib/application/files/ts-esm/vitest.config.e2e.ts +10 -0
  18. package/dist/lib/application/files/ts-esm/vitest.config.ts +10 -0
  19. package/dist/lib/application/schema.json +14 -0
  20. package/dist/lib/library/files/ts/tsconfig.lib.json +1 -0
  21. package/dist/lib/sub-app/files/ts/tsconfig.app.json +1 -0
  22. package/dist/lib/sub-app/workspace/ts/tsconfig.app.json +1 -0
  23. package/package.json +21 -49
  24. package/dist/index.d.ts +0 -2
  25. package/dist/index.js +0 -18
  26. package/dist/lib/application/application.factory.d.ts +0 -3
  27. package/dist/lib/application/application.factory.js +0 -63
  28. package/dist/lib/class/class.factory.d.ts +0 -3
  29. package/dist/lib/class/class.factory.js +0 -51
  30. package/dist/lib/client-app/angular/angular.factory.d.ts +0 -3
  31. package/dist/lib/client-app/angular/angular.factory.js +0 -103
  32. package/dist/lib/configuration/configuration.factory.d.ts +0 -3
  33. package/dist/lib/configuration/configuration.factory.js +0 -27
  34. package/dist/lib/controller/controller.factory.d.ts +0 -3
  35. package/dist/lib/controller/controller.factory.js +0 -72
  36. package/dist/lib/decorator/decorator.factory.d.ts +0 -3
  37. package/dist/lib/decorator/decorator.factory.js +0 -35
  38. package/dist/lib/defaults.d.ts +0 -14
  39. package/dist/lib/defaults.js +0 -17
  40. package/dist/lib/filter/filter.factory.d.ts +0 -3
  41. package/dist/lib/filter/filter.factory.js +0 -43
  42. package/dist/lib/gateway/gateway.factory.d.ts +0 -3
  43. package/dist/lib/gateway/gateway.factory.js +0 -72
  44. package/dist/lib/guard/guard.factory.d.ts +0 -3
  45. package/dist/lib/guard/guard.factory.js +0 -43
  46. package/dist/lib/interceptor/interceptor.factory.d.ts +0 -3
  47. package/dist/lib/interceptor/interceptor.factory.js +0 -44
  48. package/dist/lib/interface/interface.factory.d.ts +0 -3
  49. package/dist/lib/interface/interface.factory.js +0 -34
  50. package/dist/lib/library/library.factory.d.ts +0 -3
  51. package/dist/lib/library/library.factory.js +0 -216
  52. package/dist/lib/middleware/middleware.factory.d.ts +0 -3
  53. package/dist/lib/middleware/middleware.factory.js +0 -43
  54. package/dist/lib/module/module.factory.d.ts +0 -3
  55. package/dist/lib/module/module.factory.js +0 -60
  56. package/dist/lib/pipe/pipe.factory.d.ts +0 -3
  57. package/dist/lib/pipe/pipe.factory.js +0 -44
  58. package/dist/lib/provider/provider.factory.d.ts +0 -3
  59. package/dist/lib/provider/provider.factory.js +0 -76
  60. package/dist/lib/readers/file-system.reader.d.ts +0 -10
  61. package/dist/lib/readers/file-system.reader.js +0 -45
  62. package/dist/lib/readers/index.d.ts +0 -2
  63. package/dist/lib/readers/index.js +0 -18
  64. package/dist/lib/readers/reader.d.ts +0 -7
  65. package/dist/lib/readers/reader.js +0 -2
  66. package/dist/lib/resolver/resolver.factory.d.ts +0 -3
  67. package/dist/lib/resolver/resolver.factory.js +0 -71
  68. package/dist/lib/resource/resource.factory.d.ts +0 -3
  69. package/dist/lib/resource/resource.factory.js +0 -145
  70. package/dist/lib/service/service.factory.d.ts +0 -3
  71. package/dist/lib/service/service.factory.js +0 -74
  72. package/dist/lib/sub-app/sub-app.factory.d.ts +0 -3
  73. package/dist/lib/sub-app/sub-app.factory.js +0 -271
  74. package/dist/utils/dependencies.utils.d.ts +0 -15
  75. package/dist/utils/dependencies.utils.js +0 -42
  76. package/dist/utils/formatting.d.ts +0 -1
  77. package/dist/utils/formatting.js +0 -12
  78. package/dist/utils/index.d.ts +0 -11
  79. package/dist/utils/index.js +0 -27
  80. package/dist/utils/jest-module-mapper.d.ts +0 -1
  81. package/dist/utils/jest-module-mapper.js +0 -9
  82. package/dist/utils/json-file.util.d.ts +0 -15
  83. package/dist/utils/json-file.util.js +0 -72
  84. package/dist/utils/metadata.manager.d.ts +0 -13
  85. package/dist/utils/metadata.manager.js +0 -175
  86. package/dist/utils/module-import.declarator.d.ts +0 -10
  87. package/dist/utils/module-import.declarator.js +0 -40
  88. package/dist/utils/module-metadata.declarator.d.ts +0 -4
  89. package/dist/utils/module-metadata.declarator.js +0 -12
  90. package/dist/utils/module.declarator.d.ts +0 -23
  91. package/dist/utils/module.declarator.js +0 -34
  92. package/dist/utils/module.finder.d.ts +0 -13
  93. package/dist/utils/module.finder.js +0 -25
  94. package/dist/utils/name.parser.d.ts +0 -12
  95. package/dist/utils/name.parser.js +0 -17
  96. package/dist/utils/object-sorting.d.ts +0 -1
  97. package/dist/utils/object-sorting.js +0 -13
  98. package/dist/utils/path.solver.d.ts +0 -4
  99. package/dist/utils/path.solver.js +0 -12
  100. package/dist/utils/source-root.helpers.d.ts +0 -6
  101. package/dist/utils/source-root.helpers.js +0 -24
@@ -1,3 +0,0 @@
1
- import { Rule } from '@angular-devkit/schematics';
2
- import { ResourceOptions } from './resource.schema';
3
- export declare function main(options: ResourceOptions): Rule;
@@ -1,145 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = main;
4
- const core_1 = require("@angular-devkit/core");
5
- const strings_1 = require("@angular-devkit/core/src/utils/strings");
6
- const schematics_1 = require("@angular-devkit/schematics");
7
- const tasks_1 = require("@angular-devkit/schematics/tasks");
8
- const pluralize = require("pluralize");
9
- const __1 = require("../..");
10
- const dependencies_utils_1 = require("../../utils/dependencies.utils");
11
- const formatting_1 = require("../../utils/formatting");
12
- const name_parser_1 = require("../../utils/name.parser");
13
- const source_root_helpers_1 = require("../../utils/source-root.helpers");
14
- function main(options) {
15
- options = transform(options);
16
- return (tree, context) => {
17
- return (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
18
- addMappedTypesDependencyIfApplies(options),
19
- (0, source_root_helpers_1.mergeSourceRoot)(options),
20
- addDeclarationToModule(options),
21
- (0, schematics_1.mergeWith)(generate(options)),
22
- ]))(tree, context);
23
- };
24
- }
25
- function transform(options) {
26
- const target = Object.assign({}, options);
27
- if (!target.name) {
28
- throw new schematics_1.SchematicsException('Option (name) is required.');
29
- }
30
- target.metadata = 'imports';
31
- const location = new name_parser_1.NameParser().parse(target);
32
- target.name = (0, formatting_1.normalizeToKebabOrSnakeCase)(location.name);
33
- target.path = (0, formatting_1.normalizeToKebabOrSnakeCase)(location.path);
34
- target.language = target.language !== undefined ? target.language : 'ts';
35
- if (target.language === 'js') {
36
- throw new Error('The "resource" schematic does not support JavaScript language (only TypeScript is supported).');
37
- }
38
- target.specFileSuffix = (0, formatting_1.normalizeToKebabOrSnakeCase)(options.specFileSuffix || 'spec');
39
- target.path = target.flat
40
- ? target.path
41
- : (0, core_1.join)(target.path, target.name);
42
- target.isSwaggerInstalled = options.isSwaggerInstalled ?? false;
43
- return target;
44
- }
45
- function generate(options) {
46
- return (context) => (0, schematics_1.apply)((0, schematics_1.url)((0, core_1.join)('./files', options.language)), [
47
- (0, schematics_1.filter)((path) => {
48
- if (path.endsWith('.dto.ts')) {
49
- return (options.type !== 'graphql-code-first' &&
50
- options.type !== 'graphql-schema-first' &&
51
- options.crud);
52
- }
53
- if (path.endsWith('.input.ts')) {
54
- return ((options.type === 'graphql-code-first' ||
55
- options.type === 'graphql-schema-first') &&
56
- options.crud);
57
- }
58
- if (path.endsWith('.resolver.ts') ||
59
- path.endsWith('.resolver.__specFileSuffix__.ts')) {
60
- return (options.type === 'graphql-code-first' ||
61
- options.type === 'graphql-schema-first');
62
- }
63
- if (path.endsWith('.graphql')) {
64
- return options.type === 'graphql-schema-first' && options.crud;
65
- }
66
- if (path.endsWith('controller.ts') ||
67
- path.endsWith('.controller.__specFileSuffix__.ts')) {
68
- return options.type === 'microservice' || options.type === 'rest';
69
- }
70
- if (path.endsWith('.gateway.ts') ||
71
- path.endsWith('.gateway.__specFileSuffix__.ts')) {
72
- return options.type === 'ws';
73
- }
74
- if (path.includes('@ent')) {
75
- return options.crud;
76
- }
77
- return true;
78
- }),
79
- options.spec
80
- ? (0, schematics_1.noop)()
81
- : (0, schematics_1.filter)((path) => {
82
- const suffix = `.__specFileSuffix__.ts`;
83
- return !path.endsWith(suffix);
84
- }),
85
- (0, schematics_1.template)({
86
- ...core_1.strings,
87
- ...options,
88
- lowercased: (name) => {
89
- const classifiedName = (0, strings_1.classify)(name);
90
- return (classifiedName.charAt(0).toLowerCase() + classifiedName.slice(1));
91
- },
92
- singular: (name) => pluralize.singular(name),
93
- ent: (name) => name + '.entity',
94
- }),
95
- (0, schematics_1.move)(options.path),
96
- ])(context);
97
- }
98
- function addDeclarationToModule(options) {
99
- return (tree) => {
100
- if (options.skipImport !== undefined && options.skipImport) {
101
- return tree;
102
- }
103
- options.module = new __1.ModuleFinder(tree).find({
104
- name: options.name,
105
- path: options.path,
106
- });
107
- if (!options.module) {
108
- return tree;
109
- }
110
- const content = tree.read(options.module).toString();
111
- const declarator = new __1.ModuleDeclarator();
112
- tree.overwrite(options.module, declarator.declare(content, {
113
- ...options,
114
- type: 'module',
115
- }));
116
- return tree;
117
- };
118
- }
119
- function addMappedTypesDependencyIfApplies(options) {
120
- return (host, context) => {
121
- try {
122
- if (options.type === 'graphql-code-first') {
123
- return;
124
- }
125
- if (options.type === 'rest') {
126
- const nodeDependencyRef = (0, dependencies_utils_1.getPackageJsonDependency)(host, '@nestjs/swagger');
127
- if (nodeDependencyRef) {
128
- options.isSwaggerInstalled = true;
129
- return;
130
- }
131
- }
132
- const nodeDependencyRef = (0, dependencies_utils_1.getPackageJsonDependency)(host, '@nestjs/mapped-types');
133
- if (!nodeDependencyRef) {
134
- (0, dependencies_utils_1.addPackageJsonDependency)(host, {
135
- type: dependencies_utils_1.NodeDependencyType.Default,
136
- name: '@nestjs/mapped-types',
137
- version: '*',
138
- });
139
- context.addTask(new tasks_1.NodePackageInstallTask());
140
- }
141
- }
142
- catch {
143
- }
144
- };
145
- }
@@ -1,3 +0,0 @@
1
- import { Rule } from '@angular-devkit/schematics';
2
- import { ServiceOptions } from './service.schema';
3
- export declare function main(options: ServiceOptions): Rule;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = main;
4
- const core_1 = require("@angular-devkit/core");
5
- const schematics_1 = require("@angular-devkit/schematics");
6
- const formatting_1 = require("../../utils/formatting");
7
- const module_declarator_1 = require("../../utils/module.declarator");
8
- const module_finder_1 = require("../../utils/module.finder");
9
- const name_parser_1 = require("../../utils/name.parser");
10
- const source_root_helpers_1 = require("../../utils/source-root.helpers");
11
- function isNullOrUndefined(value) {
12
- return value === null || value === undefined;
13
- }
14
- function main(options) {
15
- options = transform(options);
16
- return (tree, context) => {
17
- return (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
18
- (0, source_root_helpers_1.mergeSourceRoot)(options),
19
- addDeclarationToModule(options),
20
- (0, schematics_1.mergeWith)(generate(options)),
21
- ]))(tree, context);
22
- };
23
- }
24
- function transform(source) {
25
- const target = Object.assign({}, source);
26
- target.metadata = 'providers';
27
- target.type = 'service';
28
- if (isNullOrUndefined(target.name)) {
29
- throw new schematics_1.SchematicsException('Option (name) is required.');
30
- }
31
- const location = new name_parser_1.NameParser().parse(target);
32
- target.name = (0, formatting_1.normalizeToKebabOrSnakeCase)(location.name);
33
- target.path = (0, formatting_1.normalizeToKebabOrSnakeCase)(location.path);
34
- target.language = target.language !== undefined ? target.language : 'ts';
35
- target.specFileSuffix = (0, formatting_1.normalizeToKebabOrSnakeCase)(source.specFileSuffix || 'spec');
36
- target.path = target.flat
37
- ? target.path
38
- : (0, core_1.join)(target.path, target.name);
39
- return target;
40
- }
41
- function generate(options) {
42
- return (context) => (0, schematics_1.apply)((0, schematics_1.url)((0, core_1.join)('./files', options.language)), [
43
- options.spec
44
- ? (0, schematics_1.noop)()
45
- : (0, schematics_1.filter)((path) => {
46
- const languageExtension = options.language || 'ts';
47
- const suffix = `.__specFileSuffix__.${languageExtension}`;
48
- return !path.endsWith(suffix);
49
- }),
50
- (0, schematics_1.template)({
51
- ...core_1.strings,
52
- ...options,
53
- }),
54
- (0, schematics_1.move)(options.path),
55
- ])(context);
56
- }
57
- function addDeclarationToModule(options) {
58
- return (tree) => {
59
- if (options.skipImport !== undefined && options.skipImport) {
60
- return tree;
61
- }
62
- options.module = new module_finder_1.ModuleFinder(tree).find({
63
- name: options.name,
64
- path: options.path,
65
- });
66
- if (!options.module) {
67
- return tree;
68
- }
69
- const content = tree.read(options.module).toString();
70
- const declarator = new module_declarator_1.ModuleDeclarator();
71
- tree.overwrite(options.module, declarator.declare(content, options));
72
- return tree;
73
- };
74
- }
@@ -1,3 +0,0 @@
1
- import { Rule } from '@angular-devkit/schematics';
2
- import { SubAppOptions } from './sub-app.schema';
3
- export declare function main(options: SubAppOptions): Rule;
@@ -1,271 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = main;
4
- const core_1 = require("@angular-devkit/core");
5
- const schematics_1 = require("@angular-devkit/schematics");
6
- const fs_1 = require("fs");
7
- const comment_json_1 = require("comment-json");
8
- const utils_1 = require("../../utils");
9
- const defaults_1 = require("../defaults");
10
- function main(options) {
11
- const appName = getAppNameFromPackageJson();
12
- options = transform(options);
13
- return (0, schematics_1.chain)([
14
- updateTsConfig(),
15
- updatePackageJson(options, appName),
16
- (tree, context) => isMonorepo(tree)
17
- ? (0, schematics_1.noop)()(tree, context)
18
- : (0, schematics_1.chain)([
19
- (0, schematics_1.branchAndMerge)((0, schematics_1.mergeWith)(generateWorkspace(options, appName))),
20
- moveDefaultAppToApps(options.path, appName, options.sourceRoot),
21
- ])(tree, context),
22
- addAppsToCliOptions(options.path, options.name, appName),
23
- (0, schematics_1.branchAndMerge)((0, schematics_1.mergeWith)(generate(options))),
24
- ]);
25
- }
26
- function getAppNameFromPackageJson() {
27
- try {
28
- if (!(0, fs_1.existsSync)('./package.json')) {
29
- return defaults_1.DEFAULT_DIR_ENTRY_APP;
30
- }
31
- const packageJson = JSON.parse(stripBom((0, fs_1.readFileSync)('./package.json', 'utf-8')));
32
- if (!packageJson.name) {
33
- return defaults_1.DEFAULT_DIR_ENTRY_APP;
34
- }
35
- let name = packageJson.name;
36
- name = name.replace(/[^\w.]+/g, '-').replace(/-+/g, '-');
37
- return name[0] === '-' ? name.substr(1) : name;
38
- }
39
- catch {
40
- return defaults_1.DEFAULT_DIR_ENTRY_APP;
41
- }
42
- }
43
- function stripBom(value) {
44
- if (value.charCodeAt(0) === 0xfeff) {
45
- return value.slice(1);
46
- }
47
- return value;
48
- }
49
- function transform(options) {
50
- const target = Object.assign({}, options);
51
- const defaultSourceRoot = options.rootDir !== undefined ? options.rootDir : defaults_1.DEFAULT_APPS_PATH;
52
- if (!target.name) {
53
- target.name = defaults_1.DEFAULT_APP_NAME;
54
- }
55
- target.language = target.language ? target.language : defaults_1.DEFAULT_LANGUAGE;
56
- target.name = (0, utils_1.normalizeToKebabOrSnakeCase)(target.name);
57
- target.path =
58
- target.path !== undefined
59
- ? (0, core_1.join)((0, core_1.normalize)(defaultSourceRoot), target.path)
60
- : (0, core_1.normalize)(defaultSourceRoot);
61
- return target;
62
- }
63
- function isMonorepo(host) {
64
- const nestFileExists = host.exists('nest.json');
65
- const nestCliFileExists = host.exists('nest-cli.json');
66
- if (!nestFileExists && !nestCliFileExists) {
67
- return false;
68
- }
69
- const filename = nestCliFileExists ? 'nest-cli.json' : 'nest.json';
70
- const source = host.read(filename);
71
- if (!source) {
72
- return false;
73
- }
74
- const sourceText = source.toString('utf-8');
75
- const optionsObj = (0, comment_json_1.parse)(sourceText);
76
- return !!optionsObj.monorepo;
77
- }
78
- function updateJsonFile(host, path, callback) {
79
- const source = host.read(path);
80
- if (source) {
81
- const sourceText = source.toString('utf-8');
82
- const json = (0, comment_json_1.parse)(sourceText);
83
- callback(json);
84
- host.overwrite(path, (0, comment_json_1.stringify)(json, null, 2));
85
- }
86
- return host;
87
- }
88
- function updateTsConfig() {
89
- return (host) => {
90
- if (!host.exists('tsconfig.json')) {
91
- return host;
92
- }
93
- return updateJsonFile(host, 'tsconfig.json', (tsconfig) => {
94
- if (!tsconfig.compilerOptions) {
95
- tsconfig.compilerOptions = {};
96
- }
97
- if (!tsconfig.compilerOptions.baseUrl) {
98
- tsconfig.compilerOptions.baseUrl = './';
99
- }
100
- if (!tsconfig.compilerOptions.paths) {
101
- tsconfig.compilerOptions.paths = {};
102
- }
103
- (0, utils_1.inPlaceSortByKeys)(tsconfig.compilerOptions.paths);
104
- });
105
- };
106
- }
107
- function updatePackageJson(options, defaultAppName) {
108
- return (host) => {
109
- if (!host.exists('package.json')) {
110
- return host;
111
- }
112
- return updateJsonFile(host, 'package.json', (packageJson) => {
113
- updateNpmScripts(packageJson.scripts, options, defaultAppName);
114
- updateJestOptions(packageJson.jest, options);
115
- });
116
- };
117
- }
118
- function updateNpmScripts(scripts, options, defaultAppName) {
119
- if (!scripts) {
120
- return;
121
- }
122
- const defaultFormatScriptName = 'format';
123
- const defaultStartScriptName = 'start:prod';
124
- const defaultTestScriptName = 'test:e2e';
125
- if (!scripts[defaultTestScriptName] &&
126
- !scripts[defaultFormatScriptName] &&
127
- !scripts[defaultStartScriptName]) {
128
- return;
129
- }
130
- if (scripts[defaultTestScriptName] &&
131
- scripts[defaultTestScriptName].indexOf(options.path) < 0) {
132
- const defaultTestDir = 'test';
133
- const newTestDir = (0, core_1.join)(options.path, defaultAppName, defaultTestDir);
134
- scripts[defaultTestScriptName] = scripts[defaultTestScriptName].replace(defaultTestDir, newTestDir);
135
- }
136
- if (scripts[defaultFormatScriptName] &&
137
- scripts[defaultFormatScriptName].indexOf(defaults_1.DEFAULT_PATH_NAME) >= 0) {
138
- const defaultSourceRoot = options.rootDir !== undefined ? options.rootDir : defaults_1.DEFAULT_APPS_PATH;
139
- scripts[defaultFormatScriptName] =
140
- `prettier --write "${defaultSourceRoot}/**/*.ts" "${defaults_1.DEFAULT_LIB_PATH}/**/*.ts"`;
141
- }
142
- if (scripts[defaultStartScriptName] &&
143
- scripts[defaultStartScriptName].indexOf('dist/main') >= 0) {
144
- const defaultSourceRoot = options.rootDir !== undefined ? options.rootDir : defaults_1.DEFAULT_APPS_PATH;
145
- scripts[defaultStartScriptName] =
146
- `node dist/${defaultSourceRoot}/${defaultAppName}/main`;
147
- }
148
- }
149
- function updateJestOptions(jestOptions, options) {
150
- if (!jestOptions) {
151
- return;
152
- }
153
- if (jestOptions.rootDir === defaults_1.DEFAULT_PATH_NAME) {
154
- jestOptions.rootDir = '.';
155
- jestOptions.coverageDirectory = './coverage';
156
- }
157
- const defaultSourceRoot = options.rootDir !== undefined ? options.rootDir : defaults_1.DEFAULT_APPS_PATH;
158
- const jestSourceRoot = `<rootDir>/${defaultSourceRoot}/`;
159
- if (!jestOptions.roots) {
160
- jestOptions.roots = [jestSourceRoot];
161
- }
162
- else if (jestOptions.roots.indexOf(jestSourceRoot) < 0) {
163
- jestOptions.roots.push(jestSourceRoot);
164
- const originalSourceRoot = `<rootDir>/src/`;
165
- const originalSourceRootIndex = jestOptions.roots.indexOf(originalSourceRoot);
166
- if (originalSourceRootIndex >= 0) {
167
- jestOptions.roots.splice(originalSourceRootIndex, 1);
168
- }
169
- }
170
- }
171
- function moveDefaultAppToApps(projectRoot, appName, sourceRoot = defaults_1.DEFAULT_PATH_NAME) {
172
- return (host) => {
173
- if (process.env.NODE_ENV === defaults_1.TEST_ENV) {
174
- return host;
175
- }
176
- const appDestination = (0, core_1.join)(projectRoot, appName);
177
- moveDirectoryTo(sourceRoot, appDestination, host);
178
- moveDirectoryTo('test', appDestination, host);
179
- return host;
180
- };
181
- }
182
- function moveDirectoryTo(srcDir, destination, tree) {
183
- let srcDirExists = false;
184
- tree.getDir(srcDir).visit((filePath, file) => {
185
- srcDirExists = true;
186
- const newFilePath = (0, core_1.join)(destination, filePath);
187
- tree.create(newFilePath, file.content);
188
- });
189
- if (srcDirExists) {
190
- tree.delete(srcDir);
191
- }
192
- }
193
- function addAppsToCliOptions(projectRoot, projectName, appName) {
194
- const rootPath = (0, core_1.join)(projectRoot, projectName);
195
- const project = {
196
- type: defaults_1.PROJECT_TYPE.APPLICATION,
197
- root: rootPath,
198
- entryFile: 'main',
199
- sourceRoot: (0, core_1.join)(rootPath, defaults_1.DEFAULT_PATH_NAME),
200
- compilerOptions: {
201
- tsConfigPath: (0, core_1.join)(rootPath, 'tsconfig.app.json'),
202
- },
203
- };
204
- return (host) => {
205
- const nestFileExists = host.exists('nest.json');
206
- let nestCliFileExists = host.exists('nest-cli.json');
207
- if (!nestCliFileExists && !nestFileExists) {
208
- host.create('nest-cli.json', '{}');
209
- nestCliFileExists = true;
210
- }
211
- return updateJsonFile(host, nestCliFileExists ? 'nest-cli.json' : 'nest.json', (optionsFile) => {
212
- updateMainAppOptions(optionsFile, projectRoot, appName);
213
- if (!optionsFile.projects) {
214
- optionsFile.projects = {};
215
- }
216
- if (optionsFile.projects[projectName]) {
217
- throw new schematics_1.SchematicsException(`Project "${projectName}" exists in this workspace already.`);
218
- }
219
- optionsFile.projects[projectName] = project;
220
- (0, utils_1.inPlaceSortByKeys)(optionsFile.projects);
221
- });
222
- };
223
- }
224
- function updateMainAppOptions(optionsFile, projectRoot, appName) {
225
- if (optionsFile.monorepo) {
226
- return;
227
- }
228
- const rootFilePath = (0, core_1.join)(projectRoot, appName);
229
- const tsConfigPath = (0, core_1.join)(rootFilePath, 'tsconfig.app.json');
230
- optionsFile.monorepo = true;
231
- optionsFile.root = rootFilePath;
232
- optionsFile.sourceRoot = (0, core_1.join)(projectRoot, appName, optionsFile.sourceRoot || defaults_1.DEFAULT_PATH_NAME);
233
- if (!optionsFile.compilerOptions) {
234
- optionsFile.compilerOptions = {};
235
- }
236
- optionsFile.compilerOptions.webpack = true;
237
- optionsFile.compilerOptions.tsConfigPath = tsConfigPath;
238
- if (!optionsFile.projects) {
239
- optionsFile.projects = {};
240
- }
241
- optionsFile.projects[appName] = {
242
- type: defaults_1.PROJECT_TYPE.APPLICATION,
243
- root: rootFilePath,
244
- entryFile: optionsFile.entryFile || 'main',
245
- sourceRoot: (0, core_1.join)(rootFilePath, defaults_1.DEFAULT_PATH_NAME),
246
- compilerOptions: {
247
- tsConfigPath,
248
- },
249
- };
250
- }
251
- function generateWorkspace(options, appName) {
252
- const path = (0, core_1.join)(options.path, appName);
253
- return (0, schematics_1.apply)((0, schematics_1.url)((0, core_1.join)('./workspace', options.language)), [
254
- (0, schematics_1.template)({
255
- ...core_1.strings,
256
- ...options,
257
- name: appName,
258
- }),
259
- (0, schematics_1.move)(path),
260
- ]);
261
- }
262
- function generate(options) {
263
- const path = (0, core_1.join)(options.path, options.name);
264
- return (0, schematics_1.apply)((0, schematics_1.url)((0, core_1.join)('./files', options.language)), [
265
- (0, schematics_1.template)({
266
- ...core_1.strings,
267
- ...options,
268
- }),
269
- (0, schematics_1.move)(path),
270
- ]);
271
- }
@@ -1,15 +0,0 @@
1
- import { Tree } from '@angular-devkit/schematics';
2
- export declare enum NodeDependencyType {
3
- Default = "dependencies",
4
- Dev = "devDependencies",
5
- Peer = "peerDependencies",
6
- Optional = "optionalDependencies"
7
- }
8
- export interface NodeDependency {
9
- type: NodeDependencyType;
10
- name: string;
11
- version: string;
12
- overwrite?: boolean;
13
- }
14
- export declare function addPackageJsonDependency(tree: Tree, dependency: NodeDependency, pkgJsonPath?: string): void;
15
- export declare function getPackageJsonDependency(tree: Tree, name: string, pkgJsonPath?: string): NodeDependency | null;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeDependencyType = void 0;
4
- exports.addPackageJsonDependency = addPackageJsonDependency;
5
- exports.getPackageJsonDependency = getPackageJsonDependency;
6
- const json_file_util_1 = require("./json-file.util");
7
- const PKG_JSON_PATH = '/package.json';
8
- var NodeDependencyType;
9
- (function (NodeDependencyType) {
10
- NodeDependencyType["Default"] = "dependencies";
11
- NodeDependencyType["Dev"] = "devDependencies";
12
- NodeDependencyType["Peer"] = "peerDependencies";
13
- NodeDependencyType["Optional"] = "optionalDependencies";
14
- })(NodeDependencyType || (exports.NodeDependencyType = NodeDependencyType = {}));
15
- const ALL_DEPENDENCY_TYPE = [
16
- NodeDependencyType.Default,
17
- NodeDependencyType.Dev,
18
- NodeDependencyType.Optional,
19
- NodeDependencyType.Peer,
20
- ];
21
- function addPackageJsonDependency(tree, dependency, pkgJsonPath = PKG_JSON_PATH) {
22
- const json = new json_file_util_1.JSONFile(tree, pkgJsonPath);
23
- const { overwrite, type, name, version } = dependency;
24
- const path = [type, name];
25
- if (overwrite || !json.get(path)) {
26
- json.modify(path, version);
27
- }
28
- }
29
- function getPackageJsonDependency(tree, name, pkgJsonPath = PKG_JSON_PATH) {
30
- const json = new json_file_util_1.JSONFile(tree, pkgJsonPath);
31
- for (const depType of ALL_DEPENDENCY_TYPE) {
32
- const version = json.get([depType, name]);
33
- if (typeof version === 'string') {
34
- return {
35
- type: depType,
36
- name: name,
37
- version,
38
- };
39
- }
40
- }
41
- return null;
42
- }
@@ -1 +0,0 @@
1
- export declare function normalizeToKebabOrSnakeCase(str: string): string;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeToKebabOrSnakeCase = normalizeToKebabOrSnakeCase;
4
- function normalizeToKebabOrSnakeCase(str) {
5
- const STRING_DASHERIZE_REGEXP = /\s/g;
6
- const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g;
7
- return str
8
- ?.trim()
9
- ?.replace(STRING_DECAMELIZE_REGEXP, '$1-$2')
10
- ?.toLowerCase()
11
- ?.replace(STRING_DASHERIZE_REGEXP, '-');
12
- }
@@ -1,11 +0,0 @@
1
- export * from './metadata.manager';
2
- export * from './module-import.declarator';
3
- export * from './module-metadata.declarator';
4
- export * from './module.declarator';
5
- export * from './module.finder';
6
- export * from './name.parser';
7
- export * from './path.solver';
8
- export * from './source-root.helpers';
9
- export * from './formatting';
10
- export * from './jest-module-mapper';
11
- export * from './object-sorting';
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./metadata.manager"), exports);
18
- __exportStar(require("./module-import.declarator"), exports);
19
- __exportStar(require("./module-metadata.declarator"), exports);
20
- __exportStar(require("./module.declarator"), exports);
21
- __exportStar(require("./module.finder"), exports);
22
- __exportStar(require("./name.parser"), exports);
23
- __exportStar(require("./path.solver"), exports);
24
- __exportStar(require("./source-root.helpers"), exports);
25
- __exportStar(require("./formatting"), exports);
26
- __exportStar(require("./jest-module-mapper"), exports);
27
- __exportStar(require("./object-sorting"), exports);
@@ -1 +0,0 @@
1
- export declare function createModuleNameMapper(packageKey: string, packageRoot: string): Record<string, string>;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createModuleNameMapper = createModuleNameMapper;
4
- function createModuleNameMapper(packageKey, packageRoot) {
5
- const moduleNameMapper = {};
6
- const packageKeyRegex = '^' + packageKey + '(|/.*)$';
7
- moduleNameMapper[packageKeyRegex] = packageRoot + '/$1';
8
- return moduleNameMapper;
9
- }
@@ -1,15 +0,0 @@
1
- import { JsonValue } from '@angular-devkit/core';
2
- import { Tree } from '@angular-devkit/schematics';
3
- export type InsertionIndex = (properties: string[]) => number;
4
- export type JSONPath = (string | number)[];
5
- export declare class JSONFile {
6
- private readonly host;
7
- private readonly path;
8
- content: string;
9
- constructor(host: Tree, path: string);
10
- private _jsonAst;
11
- private get JsonAst();
12
- get(jsonPath: JSONPath): unknown;
13
- modify(jsonPath: JSONPath, value: JsonValue | undefined, insertInOrder?: InsertionIndex | false): void;
14
- remove(jsonPath: JSONPath): void;
15
- }