@nx/node 16.8.0-beta.0 → 16.8.0-beta.2
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/generators.json +2 -2
- package/package.json +8 -8
- package/src/generators/application/application.d.ts +1 -0
- package/src/generators/application/application.js +49 -39
- package/src/generators/application/schema.d.ts +3 -1
- package/src/generators/application/schema.json +7 -1
- package/src/generators/e2e-project/e2e-project.d.ts +2 -1
- package/src/generators/e2e-project/e2e-project.js +35 -44
- package/src/generators/e2e-project/schema.d.ts +3 -0
- package/src/generators/e2e-project/schema.json +5 -0
- package/src/generators/library/library.d.ts +2 -2
- package/src/generators/library/library.js +39 -30
- package/src/generators/library/schema.d.ts +3 -1
- package/src/generators/library/schema.json +7 -1
package/generators.json
CHANGED
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
"hidden": true
|
|
12
12
|
},
|
|
13
13
|
"application": {
|
|
14
|
-
"factory": "./src/generators/application/application",
|
|
14
|
+
"factory": "./src/generators/application/application#applicationGeneratorInternal",
|
|
15
15
|
"schema": "./src/generators/application/schema.json",
|
|
16
16
|
"aliases": ["app"],
|
|
17
17
|
"x-type": "application",
|
|
18
18
|
"description": "Create a node application."
|
|
19
19
|
},
|
|
20
20
|
"library": {
|
|
21
|
-
"factory": "./src/generators/library/library",
|
|
21
|
+
"factory": "./src/generators/library/library#libraryGeneratorInternal",
|
|
22
22
|
"schema": "./src/generators/library/schema.json",
|
|
23
23
|
"aliases": ["lib"],
|
|
24
24
|
"x-type": "library",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/node",
|
|
3
|
-
"version": "16.8.0-beta.
|
|
3
|
+
"version": "16.8.0-beta.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Node Plugin for Nx contains generators to manage Node applications within an Nx workspace.",
|
|
6
6
|
"repository": {
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"migrations": "./migrations.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@nrwl/node": "16.8.0-beta.
|
|
34
|
-
"@nx/devkit": "16.8.0-beta.
|
|
35
|
-
"@nx/jest": "16.8.0-beta.
|
|
36
|
-
"@nx/js": "16.8.0-beta.
|
|
37
|
-
"@nx/linter": "16.8.0-beta.
|
|
38
|
-
"@nx/workspace": "16.8.0-beta.
|
|
33
|
+
"@nrwl/node": "16.8.0-beta.2",
|
|
34
|
+
"@nx/devkit": "16.8.0-beta.2",
|
|
35
|
+
"@nx/jest": "16.8.0-beta.2",
|
|
36
|
+
"@nx/js": "16.8.0-beta.2",
|
|
37
|
+
"@nx/linter": "16.8.0-beta.2",
|
|
38
|
+
"@nx/workspace": "16.8.0-beta.2",
|
|
39
39
|
"tslib": "^2.3.0"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"type": "commonjs",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "9bcc04742f9e1516d8c1ddbfb1907770c347876f"
|
|
46
46
|
}
|
|
@@ -6,5 +6,6 @@ export interface NormalizedSchema extends Schema {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function addLintingToApplication(tree: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
|
|
8
8
|
export declare function applicationGenerator(tree: Tree, schema: Schema): Promise<any>;
|
|
9
|
+
export declare function applicationGeneratorInternal(tree: Tree, schema: Schema): Promise<any>;
|
|
9
10
|
export default applicationGenerator;
|
|
10
11
|
export declare const applicationSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applicationSchematic = exports.applicationGenerator = exports.addLintingToApplication = void 0;
|
|
3
|
+
exports.applicationSchematic = exports.applicationGeneratorInternal = exports.applicationGenerator = exports.addLintingToApplication = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const
|
|
6
|
+
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
7
7
|
const jest_1 = require("@nx/jest");
|
|
8
8
|
const js_1 = require("@nx/js");
|
|
9
|
+
const versions_1 = require("@nx/js/src/utils/versions");
|
|
10
|
+
const linter_1 = require("@nx/linter");
|
|
11
|
+
const lint_project_1 = require("@nx/linter/src/generators/lint-project/lint-project");
|
|
9
12
|
const path_1 = require("path");
|
|
10
|
-
const
|
|
11
|
-
const versions_1 = require("../../utils/versions");
|
|
13
|
+
const versions_2 = require("../../utils/versions");
|
|
12
14
|
const e2e_project_1 = require("../e2e-project/e2e-project");
|
|
15
|
+
const init_1 = require("../init/init");
|
|
13
16
|
const setup_docker_1 = require("../setup-docker/setup-docker");
|
|
14
|
-
const lint_project_1 = require("@nx/linter/src/generators/lint-project/lint-project");
|
|
15
|
-
const versions_2 = require("@nx/js/src/utils/versions");
|
|
16
17
|
function getWebpackBuildConfig(project, options) {
|
|
17
18
|
return {
|
|
18
19
|
executor: `@nx/webpack:webpack`,
|
|
@@ -160,33 +161,33 @@ exports.addLintingToApplication = addLintingToApplication;
|
|
|
160
161
|
function addProjectDependencies(tree, options) {
|
|
161
162
|
const bundlers = {
|
|
162
163
|
webpack: {
|
|
163
|
-
'@nx/webpack':
|
|
164
|
+
'@nx/webpack': versions_2.nxVersion,
|
|
164
165
|
},
|
|
165
166
|
esbuild: {
|
|
166
|
-
'@nx/esbuild':
|
|
167
|
-
esbuild:
|
|
167
|
+
'@nx/esbuild': versions_2.nxVersion,
|
|
168
|
+
esbuild: versions_1.esbuildVersion,
|
|
168
169
|
},
|
|
169
170
|
};
|
|
170
171
|
const frameworkDependencies = {
|
|
171
172
|
express: {
|
|
172
|
-
express:
|
|
173
|
+
express: versions_2.expressVersion,
|
|
173
174
|
},
|
|
174
175
|
koa: {
|
|
175
|
-
koa:
|
|
176
|
+
koa: versions_2.koaVersion,
|
|
176
177
|
},
|
|
177
178
|
fastify: {
|
|
178
|
-
fastify:
|
|
179
|
-
'fastify-plugin':
|
|
180
|
-
'@fastify/autoload':
|
|
181
|
-
'@fastify/sensible':
|
|
179
|
+
fastify: versions_2.fastifyVersion,
|
|
180
|
+
'fastify-plugin': versions_2.fastifyPluginVersion,
|
|
181
|
+
'@fastify/autoload': versions_2.fastifyAutoloadVersion,
|
|
182
|
+
'@fastify/sensible': versions_2.fastifySensibleVersion,
|
|
182
183
|
},
|
|
183
184
|
};
|
|
184
185
|
const frameworkDevDependencies = {
|
|
185
186
|
express: {
|
|
186
|
-
'@types/express':
|
|
187
|
+
'@types/express': versions_2.expressTypingsVersion,
|
|
187
188
|
},
|
|
188
189
|
koa: {
|
|
189
|
-
'@types/koa':
|
|
190
|
+
'@types/koa': versions_2.koaTypingsVersion,
|
|
190
191
|
},
|
|
191
192
|
fastify: {},
|
|
192
193
|
};
|
|
@@ -204,10 +205,16 @@ function updateTsConfigOptions(tree, options) {
|
|
|
204
205
|
}
|
|
205
206
|
function applicationGenerator(tree, schema) {
|
|
206
207
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
207
|
-
|
|
208
|
+
return yield applicationGeneratorInternal(tree, Object.assign({ projectNameAndRootFormat: 'derived' }, schema));
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
exports.applicationGenerator = applicationGenerator;
|
|
212
|
+
function applicationGeneratorInternal(tree, schema) {
|
|
213
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
const options = yield normalizeOptions(tree, schema);
|
|
208
215
|
const tasks = [];
|
|
209
216
|
if (options.framework === 'nest') {
|
|
210
|
-
const { applicationGenerator } = (0, devkit_1.ensurePackage)('@nx/nest',
|
|
217
|
+
const { applicationGenerator } = (0, devkit_1.ensurePackage)('@nx/nest', versions_2.nxVersion);
|
|
211
218
|
return yield applicationGenerator(tree, Object.assign(Object.assign({}, options), { skipFormat: true }));
|
|
212
219
|
}
|
|
213
220
|
const initTask = yield (0, init_1.initGenerator)(tree, Object.assign(Object.assign({}, schema), { skipFormat: true }));
|
|
@@ -230,7 +237,7 @@ function applicationGenerator(tree, schema) {
|
|
|
230
237
|
tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/app/app.spec.ts'));
|
|
231
238
|
}
|
|
232
239
|
if (options.e2eTestRunner === 'jest') {
|
|
233
|
-
const e2eTask = yield (0, e2e_project_1.e2eProjectGenerator)(tree, Object.assign(Object.assign({}, options), { projectType: options.framework === 'none' ? 'cli' : 'server', name: options.rootProject ? 'e2e' : `${options.name}-e2e`, project: options.name, port: options.port, isNest: options.isNest, skipFormat: true }));
|
|
240
|
+
const e2eTask = yield (0, e2e_project_1.e2eProjectGenerator)(tree, Object.assign(Object.assign({}, options), { projectType: options.framework === 'none' ? 'cli' : 'server', name: options.rootProject ? 'e2e' : `${options.name}-e2e`, directory: options.rootProject ? 'e2e' : `${options.appProjectRoot}-e2e`, projectNameAndRootFormat: 'as-provided', project: options.name, port: options.port, isNest: options.isNest, skipFormat: true }));
|
|
234
241
|
tasks.push(e2eTask);
|
|
235
242
|
}
|
|
236
243
|
if (options.js) {
|
|
@@ -249,27 +256,30 @@ function applicationGenerator(tree, schema) {
|
|
|
249
256
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
250
257
|
});
|
|
251
258
|
}
|
|
252
|
-
exports.
|
|
259
|
+
exports.applicationGeneratorInternal = applicationGeneratorInternal;
|
|
253
260
|
function normalizeOptions(host, options) {
|
|
254
261
|
var _a, _b, _c, _d, _e, _f;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
262
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
264
|
+
name: options.name,
|
|
265
|
+
projectType: 'application',
|
|
266
|
+
directory: options.directory,
|
|
267
|
+
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
268
|
+
rootProject: options.rootProject,
|
|
269
|
+
callingGenerator: '@nx/node:application',
|
|
270
|
+
});
|
|
271
|
+
options.rootProject = appProjectRoot === '.';
|
|
272
|
+
options.projectNameAndRootFormat = projectNameAndRootFormat;
|
|
273
|
+
options.bundler = (_a = options.bundler) !== null && _a !== void 0 ? _a : 'esbuild';
|
|
274
|
+
options.e2eTestRunner = (_b = options.e2eTestRunner) !== null && _b !== void 0 ? _b : 'jest';
|
|
275
|
+
const parsedTags = options.tags
|
|
276
|
+
? options.tags.split(',').map((s) => s.trim())
|
|
277
|
+
: [];
|
|
278
|
+
return Object.assign(Object.assign({}, options), { name: appProjectName, frontendProject: options.frontendProject
|
|
279
|
+
? (0, devkit_1.names)(options.frontendProject).fileName
|
|
280
|
+
: undefined, appProjectRoot,
|
|
281
|
+
parsedTags, linter: (_c = options.linter) !== null && _c !== void 0 ? _c : linter_1.Linter.EsLint, unitTestRunner: (_d = options.unitTestRunner) !== null && _d !== void 0 ? _d : 'jest', rootProject: (_e = options.rootProject) !== null && _e !== void 0 ? _e : false, port: (_f = options.port) !== null && _f !== void 0 ? _f : 3000 });
|
|
282
|
+
});
|
|
273
283
|
}
|
|
274
284
|
exports.default = applicationGenerator;
|
|
275
285
|
exports.applicationSchematic = (0, devkit_1.convertNxGenerator)(applicationGenerator);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
+
import type { Linter } from '@nx/linter';
|
|
2
3
|
|
|
3
4
|
export interface Schema {
|
|
4
5
|
name: string;
|
|
5
6
|
skipFormat?: boolean;
|
|
6
7
|
skipPackageJson?: boolean;
|
|
7
8
|
directory?: string;
|
|
9
|
+
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
8
10
|
unitTestRunner?: 'jest' | 'none';
|
|
9
11
|
e2eTestRunner?: 'jest' | 'none';
|
|
10
12
|
linter?: Linter;
|
|
@@ -14,13 +14,19 @@
|
|
|
14
14
|
"index": 0
|
|
15
15
|
},
|
|
16
16
|
"x-prompt": "What name would you like to use for the node application?",
|
|
17
|
-
"x-priority": "important"
|
|
17
|
+
"x-priority": "important",
|
|
18
|
+
"pattern": "^[a-zA-Z][^:]*$"
|
|
18
19
|
},
|
|
19
20
|
"directory": {
|
|
20
21
|
"description": "The directory of the new application.",
|
|
21
22
|
"type": "string",
|
|
22
23
|
"x-priority": "important"
|
|
23
24
|
},
|
|
25
|
+
"projectNameAndRootFormat": {
|
|
26
|
+
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"enum": ["as-provided", "derived"]
|
|
29
|
+
},
|
|
24
30
|
"skipFormat": {
|
|
25
31
|
"description": "Skip formatting files",
|
|
26
32
|
"type": "boolean",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
2
|
import { Schema } from './schema';
|
|
3
|
-
export declare function e2eProjectGenerator(host: Tree,
|
|
3
|
+
export declare function e2eProjectGenerator(host: Tree, options: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function e2eProjectGeneratorInternal(host: Tree, _options: Schema): Promise<GeneratorCallback>;
|
|
4
5
|
export default e2eProjectGenerator;
|
|
5
6
|
export declare const e2eProjectSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.e2eProjectSchematic = exports.e2eProjectGenerator = void 0;
|
|
3
|
+
exports.e2eProjectSchematic = exports.e2eProjectGeneratorInternal = exports.e2eProjectGenerator = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const path = require("path");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
7
7
|
const linter_1 = require("@nx/linter");
|
|
8
|
-
const versions_1 = require("../../utils/versions");
|
|
9
|
-
const path_1 = require("path");
|
|
10
8
|
const global_eslint_config_1 = require("@nx/linter/src/generators/init/global-eslint-config");
|
|
11
|
-
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const versions_1 = require("../../utils/versions");
|
|
11
|
+
const eslint_file_1 = require("@nx/linter/src/generators/utils/eslint-file");
|
|
12
|
+
function e2eProjectGenerator(host, options) {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
return yield e2eProjectGeneratorInternal(host, Object.assign({ projectNameAndRootFormat: 'derived' }, options));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
exports.e2eProjectGenerator = e2eProjectGenerator;
|
|
18
|
+
function e2eProjectGeneratorInternal(host, _options) {
|
|
12
19
|
var _a, _b;
|
|
13
20
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
21
|
const tasks = [];
|
|
15
|
-
const options = normalizeOptions(host, _options);
|
|
22
|
+
const options = yield normalizeOptions(host, _options);
|
|
16
23
|
const appProject = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
17
24
|
(0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
|
|
18
25
|
root: options.e2eProjectRoot,
|
|
@@ -55,31 +62,13 @@ function e2eProjectGenerator(host, _options) {
|
|
|
55
62
|
rootProject: options.rootProject,
|
|
56
63
|
});
|
|
57
64
|
tasks.push(linterTask);
|
|
58
|
-
(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
? [global_eslint_config_1.globalTypeScriptOverrides, global_eslint_config_1.globalJavaScriptOverrides]
|
|
66
|
-
: []),
|
|
67
|
-
/**
|
|
68
|
-
* In order to ensure maximum efficiency when typescript-eslint generates TypeScript Programs
|
|
69
|
-
* behind the scenes during lint runs, we need to make sure the project is configured to use its
|
|
70
|
-
* own specific tsconfigs, and not fall back to the ones in the root of the workspace.
|
|
71
|
-
*/
|
|
72
|
-
{
|
|
73
|
-
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
|
74
|
-
/**
|
|
75
|
-
* Having an empty rules object present makes it more obvious to the user where they would
|
|
76
|
-
* extend things from if they needed to
|
|
77
|
-
*/
|
|
78
|
-
rules: {},
|
|
79
|
-
},
|
|
80
|
-
];
|
|
81
|
-
return json;
|
|
82
|
-
});
|
|
65
|
+
if (options.rootProject && (0, eslint_file_1.isEslintConfigSupported)(host)) {
|
|
66
|
+
(0, eslint_file_1.addPluginsToLintConfig)(host, options.e2eProjectRoot, '@nx');
|
|
67
|
+
(0, eslint_file_1.replaceOverridesInLintConfig)(host, options.e2eProjectRoot, [
|
|
68
|
+
global_eslint_config_1.typeScriptOverride,
|
|
69
|
+
global_eslint_config_1.javaScriptOverride,
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
83
72
|
}
|
|
84
73
|
if (!options.skipFormat) {
|
|
85
74
|
yield (0, devkit_1.formatFiles)(host);
|
|
@@ -87,21 +76,23 @@ function e2eProjectGenerator(host, _options) {
|
|
|
87
76
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
88
77
|
});
|
|
89
78
|
}
|
|
90
|
-
exports.
|
|
79
|
+
exports.e2eProjectGeneratorInternal = e2eProjectGeneratorInternal;
|
|
91
80
|
function normalizeOptions(tree, options) {
|
|
92
81
|
var _a, _b;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
82
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const { projectName: e2eProjectName, projectRoot: e2eProjectRoot } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
|
|
84
|
+
name: (_a = options.name) !== null && _a !== void 0 ? _a : `${options.project}-e2e`,
|
|
85
|
+
projectType: 'library',
|
|
86
|
+
directory: options.rootProject ? 'e2e' : options.directory,
|
|
87
|
+
projectNameAndRootFormat: options.rootProject
|
|
88
|
+
? 'as-provided'
|
|
89
|
+
: options.projectNameAndRootFormat,
|
|
90
|
+
// this is an internal generator, don't save defaults
|
|
91
|
+
callingGenerator: null,
|
|
92
|
+
});
|
|
93
|
+
return Object.assign(Object.assign({}, options), { e2eProjectRoot,
|
|
94
|
+
e2eProjectName, port: (_b = options.port) !== null && _b !== void 0 ? _b : 3000, rootProject: !!options.rootProject });
|
|
95
|
+
});
|
|
105
96
|
}
|
|
106
97
|
exports.default = e2eProjectGenerator;
|
|
107
98
|
exports.e2eProjectSchematic = (0, devkit_1.convertNxGenerator)(e2eProjectGenerator);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
+
|
|
1
3
|
export interface Schema {
|
|
2
4
|
project: string;
|
|
3
5
|
projectType: 'server' | 'cli';
|
|
4
6
|
directory?: string;
|
|
7
|
+
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
5
8
|
name?: string;
|
|
6
9
|
port?: number;
|
|
7
10
|
linter?: 'eslint' | 'none';
|
|
@@ -18,6 +18,11 @@
|
|
|
18
18
|
"type": "string",
|
|
19
19
|
"x-priority": "important"
|
|
20
20
|
},
|
|
21
|
+
"projectNameAndRootFormat": {
|
|
22
|
+
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
|
|
23
|
+
"type": "string",
|
|
24
|
+
"enum": ["as-provided", "derived"]
|
|
25
|
+
},
|
|
21
26
|
"name": {
|
|
22
27
|
"description": "The name of the e2e project. Defaults to the project name with '-e2e' suffix.",
|
|
23
28
|
"type": "string"
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
2
|
import { Schema } from './schema';
|
|
3
3
|
export interface NormalizedSchema extends Schema {
|
|
4
|
-
name: string;
|
|
5
4
|
fileName: string;
|
|
5
|
+
projectName: string;
|
|
6
6
|
projectRoot: string;
|
|
7
|
-
projectDirectory: string;
|
|
8
7
|
parsedTags: string[];
|
|
9
8
|
compiler: 'swc' | 'tsc';
|
|
10
9
|
}
|
|
11
10
|
export declare function libraryGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
11
|
+
export declare function libraryGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
12
12
|
export default libraryGenerator;
|
|
13
13
|
export declare const librarySchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.librarySchematic = exports.libraryGenerator = void 0;
|
|
3
|
+
exports.librarySchematic = exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
6
7
|
const js_1 = require("@nx/js");
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
9
8
|
const add_swc_config_1 = require("@nx/js/src/utils/swc/add-swc-config");
|
|
9
|
+
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
10
|
+
const path_1 = require("path");
|
|
10
11
|
const init_1 = require("../init/init");
|
|
11
|
-
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
|
12
12
|
function libraryGenerator(tree, schema) {
|
|
13
13
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
|
|
14
|
+
return yield libraryGeneratorInternal(tree, Object.assign({ projectNameAndRootFormat: 'derived' }, schema));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
exports.libraryGenerator = libraryGenerator;
|
|
18
|
+
function libraryGeneratorInternal(tree, schema) {
|
|
19
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const options = yield normalizeOptions(tree, schema);
|
|
15
21
|
const tasks = [
|
|
16
22
|
yield (0, init_1.initGenerator)(tree, Object.assign(Object.assign({}, options), { skipFormat: true })),
|
|
17
23
|
];
|
|
@@ -31,29 +37,35 @@ function libraryGenerator(tree, schema) {
|
|
|
31
37
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
|
-
exports.
|
|
40
|
+
exports.libraryGeneratorInternal = libraryGeneratorInternal;
|
|
35
41
|
exports.default = libraryGenerator;
|
|
36
42
|
exports.librarySchematic = (0, devkit_1.convertNxGenerator)(libraryGenerator);
|
|
37
43
|
function normalizeOptions(tree, options) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const { projectName, names: projectNames, projectRoot, importPath, projectNameAndRootFormat, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
|
|
46
|
+
name: options.name,
|
|
47
|
+
projectType: 'library',
|
|
48
|
+
directory: options.directory,
|
|
49
|
+
importPath: options.importPath,
|
|
50
|
+
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
51
|
+
callingGenerator: '@nx/node:library',
|
|
52
|
+
});
|
|
53
|
+
options.projectNameAndRootFormat = projectNameAndRootFormat;
|
|
54
|
+
const fileName = getCaseAwareFileName({
|
|
55
|
+
fileName: options.simpleModuleName
|
|
56
|
+
? projectNames.projectSimpleName
|
|
57
|
+
: projectNames.projectFileName,
|
|
58
|
+
pascalCaseFiles: options.pascalCaseFiles,
|
|
59
|
+
});
|
|
60
|
+
const parsedTags = options.tags
|
|
61
|
+
? options.tags.split(',').map((s) => s.trim())
|
|
62
|
+
: [];
|
|
63
|
+
return Object.assign(Object.assign({}, options), { fileName,
|
|
64
|
+
projectName,
|
|
65
|
+
projectRoot,
|
|
66
|
+
parsedTags,
|
|
67
|
+
importPath });
|
|
49
68
|
});
|
|
50
|
-
const projectRoot = (0, devkit_1.joinPathFragments)(libsDir, fullProjectDirectory);
|
|
51
|
-
const parsedTags = options.tags
|
|
52
|
-
? options.tags.split(',').map((s) => s.trim())
|
|
53
|
-
: [];
|
|
54
|
-
const importPath = options.importPath || (0, get_import_path_1.getImportPath)(tree, fullProjectDirectory);
|
|
55
|
-
return Object.assign(Object.assign({}, options), { fileName, name: projectName, projectRoot, projectDirectory: fullProjectDirectory, parsedTags,
|
|
56
|
-
importPath });
|
|
57
69
|
}
|
|
58
70
|
function getCaseAwareFileName(options) {
|
|
59
71
|
const normalized = (0, devkit_1.names)(options.fileName);
|
|
@@ -78,17 +90,14 @@ function updateProject(tree, options) {
|
|
|
78
90
|
if (!options.publishable && !options.buildable) {
|
|
79
91
|
return;
|
|
80
92
|
}
|
|
81
|
-
const project = (0, devkit_1.readProjectConfiguration)(tree, options.
|
|
82
|
-
const { libsDir } = (0, devkit_1.getWorkspaceLayout)(tree);
|
|
93
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
|
|
83
94
|
const rootProject = options.projectRoot === '.' || options.projectRoot === '';
|
|
84
95
|
project.targets = project.targets || {};
|
|
85
96
|
project.targets.build = {
|
|
86
97
|
executor: `@nx/js:${options.compiler}`,
|
|
87
98
|
outputs: ['{options.outputPath}'],
|
|
88
99
|
options: {
|
|
89
|
-
outputPath: (0, devkit_1.joinPathFragments)('dist', rootProject
|
|
90
|
-
? options.projectDirectory
|
|
91
|
-
: `${libsDir}/${options.projectDirectory}`),
|
|
100
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', rootProject ? options.projectName : options.projectRoot),
|
|
92
101
|
tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
|
|
93
102
|
packageJson: `${options.projectRoot}/package.json`,
|
|
94
103
|
main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
|
|
@@ -102,5 +111,5 @@ function updateProject(tree, options) {
|
|
|
102
111
|
if (options.rootDir) {
|
|
103
112
|
project.targets.build.options.srcRootForCompilationRoot = options.rootDir;
|
|
104
113
|
}
|
|
105
|
-
(0, devkit_1.updateProjectConfiguration)(tree, options.
|
|
114
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
|
|
106
115
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
+
import type { Linter } from '@nx/linter';
|
|
2
3
|
|
|
3
4
|
export interface Schema {
|
|
4
5
|
name: string;
|
|
5
6
|
directory?: string;
|
|
7
|
+
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
6
8
|
simpleModuleName?: boolean;
|
|
7
9
|
skipTsConfig?: boolean;
|
|
8
10
|
skipFormat?: boolean;
|
|
@@ -19,13 +19,19 @@
|
|
|
19
19
|
"$source": "argv",
|
|
20
20
|
"index": 0
|
|
21
21
|
},
|
|
22
|
-
"x-prompt": "What name would you like to use for the library?"
|
|
22
|
+
"x-prompt": "What name would you like to use for the library?",
|
|
23
|
+
"pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$"
|
|
23
24
|
},
|
|
24
25
|
"directory": {
|
|
25
26
|
"type": "string",
|
|
26
27
|
"description": "A directory where the lib is placed",
|
|
27
28
|
"alias": "dir"
|
|
28
29
|
},
|
|
30
|
+
"projectNameAndRootFormat": {
|
|
31
|
+
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
|
|
32
|
+
"type": "string",
|
|
33
|
+
"enum": ["as-provided", "derived"]
|
|
34
|
+
},
|
|
29
35
|
"simpleModuleName": {
|
|
30
36
|
"description": "Keep the module name simple (when using `--directory`).",
|
|
31
37
|
"type": "boolean",
|