feat(nx-plugin): simplify generated plugin code (#16590)
This commit is contained in:
parent
010ddeeadb
commit
7b0f96b1ba
@ -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"
|
||||
},
|
||||
|
||||
@ -71,6 +71,5 @@ describe('create-nx-plugin', () => {
|
||||
checkFilesExist(`dist/create-${pluginName}-package/bin/index.js`);
|
||||
|
||||
expect(() => runCLI(`e2e e2e`)).not.toThrow();
|
||||
expect(() => runCLI(`e2e create-${pluginName}-package-e2e`)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@ -133,7 +133,10 @@ async function main(parsedArgs: yargs.Arguments<CreateNxPluginArguments>) {
|
||||
],
|
||||
});
|
||||
|
||||
const workspaceInfo = await createWorkspace('@nx/plugin', populatedArguments);
|
||||
const workspaceInfo = await createWorkspace(
|
||||
`@nx/plugin@${nxVersion}`,
|
||||
populatedArguments
|
||||
);
|
||||
|
||||
showNxWarning(parsedArgs.pluginName);
|
||||
|
||||
|
||||
@ -165,6 +165,10 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
|
||||
|
||||
if (isKnownPreset(parsedArgs.preset)) {
|
||||
pointToTutorialAndCourse(parsedArgs.preset as Preset);
|
||||
} else {
|
||||
output.log({
|
||||
title: `Successfully applied preset: ${parsedArgs.preset}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ export interface CreateWorkspaceOptions {
|
||||
name: string; // Workspace name (e.g. org name)
|
||||
packageManager: PackageManager; // Package manager to use
|
||||
nxCloud: boolean; // Enable Nx Cloud
|
||||
presetVersion?: string; // Version of the preset to use
|
||||
/**
|
||||
* @description Enable interactive mode with presets
|
||||
* @default true
|
||||
|
||||
@ -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';
|
||||
|
||||
|
||||
@ -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}',
|
||||
},
|
||||
dependsOn: ['build'],
|
||||
});
|
||||
});
|
||||
|
||||
@ -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}`,
|
||||
},
|
||||
dependsOn: ['build'],
|
||||
};
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -10,14 +10,15 @@ 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 %>', {
|
||||
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}.`);
|
||||
|
||||
@ -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 () => {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -4,7 +4,6 @@ import {
|
||||
readJson,
|
||||
runNxCommandAsync,
|
||||
runNxCommand,
|
||||
uniq,
|
||||
} from '@nx/plugin/testing';
|
||||
|
||||
describe('<%= pluginName %> e2e', () => {
|
||||
@ -18,17 +17,17 @@ describe('<%= pluginName %> e2e', () => {
|
||||
ensureNxProject('<%= npmPackageName %>', '<%= pluginOutputPath %>');
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
afterAll(async () => {
|
||||
// `nx reset` kills the daemon, and performs
|
||||
// some work which can help clean up e2e leftovers
|
||||
runNxCommandAsync('reset');
|
||||
await runNxCommandAsync('reset');
|
||||
});
|
||||
|
||||
|
||||
// Add some tests here to check that your plugin functionality works as expected.
|
||||
// A sample test is included below to give you some ideas.
|
||||
xit('should be able to build generated projects', async () => {
|
||||
const name = uniq('proj');
|
||||
const name = 'proj';
|
||||
const generator = 'PLACEHOLDER';
|
||||
await runNxCommandAsync(`generate <%= npmPackageName %>:${generator} --name ${name}`);
|
||||
expect(() => runNxCommand('build ${proj}')).not.toThrow();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user