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, {
|
runCreatePlugin(pluginName, {
|
||||||
packageManager,
|
packageManager,
|
||||||
extraArgs: `--createPackageName='false'`,
|
extraArgs: `--createPackageName=false`,
|
||||||
});
|
});
|
||||||
|
|
||||||
checkFilesExist(
|
checkFilesExist(
|
||||||
@ -62,14 +62,14 @@ describe('create-nx-plugin', () => {
|
|||||||
|
|
||||||
runCLI(`build ${pluginName}`);
|
runCLI(`build ${pluginName}`);
|
||||||
checkFilesExist(
|
checkFilesExist(
|
||||||
`dist/${pluginName}/package.json`,
|
`dist/packages/${pluginName}/package.json`,
|
||||||
`dist/${pluginName}/generators.json`,
|
`dist/packages/${pluginName}/generators.json`,
|
||||||
`e2e/tests/${pluginName}.spec.ts`
|
`packages/${pluginName}-e2e/tests/${pluginName}.spec.ts`
|
||||||
);
|
);
|
||||||
|
|
||||||
runCLI(`build create-${pluginName}-package`);
|
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,
|
formatFiles,
|
||||||
runTasksInSerial,
|
runTasksInSerial,
|
||||||
GeneratorCallback,
|
GeneratorCallback,
|
||||||
|
names,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { Linter } from '@nx/linter';
|
import { Linter } from '@nx/linter';
|
||||||
import { PackageJson } from 'nx/src/utils/package-json';
|
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) {
|
export default async function (tree: Tree, options: PresetGeneratorSchema) {
|
||||||
const tasks: GeneratorCallback[] = [];
|
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, {
|
const pluginTask = await pluginGenerator(tree, {
|
||||||
compiler: 'tsc',
|
compiler: 'tsc',
|
||||||
linter: Linter.EsLint,
|
linter: Linter.EsLint,
|
||||||
name: options.pluginName.includes('/')
|
name: pluginProjectName,
|
||||||
? options.pluginName.split('/')[1]
|
|
||||||
: options.pluginName,
|
|
||||||
skipFormat: true,
|
skipFormat: true,
|
||||||
unitTestRunner: 'jest',
|
unitTestRunner: 'jest',
|
||||||
importPath: options.pluginName,
|
importPath: options.pluginName,
|
||||||
rootProject: true,
|
|
||||||
e2eTestRunner: 'jest',
|
e2eTestRunner: 'jest',
|
||||||
publishable: true,
|
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);
|
tasks.push(pluginTask);
|
||||||
|
|
||||||
@ -34,9 +47,11 @@ export default async function (tree: Tree, options: PresetGeneratorSchema) {
|
|||||||
moveNxPluginToDevDeps(tree);
|
moveNxPluginToDevDeps(tree);
|
||||||
|
|
||||||
if (options.createPackageName) {
|
if (options.createPackageName) {
|
||||||
|
const e2eProject = `${options.pluginName}-e2e`;
|
||||||
const cliTask = await createPackageGenerator(tree, {
|
const cliTask = await createPackageGenerator(tree, {
|
||||||
|
directory: 'packages',
|
||||||
name: options.createPackageName,
|
name: options.createPackageName,
|
||||||
e2eProject: 'e2e',
|
e2eProject: e2eProject,
|
||||||
project: options.pluginName,
|
project: options.pluginName,
|
||||||
skipFormat: true,
|
skipFormat: true,
|
||||||
unitTestRunner: 'jest',
|
unitTestRunner: 'jest',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user