diff --git a/e2e/workspace-create/src/create-nx-plugin.test.ts b/e2e/workspace-create/src/create-nx-plugin.test.ts index 5348a90e4a238..299b2580c79f9 100644 --- a/e2e/workspace-create/src/create-nx-plugin.test.ts +++ b/e2e/workspace-create/src/create-nx-plugin.test.ts @@ -20,7 +20,7 @@ describe('create-nx-plugin', () => { runCreatePlugin(pluginName, { packageManager, - extraArgs: `--createPackageName='false'`, + extraArgs: `--createPackageName=false`, }); checkFilesExist( @@ -62,14 +62,14 @@ describe('create-nx-plugin', () => { runCLI(`build ${pluginName}`); checkFilesExist( - `dist/${pluginName}/package.json`, - `dist/${pluginName}/generators.json`, - `e2e/tests/${pluginName}.spec.ts` + `dist/packages/${pluginName}/package.json`, + `dist/packages/${pluginName}/generators.json`, + `packages/${pluginName}-e2e/tests/${pluginName}.spec.ts` ); runCLI(`build create-${pluginName}-package`); - checkFilesExist(`dist/create-${pluginName}-package/bin/index.js`); + checkFilesExist(`dist/packages/create-${pluginName}-package/bin/index.js`); - expect(() => runCLI(`e2e e2e`)).not.toThrow(); + expect(() => runCLI(`e2e ${pluginName}-e2e`)).not.toThrow(); }); }); diff --git a/packages/plugin/src/generators/preset/generator.ts b/packages/plugin/src/generators/preset/generator.ts index 61dae9d564fb9..47769716d5b06 100644 --- a/packages/plugin/src/generators/preset/generator.ts +++ b/packages/plugin/src/generators/preset/generator.ts @@ -6,6 +6,7 @@ import { formatFiles, runTasksInSerial, GeneratorCallback, + names, } from '@nx/devkit'; import { Linter } from '@nx/linter'; import { PackageJson } from 'nx/src/utils/package-json'; @@ -15,18 +16,30 @@ import createPackageGenerator from '../create-package/create-package'; export default async function (tree: Tree, options: PresetGeneratorSchema) { const tasks: GeneratorCallback[] = []; + const pluginProjectName = names( + options.pluginName.includes('/') + ? options.pluginName.split('/')[1] + : options.pluginName + ).fileName; + options.createPackageName = + options.createPackageName === 'false' // for command line in e2e, it is passed as a string + ? undefined + : options.createPackageName; const pluginTask = await pluginGenerator(tree, { compiler: 'tsc', linter: Linter.EsLint, - name: options.pluginName.includes('/') - ? options.pluginName.split('/')[1] - : options.pluginName, + name: pluginProjectName, skipFormat: true, unitTestRunner: 'jest', importPath: options.pluginName, - rootProject: true, e2eTestRunner: 'jest', publishable: true, + // when creating a CLI package, the plugin will be in the packages folder + directory: + options.createPackageName && options.createPackageName !== 'false' + ? 'packages' + : undefined, + rootProject: options.createPackageName ? false : true, }); tasks.push(pluginTask); @@ -34,9 +47,11 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) { moveNxPluginToDevDeps(tree); if (options.createPackageName) { + const e2eProject = `${options.pluginName}-e2e`; const cliTask = await createPackageGenerator(tree, { + directory: 'packages', name: options.createPackageName, - e2eProject: 'e2e', + e2eProject: e2eProject, project: options.pluginName, skipFormat: true, unitTestRunner: 'jest',