From b17a297fd25c1c2637fa45e49cc6502ba2690ab2 Mon Sep 17 00:00:00 2001 From: FrozenPandaz Date: Wed, 26 Apr 2023 16:44:22 -0400 Subject: [PATCH] feat(nx-plugin): simplify generated plugin code --- .../packages/plugin/generators/create-package.json | 1 + packages/create-nx-plugin/bin/create-nx-plugin.ts | 5 ++++- .../create-nx-workspace/src/create-workspace.ts | 2 -- packages/js/src/generators/library/library.spec.ts | 7 ++----- packages/js/src/generators/library/library.ts | 5 +---- .../src/generators/create-package/create-package.ts | 3 --- .../create-framework-package/bin/index.ts__tmpl__ | 13 +++++++------ .../files/e2e/__name__.spec.ts__tmpl__ | 3 +-- .../src/generators/create-package/schema.json | 1 + 9 files changed, 17 insertions(+), 23 deletions(-) diff --git a/docs/generated/packages/plugin/generators/create-package.json b/docs/generated/packages/plugin/generators/create-package.json index a6706b8941fa17..d226f73beec1a2 100644 --- a/docs/generated/packages/plugin/generators/create-package.json +++ b/docs/generated/packages/plugin/generators/create-package.json @@ -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" }, diff --git a/packages/create-nx-plugin/bin/create-nx-plugin.ts b/packages/create-nx-plugin/bin/create-nx-plugin.ts index 4434b2dbb8b85e..6b8e1a51586cbf 100644 --- a/packages/create-nx-plugin/bin/create-nx-plugin.ts +++ b/packages/create-nx-plugin/bin/create-nx-plugin.ts @@ -133,7 +133,10 @@ async function main(parsedArgs: yargs.Arguments) { ], }); - const workspaceInfo = await createWorkspace('@nx/plugin', populatedArguments); + const workspaceInfo = await createWorkspace( + `@nx/plugin@${nxVersion}`, + populatedArguments + ); showNxWarning(parsedArgs.pluginName); diff --git a/packages/create-nx-workspace/src/create-workspace.ts b/packages/create-nx-workspace/src/create-workspace.ts index d31221311004f3..125889b930c99b 100644 --- a/packages/create-nx-workspace/src/create-workspace.ts +++ b/packages/create-nx-workspace/src/create-workspace.ts @@ -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'; diff --git a/packages/js/src/generators/library/library.spec.ts b/packages/js/src/generators/library/library.spec.ts index 152a45cea1926e..292ed60fcec24c 100644 --- a/packages/js/src/generators/library/library.spec.ts +++ b/packages/js/src/generators/library/library.spec.ts @@ -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'], }); }); diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 8f4ce27d3bd160..be9f1381a0c528 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -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'], }; } diff --git a/packages/plugin/src/generators/create-package/create-package.ts b/packages/plugin/src/generators/create-package/create-package.ts index 0163b4e0c757dd..b143cb54d245f5 100644 --- a/packages/plugin/src/generators/create-package/create-package.ts +++ b/packages/plugin/src/generators/create-package/create-package.ts @@ -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); diff --git a/packages/plugin/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ b/packages/plugin/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ index e76aec671a10d4..6df9c79f953526 100644 --- a/packages/plugin/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +++ b/packages/plugin/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ @@ -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(); \ No newline at end of file +main(); diff --git a/packages/plugin/src/generators/create-package/files/e2e/__name__.spec.ts__tmpl__ b/packages/plugin/src/generators/create-package/files/e2e/__name__.spec.ts__tmpl__ index be0960b719d23b..1ebe1bdad5610f 100644 --- a/packages/plugin/src/generators/create-package/files/e2e/__name__.spec.ts__tmpl__ +++ b/packages/plugin/src/generators/create-package/files/e2e/__name__.spec.ts__tmpl__ @@ -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 () => { diff --git a/packages/plugin/src/generators/create-package/schema.json b/packages/plugin/src/generators/create-package/schema.json index 38927754193545..8125d63f5a8943 100644 --- a/packages/plugin/src/generators/create-package/schema.json +++ b/packages/plugin/src/generators/create-package/schema.json @@ -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