Skip to content

Commit

Permalink
feat(nx-plugin): simplify generated plugin code
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 26, 2023
1 parent e4aad48 commit 92f2396
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 26 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
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
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
8 changes: 5 additions & 3 deletions packages/plugin/src/utils/testing-utils/nx-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
writeJsonFile,
} from '@nx/devkit';
import { execSync } from 'child_process';
import { dirname } from 'path';
import { dirname, join } from 'path';
import { ensureDirSync } from 'fs-extra';
import { tmpProjPath } from './paths';
import { cleanup } from './utils';
Expand Down Expand Up @@ -81,7 +81,9 @@ export function newNxProject(
export function ensureNxProject(
npmPackageName?: string,
pluginDistPath?: string
): void {
ensureDirSync(tmpProjPath());
): string {
const tempDir = tmpProjPath();
ensureDirSync(tempDir);
newNxProject(npmPackageName, pluginDistPath);
return join(tempDir, 'proj');
}

0 comments on commit 92f2396

Please sign in to comment.