Skip to content

Commit

Permalink
feat(nx-plugin): add lint option for the e2e generator (#15140)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-stepanenko committed Feb 20, 2023
1 parent 576bec2 commit b8e6679
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/generated/packages/nx-plugin/generators/e2e-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
19 changes: 18 additions & 1 deletion packages/nx-plugin/src/generators/e2e-project/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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'],
},
});
});
});
35 changes: 35 additions & 0 deletions packages/nx-plugin/src/generators/e2e-project/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
extractLayoutDirectory,
formatFiles,
generateFiles,
GeneratorCallback,
getWorkspaceLayout,
joinPathFragments,
names,
Expand All @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions packages/nx-plugin/src/generators/e2e-project/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Linter } from '@nrwl/linter';

export interface Schema {
pluginName: string;
npmPackageName: string;
projectDirectory?: string;
pluginOutputPath?: string;
jestConfig?: string;
minimal?: boolean;
linter?: Linter;
}
6 changes: 6 additions & 0 deletions packages/nx-plugin/src/generators/e2e-project/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

1 comment on commit b8e6679

@vercel
Copy link

@vercel vercel bot commented on b8e6679 Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.