feat(nx-plugin): simplify generated plugin code (#16590)
This commit is contained in:
parent
010ddeeadb
commit
7b0f96b1ba
@ -12,6 +12,7 @@
|
|||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.",
|
"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 },
|
"$default": { "$source": "argv", "index": 0 },
|
||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -71,6 +71,5 @@ describe('create-nx-plugin', () => {
|
|||||||
checkFilesExist(`dist/create-${pluginName}-package/bin/index.js`);
|
checkFilesExist(`dist/create-${pluginName}-package/bin/index.js`);
|
||||||
|
|
||||||
expect(() => runCLI(`e2e e2e`)).not.toThrow();
|
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);
|
showNxWarning(parsedArgs.pluginName);
|
||||||
|
|
||||||
|
|||||||
@ -165,6 +165,10 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
|
|||||||
|
|
||||||
if (isKnownPreset(parsedArgs.preset)) {
|
if (isKnownPreset(parsedArgs.preset)) {
|
||||||
pointToTutorialAndCourse(parsedArgs.preset as 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)
|
name: string; // Workspace name (e.g. org name)
|
||||||
packageManager: PackageManager; // Package manager to use
|
packageManager: PackageManager; // Package manager to use
|
||||||
nxCloud: boolean; // Enable Nx Cloud
|
nxCloud: boolean; // Enable Nx Cloud
|
||||||
presetVersion?: string; // Version of the preset to use
|
|
||||||
/**
|
/**
|
||||||
* @description Enable interactive mode with presets
|
* @description Enable interactive mode with presets
|
||||||
* @default true
|
* @default true
|
||||||
|
|||||||
@ -5,9 +5,7 @@ import { createSandbox } from './create-sandbox';
|
|||||||
import { createEmptyWorkspace } from './create-empty-workspace';
|
import { createEmptyWorkspace } from './create-empty-workspace';
|
||||||
import { createPreset } from './create-preset';
|
import { createPreset } from './create-preset';
|
||||||
import { setupCI } from './utils/ci/setup-ci';
|
import { setupCI } from './utils/ci/setup-ci';
|
||||||
import { messages, recordStat } from './utils/nx/ab-testing';
|
|
||||||
import { initializeGitRepo } from './utils/git/git';
|
import { initializeGitRepo } from './utils/git/git';
|
||||||
import { nxVersion } from './utils/nx/nx-version';
|
|
||||||
import { getThirdPartyPreset } from './utils/preset/get-third-party-preset';
|
import { getThirdPartyPreset } from './utils/preset/get-third-party-preset';
|
||||||
import { mapErrorToBodyLines } from './utils/error-utils';
|
import { mapErrorToBodyLines } from './utils/error-utils';
|
||||||
|
|
||||||
|
|||||||
@ -957,11 +957,8 @@ describe('lib', () => {
|
|||||||
|
|
||||||
const config = readProjectConfiguration(tree, 'my-lib');
|
const config = readProjectConfiguration(tree, 'my-lib');
|
||||||
expect(config.targets.publish).toEqual({
|
expect(config.targets.publish).toEqual({
|
||||||
executor: 'nx:run-commands',
|
command:
|
||||||
options: {
|
'node tools/scripts/publish.mjs my-lib {args.ver} {args.tag}',
|
||||||
command:
|
|
||||||
'node tools/scripts/publish.mjs my-lib {args.ver} {args.tag}',
|
|
||||||
},
|
|
||||||
dependsOn: ['build'],
|
dependsOn: ['build'],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -197,10 +197,7 @@ function addProject(
|
|||||||
const publishScriptPath = addMinimalPublishScript(tree);
|
const publishScriptPath = addMinimalPublishScript(tree);
|
||||||
|
|
||||||
projectConfiguration.targets.publish = {
|
projectConfiguration.targets.publish = {
|
||||||
executor: 'nx:run-commands',
|
command: `node ${publishScriptPath} ${options.name} {args.ver} {args.tag}`,
|
||||||
options: {
|
|
||||||
command: `node ${publishScriptPath} ${options.name} {args.ver} {args.tag}`,
|
|
||||||
},
|
|
||||||
dependsOn: ['build'],
|
dependsOn: ['build'],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,9 +39,6 @@ export async function createPackageGenerator(
|
|||||||
tasks.push(installTask);
|
tasks.push(installTask);
|
||||||
|
|
||||||
await createCliPackage(host, options, pluginPackageName);
|
await createCliPackage(host, options, pluginPackageName);
|
||||||
if (options.e2eTestRunner !== 'none') {
|
|
||||||
tasks.push(await addE2eProject(host, options));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!options.skipFormat) {
|
if (!options.skipFormat) {
|
||||||
await formatFiles(host);
|
await formatFiles(host);
|
||||||
|
|||||||
@ -10,17 +10,18 @@ async function main() {
|
|||||||
|
|
||||||
console.log(`Creating the workspace: ${name}`);
|
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
|
// TODO: update below to customize the workspace
|
||||||
const { directory } = await createWorkspace('<%= preset %>', {
|
const { directory } = await createWorkspace(`<%= preset %>@${presetVersion}`, {
|
||||||
name,
|
name,
|
||||||
nxCloud: false,
|
nxCloud: false,
|
||||||
packageManager: 'npm',
|
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}.`);
|
console.log(`Successfully created the workspace: ${directory}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
uniq,
|
|
||||||
runCreatePackageCli,
|
runCreatePackageCli,
|
||||||
removeTmpProject,
|
removeTmpProject,
|
||||||
} from '@nx/plugin/testing';
|
} from '@nx/plugin/testing';
|
||||||
|
|
||||||
describe('<%= name %> e2e', () => {
|
describe('<%= name %> e2e', () => {
|
||||||
const project = uniq('<%= name %>');
|
const project = '<%= name %>';
|
||||||
let createPackageResult;
|
let createPackageResult;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The package name of cli, e.g. `create-framework-package`. Note this must be a valid NPM name to be published.",
|
"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": {
|
"$default": {
|
||||||
"$source": "argv",
|
"$source": "argv",
|
||||||
"index": 0
|
"index": 0
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import {
|
|||||||
readJson,
|
readJson,
|
||||||
runNxCommandAsync,
|
runNxCommandAsync,
|
||||||
runNxCommand,
|
runNxCommand,
|
||||||
uniq,
|
|
||||||
} from '@nx/plugin/testing';
|
} from '@nx/plugin/testing';
|
||||||
|
|
||||||
describe('<%= pluginName %> e2e', () => {
|
describe('<%= pluginName %> e2e', () => {
|
||||||
@ -18,17 +17,17 @@ describe('<%= pluginName %> e2e', () => {
|
|||||||
ensureNxProject('<%= npmPackageName %>', '<%= pluginOutputPath %>');
|
ensureNxProject('<%= npmPackageName %>', '<%= pluginOutputPath %>');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(async () => {
|
||||||
// `nx reset` kills the daemon, and performs
|
// `nx reset` kills the daemon, and performs
|
||||||
// some work which can help clean up e2e leftovers
|
// 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.
|
// Add some tests here to check that your plugin functionality works as expected.
|
||||||
// A sample test is included below to give you some ideas.
|
// A sample test is included below to give you some ideas.
|
||||||
xit('should be able to build generated projects', async () => {
|
xit('should be able to build generated projects', async () => {
|
||||||
const name = uniq('proj');
|
const name = 'proj';
|
||||||
const generator = 'PLACEHOLDER';
|
const generator = 'PLACEHOLDER';
|
||||||
await runNxCommandAsync(`generate <%= npmPackageName %>:${generator} --name ${name}`);
|
await runNxCommandAsync(`generate <%= npmPackageName %>:${generator} --name ${name}`);
|
||||||
expect(() => runNxCommand('build ${proj}')).not.toThrow();
|
expect(() => runNxCommand('build ${proj}')).not.toThrow();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user