feat(nx-plugin): add lint option for the e2e generator (#15140)
This commit is contained in:
parent
576bec2553
commit
b8e66790a6
@ -35,6 +35,12 @@
|
||||
"default": true,
|
||||
"x-deprecated": "Nx only supports standaloneConfig"
|
||||
},
|
||||
"linter": {
|
||||
"description": "The tool to use for running lint checks.",
|
||||
"type": "string",
|
||||
"enum": ["eslint", "none"],
|
||||
"default": "eslint"
|
||||
},
|
||||
"minimal": {
|
||||
"type": "boolean",
|
||||
"description": "Generate the e2e project with a minimal setup. This would involve not generating tests for a default executor and generator.",
|
||||
|
||||
@ -28,7 +28,7 @@ describe('NxPlugin e2e-project Generator', () => {
|
||||
pluginOutputPath: `dist/libs/my-plugin`,
|
||||
npmPackageName: '@proj/my-plugin',
|
||||
})
|
||||
).resolves.not.toThrow();
|
||||
).resolves.toBeDefined();
|
||||
|
||||
await expect(
|
||||
e2eProjectGenerator(tree, {
|
||||
@ -157,4 +157,21 @@ describe('NxPlugin e2e-project Generator', () => {
|
||||
tree.read(joinPathFragments(root, 'tests/my-plugin.spec.ts'), 'utf-8')
|
||||
).not.toContain("it('should create ");
|
||||
});
|
||||
|
||||
it('should setup the eslint builder', async () => {
|
||||
await e2eProjectGenerator(tree, {
|
||||
pluginName: 'my-plugin',
|
||||
pluginOutputPath: `dist/libs/my-plugin`,
|
||||
npmPackageName: '@proj/my-plugin',
|
||||
});
|
||||
|
||||
const projectsConfigurations = getProjects(tree);
|
||||
expect(projectsConfigurations.get('my-plugin-e2e').targets.lint).toEqual({
|
||||
executor: '@nrwl/linter:eslint',
|
||||
outputs: ['{options.outputFile}'],
|
||||
options: {
|
||||
lintFilePatterns: ['apps/my-plugin-e2e/**/*.ts'],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,6 +4,7 @@ import {
|
||||
extractLayoutDirectory,
|
||||
formatFiles,
|
||||
generateFiles,
|
||||
GeneratorCallback,
|
||||
getWorkspaceLayout,
|
||||
joinPathFragments,
|
||||
names,
|
||||
@ -16,12 +17,15 @@ import { getRelativePathToRootTsConfig } from '@nrwl/js';
|
||||
import * as path from 'path';
|
||||
|
||||
import type { Schema } from './schema';
|
||||
import { Linter, lintProjectGenerator } from '@nrwl/linter';
|
||||
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
|
||||
|
||||
interface NormalizedSchema extends Schema {
|
||||
projectRoot: string;
|
||||
projectName: string;
|
||||
pluginPropertyName: string;
|
||||
npmScope: string;
|
||||
linter: Linter;
|
||||
}
|
||||
|
||||
function normalizeOptions(host: Tree, options: Schema): NormalizedSchema {
|
||||
@ -41,6 +45,7 @@ function normalizeOptions(host: Tree, options: Schema): NormalizedSchema {
|
||||
...options,
|
||||
minimal: options.minimal ?? false,
|
||||
projectName,
|
||||
linter: options.linter ?? Linter.EsLint,
|
||||
pluginPropertyName,
|
||||
projectRoot,
|
||||
npmScope,
|
||||
@ -101,14 +106,44 @@ async function addJest(host: Tree, options: NormalizedSchema) {
|
||||
updateProjectConfiguration(host, options.projectName, project);
|
||||
}
|
||||
|
||||
async function addLintingToApplication(
|
||||
tree: Tree,
|
||||
options: NormalizedSchema
|
||||
): Promise<GeneratorCallback> {
|
||||
const lintTask = await lintProjectGenerator(tree, {
|
||||
linter: options.linter,
|
||||
project: options.projectName,
|
||||
tsConfigPaths: [
|
||||
joinPathFragments(options.projectRoot, 'tsconfig.app.json'),
|
||||
],
|
||||
eslintFilePatterns: [`${options.projectRoot}/**/*.ts`],
|
||||
unitTestRunner: 'jest',
|
||||
skipFormat: true,
|
||||
setParserOptionsProject: false,
|
||||
});
|
||||
|
||||
return lintTask;
|
||||
}
|
||||
|
||||
export async function e2eProjectGenerator(host: Tree, schema: Schema) {
|
||||
const tasks: GeneratorCallback[] = [];
|
||||
|
||||
validatePlugin(host, schema.pluginName);
|
||||
const options = normalizeOptions(host, schema);
|
||||
addFiles(host, options);
|
||||
updateWorkspaceConfiguration(host, options);
|
||||
await addJest(host, options);
|
||||
|
||||
if (options.linter !== Linter.None) {
|
||||
const lintTask = await addLintingToApplication(host, {
|
||||
...options,
|
||||
});
|
||||
tasks.push(lintTask);
|
||||
}
|
||||
|
||||
await formatFiles(host);
|
||||
|
||||
return runTasksInSerial(...tasks);
|
||||
}
|
||||
|
||||
export default e2eProjectGenerator;
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { Linter } from '@nrwl/linter';
|
||||
|
||||
export interface Schema {
|
||||
pluginName: string;
|
||||
npmPackageName: string;
|
||||
@ -5,4 +7,5 @@ export interface Schema {
|
||||
pluginOutputPath?: string;
|
||||
jestConfig?: string;
|
||||
minimal?: boolean;
|
||||
linter?: Linter;
|
||||
}
|
||||
|
||||
@ -35,6 +35,12 @@
|
||||
"default": true,
|
||||
"x-deprecated": "Nx only supports standaloneConfig"
|
||||
},
|
||||
"linter": {
|
||||
"description": "The tool to use for running lint checks.",
|
||||
"type": "string",
|
||||
"enum": ["eslint", "none"],
|
||||
"default": "eslint"
|
||||
},
|
||||
"minimal": {
|
||||
"type": "boolean",
|
||||
"description": "Generate the e2e project with a minimal setup. This would involve not generating tests for a default executor and generator.",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user