@nx/plugin 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca
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/LICENSE +1 -1
- package/README.md +1 -1
- package/generators.json +4 -4
- package/migrations.json +1 -20
- package/package.json +5 -6
- package/src/generators/create-package/create-package.js +40 -15
- package/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +11 -7
- package/src/generators/create-package/files/e2e/__cliName__.spec.ts__tmpl__ +8 -6
- package/src/generators/create-package/schema.d.ts +8 -7
- package/src/generators/create-package/schema.json +16 -19
- package/src/generators/create-package/utils/normalize-schema.d.ts +6 -0
- package/src/generators/create-package/utils/normalize-schema.js +21 -4
- package/src/generators/e2e-project/e2e.d.ts +1 -2
- package/src/generators/e2e-project/e2e.js +67 -32
- package/src/generators/e2e-project/files/src/{__pluginName__.spec.ts__tmpl__ → __simplePluginName__.spec.ts__tmpl__} +9 -7
- package/src/generators/e2e-project/schema.d.ts +1 -2
- package/src/generators/e2e-project/schema.json +5 -7
- package/src/generators/executor/executor.d.ts +2 -3
- package/src/generators/executor/executor.js +31 -29
- package/src/generators/executor/files/executor/{executor.spec.ts.template → __fileName__.spec.ts.template} +11 -2
- package/src/generators/executor/schema.d.ts +3 -11
- package/src/generators/executor/schema.json +7 -29
- package/src/generators/generator/files/generator/{generator.spec.ts.template → __fileName__.spec.ts.template} +1 -1
- package/src/generators/generator/generator.d.ts +1 -2
- package/src/generators/generator/generator.js +30 -28
- package/src/generators/generator/schema.d.ts +3 -11
- package/src/generators/generator/schema.json +17 -25
- package/src/generators/migration/migration.d.ts +2 -3
- package/src/generators/migration/migration.js +39 -43
- package/src/generators/migration/schema.d.ts +1 -9
- package/src/generators/migration/schema.json +16 -22
- package/src/generators/plugin/plugin.d.ts +1 -1
- package/src/generators/plugin/plugin.js +42 -41
- package/src/generators/plugin/schema.d.ts +7 -7
- package/src/generators/plugin/schema.json +16 -18
- package/src/generators/plugin/utils/normalize-schema.d.ts +10 -4
- package/src/generators/plugin/utils/normalize-schema.js +21 -17
- package/src/generators/preset/generator.d.ts +5 -3
- package/src/generators/preset/generator.js +48 -21
- 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/utils/testing-utils/async-commands.js +1 -1
- package/src/utils/testing-utils/commands.js +1 -1
- package/src/utils/testing-utils/nx-project.js +2 -2
- package/src/migrations/update-16-0-0/cli-in-schema-json.d.ts +0 -3
- package/src/migrations/update-16-0-0/cli-in-schema-json.js +0 -134
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-2-0/replace-e2e-executor.d.ts +0 -7
- package/src/migrations/update-16-2-0/replace-e2e-executor.js +0 -32
- /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
|
@@ -10,7 +10,7 @@ describe('<%= pluginName %>', () => {
|
|
|
10
10
|
|
|
11
11
|
// The plugin has been built and published to a local registry in the jest globalSetup
|
|
12
12
|
// Install the plugin built with the latest source code into the test repo
|
|
13
|
-
execSync(`<%= packageManagerCommands.
|
|
13
|
+
execSync(`<%= packageManagerCommands.addDev %> <%= pluginPackageName %>@e2e`, {
|
|
14
14
|
cwd: projectDirectory,
|
|
15
15
|
stdio: 'inherit',
|
|
16
16
|
env: process.env,
|
|
@@ -18,11 +18,13 @@ describe('<%= pluginName %>', () => {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
afterAll(() => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
if (projectDirectory) {
|
|
22
|
+
// Cleanup the test project
|
|
23
|
+
rmSync(projectDirectory, {
|
|
24
|
+
recursive: true,
|
|
25
|
+
force: true,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
26
28
|
});
|
|
27
29
|
|
|
28
30
|
|
|
@@ -53,7 +55,7 @@ function createTestProject() {
|
|
|
53
55
|
});
|
|
54
56
|
|
|
55
57
|
execSync(
|
|
56
|
-
`<%= packageManagerCommands.
|
|
58
|
+
`<%= packageManagerCommands.dlx %> create-nx-workspace@latest ${projectName} --preset apps --nxCloud=skip --no-interactive`,
|
|
57
59
|
{
|
|
58
60
|
cwd: dirname(projectDirectory),
|
|
59
61
|
stdio: 'inherit',
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
1
|
import type { Linter, LinterType } from '@nx/eslint';
|
|
3
2
|
|
|
4
3
|
export interface Schema {
|
|
5
4
|
pluginName: string;
|
|
6
5
|
npmPackageName: string;
|
|
7
6
|
projectDirectory?: string;
|
|
8
|
-
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
9
7
|
pluginOutputPath?: string;
|
|
10
8
|
jestConfig?: string;
|
|
11
9
|
linter?: Linter | LinterType;
|
|
12
10
|
skipFormat?: boolean;
|
|
13
11
|
rootProject?: boolean;
|
|
12
|
+
useProjectJson?: boolean;
|
|
14
13
|
addPlugin?: boolean;
|
|
15
14
|
}
|
|
@@ -21,11 +21,6 @@
|
|
|
21
21
|
"type": "string",
|
|
22
22
|
"description": "the directory where the plugin is placed."
|
|
23
23
|
},
|
|
24
|
-
"projectNameAndRootFormat": {
|
|
25
|
-
"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`).",
|
|
26
|
-
"type": "string",
|
|
27
|
-
"enum": ["as-provided", "derived"]
|
|
28
|
-
},
|
|
29
24
|
"pluginOutputPath": {
|
|
30
25
|
"type": "string",
|
|
31
26
|
"description": "the output path of the plugin after it builds.",
|
|
@@ -38,8 +33,7 @@
|
|
|
38
33
|
"linter": {
|
|
39
34
|
"description": "The tool to use for running lint checks.",
|
|
40
35
|
"type": "string",
|
|
41
|
-
"enum": ["
|
|
42
|
-
"default": "eslint"
|
|
36
|
+
"enum": ["none", "eslint"]
|
|
43
37
|
},
|
|
44
38
|
"minimal": {
|
|
45
39
|
"type": "boolean",
|
|
@@ -51,6 +45,10 @@
|
|
|
51
45
|
"type": "boolean",
|
|
52
46
|
"default": false,
|
|
53
47
|
"x-priority": "internal"
|
|
48
|
+
},
|
|
49
|
+
"useProjectJson": {
|
|
50
|
+
"type": "boolean",
|
|
51
|
+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
|
|
54
52
|
}
|
|
55
53
|
},
|
|
56
54
|
"required": ["pluginName", "npmPackageName"]
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
2
|
import type { Schema } from './schema';
|
|
3
3
|
export declare function createExecutorsJson(host: Tree, projectRoot: string, projectName: string, skipLintChecks?: boolean): Promise<void>;
|
|
4
|
-
export declare function executorGenerator(
|
|
5
|
-
export declare function executorGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
|
|
4
|
+
export declare function executorGenerator(host: Tree, schema: Schema): Promise<void>;
|
|
6
5
|
export default executorGenerator;
|
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createExecutorsJson = createExecutorsJson;
|
|
4
4
|
exports.executorGenerator = executorGenerator;
|
|
5
|
-
exports.executorGeneratorInternal = executorGeneratorInternal;
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
const path = require("path");
|
|
8
|
-
const generator_1 = require("../lint-checks/generator");
|
|
9
|
-
const versions_1 = require("../../utils/versions");
|
|
10
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");
|
|
11
8
|
const path_1 = require("path");
|
|
9
|
+
const paths_1 = require("../../utils/paths");
|
|
10
|
+
const versions_1 = require("../../utils/versions");
|
|
11
|
+
const generator_1 = require("../lint-checks/generator");
|
|
12
12
|
function addFiles(host, options) {
|
|
13
|
-
(0, devkit_1.generateFiles)(host,
|
|
13
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files/executor'), options.directory, {
|
|
14
14
|
...options,
|
|
15
15
|
});
|
|
16
16
|
if (options.unitTestRunner === 'none') {
|
|
17
|
-
host.delete((0, devkit_1.joinPathFragments)(options.directory,
|
|
17
|
+
host.delete((0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.spec.ts`));
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
function addHasherFiles(host, options) {
|
|
21
|
-
(0, devkit_1.generateFiles)(host,
|
|
21
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files/hasher'), options.directory, {
|
|
22
22
|
...options,
|
|
23
23
|
});
|
|
24
24
|
if (options.unitTestRunner === 'none') {
|
|
@@ -50,6 +50,14 @@ async function updateExecutorJson(host, options) {
|
|
|
50
50
|
}
|
|
51
51
|
if (!host.exists(executorsPath)) {
|
|
52
52
|
await createExecutorsJson(host, options.projectRoot, options.project, options.skipLintChecks);
|
|
53
|
+
if (options.isTsSolutionSetup) {
|
|
54
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
|
|
55
|
+
const filesSet = new Set(json.files ?? ['dist', '!**/*.tsbuildinfo']);
|
|
56
|
+
filesSet.add('executors.json');
|
|
57
|
+
json.files = [...filesSet];
|
|
58
|
+
return json;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
53
61
|
}
|
|
54
62
|
// add dependencies
|
|
55
63
|
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
|
|
@@ -62,56 +70,50 @@ async function updateExecutorJson(host, options) {
|
|
|
62
70
|
return (0, devkit_1.updateJson)(host, executorsPath, (json) => {
|
|
63
71
|
let executors = json.executors ?? json.builders;
|
|
64
72
|
executors ||= {};
|
|
73
|
+
const dir = (0, paths_1.getArtifactMetadataDirectory)(host, options.project, options.directory, options.isTsSolutionSetup);
|
|
65
74
|
executors[options.name] = {
|
|
66
|
-
implementation:
|
|
67
|
-
schema:
|
|
75
|
+
implementation: `${dir}/${options.fileName}`,
|
|
76
|
+
schema: `${dir}/schema.json`,
|
|
68
77
|
description: options.description,
|
|
69
78
|
};
|
|
70
79
|
if (options.includeHasher) {
|
|
71
|
-
executors[options.name].hasher =
|
|
80
|
+
executors[options.name].hasher = `${dir}/hasher`;
|
|
72
81
|
}
|
|
73
82
|
json.executors = executors;
|
|
74
83
|
return json;
|
|
75
84
|
});
|
|
76
85
|
}
|
|
77
86
|
async function normalizeOptions(tree, options) {
|
|
78
|
-
const {
|
|
79
|
-
|
|
80
|
-
callingGenerator: '@nx/plugin:executor',
|
|
87
|
+
const { artifactName: name, directory, fileName, project, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
88
|
+
path: options.path,
|
|
81
89
|
name: options.name,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
directory: options.directory,
|
|
85
|
-
fileName: 'executor',
|
|
86
|
-
derivedDirectory: 'executors',
|
|
90
|
+
allowedFileExtensions: ['ts'],
|
|
91
|
+
fileExtension: 'ts',
|
|
87
92
|
});
|
|
88
|
-
const { className, propertyName } = (0, devkit_1.names)(
|
|
89
|
-
const { root: projectRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
93
|
+
const { className, propertyName } = (0, devkit_1.names)(name);
|
|
94
|
+
const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
90
95
|
let description;
|
|
91
96
|
if (options.description) {
|
|
92
97
|
description = options.description;
|
|
93
98
|
}
|
|
94
99
|
else {
|
|
95
|
-
description = `${
|
|
100
|
+
description = `${name} executor`;
|
|
96
101
|
}
|
|
97
102
|
return {
|
|
98
103
|
...options,
|
|
99
|
-
|
|
104
|
+
fileName,
|
|
100
105
|
project,
|
|
101
106
|
directory,
|
|
107
|
+
name,
|
|
102
108
|
className,
|
|
103
109
|
propertyName,
|
|
104
110
|
description,
|
|
105
111
|
projectRoot,
|
|
112
|
+
projectSourceRoot: projectSourceRoot ?? (0, path_1.join)(projectRoot, 'src'),
|
|
113
|
+
isTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree),
|
|
106
114
|
};
|
|
107
115
|
}
|
|
108
|
-
async function executorGenerator(
|
|
109
|
-
await executorGeneratorInternal(tree, {
|
|
110
|
-
nameAndDirectoryFormat: 'derived',
|
|
111
|
-
...rawOptions,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
async function executorGeneratorInternal(host, schema) {
|
|
116
|
+
async function executorGenerator(host, schema) {
|
|
115
117
|
const options = await normalizeOptions(host, schema);
|
|
116
118
|
addFiles(host, options);
|
|
117
119
|
if (options.includeHasher) {
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
|
|
3
3
|
import { <%= className %>ExecutorSchema } from './schema';
|
|
4
|
-
import executor from '
|
|
4
|
+
import executor from './<%= fileName %>';
|
|
5
5
|
|
|
6
6
|
const options: <%= className %>ExecutorSchema = {};
|
|
7
7
|
const context: ExecutorContext = {
|
|
8
8
|
root: '',
|
|
9
9
|
cwd: process.cwd(),
|
|
10
10
|
isVerbose: false,
|
|
11
|
+
projectGraph: {
|
|
12
|
+
nodes: {},
|
|
13
|
+
dependencies: {},
|
|
14
|
+
},
|
|
15
|
+
projectsConfigurations: {
|
|
16
|
+
projects: {},
|
|
17
|
+
version: 2,
|
|
18
|
+
},
|
|
19
|
+
nxJsonConfiguration: {},
|
|
11
20
|
};
|
|
12
21
|
|
|
13
22
|
describe('<%= className %> Executor', () => {
|
|
@@ -15,4 +24,4 @@ describe('<%= className %> Executor', () => {
|
|
|
15
24
|
const output = await executor(options, context);
|
|
16
25
|
expect(output.success).toBe(true);
|
|
17
26
|
});
|
|
18
|
-
});
|
|
27
|
+
});
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
|
2
|
-
|
|
3
1
|
export interface Schema {
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
path: string;
|
|
3
|
+
name?: string;
|
|
6
4
|
description?: string;
|
|
7
|
-
unitTestRunner: 'jest' | 'none';
|
|
5
|
+
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
8
6
|
includeHasher: boolean;
|
|
9
|
-
nameAndDirectoryFormat?: NameAndDirectoryFormat;
|
|
10
7
|
skipLintChecks?: boolean;
|
|
11
8
|
skipFormat?: boolean;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v20.
|
|
15
|
-
*/
|
|
16
|
-
project?: string;
|
|
17
9
|
}
|
|
@@ -6,28 +6,20 @@
|
|
|
6
6
|
"description": "Create an Executor for an Nx Plugin.",
|
|
7
7
|
"examplesFile": "../../../docs/generators/executor-examples.md",
|
|
8
8
|
"type": "object",
|
|
9
|
-
"examples": [
|
|
10
|
-
{
|
|
11
|
-
"command": "nx g executor my-executor --project=my-plugin",
|
|
12
|
-
"description": "Generate `libs/my-plugin/src/executors/my-executor`"
|
|
13
|
-
}
|
|
14
|
-
],
|
|
15
9
|
"properties": {
|
|
16
|
-
"
|
|
10
|
+
"path": {
|
|
17
11
|
"type": "string",
|
|
18
|
-
"description": "
|
|
12
|
+
"description": "The file path to the executor. Relative to the current working directory.",
|
|
13
|
+
"x-prompt": "What is the executor file path?",
|
|
19
14
|
"$default": {
|
|
20
15
|
"$source": "argv",
|
|
21
16
|
"index": 0
|
|
22
17
|
},
|
|
23
|
-
"x-prompt": "What name would you like to use for the executor?",
|
|
24
18
|
"x-priority": "important"
|
|
25
19
|
},
|
|
26
|
-
"
|
|
20
|
+
"name": {
|
|
27
21
|
"type": "string",
|
|
28
|
-
"description": "The
|
|
29
|
-
"aliases": ["dir"],
|
|
30
|
-
"x-priority": "important"
|
|
22
|
+
"description": "The executor name to export in the plugin executors collection."
|
|
31
23
|
},
|
|
32
24
|
"description": {
|
|
33
25
|
"type": "string",
|
|
@@ -36,7 +28,7 @@
|
|
|
36
28
|
},
|
|
37
29
|
"unitTestRunner": {
|
|
38
30
|
"type": "string",
|
|
39
|
-
"enum": ["jest", "none"],
|
|
31
|
+
"enum": ["jest", "vitest", "none"],
|
|
40
32
|
"description": "Test runner to use for unit tests.",
|
|
41
33
|
"default": "jest"
|
|
42
34
|
},
|
|
@@ -50,20 +42,6 @@
|
|
|
50
42
|
"default": false,
|
|
51
43
|
"description": "Do not add an eslint configuration for plugin json files."
|
|
52
44
|
},
|
|
53
|
-
"nameAndDirectoryFormat": {
|
|
54
|
-
"description": "Whether to generate the executor in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
|
|
55
|
-
"type": "string",
|
|
56
|
-
"enum": ["as-provided", "derived"]
|
|
57
|
-
},
|
|
58
|
-
"project": {
|
|
59
|
-
"type": "string",
|
|
60
|
-
"description": "The name of the project.",
|
|
61
|
-
"alias": "p",
|
|
62
|
-
"$default": {
|
|
63
|
-
"$source": "projectName"
|
|
64
|
-
},
|
|
65
|
-
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v20."
|
|
66
|
-
},
|
|
67
45
|
"skipFormat": {
|
|
68
46
|
"type": "boolean",
|
|
69
47
|
"description": "Skip formatting files.",
|
|
@@ -71,6 +49,6 @@
|
|
|
71
49
|
"x-priority": "internal"
|
|
72
50
|
}
|
|
73
51
|
},
|
|
74
|
-
"required": ["
|
|
52
|
+
"required": ["path"],
|
|
75
53
|
"additionalProperties": false
|
|
76
54
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
2
2
|
import { Tree, readProjectConfiguration } from '@nx/devkit';
|
|
3
3
|
|
|
4
|
-
import { <%= generatorFnName %> } from '
|
|
4
|
+
import { <%= generatorFnName %> } from './<%= fileName %>';
|
|
5
5
|
import { <%= schemaInterfaceName %> } from './schema';
|
|
6
6
|
|
|
7
7
|
describe('<%= name %> generator', () => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import type { Schema } from './schema';
|
|
3
3
|
export declare function createGeneratorsJson(host: Tree, projectRoot: string, projectName: string, skipLintChecks?: boolean, skipFormat?: boolean): Promise<void>;
|
|
4
|
-
export declare function generatorGenerator(
|
|
5
|
-
export declare function generatorGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
|
|
4
|
+
export declare function generatorGenerator(host: Tree, schema: Schema): Promise<void>;
|
|
6
5
|
export default generatorGenerator;
|
|
@@ -2,57 +2,56 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createGeneratorsJson = createGeneratorsJson;
|
|
4
4
|
exports.generatorGenerator = generatorGenerator;
|
|
5
|
-
exports.generatorGeneratorInternal = generatorGeneratorInternal;
|
|
6
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");
|
|
7
9
|
const has_generator_1 = require("../../utils/has-generator");
|
|
8
|
-
const
|
|
10
|
+
const paths_1 = require("../../utils/paths");
|
|
9
11
|
const versions_1 = require("../../utils/versions");
|
|
10
|
-
const
|
|
11
|
-
const path_1 = require("path");
|
|
12
|
+
const generator_1 = require("../lint-checks/generator");
|
|
12
13
|
async function normalizeOptions(tree, options) {
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
callingGenerator: '@nx/plugin:generator',
|
|
14
|
+
const { artifactName: name, directory, fileName, project, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
15
|
+
path: options.path,
|
|
16
16
|
name: options.name,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
directory: options.directory,
|
|
20
|
-
fileName: 'generator',
|
|
21
|
-
derivedDirectory: 'generators',
|
|
17
|
+
allowedFileExtensions: ['ts'],
|
|
18
|
+
fileExtension: 'ts',
|
|
22
19
|
});
|
|
23
|
-
const { className, propertyName } = (0, devkit_1.names)(
|
|
20
|
+
const { className, propertyName } = (0, devkit_1.names)(name);
|
|
24
21
|
const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
25
22
|
let description;
|
|
26
23
|
if (options.description) {
|
|
27
24
|
description = options.description;
|
|
28
25
|
}
|
|
29
26
|
else {
|
|
30
|
-
description = `${
|
|
27
|
+
description = `${name} generator`;
|
|
31
28
|
}
|
|
32
29
|
return {
|
|
33
30
|
...options,
|
|
34
|
-
project,
|
|
35
31
|
directory,
|
|
32
|
+
project,
|
|
33
|
+
name,
|
|
36
34
|
fileName,
|
|
37
35
|
className,
|
|
38
36
|
propertyName,
|
|
39
37
|
description,
|
|
40
38
|
projectRoot,
|
|
41
|
-
projectSourceRoot,
|
|
39
|
+
projectSourceRoot: projectSourceRoot ?? (0, node_path_1.join)(projectRoot, 'src'),
|
|
40
|
+
isTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree),
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
43
|
function addFiles(host, options) {
|
|
45
|
-
const indexPath = (0,
|
|
44
|
+
const indexPath = (0, node_path_1.join)(options.directory, 'files/src/index.ts.template');
|
|
46
45
|
if (!host.exists(indexPath)) {
|
|
47
46
|
host.write(indexPath, 'const variable = "<%= name %>";');
|
|
48
47
|
}
|
|
49
|
-
(0, devkit_1.generateFiles)(host, (0,
|
|
48
|
+
(0, devkit_1.generateFiles)(host, (0, node_path_1.join)(__dirname, './files/generator'), options.directory, {
|
|
50
49
|
...options,
|
|
51
50
|
generatorFnName: `${options.propertyName}Generator`,
|
|
52
51
|
schemaInterfaceName: `${options.className}GeneratorSchema`,
|
|
53
52
|
});
|
|
54
53
|
if (options.unitTestRunner === 'none') {
|
|
55
|
-
host.delete((0,
|
|
54
|
+
host.delete((0, node_path_1.join)(options.directory, `${options.fileName}.spec.ts`));
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
async function createGeneratorsJson(host, projectRoot, projectName, skipLintChecks, skipFormat) {
|
|
@@ -81,6 +80,14 @@ async function updateGeneratorJson(host, options) {
|
|
|
81
80
|
}
|
|
82
81
|
if (!host.exists(generatorsPath)) {
|
|
83
82
|
await createGeneratorsJson(host, options.projectRoot, options.project, options.skipLintChecks, options.skipFormat);
|
|
83
|
+
if (options.isTsSolutionSetup) {
|
|
84
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
|
|
85
|
+
const filesSet = new Set(json.files ?? ['dist', '!**/*.tsbuildinfo']);
|
|
86
|
+
filesSet.add('generators.json');
|
|
87
|
+
json.files = [...filesSet];
|
|
88
|
+
return json;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
84
91
|
}
|
|
85
92
|
// add dependencies
|
|
86
93
|
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
|
|
@@ -93,9 +100,10 @@ async function updateGeneratorJson(host, options) {
|
|
|
93
100
|
(0, devkit_1.updateJson)(host, generatorsPath, (json) => {
|
|
94
101
|
let generators = json.generators ?? json.schematics;
|
|
95
102
|
generators = generators || {};
|
|
103
|
+
const dir = (0, paths_1.getArtifactMetadataDirectory)(host, options.project, options.directory, options.isTsSolutionSetup);
|
|
96
104
|
generators[options.name] = {
|
|
97
|
-
factory:
|
|
98
|
-
schema:
|
|
105
|
+
factory: `${dir}/${options.fileName}`,
|
|
106
|
+
schema: `${dir}/schema.json`,
|
|
99
107
|
description: options.description,
|
|
100
108
|
};
|
|
101
109
|
// @todo(v17): Remove this, prop is defunct.
|
|
@@ -106,13 +114,7 @@ async function updateGeneratorJson(host, options) {
|
|
|
106
114
|
return json;
|
|
107
115
|
});
|
|
108
116
|
}
|
|
109
|
-
async function generatorGenerator(
|
|
110
|
-
await generatorGeneratorInternal(tree, {
|
|
111
|
-
nameAndDirectoryFormat: 'derived',
|
|
112
|
-
...rawOptions,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
async function generatorGeneratorInternal(host, schema) {
|
|
117
|
+
async function generatorGenerator(host, schema) {
|
|
116
118
|
const options = await normalizeOptions(host, schema);
|
|
117
119
|
if ((0, has_generator_1.hasGenerator)(host, options.project, options.name)) {
|
|
118
120
|
throw new Error(`Generator ${options.name} already exists.`);
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
|
2
|
-
|
|
3
1
|
export interface Schema {
|
|
4
|
-
|
|
5
|
-
name
|
|
2
|
+
path: string;
|
|
3
|
+
name?: string;
|
|
6
4
|
description?: string;
|
|
7
|
-
unitTestRunner: 'jest' | 'none';
|
|
5
|
+
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
8
6
|
skipLintChecks?: boolean;
|
|
9
7
|
skipFormat?: boolean;
|
|
10
|
-
nameAndDirectoryFormat?: NameAndDirectoryFormat;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v20.
|
|
14
|
-
*/
|
|
15
|
-
project?: string;
|
|
16
8
|
}
|
|
@@ -7,26 +7,32 @@
|
|
|
7
7
|
"type": "object",
|
|
8
8
|
"examples": [
|
|
9
9
|
{
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"description": "Generate a generator exported with the name matching the file name. It results in the generator `foo` at `mylib/src/generators/foo.ts`",
|
|
11
|
+
"command": "nx g @nx/plugin:generator mylib/src/generators/foo.ts"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"description": "Generate a generator without providing the file extension. It results in the generator `foo` at `mylib/src/generators/foo.ts`",
|
|
15
|
+
"command": "nx g @nx/plugin:generator mylib/src/generators/foo"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"description": "Generate a generator exported with a different name from the file name. It results in the generator `custom` at `mylib/src/generators/foo.ts`",
|
|
19
|
+
"command": "nx g @nx/plugin:generator mylib/src/generators/foo --name=custom"
|
|
12
20
|
}
|
|
13
21
|
],
|
|
14
22
|
"properties": {
|
|
15
|
-
"
|
|
23
|
+
"path": {
|
|
16
24
|
"type": "string",
|
|
17
|
-
"description": "
|
|
25
|
+
"description": "The file path to the generator. Relative to the current working directory.",
|
|
18
26
|
"$default": {
|
|
19
27
|
"$source": "argv",
|
|
20
28
|
"index": 0
|
|
21
29
|
},
|
|
22
|
-
"x-prompt": "What
|
|
30
|
+
"x-prompt": "What is the generator file path?",
|
|
23
31
|
"x-priority": "important"
|
|
24
32
|
},
|
|
25
|
-
"
|
|
33
|
+
"name": {
|
|
26
34
|
"type": "string",
|
|
27
|
-
"description": "The
|
|
28
|
-
"aliases": ["dir"],
|
|
29
|
-
"x-priority": "important"
|
|
35
|
+
"description": "The generator name to export in the plugin generators collection."
|
|
30
36
|
},
|
|
31
37
|
"description": {
|
|
32
38
|
"type": "string",
|
|
@@ -35,7 +41,7 @@
|
|
|
35
41
|
},
|
|
36
42
|
"unitTestRunner": {
|
|
37
43
|
"type": "string",
|
|
38
|
-
"enum": ["jest", "none"],
|
|
44
|
+
"enum": ["jest", "vitest", "none"],
|
|
39
45
|
"description": "Test runner to use for unit tests.",
|
|
40
46
|
"default": "jest"
|
|
41
47
|
},
|
|
@@ -44,27 +50,13 @@
|
|
|
44
50
|
"default": false,
|
|
45
51
|
"description": "Do not add an eslint configuration for plugin json files."
|
|
46
52
|
},
|
|
47
|
-
"project": {
|
|
48
|
-
"type": "string",
|
|
49
|
-
"description": "The name of the project.",
|
|
50
|
-
"alias": "p",
|
|
51
|
-
"$default": {
|
|
52
|
-
"$source": "projectName"
|
|
53
|
-
},
|
|
54
|
-
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v20."
|
|
55
|
-
},
|
|
56
53
|
"skipFormat": {
|
|
57
54
|
"type": "boolean",
|
|
58
55
|
"default": false,
|
|
59
56
|
"description": "Do not format files with prettier.",
|
|
60
57
|
"x-priority": "internal"
|
|
61
|
-
},
|
|
62
|
-
"nameAndDirectoryFormat": {
|
|
63
|
-
"description": "Whether to generate the generator in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
|
|
64
|
-
"type": "string",
|
|
65
|
-
"enum": ["as-provided", "derived"]
|
|
66
58
|
}
|
|
67
59
|
},
|
|
68
|
-
"required": ["
|
|
60
|
+
"required": ["path"],
|
|
69
61
|
"additionalProperties": false
|
|
70
62
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
2
|
import type { Schema } from './schema';
|
|
3
|
-
export declare function migrationGenerator(
|
|
4
|
-
export declare function migrationGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
|
|
3
|
+
export declare function migrationGenerator(host: Tree, schema: Schema): Promise<void>;
|
|
5
4
|
export default migrationGenerator;
|