feat(nx-plugin): simplify generated plugin code (#16590)

This commit is contained in:
Jason Jean 2023-04-26 18:38:04 -04:00 committed by GitHub
parent 010ddeeadb
commit 7b0f96b1ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 24 additions and 29 deletions

View File

@ -12,6 +12,7 @@
"name": {
"type": "string",
"description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.",
"pattern": "create-.+|^@.+/create(?:-.+)?",
"$default": { "$source": "argv", "index": 0 },
"x-priority": "important"
},

View File

@ -71,6 +71,5 @@ describe('create-nx-plugin', () => {
checkFilesExist(`dist/create-${pluginName}-package/bin/index.js`);
expect(() => runCLI(`e2e e2e`)).not.toThrow();
expect(() => runCLI(`e2e create-${pluginName}-package-e2e`)).not.toThrow();
});
});

View File

@ -133,7 +133,10 @@ async function main(parsedArgs: yargs.Arguments<CreateNxPluginArguments>) {
],
});
const workspaceInfo = await createWorkspace('@nx/plugin', populatedArguments);
const workspaceInfo = await createWorkspace(
`@nx/plugin@${nxVersion}`,
populatedArguments
);
showNxWarning(parsedArgs.pluginName);

View File

@ -165,6 +165,10 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
if (isKnownPreset(parsedArgs.preset)) {
pointToTutorialAndCourse(parsedArgs.preset as Preset);
} else {
output.log({
title: `Successfully applied preset: ${parsedArgs.preset}`,
});
}
}

View File

@ -5,7 +5,6 @@ export interface CreateWorkspaceOptions {
name: string; // Workspace name (e.g. org name)
packageManager: PackageManager; // Package manager to use
nxCloud: boolean; // Enable Nx Cloud
presetVersion?: string; // Version of the preset to use
/**
* @description Enable interactive mode with presets
* @default true

View File

@ -5,9 +5,7 @@ import { createSandbox } from './create-sandbox';
import { createEmptyWorkspace } from './create-empty-workspace';
import { createPreset } from './create-preset';
import { setupCI } from './utils/ci/setup-ci';
import { messages, recordStat } from './utils/nx/ab-testing';
import { initializeGitRepo } from './utils/git/git';
import { nxVersion } from './utils/nx/nx-version';
import { getThirdPartyPreset } from './utils/preset/get-third-party-preset';
import { mapErrorToBodyLines } from './utils/error-utils';

View File

@ -957,11 +957,8 @@ describe('lib', () => {
const config = readProjectConfiguration(tree, 'my-lib');
expect(config.targets.publish).toEqual({
executor: 'nx:run-commands',
options: {
command:
'node tools/scripts/publish.mjs my-lib {args.ver} {args.tag}',
},
command:
'node tools/scripts/publish.mjs my-lib {args.ver} {args.tag}',
dependsOn: ['build'],
});
});

View File

@ -197,10 +197,7 @@ function addProject(
const publishScriptPath = addMinimalPublishScript(tree);
projectConfiguration.targets.publish = {
executor: 'nx:run-commands',
options: {
command: `node ${publishScriptPath} ${options.name} {args.ver} {args.tag}`,
},
command: `node ${publishScriptPath} ${options.name} {args.ver} {args.tag}`,
dependsOn: ['build'],
};
}

View File

@ -39,9 +39,6 @@ export async function createPackageGenerator(
tasks.push(installTask);
await createCliPackage(host, options, pluginPackageName);
if (options.e2eTestRunner !== 'none') {
tasks.push(await addE2eProject(host, options));
}
if (!options.skipFormat) {
await formatFiles(host);

View File

@ -10,17 +10,18 @@ async function main() {
console.log(`Creating the workspace: ${name}`);
// This assumes "<%= preset %>" and "<%= projectName %>" are at the same version
// eslint-disable-next-line @typescript-eslint/no-var-requires
const presetVersion = require('../package.json').version,
// TODO: update below to customize the workspace
const { directory } = await createWorkspace('<%= preset %>', {
name,
const { directory } = await createWorkspace(`<%= preset %>@${presetVersion}`, {
name,
nxCloud: false,
packageManager: 'npm',
// This assumes "<%= preset %>" and "<%= projectName %>" are at the same version
// eslint-disable-next-line @typescript-eslint/no-var-requires
presetVersion: require('../package.json').version,
});
console.log(`Successfully created the workspace: ${directory}.`);
}
main();
main();

View File

@ -1,11 +1,10 @@
import {
uniq,
runCreatePackageCli,
removeTmpProject,
} from '@nx/plugin/testing';
describe('<%= name %> e2e', () => {
const project = uniq('<%= name %>');
const project = '<%= name %>';
let createPackageResult;
beforeAll(async () => {

View File

@ -9,6 +9,7 @@
"name": {
"type": "string",
"description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.",
"pattern": "create-.+|^@.+/create(?:-.+)?",
"$default": {
"$source": "argv",
"index": 0

View File

@ -4,7 +4,6 @@ import {
readJson,
runNxCommandAsync,
runNxCommand,
uniq,
} from '@nx/plugin/testing';
describe('<%= pluginName %> e2e', () => {
@ -18,17 +17,17 @@ describe('<%= pluginName %> e2e', () => {
ensureNxProject('<%= npmPackageName %>', '<%= pluginOutputPath %>');
});
afterAll(() => {
afterAll(async () => {
// `nx reset` kills the daemon, and performs
// some work which can help clean up e2e leftovers
runNxCommandAsync('reset');
await runNxCommandAsync('reset');
});
// Add some tests here to check that your plugin functionality works as expected.
// A sample test is included below to give you some ideas.
xit('should be able to build generated projects', async () => {
const name = uniq('proj');
const name = 'proj';
const generator = 'PLACEHOLDER';
await runNxCommandAsync(`generate <%= npmPackageName %>:${generator} --name ${name}`);
expect(() => runNxCommand('build ${proj}')).not.toThrow();