@nestjs/schematics 11.0.8 → 12.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/application/files/js/package.json +10 -10
- package/dist/lib/application/files/ts/eslint.config.mjs +2 -1
- package/dist/lib/application/files/ts/package.json +3 -3
- package/dist/lib/application/files/ts/tsconfig.json +0 -1
- package/dist/lib/application/files/ts-esm/.prettierrc +4 -0
- package/dist/lib/application/files/ts-esm/README.md +98 -0
- package/dist/lib/application/files/ts-esm/eslint.config.mjs +34 -0
- package/dist/lib/application/files/ts-esm/nest-cli.json +8 -0
- package/dist/lib/application/files/ts-esm/package.json +50 -0
- package/dist/lib/application/files/ts-esm/src/app.controller.__specFileSuffix__.ts +22 -0
- package/dist/lib/application/files/ts-esm/src/app.controller.ts +12 -0
- package/dist/lib/application/files/ts-esm/src/app.module.ts +10 -0
- package/dist/lib/application/files/ts-esm/src/app.service.ts +8 -0
- package/dist/lib/application/files/ts-esm/src/main.ts +8 -0
- package/dist/lib/application/files/ts-esm/test/app.e2e-__specFileSuffix__.ts +25 -0
- package/dist/lib/application/files/ts-esm/tsconfig.build.json +4 -0
- package/dist/lib/application/files/ts-esm/tsconfig.json +24 -0
- package/dist/lib/application/files/ts-esm/vitest.config.e2e.ts +10 -0
- package/dist/lib/application/files/ts-esm/vitest.config.ts +10 -0
- package/dist/lib/application/schema.json +14 -0
- package/dist/lib/library/files/ts/tsconfig.lib.json +1 -0
- package/dist/lib/sub-app/files/ts/tsconfig.app.json +1 -0
- package/dist/lib/sub-app/workspace/ts/tsconfig.app.json +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/{lib → src/lib}/application/application.factory.d.ts +1 -1
- package/dist/src/lib/application/application.factory.js +64 -0
- package/dist/{lib → src/lib}/class/class.factory.d.ts +1 -1
- package/dist/src/lib/class/class.factory.js +48 -0
- package/dist/{lib → src/lib}/client-app/angular/angular.factory.d.ts +1 -1
- package/dist/{lib → src/lib}/client-app/angular/angular.factory.js +23 -26
- package/dist/{lib → src/lib}/configuration/configuration.factory.d.ts +1 -1
- package/dist/src/lib/configuration/configuration.factory.js +24 -0
- package/dist/{lib → src/lib}/controller/controller.factory.d.ts +1 -1
- package/dist/src/lib/controller/controller.factory.js +69 -0
- package/dist/{lib → src/lib}/decorator/decorator.factory.d.ts +1 -1
- package/dist/src/lib/decorator/decorator.factory.js +32 -0
- package/dist/src/lib/defaults.js +14 -0
- package/dist/{lib → src/lib}/filter/filter.factory.d.ts +1 -1
- package/dist/src/lib/filter/filter.factory.js +40 -0
- package/dist/{lib → src/lib}/gateway/gateway.factory.d.ts +1 -1
- package/dist/src/lib/gateway/gateway.factory.js +69 -0
- package/dist/{lib → src/lib}/guard/guard.factory.d.ts +1 -1
- package/dist/src/lib/guard/guard.factory.js +40 -0
- package/dist/{lib → src/lib}/interceptor/interceptor.factory.d.ts +1 -1
- package/dist/src/lib/interceptor/interceptor.factory.js +41 -0
- package/dist/{lib → src/lib}/interface/interface.factory.d.ts +1 -1
- package/dist/src/lib/interface/interface.factory.js +31 -0
- package/dist/{lib → src/lib}/library/library.factory.d.ts +1 -1
- package/dist/{lib → src/lib}/library/library.factory.js +51 -64
- package/dist/{lib → src/lib}/middleware/middleware.factory.d.ts +1 -1
- package/dist/src/lib/middleware/middleware.factory.js +40 -0
- package/dist/{lib → src/lib}/module/module.factory.d.ts +1 -1
- package/dist/src/lib/module/module.factory.js +57 -0
- package/dist/{lib → src/lib}/pipe/pipe.factory.d.ts +1 -1
- package/dist/src/lib/pipe/pipe.factory.js +41 -0
- package/dist/{lib → src/lib}/provider/provider.factory.d.ts +1 -1
- package/dist/src/lib/provider/provider.factory.js +73 -0
- package/dist/{lib → src/lib}/readers/file-system.reader.d.ts +1 -1
- package/dist/{lib → src/lib}/readers/file-system.reader.js +3 -7
- package/dist/src/lib/readers/index.d.ts +2 -0
- package/dist/src/lib/readers/index.js +2 -0
- package/dist/src/lib/readers/reader.js +1 -0
- package/dist/{lib → src/lib}/resolver/resolver.factory.d.ts +1 -1
- package/dist/src/lib/resolver/resolver.factory.js +68 -0
- package/dist/{lib → src/lib}/resource/resource.factory.d.ts +1 -1
- package/dist/{lib → src/lib}/resource/resource.factory.js +35 -38
- package/dist/{lib → src/lib}/service/service.factory.d.ts +1 -1
- package/dist/src/lib/service/service.factory.js +71 -0
- package/dist/{lib → src/lib}/sub-app/sub-app.factory.d.ts +1 -1
- package/dist/{lib → src/lib}/sub-app/sub-app.factory.js +94 -69
- package/dist/{utils → src/utils}/dependencies.utils.js +7 -12
- package/dist/{utils → src/utils}/formatting.js +1 -4
- package/dist/src/utils/index.d.ts +11 -0
- package/dist/src/utils/index.js +11 -0
- package/dist/src/utils/jest-module-mapper.js +6 -0
- package/dist/{utils → src/utils}/json-file.util.js +9 -13
- package/dist/{utils → src/utils}/metadata.manager.d.ts +1 -1
- package/dist/{utils → src/utils}/metadata.manager.js +11 -15
- package/dist/{utils → src/utils}/module-import.declarator.d.ts +2 -2
- package/dist/{utils → src/utils}/module-import.declarator.js +6 -10
- package/dist/{utils → src/utils}/module-metadata.declarator.d.ts +1 -1
- package/dist/src/utils/module-metadata.declarator.js +8 -0
- package/dist/{utils → src/utils}/module.declarator.d.ts +2 -2
- package/dist/src/utils/module.declarator.js +30 -0
- package/dist/{utils → src/utils}/module.finder.js +3 -7
- package/dist/src/utils/name.parser.js +13 -0
- package/dist/{utils → src/utils}/object-sorting.js +1 -4
- package/dist/src/utils/path.solver.js +8 -0
- package/dist/src/utils/source-root.helpers.js +20 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +21 -49
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -18
- package/dist/lib/application/application.factory.js +0 -63
- package/dist/lib/class/class.factory.js +0 -51
- package/dist/lib/configuration/configuration.factory.js +0 -27
- package/dist/lib/controller/controller.factory.js +0 -72
- package/dist/lib/decorator/decorator.factory.js +0 -35
- package/dist/lib/defaults.js +0 -17
- package/dist/lib/filter/filter.factory.js +0 -43
- package/dist/lib/gateway/gateway.factory.js +0 -72
- package/dist/lib/guard/guard.factory.js +0 -43
- package/dist/lib/interceptor/interceptor.factory.js +0 -44
- package/dist/lib/interface/interface.factory.js +0 -34
- package/dist/lib/middleware/middleware.factory.js +0 -43
- package/dist/lib/module/module.factory.js +0 -60
- package/dist/lib/pipe/pipe.factory.js +0 -44
- package/dist/lib/provider/provider.factory.js +0 -76
- package/dist/lib/readers/index.d.ts +0 -2
- package/dist/lib/readers/index.js +0 -18
- package/dist/lib/readers/reader.js +0 -2
- package/dist/lib/resolver/resolver.factory.js +0 -71
- package/dist/lib/service/service.factory.js +0 -74
- package/dist/utils/index.d.ts +0 -11
- package/dist/utils/index.js +0 -27
- package/dist/utils/jest-module-mapper.js +0 -9
- package/dist/utils/module-metadata.declarator.js +0 -12
- package/dist/utils/module.declarator.js +0 -34
- package/dist/utils/name.parser.js +0 -17
- package/dist/utils/path.solver.js +0 -12
- package/dist/utils/source-root.helpers.js +0 -24
- /package/dist/{lib → src/lib}/defaults.d.ts +0 -0
- /package/dist/{lib → src/lib}/readers/reader.d.ts +0 -0
- /package/dist/{utils → src/utils}/dependencies.utils.d.ts +0 -0
- /package/dist/{utils → src/utils}/formatting.d.ts +0 -0
- /package/dist/{utils → src/utils}/jest-module-mapper.d.ts +0 -0
- /package/dist/{utils → src/utils}/json-file.util.d.ts +0 -0
- /package/dist/{utils → src/utils}/module.finder.d.ts +0 -0
- /package/dist/{utils → src/utils}/name.parser.d.ts +0 -0
- /package/dist/{utils → src/utils}/object-sorting.d.ts +0 -0
- /package/dist/{utils → src/utils}/path.solver.d.ts +0 -0
- /package/dist/{utils → src/utils}/source-root.helpers.d.ts +0 -0
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const defaults_1 = require("../defaults");
|
|
9
|
-
const readers_1 = require("../readers");
|
|
10
|
-
function main(options) {
|
|
1
|
+
import { join, normalize, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, branchAndMerge, chain, mergeWith, move, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { parse } from 'jsonc-parser';
|
|
4
|
+
import { createModuleNameMapper, inPlaceSortByKeys, normalizeToKebabOrSnakeCase, } from '../../utils/index.js';
|
|
5
|
+
import { DEFAULT_LANGUAGE, DEFAULT_LIB_PATH, DEFAULT_PATH_NAME, PROJECT_TYPE, } from '../defaults.js';
|
|
6
|
+
import { FileSystemReader } from '../readers/index.js';
|
|
7
|
+
export function main(options) {
|
|
11
8
|
options = transform(options);
|
|
12
|
-
return
|
|
9
|
+
return chain([
|
|
13
10
|
addLibraryToCliOptions(options.path, options.name),
|
|
14
11
|
updatePackageJson(options),
|
|
15
12
|
updateJestEndToEnd(options),
|
|
16
13
|
updateTsConfig(options.name, options.prefix, options.path),
|
|
17
|
-
|
|
14
|
+
branchAndMerge(mergeWith(generate(options))),
|
|
18
15
|
]);
|
|
19
16
|
}
|
|
20
17
|
function getDefaultLibraryPrefix(defaultLibraryPrefix = '@app') {
|
|
21
|
-
const fileSystemReader = new
|
|
18
|
+
const fileSystemReader = new FileSystemReader(process.cwd());
|
|
22
19
|
const content = fileSystemReader.readSyncAnyOf([
|
|
23
20
|
'nest-cli.json',
|
|
24
21
|
'.nestcli.json',
|
|
@@ -38,16 +35,16 @@ function getDefaultLibraryPrefix(defaultLibraryPrefix = '@app') {
|
|
|
38
35
|
}
|
|
39
36
|
function transform(options) {
|
|
40
37
|
const target = Object.assign({}, options);
|
|
41
|
-
const defaultSourceRoot = options.rootDir !== undefined ? options.rootDir :
|
|
38
|
+
const defaultSourceRoot = options.rootDir !== undefined ? options.rootDir : DEFAULT_LIB_PATH;
|
|
42
39
|
if (!target.name) {
|
|
43
|
-
throw new
|
|
40
|
+
throw new SchematicsException('Option (name) is required.');
|
|
44
41
|
}
|
|
45
|
-
target.language = target.language ? target.language :
|
|
46
|
-
target.name =
|
|
42
|
+
target.language = target.language ? target.language : DEFAULT_LANGUAGE;
|
|
43
|
+
target.name = normalizeToKebabOrSnakeCase(target.name);
|
|
47
44
|
target.path =
|
|
48
45
|
target.path !== undefined
|
|
49
|
-
?
|
|
50
|
-
:
|
|
46
|
+
? join(normalize(defaultSourceRoot), target.path)
|
|
47
|
+
: normalize(defaultSourceRoot);
|
|
51
48
|
target.prefix = target.prefix || getDefaultLibraryPrefix();
|
|
52
49
|
return target;
|
|
53
50
|
}
|
|
@@ -56,7 +53,7 @@ function updatePackageJson(options) {
|
|
|
56
53
|
if (!host.exists('package.json')) {
|
|
57
54
|
return host;
|
|
58
55
|
}
|
|
59
|
-
const distRoot =
|
|
56
|
+
const distRoot = join(options.path, options.name, 'src');
|
|
60
57
|
const packageKey = options.prefix
|
|
61
58
|
? options.prefix + '/' + options.name
|
|
62
59
|
: options.name;
|
|
@@ -70,11 +67,11 @@ function updateJestConfig(jestOptions, options, packageKey, distRoot) {
|
|
|
70
67
|
if (!jestOptions) {
|
|
71
68
|
return;
|
|
72
69
|
}
|
|
73
|
-
if (jestOptions.rootDir ===
|
|
70
|
+
if (jestOptions.rootDir === DEFAULT_PATH_NAME) {
|
|
74
71
|
jestOptions.rootDir = '.';
|
|
75
72
|
jestOptions.coverageDirectory = './coverage';
|
|
76
73
|
}
|
|
77
|
-
const defaultSourceRoot = options.rootDir !== undefined ? options.rootDir :
|
|
74
|
+
const defaultSourceRoot = options.rootDir !== undefined ? options.rootDir : DEFAULT_LIB_PATH;
|
|
78
75
|
const jestSourceRoot = `<rootDir>/${defaultSourceRoot}/`;
|
|
79
76
|
if (!jestOptions.roots) {
|
|
80
77
|
jestOptions.roots = ['<rootDir>/src/', jestSourceRoot];
|
|
@@ -85,10 +82,10 @@ function updateJestConfig(jestOptions, options, packageKey, distRoot) {
|
|
|
85
82
|
if (!jestOptions.moduleNameMapper) {
|
|
86
83
|
jestOptions.moduleNameMapper = {};
|
|
87
84
|
}
|
|
88
|
-
const packageRoot =
|
|
89
|
-
const newMapper =
|
|
85
|
+
const packageRoot = join('<rootDir>', distRoot);
|
|
86
|
+
const newMapper = createModuleNameMapper(packageKey, packageRoot);
|
|
90
87
|
Object.assign(jestOptions.moduleNameMapper, newMapper);
|
|
91
|
-
|
|
88
|
+
inPlaceSortByKeys(jestOptions.moduleNameMapper);
|
|
92
89
|
}
|
|
93
90
|
function updateNpmScripts(scripts, options) {
|
|
94
91
|
if (!scripts) {
|
|
@@ -99,19 +96,19 @@ function updateNpmScripts(scripts, options) {
|
|
|
99
96
|
return;
|
|
100
97
|
}
|
|
101
98
|
if (scripts[defaultFormatScriptName] &&
|
|
102
|
-
scripts[defaultFormatScriptName].indexOf(
|
|
103
|
-
const defaultSourceRoot = options.rootDir !== undefined ? options.rootDir :
|
|
99
|
+
scripts[defaultFormatScriptName].indexOf(DEFAULT_PATH_NAME) >= 0) {
|
|
100
|
+
const defaultSourceRoot = options.rootDir !== undefined ? options.rootDir : DEFAULT_LIB_PATH;
|
|
104
101
|
scripts[defaultFormatScriptName] =
|
|
105
102
|
`prettier --write "src/**/*.ts" "test/**/*.ts" "${defaultSourceRoot}/**/*.ts"`;
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
105
|
function updateJestEndToEnd(options) {
|
|
109
106
|
return (host) => {
|
|
110
|
-
const pathToFile =
|
|
107
|
+
const pathToFile = join('test', 'jest-e2e.json');
|
|
111
108
|
if (!host.exists(pathToFile)) {
|
|
112
109
|
return host;
|
|
113
110
|
}
|
|
114
|
-
const distRoot =
|
|
111
|
+
const distRoot = join(options.path, options.name, 'src');
|
|
115
112
|
const packageKey = options.prefix
|
|
116
113
|
? options.prefix + '/' + options.name
|
|
117
114
|
: options.name;
|
|
@@ -120,9 +117,9 @@ function updateJestEndToEnd(options) {
|
|
|
120
117
|
jestOptions.moduleNameMapper = {};
|
|
121
118
|
}
|
|
122
119
|
const packageRoot = '<rootDir>/../' + distRoot;
|
|
123
|
-
const newMapper =
|
|
120
|
+
const newMapper = createModuleNameMapper(packageKey, packageRoot);
|
|
124
121
|
Object.assign(jestOptions.moduleNameMapper, newMapper);
|
|
125
|
-
|
|
122
|
+
inPlaceSortByKeys(jestOptions.moduleNameMapper);
|
|
126
123
|
});
|
|
127
124
|
};
|
|
128
125
|
}
|
|
@@ -130,53 +127,43 @@ function updateJsonFile(host, path, callback) {
|
|
|
130
127
|
const source = host.read(path);
|
|
131
128
|
if (source) {
|
|
132
129
|
const sourceText = source.toString('utf-8');
|
|
133
|
-
const json =
|
|
130
|
+
const json = parse(sourceText);
|
|
134
131
|
callback(json);
|
|
135
132
|
host.overwrite(path, JSON.stringify(json, null, 2));
|
|
136
133
|
}
|
|
137
134
|
return host;
|
|
138
135
|
}
|
|
139
|
-
function updateTsConfig(packageName,
|
|
136
|
+
function updateTsConfig(packageName, _packagePrefix, root) {
|
|
140
137
|
return (host) => {
|
|
141
138
|
if (!host.exists('tsconfig.json')) {
|
|
142
139
|
return host;
|
|
143
140
|
}
|
|
144
|
-
const
|
|
145
|
-
const packageKey = packagePrefix
|
|
146
|
-
? packagePrefix + '/' + packageName
|
|
147
|
-
: packageName;
|
|
141
|
+
const refPath = `./${join(root, packageName, 'tsconfig.lib.json')}`;
|
|
148
142
|
return updateJsonFile(host, 'tsconfig.json', (tsconfig) => {
|
|
149
143
|
if (!tsconfig.compilerOptions) {
|
|
150
144
|
tsconfig.compilerOptions = {};
|
|
151
145
|
}
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
delete tsconfig.compilerOptions.baseUrl;
|
|
147
|
+
delete tsconfig.compilerOptions.paths;
|
|
148
|
+
if (!tsconfig.references) {
|
|
149
|
+
tsconfig.references = [];
|
|
154
150
|
}
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
const hasRef = tsconfig.references.some((ref) => ref.path === refPath);
|
|
152
|
+
if (!hasRef) {
|
|
153
|
+
tsconfig.references.push({ path: refPath });
|
|
157
154
|
}
|
|
158
|
-
if (!tsconfig.compilerOptions.paths[packageKey]) {
|
|
159
|
-
tsconfig.compilerOptions.paths[packageKey] = [];
|
|
160
|
-
}
|
|
161
|
-
tsconfig.compilerOptions.paths[packageKey].push(distRoot);
|
|
162
|
-
const deepPackagePath = packageKey + '/*';
|
|
163
|
-
if (!tsconfig.compilerOptions.paths[deepPackagePath]) {
|
|
164
|
-
tsconfig.compilerOptions.paths[deepPackagePath] = [];
|
|
165
|
-
}
|
|
166
|
-
tsconfig.compilerOptions.paths[deepPackagePath].push(distRoot + '/*');
|
|
167
|
-
(0, utils_1.inPlaceSortByKeys)(tsconfig.compilerOptions.paths);
|
|
168
155
|
});
|
|
169
156
|
};
|
|
170
157
|
}
|
|
171
158
|
function addLibraryToCliOptions(projectRoot, projectName) {
|
|
172
|
-
const rootPath =
|
|
159
|
+
const rootPath = join(projectRoot, projectName);
|
|
173
160
|
const project = {
|
|
174
|
-
type:
|
|
161
|
+
type: PROJECT_TYPE.LIBRARY,
|
|
175
162
|
root: rootPath,
|
|
176
163
|
entryFile: 'index',
|
|
177
|
-
sourceRoot:
|
|
164
|
+
sourceRoot: join(rootPath, 'src'),
|
|
178
165
|
compilerOptions: {
|
|
179
|
-
tsConfigPath:
|
|
166
|
+
tsConfigPath: join(rootPath, 'tsconfig.lib.json'),
|
|
180
167
|
},
|
|
181
168
|
};
|
|
182
169
|
return (host) => {
|
|
@@ -193,24 +180,24 @@ function addLibraryToCliOptions(projectRoot, projectName) {
|
|
|
193
180
|
if (!optionsFile.compilerOptions) {
|
|
194
181
|
optionsFile.compilerOptions = {};
|
|
195
182
|
}
|
|
196
|
-
if (optionsFile.compilerOptions.
|
|
197
|
-
optionsFile.compilerOptions.
|
|
183
|
+
if (optionsFile.compilerOptions.builder === undefined) {
|
|
184
|
+
optionsFile.compilerOptions.builder = 'rspack';
|
|
198
185
|
}
|
|
199
186
|
if (optionsFile.projects[projectName]) {
|
|
200
|
-
throw new
|
|
187
|
+
throw new SchematicsException(`Project "${projectName}" exists in this workspace already.`);
|
|
201
188
|
}
|
|
202
189
|
optionsFile.projects[projectName] = project;
|
|
203
|
-
|
|
190
|
+
inPlaceSortByKeys(optionsFile.projects);
|
|
204
191
|
});
|
|
205
192
|
};
|
|
206
193
|
}
|
|
207
194
|
function generate(options) {
|
|
208
|
-
const path =
|
|
209
|
-
return
|
|
210
|
-
|
|
211
|
-
...
|
|
195
|
+
const path = join(options.path, options.name);
|
|
196
|
+
return apply(url(join('./files', options.language)), [
|
|
197
|
+
template({
|
|
198
|
+
...strings,
|
|
212
199
|
...options,
|
|
213
200
|
}),
|
|
214
|
-
|
|
201
|
+
move(path),
|
|
215
202
|
]);
|
|
216
203
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
5
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
6
|
+
export function main(options) {
|
|
7
|
+
options = transform(options);
|
|
8
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
9
|
+
}
|
|
10
|
+
function transform(options) {
|
|
11
|
+
const target = Object.assign({}, options);
|
|
12
|
+
if (!target.name) {
|
|
13
|
+
throw new SchematicsException('Option (name) is required.');
|
|
14
|
+
}
|
|
15
|
+
const location = new NameParser().parse(target);
|
|
16
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
17
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
18
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
19
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(options.specFileSuffix || 'spec');
|
|
20
|
+
target.path = target.flat
|
|
21
|
+
? target.path
|
|
22
|
+
: join(target.path, target.name);
|
|
23
|
+
return target;
|
|
24
|
+
}
|
|
25
|
+
function generate(options) {
|
|
26
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
27
|
+
options.spec
|
|
28
|
+
? noop()
|
|
29
|
+
: filter((path) => {
|
|
30
|
+
const languageExtension = options.language || 'ts';
|
|
31
|
+
const suffix = `.__specFileSuffix__.${languageExtension}`;
|
|
32
|
+
return !path.endsWith(suffix);
|
|
33
|
+
}),
|
|
34
|
+
template({
|
|
35
|
+
...strings,
|
|
36
|
+
...options,
|
|
37
|
+
}),
|
|
38
|
+
move(options.path),
|
|
39
|
+
])(context);
|
|
40
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, branchAndMerge, chain, mergeWith, move, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { ModuleDeclarator, } from '../../utils/module.declarator.js';
|
|
5
|
+
import { ModuleFinder } from '../../utils/module.finder.js';
|
|
6
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
7
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
8
|
+
export function main(options) {
|
|
9
|
+
options = transform(options);
|
|
10
|
+
return (tree, context) => {
|
|
11
|
+
return branchAndMerge(chain([
|
|
12
|
+
mergeSourceRoot(options),
|
|
13
|
+
addDeclarationToModule(options),
|
|
14
|
+
mergeWith(generate(options)),
|
|
15
|
+
]))(tree, context);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function transform(source) {
|
|
19
|
+
const target = Object.assign({}, source);
|
|
20
|
+
target.metadata = 'imports';
|
|
21
|
+
target.type = 'module';
|
|
22
|
+
const location = new NameParser().parse(target);
|
|
23
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
24
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
25
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
26
|
+
target.path = target.flat
|
|
27
|
+
? target.path
|
|
28
|
+
: join(target.path, target.name);
|
|
29
|
+
return target;
|
|
30
|
+
}
|
|
31
|
+
function generate(options) {
|
|
32
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
33
|
+
template({
|
|
34
|
+
...strings,
|
|
35
|
+
...options,
|
|
36
|
+
}),
|
|
37
|
+
move(options.path),
|
|
38
|
+
])(context);
|
|
39
|
+
}
|
|
40
|
+
function addDeclarationToModule(options) {
|
|
41
|
+
return (tree) => {
|
|
42
|
+
if (options.skipImport !== undefined && options.skipImport) {
|
|
43
|
+
return tree;
|
|
44
|
+
}
|
|
45
|
+
options.module = new ModuleFinder(tree).find({
|
|
46
|
+
name: options.name,
|
|
47
|
+
path: options.path,
|
|
48
|
+
});
|
|
49
|
+
if (!options.module) {
|
|
50
|
+
return tree;
|
|
51
|
+
}
|
|
52
|
+
const content = tree.read(options.module).toString();
|
|
53
|
+
const declarator = new ModuleDeclarator();
|
|
54
|
+
tree.overwrite(options.module, declarator.declare(content, options));
|
|
55
|
+
return tree;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
5
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
6
|
+
export function main(options) {
|
|
7
|
+
options = transform(options);
|
|
8
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
9
|
+
}
|
|
10
|
+
function transform(options) {
|
|
11
|
+
const target = Object.assign({}, options);
|
|
12
|
+
if (!target.name) {
|
|
13
|
+
throw new SchematicsException('Option (name) is required.');
|
|
14
|
+
}
|
|
15
|
+
const location = new NameParser().parse(target);
|
|
16
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
17
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
18
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
19
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(options.specFileSuffix || 'spec');
|
|
20
|
+
target.path = target.flat
|
|
21
|
+
? target.path
|
|
22
|
+
: join(target.path, target.name);
|
|
23
|
+
return target;
|
|
24
|
+
}
|
|
25
|
+
function generate(options) {
|
|
26
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
27
|
+
options.spec ? noop() : filter((path) => !path.endsWith('.spec.ts')),
|
|
28
|
+
options.spec
|
|
29
|
+
? noop()
|
|
30
|
+
: filter((path) => {
|
|
31
|
+
const languageExtension = options.language || 'ts';
|
|
32
|
+
const suffix = `.__specFileSuffix__.${languageExtension}`;
|
|
33
|
+
return !path.endsWith(suffix);
|
|
34
|
+
}),
|
|
35
|
+
template({
|
|
36
|
+
...strings,
|
|
37
|
+
...options,
|
|
38
|
+
}),
|
|
39
|
+
move(options.path),
|
|
40
|
+
])(context);
|
|
41
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, branchAndMerge, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { ModuleDeclarator, } from '../../utils/module.declarator.js';
|
|
5
|
+
import { ModuleFinder } from '../../utils/module.finder.js';
|
|
6
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
7
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
8
|
+
export function main(options) {
|
|
9
|
+
options = transform(options);
|
|
10
|
+
return (tree, context) => {
|
|
11
|
+
return branchAndMerge(chain([
|
|
12
|
+
mergeSourceRoot(options),
|
|
13
|
+
addDeclarationToModule(options),
|
|
14
|
+
mergeWith(generate(options)),
|
|
15
|
+
]))(tree, context);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function transform(options) {
|
|
19
|
+
const target = Object.assign({}, options);
|
|
20
|
+
target.metadata = 'providers';
|
|
21
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(options.specFileSuffix || 'spec');
|
|
22
|
+
if (!target.name) {
|
|
23
|
+
throw new SchematicsException('Option (name) is required.');
|
|
24
|
+
}
|
|
25
|
+
const location = new NameParser().parse(target);
|
|
26
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
27
|
+
if (target.name.includes('.')) {
|
|
28
|
+
target.className = strings.classify(target.name).replace('.', '');
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
target.className = strings.classify(target.name);
|
|
32
|
+
}
|
|
33
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
34
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
35
|
+
target.path = target.flat
|
|
36
|
+
? target.path
|
|
37
|
+
: join(target.path, target.name);
|
|
38
|
+
return target;
|
|
39
|
+
}
|
|
40
|
+
function generate(options) {
|
|
41
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
42
|
+
options.spec
|
|
43
|
+
? noop()
|
|
44
|
+
: filter((path) => {
|
|
45
|
+
const languageExtension = options.language || 'ts';
|
|
46
|
+
const suffix = `.__specFileSuffix__.${languageExtension}`;
|
|
47
|
+
return !path.endsWith(suffix);
|
|
48
|
+
}),
|
|
49
|
+
template({
|
|
50
|
+
...strings,
|
|
51
|
+
...options,
|
|
52
|
+
}),
|
|
53
|
+
move(options.path),
|
|
54
|
+
])(context);
|
|
55
|
+
}
|
|
56
|
+
function addDeclarationToModule(options) {
|
|
57
|
+
return (tree) => {
|
|
58
|
+
if (options.skipImport !== undefined && options.skipImport) {
|
|
59
|
+
return tree;
|
|
60
|
+
}
|
|
61
|
+
options.module = new ModuleFinder(tree).find({
|
|
62
|
+
name: options.name,
|
|
63
|
+
path: options.path,
|
|
64
|
+
});
|
|
65
|
+
if (!options.module) {
|
|
66
|
+
return tree;
|
|
67
|
+
}
|
|
68
|
+
const content = tree.read(options.module).toString();
|
|
69
|
+
const declarator = new ModuleDeclarator();
|
|
70
|
+
tree.overwrite(options.module, declarator.declare(content, options));
|
|
71
|
+
return tree;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
class FileSystemReader {
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
export class FileSystemReader {
|
|
7
4
|
directory;
|
|
8
5
|
constructor(directory) {
|
|
9
6
|
this.directory = directory;
|
|
@@ -42,4 +39,3 @@ class FileSystemReader {
|
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
|
-
exports.FileSystemReader = FileSystemReader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, branchAndMerge, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { ModuleDeclarator, } from '../../utils/module.declarator.js';
|
|
5
|
+
import { ModuleFinder } from '../../utils/module.finder.js';
|
|
6
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
7
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
8
|
+
export function main(options) {
|
|
9
|
+
options = transform(options);
|
|
10
|
+
return (tree, context) => {
|
|
11
|
+
return branchAndMerge(chain([
|
|
12
|
+
mergeSourceRoot(options),
|
|
13
|
+
addDeclarationToModule(options),
|
|
14
|
+
mergeWith(generate(options)),
|
|
15
|
+
]))(tree, context);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function transform(options) {
|
|
19
|
+
const target = Object.assign({}, options);
|
|
20
|
+
if (!target.name) {
|
|
21
|
+
throw new SchematicsException('Option (name) is required.');
|
|
22
|
+
}
|
|
23
|
+
target.metadata = 'providers';
|
|
24
|
+
target.type = 'resolver';
|
|
25
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(options.specFileSuffix || 'spec');
|
|
26
|
+
const location = new NameParser().parse(target);
|
|
27
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
28
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
29
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
30
|
+
target.path = target.flat
|
|
31
|
+
? target.path
|
|
32
|
+
: join(target.path, target.name);
|
|
33
|
+
return target;
|
|
34
|
+
}
|
|
35
|
+
function generate(options) {
|
|
36
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
37
|
+
options.spec
|
|
38
|
+
? noop()
|
|
39
|
+
: filter((path) => {
|
|
40
|
+
const languageExtension = options.language || 'ts';
|
|
41
|
+
const suffix = `.__specFileSuffix__.${languageExtension}`;
|
|
42
|
+
return !path.endsWith(suffix);
|
|
43
|
+
}),
|
|
44
|
+
template({
|
|
45
|
+
...strings,
|
|
46
|
+
...options,
|
|
47
|
+
}),
|
|
48
|
+
move(options.path),
|
|
49
|
+
])(context);
|
|
50
|
+
}
|
|
51
|
+
function addDeclarationToModule(options) {
|
|
52
|
+
return (tree) => {
|
|
53
|
+
if (options.skipImport !== undefined && options.skipImport) {
|
|
54
|
+
return tree;
|
|
55
|
+
}
|
|
56
|
+
options.module = new ModuleFinder(tree).find({
|
|
57
|
+
name: options.name,
|
|
58
|
+
path: options.path,
|
|
59
|
+
});
|
|
60
|
+
if (!options.module) {
|
|
61
|
+
return tree;
|
|
62
|
+
}
|
|
63
|
+
const content = tree.read(options.module).toString();
|
|
64
|
+
const declarator = new ModuleDeclarator();
|
|
65
|
+
tree.overwrite(options.module, declarator.declare(content, options));
|
|
66
|
+
return tree;
|
|
67
|
+
};
|
|
68
|
+
}
|