feat(nx-plugin): create cli in packages folder (#18234)
This commit is contained in:
parent
717a8dd027
commit
1861c931d6
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user