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:
parent
cc2a1d55bb
commit
c486b30c4d
@ -93,6 +93,11 @@
|
|||||||
"enum": ["tsc", "swc"],
|
"enum": ["tsc", "swc"],
|
||||||
"default": "tsc",
|
"default": "tsc",
|
||||||
"description": "The compiler used by the build and test targets."
|
"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"],
|
"required": ["name"],
|
||||||
@ -144,6 +149,11 @@
|
|||||||
"standaloneConfig": {
|
"standaloneConfig": {
|
||||||
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
|
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
|
||||||
"type": "boolean"
|
"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"],
|
"required": ["pluginName", "npmPackageName"],
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import {
|
|||||||
readProjectConfiguration,
|
readProjectConfiguration,
|
||||||
readJson,
|
readJson,
|
||||||
getProjects,
|
getProjects,
|
||||||
|
joinPathFragments,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||||
import { e2eProjectGenerator } from './e2e';
|
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/tsconfig.spec.json')).toBeTruthy();
|
||||||
expect(tree.exists('apps/my-plugin-e2e/jest.config.ts')).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 ");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -34,6 +34,7 @@ function normalizeOptions(host: Tree, options: Schema): NormalizedSchema {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
|
minimal: options.minimal ?? false,
|
||||||
projectName,
|
projectName,
|
||||||
pluginPropertyName,
|
pluginPropertyName,
|
||||||
projectRoot,
|
projectRoot,
|
||||||
|
|||||||
@ -23,6 +23,8 @@ describe('<%= pluginName %> e2e', () => {
|
|||||||
runNxCommandAsync('reset');
|
runNxCommandAsync('reset');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
<% if(!minimal) { %>
|
||||||
|
|
||||||
it('should create <%= pluginName %>', async () => {
|
it('should create <%= pluginName %>', async () => {
|
||||||
const project = uniq('<%= pluginName %>');
|
const project = uniq('<%= pluginName %>');
|
||||||
await runNxCommandAsync(
|
await runNxCommandAsync(
|
||||||
@ -55,4 +57,5 @@ describe('<%= pluginName %> e2e', () => {
|
|||||||
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
|
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
|
||||||
}, 120000);
|
}, 120000);
|
||||||
});
|
});
|
||||||
|
<% } %>
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,4 +5,5 @@ export interface Schema {
|
|||||||
pluginOutputPath?: string;
|
pluginOutputPath?: string;
|
||||||
jestConfig?: string;
|
jestConfig?: string;
|
||||||
standaloneConfig?: boolean;
|
standaloneConfig?: boolean;
|
||||||
|
minimal?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,6 +34,11 @@
|
|||||||
"standaloneConfig": {
|
"standaloneConfig": {
|
||||||
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
|
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
|
||||||
"type": "boolean"
|
"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"],
|
"required": ["pluginName", "npmPackageName"],
|
||||||
|
|||||||
@ -128,6 +128,48 @@ describe('NxPlugin Plugin Generator', () => {
|
|||||||
).toContain('const variable = "<%= projectName %>";');
|
).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('--unitTestRunner', () => {
|
||||||
describe('none', () => {
|
describe('none', () => {
|
||||||
it('should not generate test files', async () => {
|
it('should not generate test files', async () => {
|
||||||
|
|||||||
@ -37,6 +37,9 @@ async function addFiles(host: Tree, options: NormalizedSchema) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (options.minimal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
await generatorGenerator(host, {
|
await generatorGenerator(host, {
|
||||||
project: options.name,
|
project: options.name,
|
||||||
name: options.name,
|
name: options.name,
|
||||||
@ -118,6 +121,7 @@ export async function pluginGenerator(host: Tree, schema: Schema) {
|
|||||||
pluginOutputPath: `dist/${options.libsDir}/${options.projectDirectory}`,
|
pluginOutputPath: `dist/${options.libsDir}/${options.projectDirectory}`,
|
||||||
npmPackageName: options.npmPackageName,
|
npmPackageName: options.npmPackageName,
|
||||||
standaloneConfig: options.standaloneConfig ?? true,
|
standaloneConfig: options.standaloneConfig ?? true,
|
||||||
|
minimal: options.minimal ?? false,
|
||||||
});
|
});
|
||||||
if (options.linter === Linter.EsLint && !options.skipLintChecks) {
|
if (options.linter === Linter.EsLint && !options.skipLintChecks) {
|
||||||
await pluginLintCheckGenerator(host, { projectName: options.name });
|
await pluginLintCheckGenerator(host, { projectName: options.name });
|
||||||
|
|||||||
@ -13,4 +13,5 @@ export interface Schema {
|
|||||||
standaloneConfig?: boolean;
|
standaloneConfig?: boolean;
|
||||||
setParserOptionsProject?: boolean;
|
setParserOptionsProject?: boolean;
|
||||||
compiler: 'swc' | 'tsc';
|
compiler: 'swc' | 'tsc';
|
||||||
|
minimal?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,6 +77,11 @@
|
|||||||
"enum": ["tsc", "swc"],
|
"enum": ["tsc", "swc"],
|
||||||
"default": "tsc",
|
"default": "tsc",
|
||||||
"description": "The compiler used by the build and test targets."
|
"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"],
|
"required": ["name"],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user