Skip to content

Commit

Permalink
feat(nx-plugin): simplify generated plugin code (#16590)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Apr 26, 2023
1 parent 010ddee commit 7b0f96b
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
1 change: 0 additions & 1 deletion e2e/workspace-create/src/create-nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
5 changes: 4 additions & 1 deletion packages/create-nx-plugin/bin/create-nx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions packages/create-nx-workspace/src/create-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
7 changes: 2 additions & 5 deletions packages/js/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
},
command:
'node tools/scripts/publish.mjs my-lib {args.ver} {args.tag}',
dependsOn: ['build'],
});
});
Expand Down
5 changes: 1 addition & 4 deletions packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
},
command: `node ${publishScriptPath} ${options.name} {args.ver} {args.tag}`,
dependsOn: ['build'],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ 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 %>', {
name,
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}.`);
}

main();
main();
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin/src/generators/create-package/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
readJson,
runNxCommandAsync,
runNxCommand,
uniq,
} from '@nx/plugin/testing';

describe('<%= pluginName %> e2e', () => {
Expand All @@ -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();
Expand Down

1 comment on commit 7b0f96b

@vercel
Copy link

@vercel vercel bot commented on 7b0f96b Apr 26, 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.dev
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app

Please sign in to comment.