@nx/plugin 0.0.0-pr-22179-271588f
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 +22 -0
- package/README.md +72 -0
- package/executors.json +10 -0
- package/generators.d.ts +6 -0
- package/generators.js +9 -0
- package/generators.json +49 -0
- package/index.d.ts +0 -0
- package/index.js +0 -0
- package/migrations.json +40 -0
- package/package.json +44 -0
- package/src/executors/e2e/e2e.impl.d.ts +6 -0
- package/src/executors/e2e/e2e.impl.js +43 -0
- package/src/executors/e2e/schema.d.ts +6 -0
- package/src/executors/e2e/schema.json +220 -0
- package/src/generators/create-package/create-package.d.ts +5 -0
- package/src/generators/create-package/create-package.js +112 -0
- package/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +27 -0
- package/src/generators/create-package/files/e2e/__cliName__.spec.ts__tmpl__ +56 -0
- package/src/generators/create-package/schema.d.ts +19 -0
- package/src/generators/create-package/schema.json +79 -0
- package/src/generators/create-package/utils/normalize-schema.d.ts +8 -0
- package/src/generators/create-package/utils/normalize-schema.js +22 -0
- package/src/generators/e2e-project/e2e.d.ts +6 -0
- package/src/generators/e2e-project/e2e.js +144 -0
- package/src/generators/e2e-project/files/src/__pluginName__.spec.ts__tmpl__ +66 -0
- package/src/generators/e2e-project/files/tsconfig.json__tmpl__ +6 -0
- package/src/generators/e2e-project/schema.d.ts +15 -0
- package/src/generators/e2e-project/schema.json +57 -0
- package/src/generators/executor/executor.d.ts +6 -0
- package/src/generators/executor/executor.js +126 -0
- package/src/generators/executor/files/executor/executor.spec.ts.template +11 -0
- package/src/generators/executor/files/executor/executor.ts.template +11 -0
- package/src/generators/executor/files/executor/schema.d.ts.template +1 -0
- package/src/generators/executor/files/executor/schema.json.template +9 -0
- package/src/generators/executor/files/hasher/hasher.spec.ts.template +23 -0
- package/src/generators/executor/files/hasher/hasher.ts.template +12 -0
- package/src/generators/executor/schema.d.ts +17 -0
- package/src/generators/executor/schema.json +76 -0
- package/src/generators/generator/files/generator/generator.spec.ts.template +20 -0
- package/src/generators/generator/files/generator/generator.ts.template +26 -0
- package/src/generators/generator/files/generator/schema.d.ts.template +3 -0
- package/src/generators/generator/files/generator/schema.json.template +18 -0
- package/src/generators/generator/generator.d.ts +6 -0
- package/src/generators/generator/generator.js +127 -0
- package/src/generators/generator/schema.d.ts +16 -0
- package/src/generators/generator/schema.json +70 -0
- package/src/generators/lint-checks/generator.d.ts +7 -0
- package/src/generators/lint-checks/generator.js +187 -0
- package/src/generators/lint-checks/schema.d.ts +4 -0
- package/src/generators/lint-checks/schema.json +31 -0
- package/src/generators/migration/files/migration/__name__.spec.ts__tmpl__ +17 -0
- package/src/generators/migration/files/migration/__name__.ts__tmpl__ +6 -0
- package/src/generators/migration/migration.d.ts +5 -0
- package/src/generators/migration/migration.js +135 -0
- package/src/generators/migration/schema.d.ts +16 -0
- package/src/generators/migration/schema.json +68 -0
- package/src/generators/plugin/files/plugin/src/index.ts__tmpl__ +0 -0
- package/src/generators/plugin/plugin.d.ts +5 -0
- package/src/generators/plugin/plugin.js +107 -0
- package/src/generators/plugin/schema.d.ts +20 -0
- package/src/generators/plugin/schema.json +104 -0
- package/src/generators/plugin/utils/normalize-schema.d.ts +13 -0
- package/src/generators/plugin/utils/normalize-schema.js +44 -0
- package/src/generators/preset/generator.d.ts +3 -0
- package/src/generators/preset/generator.js +58 -0
- package/src/generators/preset/schema.d.ts +4 -0
- package/src/generators/preset/schema.json +30 -0
- package/src/migrations/update-15-0-0/specify-output-capture.d.ts +2 -0
- package/src/migrations/update-15-0-0/specify-output-capture.js +53 -0
- package/src/migrations/update-15-9-0/jest-29-configs.d.ts +3 -0
- package/src/migrations/update-15-9-0/jest-29-configs.js +147 -0
- package/src/migrations/update-15-9-0/jest-29-tests.d.ts +5 -0
- package/src/migrations/update-15-9-0/jest-29-tests.js +61 -0
- package/src/migrations/update-16-0-0/cli-in-schema-json.d.ts +3 -0
- package/src/migrations/update-16-0-0/cli-in-schema-json.js +135 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-2-0/replace-e2e-executor.d.ts +2 -0
- package/src/migrations/update-16-2-0/replace-e2e-executor.js +32 -0
- package/src/utils/has-generator.d.ts +2 -0
- package/src/utils/has-generator.js +16 -0
- package/src/utils/testing-utils/async-commands.d.ts +28 -0
- package/src/utils/testing-utils/async-commands.js +50 -0
- package/src/utils/testing-utils/commands.d.ts +17 -0
- package/src/utils/testing-utils/commands.js +63 -0
- package/src/utils/testing-utils/index.d.ts +5 -0
- package/src/utils/testing-utils/index.js +8 -0
- package/src/utils/testing-utils/nx-project.d.ts +25 -0
- package/src/utils/testing-utils/nx-project.js +70 -0
- package/src/utils/testing-utils/paths.d.ts +15 -0
- package/src/utils/testing-utils/paths.js +32 -0
- package/src/utils/testing-utils/utils.d.ts +80 -0
- package/src/utils/testing-utils/utils.js +144 -0
- package/src/utils/versions.d.ts +2 -0
- package/src/utils/versions.js +5 -0
- package/testing.d.ts +1 -0
- package/testing.js +4 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executorGeneratorInternal = exports.executorGenerator = exports.createExecutorsJson = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const generator_1 = require("../lint-checks/generator");
|
|
7
|
+
const versions_1 = require("../../utils/versions");
|
|
8
|
+
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
function addFiles(host, options) {
|
|
11
|
+
(0, devkit_1.generateFiles)(host, path.join(__dirname, './files/executor'), options.directory, {
|
|
12
|
+
...options,
|
|
13
|
+
});
|
|
14
|
+
if (options.unitTestRunner === 'none') {
|
|
15
|
+
host.delete((0, devkit_1.joinPathFragments)(options.directory, `executor.spec.ts`));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function addHasherFiles(host, options) {
|
|
19
|
+
(0, devkit_1.generateFiles)(host, path.join(__dirname, './files/hasher'), options.directory, {
|
|
20
|
+
...options,
|
|
21
|
+
});
|
|
22
|
+
if (options.unitTestRunner === 'none') {
|
|
23
|
+
host.delete((0, devkit_1.joinPathFragments)(options.directory, 'hasher.spec.ts'));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function createExecutorsJson(host, projectRoot, projectName, skipLintChecks) {
|
|
27
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'), (json) => {
|
|
28
|
+
json.executors ??= './executors.json';
|
|
29
|
+
return json;
|
|
30
|
+
});
|
|
31
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'executors.json'), {
|
|
32
|
+
executors: {},
|
|
33
|
+
});
|
|
34
|
+
if (!skipLintChecks) {
|
|
35
|
+
await (0, generator_1.default)(host, {
|
|
36
|
+
projectName,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.createExecutorsJson = createExecutorsJson;
|
|
41
|
+
async function updateExecutorJson(host, options) {
|
|
42
|
+
const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'));
|
|
43
|
+
const packageJsonExecutors = packageJson.executors ?? packageJson.builders;
|
|
44
|
+
let executorsPath = packageJsonExecutors
|
|
45
|
+
? (0, devkit_1.joinPathFragments)(options.projectRoot, packageJsonExecutors)
|
|
46
|
+
: null;
|
|
47
|
+
if (!executorsPath) {
|
|
48
|
+
executorsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'executors.json');
|
|
49
|
+
}
|
|
50
|
+
if (!host.exists(executorsPath)) {
|
|
51
|
+
await createExecutorsJson(host, options.projectRoot, options.project, options.skipLintChecks);
|
|
52
|
+
}
|
|
53
|
+
// add dependencies
|
|
54
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
|
|
55
|
+
json.dependencies = {
|
|
56
|
+
'@nx/devkit': versions_1.nxVersion,
|
|
57
|
+
...json.dependencies,
|
|
58
|
+
};
|
|
59
|
+
return json;
|
|
60
|
+
});
|
|
61
|
+
return (0, devkit_1.updateJson)(host, executorsPath, (json) => {
|
|
62
|
+
let executors = json.executors ?? json.builders;
|
|
63
|
+
executors ||= {};
|
|
64
|
+
executors[options.name] = {
|
|
65
|
+
implementation: `./${(0, devkit_1.joinPathFragments)((0, path_1.relative)(options.projectRoot, options.directory), 'executor')}`,
|
|
66
|
+
schema: `./${(0, devkit_1.joinPathFragments)((0, path_1.relative)(options.projectRoot, options.directory), 'schema.json')}`,
|
|
67
|
+
description: options.description,
|
|
68
|
+
};
|
|
69
|
+
if (options.includeHasher) {
|
|
70
|
+
executors[options.name].hasher = `./${(0, devkit_1.joinPathFragments)((0, path_1.relative)(options.projectRoot, options.directory), 'hasher')}`;
|
|
71
|
+
}
|
|
72
|
+
json.executors = executors;
|
|
73
|
+
return json;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async function normalizeOptions(tree, options) {
|
|
77
|
+
const { project, artifactName, filePath, directory } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
78
|
+
artifactType: 'executor',
|
|
79
|
+
callingGenerator: '@nx/plugin:executor',
|
|
80
|
+
name: options.name,
|
|
81
|
+
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
|
82
|
+
project: options.project,
|
|
83
|
+
directory: options.directory,
|
|
84
|
+
fileName: 'executor',
|
|
85
|
+
derivedDirectory: 'executors',
|
|
86
|
+
});
|
|
87
|
+
const { className, propertyName } = (0, devkit_1.names)(artifactName);
|
|
88
|
+
const { root: projectRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
89
|
+
let description;
|
|
90
|
+
if (options.description) {
|
|
91
|
+
description = options.description;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
description = `${options.name} executor`;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
...options,
|
|
98
|
+
filePath,
|
|
99
|
+
project,
|
|
100
|
+
directory,
|
|
101
|
+
className,
|
|
102
|
+
propertyName,
|
|
103
|
+
description,
|
|
104
|
+
projectRoot,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async function executorGenerator(tree, rawOptions) {
|
|
108
|
+
await executorGeneratorInternal(tree, {
|
|
109
|
+
nameAndDirectoryFormat: 'derived',
|
|
110
|
+
...rawOptions,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
exports.executorGenerator = executorGenerator;
|
|
114
|
+
async function executorGeneratorInternal(host, schema) {
|
|
115
|
+
const options = await normalizeOptions(host, schema);
|
|
116
|
+
addFiles(host, options);
|
|
117
|
+
if (options.includeHasher) {
|
|
118
|
+
addHasherFiles(host, options);
|
|
119
|
+
}
|
|
120
|
+
await updateExecutorJson(host, options);
|
|
121
|
+
if (!schema.skipFormat) {
|
|
122
|
+
await (0, devkit_1.formatFiles)(host);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.executorGeneratorInternal = executorGeneratorInternal;
|
|
126
|
+
exports.default = executorGenerator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { <%= className %>ExecutorSchema } from './schema';
|
|
2
|
+
import executor from './executor';
|
|
3
|
+
|
|
4
|
+
const options: <%= className %>ExecutorSchema = {};
|
|
5
|
+
|
|
6
|
+
describe('<%= className %> Executor', () => {
|
|
7
|
+
it('can run', async () => {
|
|
8
|
+
const output = await executor(options);
|
|
9
|
+
expect(output.success).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export interface <%= className %>ExecutorSchema {} // eslint-disable-line
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TaskHasher, HasherContext } from '@nx/devkit';
|
|
2
|
+
|
|
3
|
+
import { <%=propertyName%>Hasher } from './hasher';
|
|
4
|
+
|
|
5
|
+
describe('<%=propertyName%>Hasher', () => {
|
|
6
|
+
it('should generate hash', async () => {
|
|
7
|
+
const mockHasher: TaskHasher = {
|
|
8
|
+
hashTask: jest.fn().mockReturnValue({value: 'hashed-task'})
|
|
9
|
+
} as unknown as TaskHasher
|
|
10
|
+
const hash = await <%=propertyName%>Hasher({
|
|
11
|
+
id: 'my-task-id',
|
|
12
|
+
target: {
|
|
13
|
+
project: 'proj',
|
|
14
|
+
target: 'target'
|
|
15
|
+
},
|
|
16
|
+
overrides: {},
|
|
17
|
+
outputs: []
|
|
18
|
+
}, {
|
|
19
|
+
hasher: mockHasher
|
|
20
|
+
} as unknown as HasherContext)
|
|
21
|
+
expect(hash).toEqual({value: 'hashed-task'})
|
|
22
|
+
})
|
|
23
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CustomHasher } from '@nx/devkit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is a boilerplate custom hasher that matches
|
|
5
|
+
* the default Nx hasher. If you need to extend the behavior,
|
|
6
|
+
* you can consume workspace details from the context.
|
|
7
|
+
*/
|
|
8
|
+
export const <%=propertyName%>Hasher: CustomHasher = async (task, context) => {
|
|
9
|
+
return context.hasher.hashTask(task, context.taskGraph);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default <%=propertyName%>Hasher;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
|
2
|
+
|
|
3
|
+
export interface Schema {
|
|
4
|
+
name: string;
|
|
5
|
+
directory?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
unitTestRunner: 'jest' | 'none';
|
|
8
|
+
includeHasher: boolean;
|
|
9
|
+
nameAndDirectoryFormat?: NameAndDirectoryFormat;
|
|
10
|
+
skipLintChecks?: boolean;
|
|
11
|
+
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 v19.
|
|
15
|
+
*/
|
|
16
|
+
project?: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxPluginExecutor",
|
|
5
|
+
"title": "Create an Executor for an Nx Plugin",
|
|
6
|
+
"description": "Create an Executor for an Nx Plugin.",
|
|
7
|
+
"examplesFile": "../../../docs/generators/executor-examples.md",
|
|
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
|
+
"properties": {
|
|
16
|
+
"name": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Executor name.",
|
|
19
|
+
"$default": {
|
|
20
|
+
"$source": "argv",
|
|
21
|
+
"index": 0
|
|
22
|
+
},
|
|
23
|
+
"x-prompt": "What name would you like to use for the executor?",
|
|
24
|
+
"x-priority": "important"
|
|
25
|
+
},
|
|
26
|
+
"directory": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "The directory at which to create the executor file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
|
29
|
+
"aliases": ["dir"],
|
|
30
|
+
"x-priority": "important"
|
|
31
|
+
},
|
|
32
|
+
"description": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"description": "Executor description.",
|
|
35
|
+
"x-priority": "important"
|
|
36
|
+
},
|
|
37
|
+
"unitTestRunner": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"enum": ["jest", "none"],
|
|
40
|
+
"description": "Test runner to use for unit tests.",
|
|
41
|
+
"default": "jest"
|
|
42
|
+
},
|
|
43
|
+
"includeHasher": {
|
|
44
|
+
"type": "boolean",
|
|
45
|
+
"default": false,
|
|
46
|
+
"description": "Should the boilerplate for a custom hasher be generated?"
|
|
47
|
+
},
|
|
48
|
+
"skipLintChecks": {
|
|
49
|
+
"type": "boolean",
|
|
50
|
+
"default": false,
|
|
51
|
+
"description": "Do not add an eslint configuration for plugin json files."
|
|
52
|
+
},
|
|
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 v19."
|
|
66
|
+
},
|
|
67
|
+
"skipFormat": {
|
|
68
|
+
"type": "boolean",
|
|
69
|
+
"description": "Skip formatting files.",
|
|
70
|
+
"default": false,
|
|
71
|
+
"x-priority": "internal"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"required": ["name"],
|
|
75
|
+
"additionalProperties": false
|
|
76
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
2
|
+
import { Tree, readProjectConfiguration } from '@nx/devkit';
|
|
3
|
+
|
|
4
|
+
import { <%= generatorFnName %> } from './generator';
|
|
5
|
+
import { <%= schemaInterfaceName %> } from './schema';
|
|
6
|
+
|
|
7
|
+
describe('<%= name %> generator', () => {
|
|
8
|
+
let tree: Tree;
|
|
9
|
+
const options: <%= schemaInterfaceName %> = { name: 'test' };
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
tree = createTreeWithEmptyWorkspace();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should run successfully', async () => {
|
|
16
|
+
await <%= generatorFnName %>(tree, options);
|
|
17
|
+
const config = readProjectConfiguration(tree, 'test');
|
|
18
|
+
expect(config).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addProjectConfiguration,
|
|
3
|
+
formatFiles,
|
|
4
|
+
generateFiles,
|
|
5
|
+
Tree,
|
|
6
|
+
} from '@nx/devkit';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { <%= className %>GeneratorSchema } from './schema';
|
|
9
|
+
|
|
10
|
+
export async function <%= generatorFnName %> (tree: Tree, options: <%= schemaInterfaceName %>) {
|
|
11
|
+
const projectRoot = `libs/${options.name}`;
|
|
12
|
+
addProjectConfiguration(
|
|
13
|
+
tree,
|
|
14
|
+
options.name,
|
|
15
|
+
{
|
|
16
|
+
root: projectRoot,
|
|
17
|
+
projectType: 'library',
|
|
18
|
+
sourceRoot: `${projectRoot}/src`,
|
|
19
|
+
targets: {}
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
generateFiles(tree, path.join(__dirname, 'files'), projectRoot, options);
|
|
23
|
+
await formatFiles(tree);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default <%= generatorFnName %>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "<%= className %>",
|
|
4
|
+
"title": "",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "argv",
|
|
12
|
+
"index": 0
|
|
13
|
+
},
|
|
14
|
+
"x-prompt": "What name would you like to use?"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"required": ["name"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import type { Schema } from './schema';
|
|
3
|
+
export declare function createGeneratorsJson(host: Tree, projectRoot: string, projectName: string, skipLintChecks?: boolean, skipFormat?: boolean): Promise<void>;
|
|
4
|
+
export declare function generatorGenerator(tree: Tree, rawOptions: Schema): Promise<void>;
|
|
5
|
+
export declare function generatorGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
|
|
6
|
+
export default generatorGenerator;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generatorGeneratorInternal = exports.generatorGenerator = exports.createGeneratorsJson = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const has_generator_1 = require("../../utils/has-generator");
|
|
6
|
+
const generator_1 = require("../lint-checks/generator");
|
|
7
|
+
const versions_1 = require("../../utils/versions");
|
|
8
|
+
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
async function normalizeOptions(tree, options) {
|
|
11
|
+
const { project, fileName, artifactName, filePath, directory } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
12
|
+
artifactType: 'generator',
|
|
13
|
+
callingGenerator: '@nx/plugin:generator',
|
|
14
|
+
name: options.name,
|
|
15
|
+
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
|
16
|
+
project: options.project,
|
|
17
|
+
directory: options.directory,
|
|
18
|
+
fileName: 'generator',
|
|
19
|
+
derivedDirectory: 'generators',
|
|
20
|
+
});
|
|
21
|
+
const { className, propertyName } = (0, devkit_1.names)(artifactName);
|
|
22
|
+
const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
23
|
+
let description;
|
|
24
|
+
if (options.description) {
|
|
25
|
+
description = options.description;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
description = `${options.name} generator`;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
...options,
|
|
32
|
+
project,
|
|
33
|
+
directory,
|
|
34
|
+
fileName,
|
|
35
|
+
className,
|
|
36
|
+
propertyName,
|
|
37
|
+
description,
|
|
38
|
+
projectRoot,
|
|
39
|
+
projectSourceRoot,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function addFiles(host, options) {
|
|
43
|
+
const indexPath = (0, path_1.join)(options.directory, 'files/src/index.ts.template');
|
|
44
|
+
if (!host.exists(indexPath)) {
|
|
45
|
+
host.write(indexPath, 'const variable = "<%= name %>";');
|
|
46
|
+
}
|
|
47
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files/generator'), options.directory, {
|
|
48
|
+
...options,
|
|
49
|
+
generatorFnName: `${options.propertyName}Generator`,
|
|
50
|
+
schemaInterfaceName: `${options.className}GeneratorSchema`,
|
|
51
|
+
});
|
|
52
|
+
if (options.unitTestRunner === 'none') {
|
|
53
|
+
host.delete((0, path_1.join)(options.directory, `generator.spec.ts`));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function createGeneratorsJson(host, projectRoot, projectName, skipLintChecks, skipFormat) {
|
|
57
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'), (json) => {
|
|
58
|
+
json.generators ??= './generators.json';
|
|
59
|
+
return json;
|
|
60
|
+
});
|
|
61
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'generators.json'), {
|
|
62
|
+
generators: {},
|
|
63
|
+
});
|
|
64
|
+
if (!skipLintChecks) {
|
|
65
|
+
await (0, generator_1.default)(host, {
|
|
66
|
+
projectName,
|
|
67
|
+
skipFormat,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.createGeneratorsJson = createGeneratorsJson;
|
|
72
|
+
async function updateGeneratorJson(host, options) {
|
|
73
|
+
const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'));
|
|
74
|
+
const packageJsonGenerators = packageJson.generators ?? packageJson.schematics;
|
|
75
|
+
let generatorsPath = packageJsonGenerators
|
|
76
|
+
? (0, devkit_1.joinPathFragments)(options.projectRoot, packageJsonGenerators)
|
|
77
|
+
: null;
|
|
78
|
+
if (!generatorsPath) {
|
|
79
|
+
generatorsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'generators.json');
|
|
80
|
+
}
|
|
81
|
+
if (!host.exists(generatorsPath)) {
|
|
82
|
+
await createGeneratorsJson(host, options.projectRoot, options.project, options.skipLintChecks, options.skipFormat);
|
|
83
|
+
}
|
|
84
|
+
// add dependencies
|
|
85
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (json) => {
|
|
86
|
+
json.dependencies = {
|
|
87
|
+
'@nx/devkit': versions_1.nxVersion,
|
|
88
|
+
...json.dependencies,
|
|
89
|
+
};
|
|
90
|
+
return json;
|
|
91
|
+
});
|
|
92
|
+
(0, devkit_1.updateJson)(host, generatorsPath, (json) => {
|
|
93
|
+
let generators = json.generators ?? json.schematics;
|
|
94
|
+
generators = generators || {};
|
|
95
|
+
generators[options.name] = {
|
|
96
|
+
factory: `./${(0, devkit_1.joinPathFragments)((0, path_1.relative)(options.projectRoot, options.directory), 'generator')}`,
|
|
97
|
+
schema: `./${(0, devkit_1.joinPathFragments)((0, path_1.relative)(options.projectRoot, options.directory), 'schema.json')}`,
|
|
98
|
+
description: options.description,
|
|
99
|
+
};
|
|
100
|
+
// @todo(v17): Remove this, prop is defunct.
|
|
101
|
+
if (options.name === 'preset') {
|
|
102
|
+
generators[options.name]['x-use-standalone-layout'] = true;
|
|
103
|
+
}
|
|
104
|
+
json.generators = generators;
|
|
105
|
+
return json;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async function generatorGenerator(tree, rawOptions) {
|
|
109
|
+
await generatorGeneratorInternal(tree, {
|
|
110
|
+
nameAndDirectoryFormat: 'derived',
|
|
111
|
+
...rawOptions,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
exports.generatorGenerator = generatorGenerator;
|
|
115
|
+
async function generatorGeneratorInternal(host, schema) {
|
|
116
|
+
const options = await normalizeOptions(host, schema);
|
|
117
|
+
if ((0, has_generator_1.hasGenerator)(host, options.project, options.name)) {
|
|
118
|
+
throw new Error(`Generator ${options.name} already exists.`);
|
|
119
|
+
}
|
|
120
|
+
addFiles(host, options);
|
|
121
|
+
await updateGeneratorJson(host, options);
|
|
122
|
+
if (!options.skipFormat) {
|
|
123
|
+
await (0, devkit_1.formatFiles)(host);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.generatorGeneratorInternal = generatorGeneratorInternal;
|
|
127
|
+
exports.default = generatorGenerator;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
|
2
|
+
|
|
3
|
+
export interface Schema {
|
|
4
|
+
directory?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
unitTestRunner: 'jest' | 'none';
|
|
8
|
+
skipLintChecks?: boolean;
|
|
9
|
+
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 v19.
|
|
14
|
+
*/
|
|
15
|
+
project?: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxPluginGenerator",
|
|
5
|
+
"title": "Create a Generator for an Nx Plugin",
|
|
6
|
+
"description": "Create a Generator for an Nx Plugin.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"command": "nx g generator my-generator --project=my-plugin",
|
|
11
|
+
"description": "Generate `libs/my-plugin/src/generators/my-generator`"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"properties": {
|
|
15
|
+
"name": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "Generator name.",
|
|
18
|
+
"$default": {
|
|
19
|
+
"$source": "argv",
|
|
20
|
+
"index": 0
|
|
21
|
+
},
|
|
22
|
+
"x-prompt": "What name would you like to use for the generator?",
|
|
23
|
+
"x-priority": "important"
|
|
24
|
+
},
|
|
25
|
+
"directory": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "The directory at which to create the generator file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
|
28
|
+
"aliases": ["dir"],
|
|
29
|
+
"x-priority": "important"
|
|
30
|
+
},
|
|
31
|
+
"description": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"description": "Generator description.",
|
|
34
|
+
"x-priority": "important"
|
|
35
|
+
},
|
|
36
|
+
"unitTestRunner": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"enum": ["jest", "none"],
|
|
39
|
+
"description": "Test runner to use for unit tests.",
|
|
40
|
+
"default": "jest"
|
|
41
|
+
},
|
|
42
|
+
"skipLintChecks": {
|
|
43
|
+
"type": "boolean",
|
|
44
|
+
"default": false,
|
|
45
|
+
"description": "Do not add an eslint configuration for plugin json files."
|
|
46
|
+
},
|
|
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 v19."
|
|
55
|
+
},
|
|
56
|
+
"skipFormat": {
|
|
57
|
+
"type": "boolean",
|
|
58
|
+
"default": false,
|
|
59
|
+
"description": "Do not format files with prettier.",
|
|
60
|
+
"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
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"required": ["name"],
|
|
69
|
+
"additionalProperties": false
|
|
70
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ProjectConfiguration, TargetConfiguration, Tree } from '@nx/devkit';
|
|
2
|
+
import type { Schema as EsLintExecutorOptions } from '@nx/eslint/src/executors/lint/schema';
|
|
3
|
+
import { PluginLintChecksGeneratorSchema } from './schema';
|
|
4
|
+
import { PackageJson } from 'nx/src/utils/package-json';
|
|
5
|
+
export default function pluginLintCheckGenerator(host: Tree, options: PluginLintChecksGeneratorSchema): Promise<void>;
|
|
6
|
+
export declare function addMigrationJsonChecks(host: Tree, options: PluginLintChecksGeneratorSchema, packageJson: PackageJson): void;
|
|
7
|
+
export declare function getEsLintOptions(project: ProjectConfiguration): [target: string, configuration: TargetConfiguration<EsLintExecutorOptions>];
|