@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,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEsLintOptions = exports.addMigrationJsonChecks = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const logger_1 = require("nx/src/utils/logger");
|
|
6
|
+
const package_json_1 = require("nx/src/utils/package-json");
|
|
7
|
+
const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
|
|
8
|
+
const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
|
|
9
|
+
async function pluginLintCheckGenerator(host, options) {
|
|
10
|
+
const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
11
|
+
const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(project.root, 'package.json'));
|
|
12
|
+
// This rule is eslint **only**
|
|
13
|
+
if (projectIsEsLintEnabled(host, project)) {
|
|
14
|
+
updateRootEslintConfig(host);
|
|
15
|
+
updateProjectEslintConfig(host, project, packageJson);
|
|
16
|
+
updateProjectTarget(host, options, packageJson);
|
|
17
|
+
// Project is setup for vscode
|
|
18
|
+
if (host.exists('.vscode')) {
|
|
19
|
+
setupVsCodeLintingForJsonFiles(host);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
devkit_1.logger.error(`${logger_1.NX_PREFIX} plugin lint checks can only be added to plugins which use eslint for linting`);
|
|
24
|
+
}
|
|
25
|
+
if (!options.skipFormat) {
|
|
26
|
+
await (0, devkit_1.formatFiles)(host);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.default = pluginLintCheckGenerator;
|
|
30
|
+
function addMigrationJsonChecks(host, options, packageJson) {
|
|
31
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
32
|
+
if (!projectIsEsLintEnabled(host, projectConfiguration)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const [eslintTarget, eslintTargetConfiguration] = getEsLintOptions(projectConfiguration) ?? [];
|
|
36
|
+
const relativeMigrationsJsonPath = (0, package_json_1.readNxMigrateConfig)(packageJson).migrations;
|
|
37
|
+
if (!relativeMigrationsJsonPath) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const migrationsJsonPath = (0, devkit_1.joinPathFragments)(projectConfiguration.root, relativeMigrationsJsonPath);
|
|
41
|
+
if (!eslintTarget) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Add path to lintFilePatterns if different than default "{projectRoot}"
|
|
45
|
+
if (eslintTargetConfiguration.options?.lintFilePatterns &&
|
|
46
|
+
!eslintTargetConfiguration.options.lintFilePatterns.includes(migrationsJsonPath)) {
|
|
47
|
+
eslintTargetConfiguration.options.lintFilePatterns.push(migrationsJsonPath);
|
|
48
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
|
|
49
|
+
}
|
|
50
|
+
// Update project level eslintrc
|
|
51
|
+
(0, eslint_file_1.updateOverrideInLintConfig)(host, projectConfiguration.root, (o) => Object.keys(o.rules ?? {})?.includes('@nx/nx-plugin-checks') ||
|
|
52
|
+
Object.keys(o.rules ?? {})?.includes('@nrwl/nx/nx-plugin-checks'), (o) => {
|
|
53
|
+
const fileSet = new Set(Array.isArray(o.files) ? o.files : [o.files]);
|
|
54
|
+
fileSet.add(relativeMigrationsJsonPath);
|
|
55
|
+
return {
|
|
56
|
+
...o,
|
|
57
|
+
files: Array.from(fileSet),
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.addMigrationJsonChecks = addMigrationJsonChecks;
|
|
62
|
+
function updateProjectTarget(host, options, packageJson) {
|
|
63
|
+
const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
64
|
+
if (!project.targets) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
for (const [target, configuration] of Object.entries(project.targets)) {
|
|
68
|
+
if (configuration.executor === '@nx/eslint:lint' &&
|
|
69
|
+
// only add patterns if there are already hardcoded ones
|
|
70
|
+
configuration.options?.lintFilePatterns) {
|
|
71
|
+
const opts = configuration.options ?? {};
|
|
72
|
+
opts.lintFilePatterns ??= [];
|
|
73
|
+
if (packageJson.generators) {
|
|
74
|
+
opts.lintFilePatterns.push((0, devkit_1.joinPathFragments)(project.root, packageJson.generators));
|
|
75
|
+
}
|
|
76
|
+
if (packageJson.schematics &&
|
|
77
|
+
packageJson.schematics !== packageJson.generators) {
|
|
78
|
+
opts.lintFilePatterns.push((0, devkit_1.joinPathFragments)(project.root, packageJson.schematics));
|
|
79
|
+
}
|
|
80
|
+
if (packageJson.executors) {
|
|
81
|
+
opts.lintFilePatterns.push((0, devkit_1.joinPathFragments)(project.root, packageJson.executors));
|
|
82
|
+
}
|
|
83
|
+
if (packageJson.builders &&
|
|
84
|
+
packageJson.builders !== packageJson.executors) {
|
|
85
|
+
opts.lintFilePatterns.push((0, devkit_1.joinPathFragments)(project.root, packageJson.builders));
|
|
86
|
+
}
|
|
87
|
+
opts.lintFilePatterns.push(`${project.root}/package.json`);
|
|
88
|
+
opts.lintFilePatterns = [...new Set(opts.lintFilePatterns)];
|
|
89
|
+
project.targets[target].options = opts;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, project);
|
|
93
|
+
}
|
|
94
|
+
function updateProjectEslintConfig(host, options, packageJson) {
|
|
95
|
+
if ((0, eslint_file_1.isEslintConfigSupported)(host, options.root)) {
|
|
96
|
+
const lookup = (o) => Object.keys(o.rules ?? {}).includes('@nx/nx-plugin-checks') ||
|
|
97
|
+
Object.keys(o.rules ?? {}).includes('@nrwl/nx/nx-plugin-checks');
|
|
98
|
+
const files = [
|
|
99
|
+
'./package.json',
|
|
100
|
+
packageJson.generators,
|
|
101
|
+
packageJson.executors,
|
|
102
|
+
packageJson.schematics,
|
|
103
|
+
packageJson.builders,
|
|
104
|
+
(0, package_json_1.readNxMigrateConfig)(packageJson).migrations,
|
|
105
|
+
].filter((f) => !!f);
|
|
106
|
+
const parser = (0, flat_config_1.useFlatConfig)(host)
|
|
107
|
+
? { languageOptions: { parser: 'jsonc-eslint-parser' } }
|
|
108
|
+
: { parser: 'jsonc-eslint-parser' };
|
|
109
|
+
if ((0, eslint_file_1.lintConfigHasOverride)(host, options.root, lookup)) {
|
|
110
|
+
// update it
|
|
111
|
+
(0, eslint_file_1.updateOverrideInLintConfig)(host, options.root, lookup, (o) => ({
|
|
112
|
+
...o,
|
|
113
|
+
files: [
|
|
114
|
+
...new Set([
|
|
115
|
+
...(Array.isArray(o.files) ? o.files : [o.files]),
|
|
116
|
+
...files,
|
|
117
|
+
]),
|
|
118
|
+
],
|
|
119
|
+
...parser,
|
|
120
|
+
rules: {
|
|
121
|
+
...o.rules,
|
|
122
|
+
'@nx/nx-plugin-checks': 'error',
|
|
123
|
+
},
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// add it
|
|
128
|
+
(0, eslint_file_1.addOverrideToLintConfig)(host, options.root, {
|
|
129
|
+
files,
|
|
130
|
+
...parser,
|
|
131
|
+
rules: {
|
|
132
|
+
'@nx/nx-plugin-checks': 'error',
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Update the root eslint to specify a parser for json files
|
|
139
|
+
// This is required, otherwise every json file that is not overriden
|
|
140
|
+
// will display false errors in the IDE
|
|
141
|
+
function updateRootEslintConfig(host) {
|
|
142
|
+
if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
|
|
143
|
+
if (!(0, eslint_file_1.lintConfigHasOverride)(host, '', (o) => Array.isArray(o.files)
|
|
144
|
+
? o.files.some((f) => f.match(/\.json$/))
|
|
145
|
+
: !!o.files?.match(/\.json$/), true)) {
|
|
146
|
+
(0, eslint_file_1.addOverrideToLintConfig)(host, '', {
|
|
147
|
+
files: '*.json',
|
|
148
|
+
parser: 'jsonc-eslint-parser',
|
|
149
|
+
rules: {},
|
|
150
|
+
}, { checkBaseConfig: true });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
devkit_1.output.note({
|
|
155
|
+
title: 'Unable to update root eslint config.',
|
|
156
|
+
bodyLines: [
|
|
157
|
+
'We only automatically update the root eslint config if it is json or flat config.',
|
|
158
|
+
'If you are using a different format, you will need to update it manually.',
|
|
159
|
+
'You need to set the parser to jsonc-eslint-parser for json files.',
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function setupVsCodeLintingForJsonFiles(host) {
|
|
165
|
+
let existing = {};
|
|
166
|
+
if (host.exists('.vscode/settings.json')) {
|
|
167
|
+
existing = (0, devkit_1.readJson)(host, '.vscode/settings.json');
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
devkit_1.logger.info(`${logger_1.NX_PREFIX} We've updated the vscode settings for this repository to ensure that plugin lint checks show up inside your IDE. This created .vscode/settings.json. To read more about this file, check vscode's documentation. It is frequently not committed, so other developers may need to add similar settings if they'd like to see the lint checks in the IDE rather than only during linting.`);
|
|
171
|
+
}
|
|
172
|
+
// setup eslint validation for json files
|
|
173
|
+
const eslintValidate = existing['eslint.validate'] ?? [];
|
|
174
|
+
if (!eslintValidate.includes('json')) {
|
|
175
|
+
existing['eslint.validate'] = [...eslintValidate, 'json'];
|
|
176
|
+
}
|
|
177
|
+
(0, devkit_1.writeJson)(host, '.vscode/settings.json', existing);
|
|
178
|
+
}
|
|
179
|
+
function projectIsEsLintEnabled(tree, project) {
|
|
180
|
+
return !!(0, eslint_file_1.findEslintFile)(tree, project.root);
|
|
181
|
+
}
|
|
182
|
+
function getEsLintOptions(project) {
|
|
183
|
+
return Object.entries(project.targets || {}).find(([, x]) => x.executor === '@nx/eslint:lint' ||
|
|
184
|
+
x.executor === '@nx/linter:eslint' ||
|
|
185
|
+
x.executor === '@nrwl/linter:eslint');
|
|
186
|
+
}
|
|
187
|
+
exports.getEsLintOptions = getEsLintOptions;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "PluginLint",
|
|
5
|
+
"title": "",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"description": "Adds linting configuration to validate common json files for nx plugins.",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"command": "nx g @nx/plugin:lint-checks",
|
|
11
|
+
"description": "Sets up linting configuration to validate common json files for an nx plugin project."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"properties": {
|
|
15
|
+
"projectName": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "Which project should be the configuration be added to?",
|
|
18
|
+
"$default": {
|
|
19
|
+
"$source": "projectName"
|
|
20
|
+
},
|
|
21
|
+
"x-priority": "important"
|
|
22
|
+
},
|
|
23
|
+
"skipFormat": {
|
|
24
|
+
"type": "boolean",
|
|
25
|
+
"x-priority": "internal",
|
|
26
|
+
"description": "Skip formatting files with prettier.",
|
|
27
|
+
"default": false
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"required": ["projectName"]
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
2
|
+
import { Tree } from '@nx/devkit';
|
|
3
|
+
|
|
4
|
+
import update from './<%= name %>';
|
|
5
|
+
|
|
6
|
+
describe('<%= name %> migration', () => {
|
|
7
|
+
let tree: Tree;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
tree = createTreeWithEmptyWorkspace({layout: 'apps-libs'});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should run successfully', async () => {
|
|
14
|
+
await update(tree);
|
|
15
|
+
// ... expect changes made
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Tree } from '@nx/devkit';
|
|
2
|
+
import type { Schema } from './schema';
|
|
3
|
+
export declare function migrationGenerator(tree: Tree, rawOptions: Schema): Promise<void>;
|
|
4
|
+
export declare function migrationGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
|
|
5
|
+
export default migrationGenerator;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrationGeneratorInternal = exports.migrationGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const generator_1 = require("../lint-checks/generator");
|
|
8
|
+
const package_json_1 = require("nx/src/utils/package-json");
|
|
9
|
+
const versions_1 = require("../../utils/versions");
|
|
10
|
+
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
11
|
+
async function normalizeOptions(tree, options) {
|
|
12
|
+
let name;
|
|
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
|
+
artifactType: 'migration',
|
|
21
|
+
callingGenerator: '@nx/plugin:migration',
|
|
22
|
+
name: name,
|
|
23
|
+
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
|
24
|
+
project: options.project,
|
|
25
|
+
directory: options.directory,
|
|
26
|
+
fileName: name,
|
|
27
|
+
derivedDirectory: 'migrations',
|
|
28
|
+
});
|
|
29
|
+
const { className, propertyName } = (0, devkit_1.names)(artifactName);
|
|
30
|
+
const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
31
|
+
const description = options.description ?? `Migration for v${options.packageVersion}`;
|
|
32
|
+
// const { root: projectRoot, sourceRoot: projectSourceRoot } =
|
|
33
|
+
// readProjectConfiguration(host, options.project);
|
|
34
|
+
const normalized = {
|
|
35
|
+
...options,
|
|
36
|
+
project,
|
|
37
|
+
name: artifactName,
|
|
38
|
+
directory,
|
|
39
|
+
description,
|
|
40
|
+
projectRoot,
|
|
41
|
+
projectSourceRoot,
|
|
42
|
+
};
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
function addFiles(host, options) {
|
|
46
|
+
(0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/migration'), options.directory, { ...options, tmpl: '' });
|
|
47
|
+
}
|
|
48
|
+
function updateMigrationsJson(host, options) {
|
|
49
|
+
const configuredMigrationPath = (0, package_json_1.readNxMigrateConfig)((0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'))).migrations;
|
|
50
|
+
const migrationsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, configuredMigrationPath ?? 'migrations.json');
|
|
51
|
+
const migrations = host.exists(migrationsPath)
|
|
52
|
+
? (0, devkit_1.readJson)(host, migrationsPath)
|
|
53
|
+
: {};
|
|
54
|
+
const generators = migrations.generators ?? {};
|
|
55
|
+
generators[options.name] = {
|
|
56
|
+
version: options.packageVersion,
|
|
57
|
+
description: options.description,
|
|
58
|
+
implementation: `./${(0, devkit_1.joinPathFragments)((0, path_1.relative)(options.projectRoot, options.directory), options.name)}`,
|
|
59
|
+
};
|
|
60
|
+
migrations.generators = generators;
|
|
61
|
+
if (options.packageJsonUpdates) {
|
|
62
|
+
const packageJsonUpdatesObj = migrations.packageJsonUpdates ?? {};
|
|
63
|
+
if (!packageJsonUpdatesObj[options.packageVersion]) {
|
|
64
|
+
packageJsonUpdatesObj[options.packageVersion] = {
|
|
65
|
+
version: options.packageVersion,
|
|
66
|
+
packages: {},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
migrations.packageJsonUpdates = packageJsonUpdatesObj;
|
|
70
|
+
}
|
|
71
|
+
(0, devkit_1.writeJson)(host, migrationsPath, migrations);
|
|
72
|
+
}
|
|
73
|
+
function updatePackageJson(host, options) {
|
|
74
|
+
(0, devkit_1.updateJson)(host, path.join(options.projectRoot, 'package.json'), (json) => {
|
|
75
|
+
const migrationKey = json['ng-update'] ? 'ng-update' : 'nx-migrations';
|
|
76
|
+
const preexistingValue = json[migrationKey];
|
|
77
|
+
if (typeof preexistingValue === 'string') {
|
|
78
|
+
return json;
|
|
79
|
+
}
|
|
80
|
+
else if (!json[migrationKey]) {
|
|
81
|
+
json[migrationKey] = {
|
|
82
|
+
migrations: './migrations.json',
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
else if (preexistingValue.migrations) {
|
|
86
|
+
preexistingValue.migrations = './migrations.json';
|
|
87
|
+
}
|
|
88
|
+
// add dependencies
|
|
89
|
+
json.dependencies = {
|
|
90
|
+
'@nx/devkit': versions_1.nxVersion,
|
|
91
|
+
...json.dependencies,
|
|
92
|
+
};
|
|
93
|
+
return json;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function updateProjectConfig(host, options) {
|
|
97
|
+
const project = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
98
|
+
const assets = project.targets.build?.options?.assets;
|
|
99
|
+
if (assets &&
|
|
100
|
+
assets.filter((a) => a.glob === 'migrations.json').length === 0) {
|
|
101
|
+
project.targets.build.options.assets = [
|
|
102
|
+
...assets,
|
|
103
|
+
{
|
|
104
|
+
input: `./${options.projectRoot}`,
|
|
105
|
+
glob: 'migrations.json',
|
|
106
|
+
output: '.',
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.project, project);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function migrationGenerator(tree, rawOptions) {
|
|
113
|
+
await migrationGeneratorInternal(tree, {
|
|
114
|
+
nameAndDirectoryFormat: 'derived',
|
|
115
|
+
...rawOptions,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.migrationGenerator = migrationGenerator;
|
|
119
|
+
async function migrationGeneratorInternal(host, schema) {
|
|
120
|
+
const options = await normalizeOptions(host, schema);
|
|
121
|
+
addFiles(host, options);
|
|
122
|
+
updateMigrationsJson(host, options);
|
|
123
|
+
updateProjectConfig(host, options);
|
|
124
|
+
updateMigrationsJson(host, options);
|
|
125
|
+
updatePackageJson(host, options);
|
|
126
|
+
if (!host.exists('migrations.json')) {
|
|
127
|
+
const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
|
|
128
|
+
(0, generator_1.addMigrationJsonChecks)(host, { projectName: options.project }, (0, devkit_1.readJson)(host, packageJsonPath));
|
|
129
|
+
}
|
|
130
|
+
if (!options.skipFormat) {
|
|
131
|
+
await (0, devkit_1.formatFiles)(host);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.migrationGeneratorInternal = migrationGeneratorInternal;
|
|
135
|
+
exports.default = migrationGenerator;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { 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
|
+
packageVersion: string;
|
|
8
|
+
packageJsonUpdates?: 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,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxPluginMigration",
|
|
5
|
+
"title": "Create a Migration for an Nx Plugin",
|
|
6
|
+
"description": "Create a Migration for an Nx Plugin.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"command": "nx g migration my-migration --project=my-plugin --version=1.0.0",
|
|
11
|
+
"description": "Adds a new migration to the project `my-plugin`, which will be triggered when migrating to version 1.0.0 or above from a previous version."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"properties": {
|
|
15
|
+
"name": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "Migration name.",
|
|
18
|
+
"$default": {
|
|
19
|
+
"$source": "argv",
|
|
20
|
+
"index": 0
|
|
21
|
+
},
|
|
22
|
+
"x-priority": "important"
|
|
23
|
+
},
|
|
24
|
+
"directory": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "The directory at which to create the migration file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
|
27
|
+
"aliases": ["dir"]
|
|
28
|
+
},
|
|
29
|
+
"description": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "Migration description."
|
|
32
|
+
},
|
|
33
|
+
"packageVersion": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"description": "Version to use for the migration.",
|
|
36
|
+
"alias": "v",
|
|
37
|
+
"x-prompt": "What version would you like to use for the migration?",
|
|
38
|
+
"x-priority": "important"
|
|
39
|
+
},
|
|
40
|
+
"project": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"description": "The name of the project.",
|
|
43
|
+
"alias": "p",
|
|
44
|
+
"$default": {
|
|
45
|
+
"$source": "projectName"
|
|
46
|
+
},
|
|
47
|
+
"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."
|
|
48
|
+
},
|
|
49
|
+
"packageJsonUpdates": {
|
|
50
|
+
"type": "boolean",
|
|
51
|
+
"description": "Whether or not to include `package.json` updates.",
|
|
52
|
+
"alias": "p",
|
|
53
|
+
"default": false
|
|
54
|
+
},
|
|
55
|
+
"skipLintChecks": {
|
|
56
|
+
"type": "boolean",
|
|
57
|
+
"default": false,
|
|
58
|
+
"description": "Do not eslint configuration for plugin json files."
|
|
59
|
+
},
|
|
60
|
+
"nameAndDirectoryFormat": {
|
|
61
|
+
"description": "Whether to generate the migration 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`).",
|
|
62
|
+
"type": "string",
|
|
63
|
+
"enum": ["as-provided", "derived"]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"required": ["packageVersion"],
|
|
67
|
+
"additionalProperties": false
|
|
68
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import type { Schema } from './schema';
|
|
3
|
+
export declare function pluginGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function pluginGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
5
|
+
export default pluginGenerator;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pluginGeneratorInternal = exports.pluginGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const js_1 = require("@nx/js");
|
|
6
|
+
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
7
|
+
const eslint_1 = require("@nx/eslint");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const e2e_1 = require("../e2e-project/e2e");
|
|
10
|
+
const generator_1 = require("../lint-checks/generator");
|
|
11
|
+
const normalize_schema_1 = require("./utils/normalize-schema");
|
|
12
|
+
const add_tslib_dependencies_1 = require("@nx/js/src/utils/typescript/add-tslib-dependencies");
|
|
13
|
+
const add_swc_dependencies_2 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
14
|
+
const nxVersion = require('../../../package.json').version;
|
|
15
|
+
async function addFiles(host, options) {
|
|
16
|
+
host.delete((0, devkit_1.normalizePath)(`${options.projectRoot}/src/lib`));
|
|
17
|
+
(0, devkit_1.generateFiles)(host, path.join(__dirname, './files/plugin'), options.projectRoot, {
|
|
18
|
+
...options,
|
|
19
|
+
tmpl: '',
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function updatePluginConfig(host, options) {
|
|
23
|
+
const project = (0, devkit_1.readProjectConfiguration)(host, options.name);
|
|
24
|
+
if (project.targets.build) {
|
|
25
|
+
project.targets.build.options.assets ??= [];
|
|
26
|
+
const root = options.projectRoot === '.' ? '.' : './' + options.projectRoot;
|
|
27
|
+
project.targets.build.options.assets = [
|
|
28
|
+
...project.targets.build.options.assets,
|
|
29
|
+
{
|
|
30
|
+
input: `${root}/src`,
|
|
31
|
+
glob: '**/!(*.ts)',
|
|
32
|
+
output: './src',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
input: `${root}/src`,
|
|
36
|
+
glob: '**/*.d.ts',
|
|
37
|
+
output: './src',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
input: root,
|
|
41
|
+
glob: 'generators.json',
|
|
42
|
+
output: '.',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
input: root,
|
|
46
|
+
glob: 'executors.json',
|
|
47
|
+
output: '.',
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.name, project);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function pluginGenerator(host, schema) {
|
|
54
|
+
return await pluginGeneratorInternal(host, {
|
|
55
|
+
projectNameAndRootFormat: 'derived',
|
|
56
|
+
...schema,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.pluginGenerator = pluginGenerator;
|
|
60
|
+
async function pluginGeneratorInternal(host, schema) {
|
|
61
|
+
const options = await (0, normalize_schema_1.normalizeOptions)(host, schema);
|
|
62
|
+
const tasks = [];
|
|
63
|
+
tasks.push(await (0, js_1.libraryGenerator)(host, {
|
|
64
|
+
...schema,
|
|
65
|
+
config: 'project',
|
|
66
|
+
bundler: options.bundler,
|
|
67
|
+
publishable: options.publishable,
|
|
68
|
+
importPath: options.npmPackageName,
|
|
69
|
+
skipFormat: true,
|
|
70
|
+
}));
|
|
71
|
+
if (options.bundler === 'tsc') {
|
|
72
|
+
tasks.push((0, add_tslib_dependencies_1.addTsLibDependencies)(host));
|
|
73
|
+
}
|
|
74
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {
|
|
75
|
+
'@nx/devkit': nxVersion,
|
|
76
|
+
}, {
|
|
77
|
+
'@nx/jest': nxVersion,
|
|
78
|
+
'@nx/js': nxVersion,
|
|
79
|
+
'@nx/plugin': nxVersion,
|
|
80
|
+
}));
|
|
81
|
+
// Ensures Swc Deps are installed to handle running
|
|
82
|
+
// local plugin generators and executors
|
|
83
|
+
tasks.push((0, add_swc_dependencies_1.addSwcDependencies)(host));
|
|
84
|
+
tasks.push((0, add_swc_dependencies_2.addSwcRegisterDependencies)(host));
|
|
85
|
+
await addFiles(host, options);
|
|
86
|
+
updatePluginConfig(host, options);
|
|
87
|
+
if (options.e2eTestRunner !== 'none') {
|
|
88
|
+
tasks.push(await (0, e2e_1.e2eProjectGenerator)(host, {
|
|
89
|
+
pluginName: options.name,
|
|
90
|
+
projectDirectory: options.projectDirectory,
|
|
91
|
+
pluginOutputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : options.projectRoot),
|
|
92
|
+
npmPackageName: options.npmPackageName,
|
|
93
|
+
skipFormat: true,
|
|
94
|
+
rootProject: options.rootProject,
|
|
95
|
+
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
if (options.linter === eslint_1.Linter.EsLint && !options.skipLintChecks) {
|
|
99
|
+
await (0, generator_1.default)(host, { projectName: options.name });
|
|
100
|
+
}
|
|
101
|
+
if (!options.skipFormat) {
|
|
102
|
+
await (0, devkit_1.formatFiles)(host);
|
|
103
|
+
}
|
|
104
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
105
|
+
}
|
|
106
|
+
exports.pluginGeneratorInternal = pluginGeneratorInternal;
|
|
107
|
+
exports.default = pluginGenerator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
+
import type { Linter } from '@nx/eslint';
|
|
3
|
+
|
|
4
|
+
export interface Schema {
|
|
5
|
+
name: string;
|
|
6
|
+
directory?: string;
|
|
7
|
+
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
8
|
+
importPath?: string;
|
|
9
|
+
skipTsConfig?: boolean; // default is false
|
|
10
|
+
skipFormat?: boolean; // default is false
|
|
11
|
+
skipLintChecks?: boolean; // default is false
|
|
12
|
+
e2eTestRunner?: 'jest' | 'none';
|
|
13
|
+
tags?: string;
|
|
14
|
+
unitTestRunner: 'jest' | 'none';
|
|
15
|
+
linter: Linter;
|
|
16
|
+
setParserOptionsProject?: boolean;
|
|
17
|
+
compiler: 'swc' | 'tsc';
|
|
18
|
+
rootProject?: boolean;
|
|
19
|
+
publishable?: boolean;
|
|
20
|
+
}
|