@nx/plugin 20.1.0 → 20.2.0-beta.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.
- package/generators.json +3 -3
- package/package.json +5 -5
- package/src/generators/create-package/create-package.d.ts +1 -0
- package/src/generators/create-package/create-package.js +47 -11
- package/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +3 -2
- package/src/generators/create-package/schema.d.ts +7 -4
- package/src/generators/create-package/schema.json +7 -5
- package/src/generators/create-package/utils/normalize-schema.d.ts +6 -0
- package/src/generators/create-package/utils/normalize-schema.js +17 -0
- package/src/generators/e2e-project/e2e.d.ts +1 -2
- package/src/generators/e2e-project/e2e.js +57 -10
- package/src/generators/e2e-project/schema.d.ts +2 -0
- package/src/generators/e2e-project/schema.json +5 -2
- package/src/generators/executor/executor.d.ts +1 -1
- package/src/generators/executor/executor.js +29 -17
- package/src/generators/executor/files/executor/{executor.spec.ts.template → __fileName__.spec.ts.template} +1 -1
- package/src/generators/generator/files/generator/{generator.spec.ts.template → __fileName__.spec.ts.template} +1 -1
- package/src/generators/generator/generator.js +25 -13
- package/src/generators/migration/migration.d.ts +1 -1
- package/src/generators/migration/migration.js +30 -26
- package/src/generators/plugin/plugin.d.ts +2 -1
- package/src/generators/plugin/plugin.js +41 -30
- package/src/generators/plugin/schema.d.ts +5 -3
- package/src/generators/plugin/schema.json +9 -5
- package/src/generators/plugin/utils/normalize-schema.d.ts +8 -2
- package/src/generators/plugin/utils/normalize-schema.js +17 -0
- package/src/generators/preset/generator.d.ts +5 -3
- package/src/generators/preset/generator.js +46 -20
- package/src/generators/preset/schema.d.ts +9 -0
- package/src/generators/preset/schema.json +4 -0
- package/src/utils/paths.d.ts +2 -0
- package/src/utils/paths.js +31 -0
- /package/src/generators/executor/files/executor/{executor.ts.template → __fileName__.ts.template} +0 -0
- /package/src/generators/generator/files/generator/{generator.ts.template → __fileName__.ts.template} +0 -0
- /package/src/generators/migration/files/migration/{__name__.spec.ts__tmpl__ → __fileName__.spec.ts__tmpl__} +0 -0
- /package/src/generators/migration/files/migration/{__name__.ts__tmpl__ → __fileName__.ts__tmpl__} +0 -0
|
@@ -3,50 +3,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createGeneratorsJson = createGeneratorsJson;
|
|
4
4
|
exports.generatorGenerator = generatorGenerator;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
6
9
|
const has_generator_1 = require("../../utils/has-generator");
|
|
7
|
-
const
|
|
10
|
+
const paths_1 = require("../../utils/paths");
|
|
8
11
|
const versions_1 = require("../../utils/versions");
|
|
9
|
-
const
|
|
10
|
-
const path_1 = require("path");
|
|
12
|
+
const generator_1 = require("../lint-checks/generator");
|
|
11
13
|
async function normalizeOptions(tree, options) {
|
|
12
|
-
const {
|
|
13
|
-
name: options.name,
|
|
14
|
+
const { artifactName: name, directory, fileName, project, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
14
15
|
path: options.path,
|
|
15
|
-
|
|
16
|
+
name: options.name,
|
|
16
17
|
});
|
|
17
|
-
const { className, propertyName } = (0, devkit_1.names)(
|
|
18
|
+
const { className, propertyName } = (0, devkit_1.names)(name);
|
|
18
19
|
const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
19
20
|
let description;
|
|
20
21
|
if (options.description) {
|
|
21
22
|
description = options.description;
|
|
22
23
|
}
|
|
23
24
|
else {
|
|
24
|
-
description = `${
|
|
25
|
+
description = `${name} generator`;
|
|
25
26
|
}
|
|
26
27
|
return {
|
|
27
28
|
...options,
|
|
28
29
|
directory,
|
|
29
30
|
project,
|
|
31
|
+
name,
|
|
30
32
|
fileName,
|
|
31
33
|
className,
|
|
32
34
|
propertyName,
|
|
33
35
|
description,
|
|
34
36
|
projectRoot,
|
|
35
37
|
projectSourceRoot,
|
|
38
|
+
isTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree),
|
|
36
39
|
};
|
|
37
40
|
}
|
|
38
41
|
function addFiles(host, options) {
|
|
39
|
-
const indexPath = (0,
|
|
42
|
+
const indexPath = (0, node_path_1.join)(options.directory, 'files/src/index.ts.template');
|
|
40
43
|
if (!host.exists(indexPath)) {
|
|
41
44
|
host.write(indexPath, 'const variable = "<%= name %>";');
|
|
42
45
|
}
|
|
43
|
-
(0, devkit_1.generateFiles)(host, (0,
|
|
46
|
+
(0, devkit_1.generateFiles)(host, (0, node_path_1.join)(__dirname, './files/generator'), options.directory, {
|
|
44
47
|
...options,
|
|
45
48
|
generatorFnName: `${options.propertyName}Generator`,
|
|
46
49
|
schemaInterfaceName: `${options.className}GeneratorSchema`,
|
|
47
50
|
});
|
|
48
51
|
if (options.unitTestRunner === 'none') {
|
|
49
|
-
host.delete((0,
|
|
52
|
+
host.delete((0, node_path_1.join)(options.directory, `${options.fileName}.spec.ts`));
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
async function createGeneratorsJson(host, projectRoot, projectName, skipLintChecks, skipFormat) {
|
|
@@ -75,6 +78,14 @@ async function updateGeneratorJson(host, options) {
|
|
|
75
78
|
}
|
|
76
79
|
if (!host.exists(generatorsPath)) {
|
|
77
80
|
await createGeneratorsJson(host, options.projectRoot, options.project, options.skipLintChecks, options.skipFormat);
|
|
81
|
+
if (options.isTsSolutionSetup) {
|
|
82
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
|
|
83
|
+
const filesSet = new Set(json.files ?? ['dist', '!**/*.tsbuildinfo']);
|
|
84
|
+
filesSet.add('generators.json');
|
|
85
|
+
json.files = [...filesSet];
|
|
86
|
+
return json;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
78
89
|
}
|
|
79
90
|
// add dependencies
|
|
80
91
|
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
|
|
@@ -87,9 +98,10 @@ async function updateGeneratorJson(host, options) {
|
|
|
87
98
|
(0, devkit_1.updateJson)(host, generatorsPath, (json) => {
|
|
88
99
|
let generators = json.generators ?? json.schematics;
|
|
89
100
|
generators = generators || {};
|
|
101
|
+
const dir = (0, paths_1.getArtifactMetadataDirectory)(host, options.project, options.directory, options.isTsSolutionSetup);
|
|
90
102
|
generators[options.name] = {
|
|
91
|
-
factory:
|
|
92
|
-
schema:
|
|
103
|
+
factory: `${dir}/${options.fileName}`,
|
|
104
|
+
schema: `${dir}/schema.json`,
|
|
93
105
|
description: options.description,
|
|
94
106
|
};
|
|
95
107
|
// @todo(v17): Remove this, prop is defunct.
|
|
@@ -2,42 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.migrationGenerator = migrationGenerator;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
6
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
8
|
const package_json_1 = require("nx/src/utils/package-json");
|
|
9
|
+
const paths_1 = require("../../utils/paths");
|
|
9
10
|
const versions_1 = require("../../utils/versions");
|
|
10
|
-
const
|
|
11
|
+
const generator_1 = require("../lint-checks/generator");
|
|
11
12
|
async function normalizeOptions(tree, options) {
|
|
12
|
-
|
|
13
|
-
if (options.name) {
|
|
14
|
-
name = (0, devkit_1.names)(options.name).fileName;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
name = (0, devkit_1.names)(`update-${options.packageVersion}`).fileName;
|
|
18
|
-
}
|
|
19
|
-
const { project, fileName, artifactName, filePath, directory } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
20
|
-
name: name,
|
|
13
|
+
const { artifactName: name, directory, fileName, project, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
21
14
|
path: options.path,
|
|
22
|
-
|
|
15
|
+
name: options.name,
|
|
23
16
|
});
|
|
24
17
|
const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
25
18
|
const description = options.description ?? `Migration for v${options.packageVersion}`;
|
|
26
|
-
// const { root: projectRoot, sourceRoot: projectSourceRoot } =
|
|
27
|
-
// readProjectConfiguration(host, options.project);
|
|
28
19
|
const normalized = {
|
|
29
20
|
...options,
|
|
30
21
|
directory,
|
|
22
|
+
fileName,
|
|
31
23
|
project,
|
|
32
|
-
name
|
|
24
|
+
name,
|
|
33
25
|
description,
|
|
34
26
|
projectRoot,
|
|
35
27
|
projectSourceRoot,
|
|
28
|
+
isTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree),
|
|
36
29
|
};
|
|
37
30
|
return normalized;
|
|
38
31
|
}
|
|
39
32
|
function addFiles(host, options) {
|
|
40
|
-
(0, devkit_1.generateFiles)(host,
|
|
33
|
+
(0, devkit_1.generateFiles)(host, (0, node_path_1.join)(__dirname, 'files/migration'), options.directory, {
|
|
41
34
|
...options,
|
|
42
35
|
tmpl: '',
|
|
43
36
|
});
|
|
@@ -49,10 +42,11 @@ function updateMigrationsJson(host, options) {
|
|
|
49
42
|
? (0, devkit_1.readJson)(host, migrationsPath)
|
|
50
43
|
: {};
|
|
51
44
|
const generators = migrations.generators ?? {};
|
|
45
|
+
const dir = (0, paths_1.getArtifactMetadataDirectory)(host, options.project, options.directory, options.isTsSolutionSetup);
|
|
52
46
|
generators[options.name] = {
|
|
53
47
|
version: options.packageVersion,
|
|
54
48
|
description: options.description,
|
|
55
|
-
implementation:
|
|
49
|
+
implementation: `${dir}/${options.fileName}`,
|
|
56
50
|
};
|
|
57
51
|
migrations.generators = generators;
|
|
58
52
|
if (options.packageJsonUpdates) {
|
|
@@ -68,10 +62,17 @@ function updateMigrationsJson(host, options) {
|
|
|
68
62
|
(0, devkit_1.writeJson)(host, migrationsPath, migrations);
|
|
69
63
|
}
|
|
70
64
|
function updatePackageJson(host, options) {
|
|
71
|
-
(0, devkit_1.updateJson)(host,
|
|
65
|
+
(0, devkit_1.updateJson)(host, (0, node_path_1.join)(options.projectRoot, 'package.json'), (json) => {
|
|
66
|
+
const addFile = (file) => {
|
|
67
|
+
if (options.isTsSolutionSetup) {
|
|
68
|
+
const filesSet = new Set(json.files ?? ['dist', '!**/*.tsbuildinfo']);
|
|
69
|
+
filesSet.add(file.replace(/^\.\//, ''));
|
|
70
|
+
json.files = [...filesSet];
|
|
71
|
+
}
|
|
72
|
+
};
|
|
72
73
|
const migrationKey = json['ng-update'] ? 'ng-update' : 'nx-migrations';
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
if (typeof json[migrationKey] === 'string') {
|
|
75
|
+
addFile(json[migrationKey]);
|
|
75
76
|
return json;
|
|
76
77
|
}
|
|
77
78
|
else if (!json[migrationKey]) {
|
|
@@ -79,9 +80,10 @@ function updatePackageJson(host, options) {
|
|
|
79
80
|
migrations: './migrations.json',
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
|
-
else if (
|
|
83
|
-
|
|
83
|
+
else if (json[migrationKey].migrations) {
|
|
84
|
+
json[migrationKey].migrations = './migrations.json';
|
|
84
85
|
}
|
|
86
|
+
addFile(json[migrationKey].migrations);
|
|
85
87
|
// add dependencies
|
|
86
88
|
json.dependencies = {
|
|
87
89
|
'@nx/devkit': versions_1.nxVersion,
|
|
@@ -91,6 +93,9 @@ function updatePackageJson(host, options) {
|
|
|
91
93
|
});
|
|
92
94
|
}
|
|
93
95
|
function updateProjectConfig(host, options) {
|
|
96
|
+
if (options.isTsSolutionSetup) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
94
99
|
const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
95
100
|
const assets = project.targets.build?.options?.assets;
|
|
96
101
|
if (assets &&
|
|
@@ -109,10 +114,9 @@ function updateProjectConfig(host, options) {
|
|
|
109
114
|
async function migrationGenerator(host, schema) {
|
|
110
115
|
const options = await normalizeOptions(host, schema);
|
|
111
116
|
addFiles(host, options);
|
|
117
|
+
updatePackageJson(host, options);
|
|
112
118
|
updateMigrationsJson(host, options);
|
|
113
119
|
updateProjectConfig(host, options);
|
|
114
|
-
updateMigrationsJson(host, options);
|
|
115
|
-
updatePackageJson(host, options);
|
|
116
120
|
if (!host.exists('migrations.json')) {
|
|
117
121
|
const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
|
|
118
122
|
(0, generator_1.addMigrationJsonChecks)(host, { projectName: options.project }, (0, devkit_1.readJson)(host, packageJsonPath));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
2
|
import type { Schema } from './schema';
|
|
3
|
-
export declare function pluginGenerator(
|
|
3
|
+
export declare function pluginGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function pluginGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
5
|
export default pluginGenerator;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pluginGenerator = pluginGenerator;
|
|
4
|
+
exports.pluginGeneratorInternal = pluginGeneratorInternal;
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const eslint_1 = require("@nx/eslint");
|
|
5
7
|
const js_1 = require("@nx/js");
|
|
8
|
+
const package_manager_workspaces_1 = require("@nx/js/src/utils/package-manager-workspaces");
|
|
6
9
|
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
7
|
-
const
|
|
8
|
-
const eslint_1 = require("@nx/eslint");
|
|
10
|
+
const add_tslib_dependencies_1 = require("@nx/js/src/utils/typescript/add-tslib-dependencies");
|
|
9
11
|
const path = require("path");
|
|
10
12
|
const e2e_1 = require("../e2e-project/e2e");
|
|
11
13
|
const generator_1 = require("../lint-checks/generator");
|
|
12
14
|
const normalize_schema_1 = require("./utils/normalize-schema");
|
|
13
|
-
const add_tslib_dependencies_1 = require("@nx/js/src/utils/typescript/add-tslib-dependencies");
|
|
14
|
-
const add_swc_dependencies_2 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
15
15
|
const nxVersion = require('../../../package.json').version;
|
|
16
16
|
async function addFiles(host, options) {
|
|
17
17
|
host.delete((0, devkit_1.normalizePath)(`${options.projectRoot}/src/lib`));
|
|
@@ -23,36 +23,31 @@ async function addFiles(host, options) {
|
|
|
23
23
|
function updatePluginConfig(host, options) {
|
|
24
24
|
const project = (0, devkit_1.readProjectConfiguration)(host, options.name);
|
|
25
25
|
if (project.targets.build) {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
if (options.isTsSolutionSetup && options.bundler === 'tsc') {
|
|
27
|
+
project.targets.build.options.rootDir = project.sourceRoot;
|
|
28
|
+
project.targets.build.options.generatePackageJson = false;
|
|
29
|
+
}
|
|
28
30
|
project.targets.build.options.assets = [
|
|
29
|
-
...project.targets.build.options.assets,
|
|
30
|
-
{
|
|
31
|
-
input: `${root}/src`,
|
|
32
|
-
glob: '**/!(*.ts)',
|
|
33
|
-
output: './src',
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
input: `${root}/src`,
|
|
37
|
-
glob: '**/*.d.ts',
|
|
38
|
-
output: './src',
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
input: root,
|
|
42
|
-
glob: 'generators.json',
|
|
43
|
-
output: '.',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
input: root,
|
|
47
|
-
glob: 'executors.json',
|
|
48
|
-
output: '.',
|
|
49
|
-
},
|
|
31
|
+
...(project.targets.build.options.assets ?? []),
|
|
50
32
|
];
|
|
33
|
+
const root = options.projectRoot === '.' ? '.' : './' + options.projectRoot;
|
|
34
|
+
if (options.isTsSolutionSetup) {
|
|
35
|
+
project.targets.build.options.assets.push({ input: `${root}/src`, glob: '**/!(*.ts)', output: '.' }, { input: `${root}/src`, glob: '**/*.d.ts', output: '.' });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
project.targets.build.options.assets.push({ input: `${root}/src`, glob: '**/!(*.ts)', output: './src' }, { input: `${root}/src`, glob: '**/*.d.ts', output: './src' }, { input: root, glob: 'generators.json', output: '.' }, { input: root, glob: 'executors.json', output: '.' });
|
|
39
|
+
}
|
|
51
40
|
(0, devkit_1.updateProjectConfiguration)(host, options.name, project);
|
|
52
41
|
}
|
|
53
42
|
}
|
|
54
|
-
async function pluginGenerator(
|
|
55
|
-
|
|
43
|
+
async function pluginGenerator(tree, schema) {
|
|
44
|
+
return await pluginGeneratorInternal(tree, {
|
|
45
|
+
useProjectJson: true,
|
|
46
|
+
addPlugin: false,
|
|
47
|
+
...schema,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async function pluginGeneratorInternal(host, schema) {
|
|
56
51
|
const options = await (0, normalize_schema_1.normalizeOptions)(host, schema);
|
|
57
52
|
const tasks = [];
|
|
58
53
|
tasks.push(await (0, js_1.libraryGenerator)(host, {
|
|
@@ -63,7 +58,13 @@ async function pluginGenerator(host, schema) {
|
|
|
63
58
|
bundler: options.bundler,
|
|
64
59
|
publishable: options.publishable,
|
|
65
60
|
importPath: options.npmPackageName,
|
|
61
|
+
linter: options.linter,
|
|
62
|
+
unitTestRunner: options.unitTestRunner,
|
|
63
|
+
useProjectJson: options.useProjectJson,
|
|
64
|
+
addPlugin: options.addPlugin,
|
|
66
65
|
skipFormat: true,
|
|
66
|
+
skipWorkspacesWarning: true,
|
|
67
|
+
useTscExecutor: true,
|
|
67
68
|
}));
|
|
68
69
|
if (options.bundler === 'tsc') {
|
|
69
70
|
tasks.push((0, add_tslib_dependencies_1.addTsLibDependencies)(host));
|
|
@@ -78,7 +79,7 @@ async function pluginGenerator(host, schema) {
|
|
|
78
79
|
// Ensures Swc Deps are installed to handle running
|
|
79
80
|
// local plugin generators and executors
|
|
80
81
|
tasks.push((0, add_swc_dependencies_1.addSwcDependencies)(host));
|
|
81
|
-
tasks.push((0,
|
|
82
|
+
tasks.push((0, add_swc_dependencies_1.addSwcRegisterDependencies)(host));
|
|
82
83
|
await addFiles(host, options);
|
|
83
84
|
updatePluginConfig(host, options);
|
|
84
85
|
if (options.e2eTestRunner !== 'none') {
|
|
@@ -89,6 +90,10 @@ async function pluginGenerator(host, schema) {
|
|
|
89
90
|
npmPackageName: options.npmPackageName,
|
|
90
91
|
skipFormat: true,
|
|
91
92
|
rootProject: options.rootProject,
|
|
93
|
+
linter: options.linter,
|
|
94
|
+
useProjectJson: options.useProjectJson,
|
|
95
|
+
addPlugin: options.addPlugin,
|
|
96
|
+
skipWorkspacesWarning: true,
|
|
92
97
|
}));
|
|
93
98
|
}
|
|
94
99
|
if (options.linter === eslint_1.Linter.EsLint && !options.skipLintChecks) {
|
|
@@ -97,6 +102,12 @@ async function pluginGenerator(host, schema) {
|
|
|
97
102
|
if (!options.skipFormat) {
|
|
98
103
|
await (0, devkit_1.formatFiles)(host);
|
|
99
104
|
}
|
|
105
|
+
if (options.isTsSolutionSetup) {
|
|
106
|
+
const projectPackageManagerWorkspaceState = (0, package_manager_workspaces_1.getProjectPackageManagerWorkspaceState)(host, options.projectRoot);
|
|
107
|
+
if (projectPackageManagerWorkspaceState !== 'included') {
|
|
108
|
+
tasks.push((0, package_manager_workspaces_1.getProjectPackageManagerWorkspaceStateWarningTask)(projectPackageManagerWorkspaceState, host.root));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
100
111
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
101
112
|
}
|
|
102
113
|
exports.default = pluginGenerator;
|
|
@@ -9,10 +9,12 @@ export interface Schema {
|
|
|
9
9
|
skipLintChecks?: boolean; // default is false
|
|
10
10
|
e2eTestRunner?: 'jest' | 'none';
|
|
11
11
|
tags?: string;
|
|
12
|
-
unitTestRunner
|
|
13
|
-
linter
|
|
12
|
+
unitTestRunner?: 'jest' | 'none';
|
|
13
|
+
linter?: Linter | LinterType;
|
|
14
14
|
setParserOptionsProject?: boolean;
|
|
15
|
-
compiler
|
|
15
|
+
compiler?: 'swc' | 'tsc';
|
|
16
16
|
rootProject?: boolean;
|
|
17
17
|
publishable?: boolean;
|
|
18
|
+
useProjectJson?: boolean;
|
|
19
|
+
addPlugin?: boolean;
|
|
18
20
|
}
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"linter": {
|
|
35
35
|
"description": "The tool to use for running lint checks.",
|
|
36
36
|
"type": "string",
|
|
37
|
-
"enum": ["eslint"],
|
|
38
|
-
"
|
|
37
|
+
"enum": ["none", "eslint"],
|
|
38
|
+
"x-priority": "important"
|
|
39
39
|
},
|
|
40
40
|
"unitTestRunner": {
|
|
41
|
-
"type": "string",
|
|
42
|
-
"enum": ["jest", "none"],
|
|
43
41
|
"description": "Test runner to use for unit tests.",
|
|
44
|
-
"
|
|
42
|
+
"type": "string",
|
|
43
|
+
"enum": ["none", "jest"],
|
|
44
|
+
"x-priority": "important"
|
|
45
45
|
},
|
|
46
46
|
"tags": {
|
|
47
47
|
"type": "string",
|
|
@@ -92,6 +92,10 @@
|
|
|
92
92
|
"type": "boolean",
|
|
93
93
|
"description": "Generates a boilerplate for publishing the plugin to npm.",
|
|
94
94
|
"default": false
|
|
95
|
+
},
|
|
96
|
+
"useProjectJson": {
|
|
97
|
+
"type": "boolean",
|
|
98
|
+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
|
|
95
99
|
}
|
|
96
100
|
},
|
|
97
101
|
"required": ["directory"]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
|
2
|
-
import {
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
import type { LinterType } from '@nx/eslint';
|
|
3
|
+
import type { Schema } from '../schema';
|
|
3
4
|
export interface NormalizedSchema extends Schema {
|
|
4
5
|
name: string;
|
|
5
6
|
fileName: string;
|
|
@@ -9,5 +10,10 @@ export interface NormalizedSchema extends Schema {
|
|
|
9
10
|
npmPackageName: string;
|
|
10
11
|
bundler: 'swc' | 'tsc';
|
|
11
12
|
publishable: boolean;
|
|
13
|
+
unitTestRunner: 'jest' | 'none';
|
|
14
|
+
linter: LinterType;
|
|
15
|
+
useProjectJson: boolean;
|
|
16
|
+
addPlugin: boolean;
|
|
17
|
+
isTsSolutionSetup: boolean;
|
|
12
18
|
}
|
|
13
19
|
export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeOptions = normalizeOptions;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
5
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
6
|
+
const generator_prompts_1 = require("@nx/js/src/utils/generator-prompts");
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
5
8
|
async function normalizeOptions(host, options) {
|
|
9
|
+
const linter = await (0, generator_prompts_1.normalizeLinterOption)(host, options.linter);
|
|
10
|
+
const unitTestRunner = await (0, generator_prompts_1.normalizeUnitTestRunnerOption)(host, options.unitTestRunner, ['jest']);
|
|
11
|
+
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
12
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
13
|
+
const addPlugin = options.addPlugin ??
|
|
14
|
+
(isTsSolutionSetup &&
|
|
15
|
+
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
16
|
+
nxJson.useInferencePlugins !== false);
|
|
6
17
|
await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'application');
|
|
7
18
|
const { projectName, projectRoot, importPath: npmPackageName, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
8
19
|
name: options.name,
|
|
@@ -26,5 +37,11 @@ async function normalizeOptions(host, options) {
|
|
|
26
37
|
parsedTags,
|
|
27
38
|
npmPackageName,
|
|
28
39
|
publishable: options.publishable ?? false,
|
|
40
|
+
linter,
|
|
41
|
+
unitTestRunner,
|
|
42
|
+
// We default to generate a project.json file if the new setup is not being used
|
|
43
|
+
useProjectJson: options.useProjectJson ?? !isTsSolutionSetup,
|
|
44
|
+
addPlugin,
|
|
45
|
+
isTsSolutionSetup,
|
|
29
46
|
};
|
|
30
47
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
-
import { PresetGeneratorSchema } from './schema';
|
|
3
|
-
export
|
|
1
|
+
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
2
|
+
import type { PresetGeneratorSchema } from './schema';
|
|
3
|
+
export declare function presetGenerator(tree: Tree, rawOptions: PresetGeneratorSchema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function presetGeneratorInternal(tree: Tree, rawOptions: PresetGeneratorSchema): Promise<GeneratorCallback>;
|
|
5
|
+
export default presetGenerator;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.presetGenerator = presetGenerator;
|
|
4
|
+
exports.presetGeneratorInternal = presetGeneratorInternal;
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const eslint_1 = require("@nx/eslint");
|
|
6
6
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
7
|
-
const plugin_1 = require("../plugin/plugin");
|
|
8
7
|
const create_package_1 = require("../create-package/create-package");
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const plugin_1 = require("../plugin/plugin");
|
|
9
|
+
async function presetGenerator(tree, rawOptions) {
|
|
10
|
+
return await presetGeneratorInternal(tree, {
|
|
11
|
+
addPlugin: false,
|
|
12
|
+
useProjectJson: true,
|
|
13
|
+
...rawOptions,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async function presetGeneratorInternal(tree, rawOptions) {
|
|
11
17
|
const tasks = [];
|
|
12
|
-
const
|
|
13
|
-
? options.pluginName.split('/')[1]
|
|
14
|
-
: options.pluginName).fileName;
|
|
15
|
-
options.createPackageName =
|
|
16
|
-
options.createPackageName === 'false' // for command line in e2e, it is passed as a string
|
|
17
|
-
? undefined
|
|
18
|
-
: options.createPackageName;
|
|
18
|
+
const options = normalizeOptions(tree, rawOptions);
|
|
19
19
|
const pluginTask = await (0, plugin_1.pluginGenerator)(tree, {
|
|
20
20
|
compiler: 'tsc',
|
|
21
|
-
linter:
|
|
21
|
+
linter: 'eslint',
|
|
22
22
|
skipFormat: true,
|
|
23
23
|
unitTestRunner: 'jest',
|
|
24
24
|
importPath: options.pluginName,
|
|
@@ -26,23 +26,27 @@ async function default_1(tree, options) {
|
|
|
26
26
|
publishable: true,
|
|
27
27
|
// when creating a CLI package, the plugin will be in the packages folder
|
|
28
28
|
directory: options.createPackageName && options.createPackageName !== 'false'
|
|
29
|
-
? `packages/${
|
|
30
|
-
:
|
|
29
|
+
? `packages/${options.pluginName}`
|
|
30
|
+
: options.pluginName,
|
|
31
31
|
rootProject: options.createPackageName ? false : true,
|
|
32
|
+
useProjectJson: options.useProjectJson,
|
|
33
|
+
addPlugin: options.addPlugin,
|
|
32
34
|
});
|
|
33
35
|
tasks.push(pluginTask);
|
|
34
36
|
moveNxPluginToDevDeps(tree);
|
|
35
37
|
if (options.createPackageName) {
|
|
36
38
|
const e2eProject = `${options.pluginName}-e2e`;
|
|
37
|
-
const cliTask = await (0, create_package_1.
|
|
39
|
+
const cliTask = await (0, create_package_1.createPackageGenerator)(tree, {
|
|
38
40
|
directory: `packages/${options.createPackageName}`,
|
|
39
41
|
name: options.createPackageName,
|
|
40
42
|
e2eProject: e2eProject,
|
|
41
43
|
project: options.pluginName,
|
|
42
44
|
skipFormat: true,
|
|
43
45
|
unitTestRunner: 'jest',
|
|
44
|
-
linter:
|
|
46
|
+
linter: 'eslint',
|
|
45
47
|
compiler: 'tsc',
|
|
48
|
+
useProjectJson: options.useProjectJson,
|
|
49
|
+
addPlugin: options.addPlugin,
|
|
46
50
|
});
|
|
47
51
|
tasks.push(cliTask);
|
|
48
52
|
}
|
|
@@ -51,9 +55,31 @@ async function default_1(tree, options) {
|
|
|
51
55
|
}
|
|
52
56
|
function moveNxPluginToDevDeps(tree) {
|
|
53
57
|
(0, devkit_1.updateJson)(tree, 'package.json', (json) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
if (json.dependencies['@nx/plugin']) {
|
|
59
|
+
const nxPluginEntry = json.dependencies['@nx/plugin'];
|
|
60
|
+
delete json.dependencies['@nx/plugin'];
|
|
61
|
+
json.devDependencies['@nx/plugin'] = nxPluginEntry;
|
|
62
|
+
}
|
|
57
63
|
return json;
|
|
58
64
|
});
|
|
59
65
|
}
|
|
66
|
+
function normalizeOptions(tree, options) {
|
|
67
|
+
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
|
|
68
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
69
|
+
const addPlugin = options.addPlugin ??
|
|
70
|
+
(isTsSolutionSetup &&
|
|
71
|
+
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
72
|
+
nxJson.useInferencePlugins !== false);
|
|
73
|
+
return {
|
|
74
|
+
...options,
|
|
75
|
+
pluginName: (0, devkit_1.names)(options.pluginName.includes('/')
|
|
76
|
+
? options.pluginName.split('/')[1]
|
|
77
|
+
: options.pluginName).fileName,
|
|
78
|
+
createPackageName: options.createPackageName === 'false' // for command line in e2e, it is passed as a string
|
|
79
|
+
? undefined
|
|
80
|
+
: options.createPackageName,
|
|
81
|
+
addPlugin,
|
|
82
|
+
useProjectJson: options.useProjectJson ?? !isTsSolutionSetup,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
exports.default = presetGenerator;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
export interface PresetGeneratorSchema {
|
|
2
2
|
pluginName: string;
|
|
3
3
|
createPackageName?: string;
|
|
4
|
+
useProjectJson?: boolean;
|
|
5
|
+
addPlugin?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface NormalizedPresetGeneratorOptions
|
|
9
|
+
extends PresetGeneratorSchema {
|
|
10
|
+
createPackageName: string;
|
|
11
|
+
useProjectJson: boolean;
|
|
12
|
+
addPlugin: boolean;
|
|
4
13
|
}
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"createPackageName": {
|
|
25
25
|
"type": "string",
|
|
26
26
|
"description": "Name of package which creates a workspace"
|
|
27
|
+
},
|
|
28
|
+
"useProjectJson": {
|
|
29
|
+
"type": "boolean",
|
|
30
|
+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
|
|
27
31
|
}
|
|
28
32
|
},
|
|
29
33
|
"required": ["pluginName"]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getArtifactMetadataDirectory = getArtifactMetadataDirectory;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const posix_1 = require("node:path/posix");
|
|
6
|
+
function getArtifactMetadataDirectory(tree, projectName, sourceDirectory, isTsSolutionSetup) {
|
|
7
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
8
|
+
if (!isTsSolutionSetup) {
|
|
9
|
+
return `./${(0, posix_1.relative)(project.root, sourceDirectory)}`;
|
|
10
|
+
}
|
|
11
|
+
const target = Object.values(project.targets ?? {}).find((t) => t.executor === '@nx/js:tsc' || t.executor === '@nx/js:swc');
|
|
12
|
+
// the repo is using the new ts setup where the outputs are contained inside the project
|
|
13
|
+
if (target?.executor === '@nx/js:tsc') {
|
|
14
|
+
// the @nx/js:tsc executor defaults rootDir to the project root
|
|
15
|
+
return `./${(0, posix_1.join)('dist', (0, posix_1.relative)(target.options.rootDir ?? project.root, sourceDirectory))}`;
|
|
16
|
+
}
|
|
17
|
+
if (target?.executor === '@nx/js:swc') {
|
|
18
|
+
return `./${(0, posix_1.join)('dist', target.options.stripLeadingPaths
|
|
19
|
+
? (0, posix_1.relative)((0, posix_1.dirname)(target.options.main), sourceDirectory)
|
|
20
|
+
: (0, posix_1.relative)(project.root, sourceDirectory))}`;
|
|
21
|
+
}
|
|
22
|
+
// We generate the plugin with the executors above, so we shouldn't get here
|
|
23
|
+
// unless the user manually changed the build process. In that case, we can't
|
|
24
|
+
// reliably determine the output directory because it depends on the build
|
|
25
|
+
// tool, so we'll just assume some defaults.
|
|
26
|
+
const baseDir = project.sourceRoot ??
|
|
27
|
+
(tree.exists((0, posix_1.join)(project.root, 'src'))
|
|
28
|
+
? (0, posix_1.join)(project.root, 'src')
|
|
29
|
+
: project.root);
|
|
30
|
+
return `./${(0, posix_1.join)('dist', (0, posix_1.relative)(baseDir, sourceDirectory))}`;
|
|
31
|
+
}
|
/package/src/generators/executor/files/executor/{executor.ts.template → __fileName__.ts.template}
RENAMED
|
File without changes
|
/package/src/generators/generator/files/generator/{generator.ts.template → __fileName__.ts.template}
RENAMED
|
File without changes
|
|
File without changes
|
/package/src/generators/migration/files/migration/{__name__.ts__tmpl__ → __fileName__.ts__tmpl__}
RENAMED
|
File without changes
|