feat(nx-plugin): add a minimal setup flag to produce an empty nx-plugin (#10718)

* feat(nx-plugin): add a minimal setup flag to produce an empty nx-plugin

* feat(nx-plugin): add e2e minimal setup
This commit is contained in:
Colum Ferry 2022-06-16 22:15:27 +01:00 committed by GitHub
parent cc2a1d55bb
commit c486b30c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 92 additions and 0 deletions

View File

@ -93,6 +93,11 @@
"enum": ["tsc", "swc"],
"default": "tsc",
"description": "The compiler used by the build and test targets."
},
"minimal": {
"type": "boolean",
"description": "Generate the plugin with a minimal setup. This would involve not generating a default executor and generator.",
"default": false
}
},
"required": ["name"],
@ -144,6 +149,11 @@
"standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean"
},
"minimal": {
"type": "boolean",
"description": "Generate the e2e project with a minimal setup. This would involve not generating tests for a default executor and generator.",
"default": false
}
},
"required": ["pluginName", "npmPackageName"],

View File

@ -4,6 +4,7 @@ import {
readProjectConfiguration,
readJson,
getProjects,
joinPathFragments,
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { e2eProjectGenerator } from './e2e';
@ -147,4 +148,23 @@ describe('NxPlugin e2e-project Generator', () => {
expect(tree.exists('apps/my-plugin-e2e/tsconfig.spec.json')).toBeTruthy();
expect(tree.exists('apps/my-plugin-e2e/jest.config.ts')).toBeTruthy();
});
it('should not generate tests when minimal flag is passed', async () => {
// ARRANGE & ACT
await e2eProjectGenerator(tree, {
pluginName: 'my-plugin',
pluginOutputPath: `dist/libs/my-plugin`,
npmPackageName: '@proj/my-plugin',
standaloneConfig: false,
minimal: true,
});
const { root } = readProjectConfiguration(tree, 'my-plugin-e2e');
// ASSERT
expect(
tree.read(joinPathFragments(root, 'tests/my-plugin.spec.ts'), 'utf-8')
).not.toContain("it('should create ");
});
});

View File

@ -34,6 +34,7 @@ function normalizeOptions(host: Tree, options: Schema): NormalizedSchema {
return {
...options,
minimal: options.minimal ?? false,
projectName,
pluginPropertyName,
projectRoot,

View File

@ -23,6 +23,8 @@ describe('<%= pluginName %> e2e', () => {
runNxCommandAsync('reset');
});
<% if(!minimal) { %>
it('should create <%= pluginName %>', async () => {
const project = uniq('<%= pluginName %>');
await runNxCommandAsync(
@ -55,4 +57,5 @@ describe('<%= pluginName %> e2e', () => {
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
}, 120000);
});
<% } %>
});

View File

@ -5,4 +5,5 @@ export interface Schema {
pluginOutputPath?: string;
jestConfig?: string;
standaloneConfig?: boolean;
minimal?: boolean;
}

View File

@ -34,6 +34,11 @@
"standaloneConfig": {
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
"type": "boolean"
},
"minimal": {
"type": "boolean",
"description": "Generate the e2e project with a minimal setup. This would involve not generating tests for a default executor and generator.",
"default": false
}
},
"required": ["pluginName", "npmPackageName"],

View File

@ -128,6 +128,48 @@ describe('NxPlugin Plugin Generator', () => {
).toContain('const variable = "<%= projectName %>";');
});
it('should not create generator and executor files for minimal setups', async () => {
await pluginGenerator(tree, getSchema({ name: 'myPlugin', minimal: true }));
[
'libs/my-plugin/project.json',
'libs/my-plugin/generators.json',
'libs/my-plugin/executors.json',
].forEach((path) => expect(tree.exists(path)).toBeTruthy());
[
'libs/my-plugin/src/generators/my-plugin/schema.d.ts',
'libs/my-plugin/src/generators/my-plugin/generator.ts',
'libs/my-plugin/src/generators/my-plugin/generator.spec.ts',
'libs/my-plugin/src/generators/my-plugin/schema.json',
'libs/my-plugin/src/generators/my-plugin/schema.d.ts',
'libs/my-plugin/src/generators/my-plugin/files/src/index.ts__template__',
'libs/my-plugin/src/executors/build/executor.ts',
'libs/my-plugin/src/executors/build/executor.spec.ts',
'libs/my-plugin/src/executors/build/schema.json',
'libs/my-plugin/src/executors/build/schema.d.ts',
].forEach((path) => expect(tree.exists(path)).toBeFalsy());
expect(tree.read('libs/my-plugin/generators.json', 'utf-8'))
.toMatchInlineSnapshot(`
"{
\\"$schema\\": \\"http://json-schema.org/schema\\",
\\"name\\": \\"my-plugin\\",
\\"version\\": \\"0.0.1\\",
\\"generators\\": {}
}
"
`);
expect(tree.read('libs/my-plugin/executors.json', 'utf-8'))
.toMatchInlineSnapshot(`
"{
\\"$schema\\": \\"http://json-schema.org/schema\\",
\\"executors\\": {}
}
"
`);
});
describe('--unitTestRunner', () => {
describe('none', () => {
it('should not generate test files', async () => {

View File

@ -37,6 +37,9 @@ async function addFiles(host: Tree, options: NormalizedSchema) {
}
);
if (options.minimal) {
return;
}
await generatorGenerator(host, {
project: options.name,
name: options.name,
@ -118,6 +121,7 @@ export async function pluginGenerator(host: Tree, schema: Schema) {
pluginOutputPath: `dist/${options.libsDir}/${options.projectDirectory}`,
npmPackageName: options.npmPackageName,
standaloneConfig: options.standaloneConfig ?? true,
minimal: options.minimal ?? false,
});
if (options.linter === Linter.EsLint && !options.skipLintChecks) {
await pluginLintCheckGenerator(host, { projectName: options.name });

View File

@ -13,4 +13,5 @@ export interface Schema {
standaloneConfig?: boolean;
setParserOptionsProject?: boolean;
compiler: 'swc' | 'tsc';
minimal?: boolean;
}

View File

@ -77,6 +77,11 @@
"enum": ["tsc", "swc"],
"default": "tsc",
"description": "The compiler used by the build and test targets."
},
"minimal": {
"type": "boolean",
"description": "Generate the plugin with a minimal setup. This would involve not generating a default executor and generator.",
"default": false
}
},
"required": ["name"],