Skip to content

Commit

Permalink
feat(nx-plugin): create cli in packages folder (#18234)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi authored Jul 21, 2023
1 parent 717a8dd commit 1861c93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
12 changes: 6 additions & 6 deletions e2e/workspace-create/src/create-nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('create-nx-plugin', () => {

runCreatePlugin(pluginName, {
packageManager,
extraArgs: `--createPackageName='false'`,
extraArgs: `--createPackageName=false`,
});

checkFilesExist(
Expand Down Expand Up @@ -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();
});
});
25 changes: 20 additions & 5 deletions packages/plugin/src/generators/preset/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,28 +16,42 @@ 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);

removeNpmScope(tree);
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',
Expand Down

1 comment on commit 1861c93

@vercel
Copy link

@vercel vercel bot commented on 1861c93 Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.