@nx/plugin 0.0.0-pr-30715-a5f5e3b → 0.0.0-pr-31222-862e973
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 +20 -1
- package/package.json +6 -5
- package/src/generators/create-package/create-package.js +15 -40
- package/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +7 -11
- package/src/generators/create-package/files/e2e/__cliName__.spec.ts__tmpl__ +6 -8
- package/src/generators/create-package/schema.d.ts +7 -8
- package/src/generators/create-package/schema.json +19 -16
- package/src/generators/create-package/utils/normalize-schema.d.ts +0 -6
- package/src/generators/create-package/utils/normalize-schema.js +4 -21
- package/src/generators/e2e-project/e2e.d.ts +2 -1
- package/src/generators/e2e-project/e2e.js +32 -67
- package/src/generators/e2e-project/files/src/{__simplePluginName__.spec.ts__tmpl__ → __pluginName__.spec.ts__tmpl__} +7 -9
- package/src/generators/e2e-project/schema.d.ts +2 -1
- package/src/generators/e2e-project/schema.json +7 -5
- package/src/generators/executor/executor.d.ts +3 -2
- package/src/generators/executor/executor.js +29 -31
- package/src/generators/executor/files/executor/{__fileName__.spec.ts.template → executor.spec.ts.template} +2 -11
- package/src/generators/executor/schema.d.ts +11 -3
- package/src/generators/executor/schema.json +29 -7
- package/src/generators/generator/files/generator/{__fileName__.spec.ts.template → generator.spec.ts.template} +1 -1
- package/src/generators/generator/generator.d.ts +2 -1
- package/src/generators/generator/generator.js +28 -30
- package/src/generators/generator/schema.d.ts +11 -3
- package/src/generators/generator/schema.json +25 -17
- package/src/generators/migration/migration.d.ts +3 -2
- package/src/generators/migration/migration.js +43 -39
- package/src/generators/migration/schema.d.ts +9 -1
- package/src/generators/migration/schema.json +22 -16
- package/src/generators/plugin/plugin.d.ts +1 -1
- package/src/generators/plugin/plugin.js +41 -42
- package/src/generators/plugin/schema.d.ts +7 -7
- package/src/generators/plugin/schema.json +18 -16
- package/src/generators/plugin/utils/normalize-schema.d.ts +4 -10
- package/src/generators/plugin/utils/normalize-schema.js +17 -21
- package/src/generators/preset/generator.d.ts +3 -5
- package/src/generators/preset/generator.js +21 -48
- package/src/generators/preset/schema.d.ts +0 -9
- package/src/generators/preset/schema.json +0 -4
- 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 +134 -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 +7 -0
- package/src/migrations/update-16-2-0/replace-e2e-executor.js +32 -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/utils/paths.d.ts +0 -2
- package/src/utils/paths.js +0 -31
- /package/src/generators/executor/files/executor/{__fileName__.ts.template → executor.ts.template} +0 -0
- /package/src/generators/generator/files/generator/{__fileName__.ts.template → generator.ts.template} +0 -0
- /package/src/generators/migration/files/migration/{__fileName__.spec.ts__tmpl__ → __name__.spec.ts__tmpl__} +0 -0
- /package/src/generators/migration/files/migration/{__fileName__.ts__tmpl__ → __name__.ts__tmpl__} +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
[](https://circleci.com/gh/nrwl/nx)
|
|
11
11
|
[]()
|
|
12
|
-
[](https://www.npmjs.com/@nx/workspace)
|
|
13
13
|
[]()
|
|
14
14
|
[](http://commitizen.github.io/cz-cli/)
|
|
15
15
|
[](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
package/generators.json
CHANGED
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
"description": "Create a E2E application for a Nx Plugin."
|
|
20
20
|
},
|
|
21
21
|
"migration": {
|
|
22
|
-
"factory": "./src/generators/migration/migration",
|
|
22
|
+
"factory": "./src/generators/migration/migration#migrationGeneratorInternal",
|
|
23
23
|
"schema": "./src/generators/migration/schema.json",
|
|
24
24
|
"description": "Create a migration for an Nx Plugin."
|
|
25
25
|
},
|
|
26
26
|
"generator": {
|
|
27
|
-
"factory": "./src/generators/generator/generator",
|
|
27
|
+
"factory": "./src/generators/generator/generator#generatorGeneratorInternal",
|
|
28
28
|
"schema": "./src/generators/generator/schema.json",
|
|
29
29
|
"description": "Create a generator for an Nx Plugin."
|
|
30
30
|
},
|
|
31
31
|
"executor": {
|
|
32
|
-
"factory": "./src/generators/executor/executor",
|
|
32
|
+
"factory": "./src/generators/executor/executor#executorGeneratorInternal",
|
|
33
33
|
"schema": "./src/generators/executor/schema.json",
|
|
34
34
|
"description": "Create an executor for an Nx Plugin."
|
|
35
35
|
},
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"description": "Adds linting configuration to validate common json files for nx plugins."
|
|
40
40
|
},
|
|
41
41
|
"preset": {
|
|
42
|
-
"factory": "./src/generators/preset/generator
|
|
42
|
+
"factory": "./src/generators/preset/generator",
|
|
43
43
|
"schema": "./src/generators/preset/schema.json",
|
|
44
44
|
"description": "Initializes a workspace with an nx-plugin inside of it. Use as: `create-nx-workspace --preset @nx/plugin`.",
|
|
45
45
|
"hidden": true,
|
package/migrations.json
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
"generators": {
|
|
2
|
+
"generators": {
|
|
3
|
+
"update-remove-cli-prop": {
|
|
4
|
+
"version": "16.0.0-beta.1",
|
|
5
|
+
"cli": "nx",
|
|
6
|
+
"description": "Removes CLI property within schema.json files and moves generators and schematics to the proper root node in migrations.json",
|
|
7
|
+
"factory": "./src/migrations/update-16-0-0/cli-in-schema-json"
|
|
8
|
+
},
|
|
9
|
+
"update-16-0-0-add-nx-packages": {
|
|
10
|
+
"cli": "nx",
|
|
11
|
+
"version": "16.0.0-beta.1",
|
|
12
|
+
"description": "Replace @nrwl/nx-plugin with @nx/plugin",
|
|
13
|
+
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
|
14
|
+
},
|
|
15
|
+
"update-16-2-0-replace-e2e-executor": {
|
|
16
|
+
"cli": "nx",
|
|
17
|
+
"version": "16.2.0-beta.0",
|
|
18
|
+
"description": "Replace @nx/plugin:e2e with @nx/jest",
|
|
19
|
+
"implementation": "./src/migrations/update-16-2-0/replace-e2e-executor"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
3
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/plugin",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-31222-862e973",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "This plugin is used to create Nx plugins! It contains generators for generating common plugin features like generators, executors, migrations and more.",
|
|
6
6
|
"repository": {
|
|
@@ -28,10 +28,11 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"tslib": "^2.3.0",
|
|
31
|
-
"@nx/devkit": "0.0.0-pr-
|
|
32
|
-
"@nx/jest": "0.0.0-pr-
|
|
33
|
-
"@nx/js": "0.0.0-pr-
|
|
34
|
-
"@nx/eslint": "0.0.0-pr-
|
|
31
|
+
"@nx/devkit": "0.0.0-pr-31222-862e973",
|
|
32
|
+
"@nx/jest": "0.0.0-pr-31222-862e973",
|
|
33
|
+
"@nx/js": "0.0.0-pr-31222-862e973",
|
|
34
|
+
"@nx/eslint": "0.0.0-pr-31222-862e973",
|
|
35
|
+
"@nrwl/nx-plugin": "0.0.0-pr-31222-862e973"
|
|
35
36
|
},
|
|
36
37
|
"publishConfig": {
|
|
37
38
|
"access": "public"
|
|
@@ -5,17 +5,15 @@ exports.createPackageGeneratorInternal = createPackageGeneratorInternal;
|
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const js_1 = require("@nx/js");
|
|
7
7
|
const add_tslib_dependencies_1 = require("@nx/js/src/utils/typescript/add-tslib-dependencies");
|
|
8
|
-
const
|
|
9
|
-
const versions_1 = require("@nx/js/src/utils/versions");
|
|
10
|
-
const versions_2 = require("nx/src/utils/versions");
|
|
11
|
-
const path_1 = require("path");
|
|
12
|
-
const has_generator_1 = require("../../utils/has-generator");
|
|
8
|
+
const versions_1 = require("nx/src/utils/versions");
|
|
13
9
|
const generator_1 = require("../generator/generator");
|
|
14
10
|
const normalize_schema_1 = require("./utils/normalize-schema");
|
|
11
|
+
const has_generator_1 = require("../../utils/has-generator");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const versions_2 = require("@nx/js/src/utils/versions");
|
|
15
14
|
async function createPackageGenerator(host, schema) {
|
|
16
15
|
return await createPackageGeneratorInternal(host, {
|
|
17
|
-
|
|
18
|
-
addPlugin: false,
|
|
16
|
+
projectNameAndRootFormat: 'derived',
|
|
19
17
|
...schema,
|
|
20
18
|
});
|
|
21
19
|
}
|
|
@@ -27,11 +25,10 @@ async function createPackageGeneratorInternal(host, schema) {
|
|
|
27
25
|
tasks.push((0, add_tslib_dependencies_1.addTsLibDependencies)(host));
|
|
28
26
|
}
|
|
29
27
|
const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, {
|
|
30
|
-
'create-nx-workspace':
|
|
28
|
+
'create-nx-workspace': versions_1.nxVersion,
|
|
31
29
|
}, {});
|
|
32
30
|
tasks.push(installTask);
|
|
33
|
-
|
|
34
|
-
tasks.push(cliPackageTask);
|
|
31
|
+
await createCliPackage(host, options, pluginPackageName);
|
|
35
32
|
if (options.e2eProject) {
|
|
36
33
|
addE2eProject(host, options);
|
|
37
34
|
}
|
|
@@ -49,20 +46,19 @@ async function createPackageGeneratorInternal(host, schema) {
|
|
|
49
46
|
async function addPresetGenerator(host, schema) {
|
|
50
47
|
const { root: projectRoot } = (0, devkit_1.readProjectConfiguration)(host, schema.project);
|
|
51
48
|
if (!(0, has_generator_1.hasGenerator)(host, schema.project, 'preset')) {
|
|
52
|
-
await (0, generator_1.
|
|
49
|
+
await (0, generator_1.default)(host, {
|
|
53
50
|
name: 'preset',
|
|
54
|
-
|
|
51
|
+
directory: (0, path_1.join)(projectRoot, 'src/generators/preset'),
|
|
55
52
|
unitTestRunner: schema.unitTestRunner,
|
|
56
53
|
skipFormat: true,
|
|
57
|
-
|
|
54
|
+
nameAndDirectoryFormat: 'as-provided',
|
|
58
55
|
});
|
|
59
56
|
}
|
|
60
57
|
return (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'))?.name;
|
|
61
58
|
}
|
|
62
59
|
async function createCliPackage(host, options, pluginPackageName) {
|
|
63
|
-
|
|
60
|
+
await (0, js_1.libraryGenerator)(host, {
|
|
64
61
|
...options,
|
|
65
|
-
directory: options.directory,
|
|
66
62
|
rootProject: false,
|
|
67
63
|
config: 'project',
|
|
68
64
|
publishable: true,
|
|
@@ -70,26 +66,16 @@ async function createCliPackage(host, options, pluginPackageName) {
|
|
|
70
66
|
importPath: options.name,
|
|
71
67
|
skipFormat: true,
|
|
72
68
|
skipTsConfig: true,
|
|
73
|
-
useTscExecutor: true,
|
|
74
69
|
});
|
|
75
70
|
host.delete((0, devkit_1.joinPathFragments)(options.projectRoot, 'src'));
|
|
76
|
-
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
77
71
|
// Add the bin entry to the package.json
|
|
78
72
|
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (packageJson) => {
|
|
79
73
|
packageJson.bin = {
|
|
80
74
|
[options.name]: './bin/index.js',
|
|
81
75
|
};
|
|
82
|
-
if (isTsSolutionSetup) {
|
|
83
|
-
packageJson.bin[options.name] = './dist/bin/index.js';
|
|
84
|
-
// this package only exposes a binary entry point and no JS programmatic API
|
|
85
|
-
delete packageJson.main;
|
|
86
|
-
delete packageJson.types;
|
|
87
|
-
delete packageJson.typings;
|
|
88
|
-
delete packageJson.exports;
|
|
89
|
-
}
|
|
90
76
|
packageJson.dependencies = {
|
|
91
|
-
'create-nx-workspace':
|
|
92
|
-
...(options.bundler === 'tsc' && { tslib:
|
|
77
|
+
'create-nx-workspace': versions_1.nxVersion,
|
|
78
|
+
...(options.bundler === 'tsc' && { tslib: versions_2.tsLibVersion }),
|
|
93
79
|
};
|
|
94
80
|
return packageJson;
|
|
95
81
|
});
|
|
@@ -98,20 +84,10 @@ async function createCliPackage(host, options, pluginPackageName) {
|
|
|
98
84
|
projectConfiguration.sourceRoot = (0, devkit_1.joinPathFragments)(options.projectRoot, 'bin');
|
|
99
85
|
projectConfiguration.targets.build.options.main = (0, devkit_1.joinPathFragments)(options.projectRoot, 'bin/index.ts');
|
|
100
86
|
projectConfiguration.implicitDependencies = [options.project];
|
|
101
|
-
if (options.isTsSolutionSetup) {
|
|
102
|
-
if (options.bundler === 'tsc') {
|
|
103
|
-
projectConfiguration.targets.build.options.generatePackageJson = false;
|
|
104
|
-
}
|
|
105
|
-
else if (options.bundler === 'swc') {
|
|
106
|
-
delete projectConfiguration.targets.build.options.stripLeadingPaths;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
87
|
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
|
|
110
|
-
// Add bin files
|
|
88
|
+
// Add bin files to tsconfg.lib.json
|
|
111
89
|
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'), (tsConfig) => {
|
|
112
90
|
tsConfig.include.push('bin/**/*.ts');
|
|
113
|
-
tsConfig.compilerOptions ??= {};
|
|
114
|
-
tsConfig.compilerOptions.rootDir = '.';
|
|
115
91
|
return tsConfig;
|
|
116
92
|
});
|
|
117
93
|
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/create-framework-package'), options.projectRoot, {
|
|
@@ -119,7 +95,6 @@ async function createCliPackage(host, options, pluginPackageName) {
|
|
|
119
95
|
preset: pluginPackageName,
|
|
120
96
|
tmpl: '',
|
|
121
97
|
});
|
|
122
|
-
return jsLibraryTask;
|
|
123
98
|
}
|
|
124
99
|
/**
|
|
125
100
|
* Add a test file to plugin e2e project
|
|
@@ -134,7 +109,7 @@ function addE2eProject(host, options) {
|
|
|
134
109
|
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/e2e'), e2eProjectConfiguration.sourceRoot, {
|
|
135
110
|
pluginName: options.project,
|
|
136
111
|
cliName: options.name,
|
|
137
|
-
packageManagerCommands: (0, devkit_1.getPackageManagerCommand)(),
|
|
112
|
+
packageManagerCommands: (0, devkit_1.getPackageManagerCommand)('npm'),
|
|
138
113
|
pluginPackageName,
|
|
139
114
|
tmpl: '',
|
|
140
115
|
});
|
|
@@ -11,19 +11,15 @@ async function main() {
|
|
|
11
11
|
console.log(`Creating the workspace: ${name}`);
|
|
12
12
|
|
|
13
13
|
// This assumes "<%= preset %>" and "<%= projectName %>" are at the same version
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
15
|
-
const presetVersion = require('
|
|
16
|
-
const presetVersion = require('../package.json').version;<% } %>
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
15
|
+
const presetVersion = require('../package.json').version,
|
|
17
16
|
|
|
18
17
|
// TODO: update below to customize the workspace
|
|
19
|
-
const { directory } = await createWorkspace(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
packageManager: 'npm',
|
|
25
|
-
}
|
|
26
|
-
);
|
|
18
|
+
const { directory } = await createWorkspace(`<%= preset %>@${presetVersion}`, {
|
|
19
|
+
name,
|
|
20
|
+
nxCloud: 'skip',
|
|
21
|
+
packageManager: 'npm',
|
|
22
|
+
});
|
|
27
23
|
|
|
28
24
|
console.log(`Successfully created the workspace: ${directory}.`);
|
|
29
25
|
}
|
|
@@ -6,13 +6,11 @@ describe('<%= cliName %>', () => {
|
|
|
6
6
|
let projectDirectory: string;
|
|
7
7
|
|
|
8
8
|
afterAll(() => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
}
|
|
9
|
+
// Cleanup the test project
|
|
10
|
+
rmSync(projectDirectory, {
|
|
11
|
+
recursive: true,
|
|
12
|
+
force: true,
|
|
13
|
+
});
|
|
16
14
|
});
|
|
17
15
|
|
|
18
16
|
|
|
@@ -45,7 +43,7 @@ function createTestProject(extraArgs = '') {
|
|
|
45
43
|
});
|
|
46
44
|
|
|
47
45
|
execSync(
|
|
48
|
-
`<%= packageManagerCommands.
|
|
46
|
+
`<%= packageManagerCommands.exec %> --yes <%= cliName %>@e2e ${projectName} ${extraArgs}`,
|
|
49
47
|
{
|
|
50
48
|
cwd: dirname(projectDirectory),
|
|
51
49
|
stdio: 'inherit',
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
+
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
1
2
|
import type { Linter, LinterType } from '@nx/eslint';
|
|
2
3
|
|
|
3
4
|
export interface CreatePackageSchema {
|
|
4
5
|
name: string;
|
|
5
6
|
project: string;
|
|
6
|
-
directory: string;
|
|
7
7
|
|
|
8
8
|
// options to create cli package, passed to js library generator
|
|
9
|
-
|
|
9
|
+
directory?: string;
|
|
10
|
+
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
11
|
+
skipFormat: boolean;
|
|
10
12
|
tags?: string;
|
|
11
|
-
unitTestRunner
|
|
12
|
-
linter
|
|
13
|
-
compiler
|
|
13
|
+
unitTestRunner: 'jest' | 'none';
|
|
14
|
+
linter: Linter | LinterType;
|
|
15
|
+
compiler: 'swc' | 'tsc';
|
|
14
16
|
|
|
15
17
|
// options to create e2e project, passed to e2e project generator
|
|
16
18
|
e2eProject?: string;
|
|
17
|
-
|
|
18
|
-
useProjectJson?: boolean;
|
|
19
|
-
addPlugin?: boolean;
|
|
20
19
|
}
|
|
@@ -7,18 +7,14 @@
|
|
|
7
7
|
"examplesFile": "../../../docs/generators/create-package-examples.md",
|
|
8
8
|
"type": "object",
|
|
9
9
|
"properties": {
|
|
10
|
-
"directory": {
|
|
11
|
-
"type": "string",
|
|
12
|
-
"description": "A directory where the app is placed.",
|
|
13
|
-
"$default": {
|
|
14
|
-
"$source": "argv",
|
|
15
|
-
"index": 0
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
10
|
"name": {
|
|
19
11
|
"type": "string",
|
|
20
12
|
"description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.",
|
|
21
13
|
"pattern": "create-.+|^@.+/create(?:-.+)?",
|
|
14
|
+
"$default": {
|
|
15
|
+
"$source": "argv",
|
|
16
|
+
"index": 0
|
|
17
|
+
},
|
|
22
18
|
"x-priority": "important"
|
|
23
19
|
},
|
|
24
20
|
"project": {
|
|
@@ -33,13 +29,24 @@
|
|
|
33
29
|
},
|
|
34
30
|
"unitTestRunner": {
|
|
35
31
|
"type": "string",
|
|
36
|
-
"enum": ["
|
|
37
|
-
"description": "Test runner to use for unit tests."
|
|
32
|
+
"enum": ["jest", "none"],
|
|
33
|
+
"description": "Test runner to use for unit tests.",
|
|
34
|
+
"default": "jest"
|
|
35
|
+
},
|
|
36
|
+
"directory": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"description": "A directory where the app is placed."
|
|
39
|
+
},
|
|
40
|
+
"projectNameAndRootFormat": {
|
|
41
|
+
"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`).",
|
|
42
|
+
"type": "string",
|
|
43
|
+
"enum": ["as-provided", "derived"]
|
|
38
44
|
},
|
|
39
45
|
"linter": {
|
|
40
46
|
"description": "The tool to use for running lint checks.",
|
|
41
47
|
"type": "string",
|
|
42
|
-
"enum": ["
|
|
48
|
+
"enum": ["eslint"],
|
|
49
|
+
"default": "eslint"
|
|
43
50
|
},
|
|
44
51
|
"tags": {
|
|
45
52
|
"type": "string",
|
|
@@ -62,11 +69,7 @@
|
|
|
62
69
|
"type": "string",
|
|
63
70
|
"description": "The name of the e2e project.",
|
|
64
71
|
"x-prompt": "What is the name of the e2e project? Leave blank to skip e2e tests"
|
|
65
|
-
},
|
|
66
|
-
"useProjectJson": {
|
|
67
|
-
"type": "boolean",
|
|
68
|
-
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
|
|
69
72
|
}
|
|
70
73
|
},
|
|
71
|
-
"required": ["
|
|
74
|
+
"required": ["name", "project"]
|
|
72
75
|
}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
|
-
import type { LinterType } from '@nx/eslint';
|
|
3
2
|
import { CreatePackageSchema } from '../schema';
|
|
4
3
|
export interface NormalizedSchema extends CreatePackageSchema {
|
|
5
4
|
bundler: 'swc' | 'tsc';
|
|
6
5
|
projectName: string;
|
|
7
6
|
projectRoot: string;
|
|
8
|
-
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
9
|
-
linter: LinterType;
|
|
10
|
-
useProjectJson: boolean;
|
|
11
|
-
addPlugin: boolean;
|
|
12
|
-
isTsSolutionSetup: boolean;
|
|
13
7
|
}
|
|
14
8
|
export declare function normalizeSchema(host: Tree, schema: CreatePackageSchema): Promise<NormalizedSchema>;
|
|
@@ -1,38 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeSchema = normalizeSchema;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
4
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
6
|
-
const generator_prompts_1 = require("@nx/js/src/utils/generator-prompts");
|
|
7
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
5
|
async function normalizeSchema(host, schema) {
|
|
9
|
-
const
|
|
10
|
-
const unitTestRunner = await (0, generator_prompts_1.normalizeUnitTestRunnerOption)(host, schema.unitTestRunner, ['jest']);
|
|
11
|
-
if (!schema.directory) {
|
|
12
|
-
throw new Error(`Please provide the --directory option. It should be the directory containing the project '${schema.project}'.`);
|
|
13
|
-
}
|
|
14
|
-
const { projectName, names: projectNames, projectRoot, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
6
|
+
const { projectName, names: projectNames, projectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
15
7
|
name: schema.name,
|
|
16
8
|
projectType: 'library',
|
|
17
9
|
directory: schema.directory,
|
|
10
|
+
projectNameAndRootFormat: schema.projectNameAndRootFormat,
|
|
11
|
+
callingGenerator: '@nx/plugin:create-package',
|
|
18
12
|
});
|
|
19
|
-
|
|
20
|
-
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
21
|
-
const addPlugin = schema.addPlugin ??
|
|
22
|
-
(isTsSolutionSetup &&
|
|
23
|
-
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
24
|
-
nxJson.useInferencePlugins !== false);
|
|
13
|
+
schema.projectNameAndRootFormat = projectNameAndRootFormat;
|
|
25
14
|
return {
|
|
26
15
|
...schema,
|
|
27
16
|
bundler: schema.compiler ?? 'tsc',
|
|
28
17
|
projectName,
|
|
29
18
|
projectRoot,
|
|
30
19
|
name: projectNames.projectSimpleName,
|
|
31
|
-
linter,
|
|
32
|
-
unitTestRunner,
|
|
33
|
-
// We default to generate a project.json file if the new setup is not being used
|
|
34
|
-
useProjectJson: schema.useProjectJson ?? !isTsSolutionSetup,
|
|
35
|
-
addPlugin,
|
|
36
|
-
isTsSolutionSetup,
|
|
37
20
|
};
|
|
38
21
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Tree } from '@nx/devkit';
|
|
2
|
+
import { GeneratorCallback } from '@nx/devkit';
|
|
2
3
|
import type { Schema } from './schema';
|
|
3
4
|
export declare function e2eProjectGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
5
|
export declare function e2eProjectGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
@@ -4,41 +4,48 @@ exports.e2eProjectGenerator = e2eProjectGenerator;
|
|
|
4
4
|
exports.e2eProjectGeneratorInternal = e2eProjectGeneratorInternal;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
7
|
-
const eslint_1 = require("@nx/eslint");
|
|
8
7
|
const jest_1 = require("@nx/jest");
|
|
9
8
|
const js_1 = require("@nx/js");
|
|
10
9
|
const generator_1 = require("@nx/js/src/generators/setup-verdaccio/generator");
|
|
11
10
|
const add_local_registry_scripts_1 = require("@nx/js/src/utils/add-local-registry-scripts");
|
|
12
|
-
const
|
|
13
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
11
|
+
const eslint_1 = require("@nx/eslint");
|
|
14
12
|
const path_1 = require("path");
|
|
15
13
|
async function normalizeOptions(host, options) {
|
|
16
|
-
const linter = await (0, generator_prompts_1.normalizeLinterOption)(host, options.linter);
|
|
17
14
|
const projectName = options.rootProject ? 'e2e' : `${options.pluginName}-e2e`;
|
|
18
15
|
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
19
|
-
const addPlugin =
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
17
|
+
nxJson.useInferencePlugins !== false;
|
|
18
|
+
options.addPlugin ??= addPlugin;
|
|
22
19
|
let projectRoot;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
if (options.projectNameAndRootFormat === 'as-provided') {
|
|
21
|
+
const projectNameAndRootOptions = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
22
|
+
name: projectName,
|
|
23
|
+
projectType: 'application',
|
|
24
|
+
directory: options.rootProject || !options.projectDirectory
|
|
25
|
+
? projectName
|
|
26
|
+
: `${options.projectDirectory}-e2e`,
|
|
27
|
+
projectNameAndRootFormat: `as-provided`,
|
|
28
|
+
callingGenerator: '@nx/plugin:e2e-project',
|
|
29
|
+
});
|
|
30
|
+
projectRoot = projectNameAndRootOptions.projectRoot;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.projectDirectory);
|
|
34
|
+
const { appsDir: defaultAppsDir } = (0, devkit_1.getWorkspaceLayout)(host);
|
|
35
|
+
const appsDir = layoutDirectory ?? defaultAppsDir;
|
|
36
|
+
projectRoot = options.rootProject
|
|
27
37
|
? projectName
|
|
28
|
-
:
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
: projectDirectory
|
|
39
|
+
? (0, devkit_1.joinPathFragments)(appsDir, `${projectDirectory}-e2e`)
|
|
40
|
+
: (0, devkit_1.joinPathFragments)(appsDir, projectName);
|
|
41
|
+
}
|
|
31
42
|
const pluginPropertyName = (0, devkit_1.names)(options.pluginName).propertyName;
|
|
32
|
-
const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
33
43
|
return {
|
|
34
44
|
...options,
|
|
35
45
|
projectName,
|
|
36
|
-
linter,
|
|
46
|
+
linter: options.linter ?? eslint_1.Linter.EsLint,
|
|
37
47
|
pluginPropertyName,
|
|
38
48
|
projectRoot,
|
|
39
|
-
addPlugin,
|
|
40
|
-
useProjectJson: options.useProjectJson ?? !isTsSolutionSetup,
|
|
41
|
-
isTsSolutionSetup,
|
|
42
49
|
};
|
|
43
50
|
}
|
|
44
51
|
function validatePlugin(host, pluginName) {
|
|
@@ -52,36 +59,22 @@ function validatePlugin(host, pluginName) {
|
|
|
52
59
|
function addFiles(host, options) {
|
|
53
60
|
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.pluginName);
|
|
54
61
|
const { name: pluginPackageName } = (0, devkit_1.readJson)(host, (0, path_1.join)(projectConfiguration.root, 'package.json'));
|
|
55
|
-
const simplePluginName = options.pluginName.split('/').pop();
|
|
56
62
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.projectRoot, {
|
|
57
63
|
...options,
|
|
58
64
|
tmpl: '',
|
|
59
65
|
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot),
|
|
60
|
-
packageManagerCommands: (0, devkit_1.getPackageManagerCommand)(),
|
|
66
|
+
packageManagerCommands: (0, devkit_1.getPackageManagerCommand)('npm'),
|
|
61
67
|
pluginPackageName,
|
|
62
|
-
simplePluginName,
|
|
63
68
|
});
|
|
64
69
|
}
|
|
65
70
|
async function addJest(host, options) {
|
|
66
|
-
|
|
67
|
-
name: options.projectName,
|
|
71
|
+
(0, devkit_1.addProjectConfiguration)(host, options.projectName, {
|
|
68
72
|
root: options.projectRoot,
|
|
69
73
|
projectType: 'application',
|
|
70
74
|
sourceRoot: `${options.projectRoot}/src`,
|
|
75
|
+
targets: {},
|
|
71
76
|
implicitDependencies: [options.pluginName],
|
|
72
|
-
};
|
|
73
|
-
if (options.isTsSolutionSetup) {
|
|
74
|
-
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), {
|
|
75
|
-
name: options.projectName,
|
|
76
|
-
version: '0.0.1',
|
|
77
|
-
private: true,
|
|
78
|
-
});
|
|
79
|
-
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
projectConfiguration.targets = {};
|
|
83
|
-
(0, devkit_1.addProjectConfiguration)(host, options.projectName, projectConfiguration);
|
|
84
|
-
}
|
|
77
|
+
});
|
|
85
78
|
const jestTask = await (0, jest_1.configurationGenerator)(host, {
|
|
86
79
|
project: options.projectName,
|
|
87
80
|
targetName: 'e2e',
|
|
@@ -90,13 +83,11 @@ async function addJest(host, options) {
|
|
|
90
83
|
skipSerializers: true,
|
|
91
84
|
skipFormat: true,
|
|
92
85
|
addPlugin: options.addPlugin,
|
|
93
|
-
compiler: options.isTsSolutionSetup ? 'swc' : undefined,
|
|
94
86
|
});
|
|
95
87
|
const { startLocalRegistryPath, stopLocalRegistryPath } = (0, add_local_registry_scripts_1.addLocalRegistryScripts)(host);
|
|
96
88
|
(0, jest_1.addPropertyToJestConfig)(host, (0, path_1.join)(options.projectRoot, 'jest.config.ts'), 'globalSetup', (0, path_1.join)((0, devkit_1.offsetFromRoot)(options.projectRoot), startLocalRegistryPath));
|
|
97
89
|
(0, jest_1.addPropertyToJestConfig)(host, (0, path_1.join)(options.projectRoot, 'jest.config.ts'), 'globalTeardown', (0, path_1.join)((0, devkit_1.offsetFromRoot)(options.projectRoot), stopLocalRegistryPath));
|
|
98
90
|
const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
99
|
-
project.targets ??= {};
|
|
100
91
|
const e2eTarget = project.targets.e2e;
|
|
101
92
|
project.targets.e2e = {
|
|
102
93
|
...e2eTarget,
|
|
@@ -123,18 +114,10 @@ async function addLintingToApplication(tree, options) {
|
|
|
123
114
|
});
|
|
124
115
|
return lintTask;
|
|
125
116
|
}
|
|
126
|
-
function updatePluginPackageJson(tree, options) {
|
|
127
|
-
const { root } = (0, devkit_1.readProjectConfiguration)(tree, options.pluginName);
|
|
128
|
-
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(root, 'package.json'), (json) => {
|
|
129
|
-
// to publish the plugin, we need to remove the private flag
|
|
130
|
-
delete json.private;
|
|
131
|
-
return json;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
117
|
async function e2eProjectGenerator(host, schema) {
|
|
135
118
|
return await e2eProjectGeneratorInternal(host, {
|
|
136
119
|
addPlugin: false,
|
|
137
|
-
|
|
120
|
+
projectNameAndRootFormat: 'derived',
|
|
138
121
|
...schema,
|
|
139
122
|
});
|
|
140
123
|
}
|
|
@@ -147,29 +130,11 @@ async function e2eProjectGeneratorInternal(host, schema) {
|
|
|
147
130
|
skipFormat: true,
|
|
148
131
|
}));
|
|
149
132
|
tasks.push(await addJest(host, options));
|
|
150
|
-
|
|
151
|
-
if (options.linter !== 'none') {
|
|
133
|
+
if (options.linter !== eslint_1.Linter.None) {
|
|
152
134
|
tasks.push(await addLintingToApplication(host, {
|
|
153
135
|
...options,
|
|
154
136
|
}));
|
|
155
137
|
}
|
|
156
|
-
if (options.isTsSolutionSetup && !options.rootProject) {
|
|
157
|
-
// update root tsconfig.json references with the new lib tsconfig
|
|
158
|
-
(0, devkit_1.updateJson)(host, 'tsconfig.json', (json) => {
|
|
159
|
-
json.references ??= [];
|
|
160
|
-
json.references.push({
|
|
161
|
-
path: options.projectRoot.startsWith('./')
|
|
162
|
-
? options.projectRoot
|
|
163
|
-
: './' + options.projectRoot,
|
|
164
|
-
});
|
|
165
|
-
return json;
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
// If we are using the new TS solution
|
|
169
|
-
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
|
170
|
-
if (options.isTsSolutionSetup) {
|
|
171
|
-
await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
|
|
172
|
-
}
|
|
173
138
|
if (!options.skipFormat) {
|
|
174
139
|
await (0, devkit_1.formatFiles)(host);
|
|
175
140
|
}
|
|
@@ -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.install %> <%= pluginPackageName %>@e2e`, {
|
|
14
14
|
cwd: projectDirectory,
|
|
15
15
|
stdio: 'inherit',
|
|
16
16
|
env: process.env,
|
|
@@ -18,13 +18,11 @@ describe('<%= pluginName %>', () => {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
afterAll(() => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
}
|
|
21
|
+
// Cleanup the test project
|
|
22
|
+
rmSync(projectDirectory, {
|
|
23
|
+
recursive: true,
|
|
24
|
+
force: true,
|
|
25
|
+
});
|
|
28
26
|
});
|
|
29
27
|
|
|
30
28
|
|
|
@@ -55,7 +53,7 @@ function createTestProject() {
|
|
|
55
53
|
});
|
|
56
54
|
|
|
57
55
|
execSync(
|
|
58
|
-
`<%= packageManagerCommands.
|
|
56
|
+
`<%= packageManagerCommands.exec %> --yes create-nx-workspace@latest ${projectName} --preset apps --nxCloud=skip --no-interactive`,
|
|
59
57
|
{
|
|
60
58
|
cwd: dirname(projectDirectory),
|
|
61
59
|
stdio: 'inherit',
|