Skip to content

Commit

Permalink
feat(nx-plugin): add nx-plugin preset generator
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Mar 31, 2023
1 parent 03af7c2 commit 78eb03f
Show file tree
Hide file tree
Showing 40 changed files with 321 additions and 278 deletions.
8 changes: 8 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -5512,6 +5512,14 @@
"children": [],
"isExternal": false,
"disableCollapsible": false
},
{
"id": "preset",
"path": "/packages/nx-plugin/generators/preset",
"name": "preset",
"children": [],
"isExternal": false,
"disableCollapsible": false
}
],
"isExternal": false,
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/manifests/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,15 @@
"originalFilePath": "/packages/nx-plugin/src/generators/lint-checks/schema.json",
"path": "/packages/nx-plugin/generators/plugin-lint-checks",
"type": "generator"
},
"/packages/nx-plugin/generators/preset": {
"description": "Initializes a workspace with an nx-plugin inside of it. Use as: `create-nx-workspace --preset @nrwl/nx-plugin`.",
"file": "generated/packages/nx-plugin/generators/preset.json",
"hidden": true,
"name": "preset",
"originalFilePath": "/packages/nx-plugin/src/generators/preset/schema.json",
"path": "/packages/nx-plugin/generators/preset",
"type": "generator"
}
},
"path": "/packages/nx-plugin"
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,15 @@
"originalFilePath": "/packages/nx-plugin/src/generators/lint-checks/schema.json",
"path": "nx-plugin/generators/plugin-lint-checks",
"type": "generator"
},
{
"description": "Initializes a workspace with an nx-plugin inside of it. Use as: `create-nx-workspace --preset @nrwl/nx-plugin`.",
"file": "generated/packages/nx-plugin/generators/preset.json",
"hidden": true,
"name": "preset",
"originalFilePath": "/packages/nx-plugin/src/generators/preset/schema.json",
"path": "nx-plugin/generators/preset",
"type": "generator"
}
],
"githubRoot": "https://github.com/nrwl/nx/blob/master",
Expand Down
28 changes: 28 additions & 0 deletions docs/generated/packages/nx-plugin/generators/preset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "preset",
"factory": "./src/generators/preset/generator",
"schema": {
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "NxPluginPreset",
"title": "Generator ran by create-nx-plugin",
"description": "Initializes a workspace with an nx-plugin inside of it. Use as: `create-nx-plugin` or `create-nx-workspace --preset @nrwl/nx-plugin`.",
"type": "object",
"properties": {
"pluginName": {
"type": "string",
"description": "Plugin name",
"aliases": ["name"]
}
},
"required": ["pluginName"],
"presets": []
},
"description": "Initializes a workspace with an nx-plugin inside of it. Use as: `create-nx-workspace --preset @nrwl/nx-plugin`.",
"hidden": true,
"x-use-standalone-layout": true,
"implementation": "/packages/nx-plugin/src/generators/preset/generator.ts",
"aliases": [],
"path": "/packages/nx-plugin/src/generators/preset/schema.json",
"type": "generator"
}
2 changes: 1 addition & 1 deletion e2e/utils/create-project-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export function runCreatePlugin(
} create-nx-plugin@${getPublishedVersion()} ${name}`;

if (pluginName) {
command += ` --pluginName=${pluginName}`;
command += ` --pluginName=${pluginName} --no-nxCloud`;
}

if (packageManager && !useDetectedPm) {
Expand Down
8 changes: 5 additions & 3 deletions e2e/workspace-create/src/create-nx-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
uniq,
runCreatePlugin,
cleanupProject,
tmpProjPath,
} from '@nrwl/e2e/utils';

describe('create-nx-plugin', () => {
Expand All @@ -25,10 +26,11 @@ describe('create-nx-plugin', () => {
checkFilesExist(
'package.json',
packageManagerLockFile[packageManager],
`packages/${pluginName}/package.json`,
`packages/${pluginName}/project.json`
`project.json`,
`generators.json`,
`executors.json`
);

expect(() => runCLI(`e2e ${pluginName}-e2e`)).not.toThrow();
expect(() => runCLI(`e2e e2e`)).not.toThrow();
});
});
3 changes: 1 addition & 2 deletions packages/create-nx-plugin/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
}
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
Expand Down
44 changes: 23 additions & 21 deletions packages/create-nx-plugin/bin/create-nx-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
import chalk = require('chalk');
import enquirer = require('enquirer');
import yargs = require('yargs');
Expand All @@ -16,11 +17,10 @@ import {
withOptions,
withPackageManager,
} from 'create-nx-workspace/src/internal-utils/yargs-options';
import { createWorkspace } from 'create-nx-workspace';
import { createWorkspace, CreateWorkspaceOptions } from 'create-nx-workspace';
import { output } from 'create-nx-workspace/src/utils/output';
import { CI } from 'create-nx-workspace/src/utils/ci/ci-list';
import { CreateWorkspaceOptions } from 'create-nx-workspace/src/create-workspace-options';
import { PackageManager } from 'create-nx-workspace/src/utils/package-manager';
import type { PackageManager } from 'create-nx-workspace/src/utils/package-manager';

export const yargsDecorator = {
'Options:': `${chalk.green`Options`}:`,
Expand All @@ -38,8 +38,8 @@ export const yargsDecorator = {
const nxVersion = require('../package.json').version;

function determinePluginName(parsedArgs: CreateNxPluginArguments) {
if (parsedArgs.name) {
return Promise.resolve(parsedArgs.name);
if (parsedArgs.pluginName) {
return Promise.resolve(parsedArgs.pluginName);
}

return enquirer
Expand All @@ -64,8 +64,7 @@ function determinePluginName(parsedArgs: CreateNxPluginArguments) {
}

interface CreateNxPluginArguments {
name: string;
importPath: string;
pluginName: string;
packageManager: PackageManager;
ci: CI;
allPrompts: boolean;
Expand All @@ -82,19 +81,19 @@ export const commandsObject: yargs.Argv<CreateNxPluginArguments> = yargs
// this is the default and only command
'$0 [name] [options]',
'Create a new Nx plugin workspace',
withOptions(
(yargs) =>
yargs.option('name', {
(yargs) =>
withOptions(
yargs.positional('pluginName', {
describe: chalk.dim`Plugin name`,
type: 'string',
alias: ['pluginName'],
alias: ['name'],
}),
withNxCloud,
withCI,
withAllPrompts,
withPackageManager,
withGitOptions
),
withNxCloud,
withCI,
withAllPrompts,
withPackageManager,
withGitOptions
),
async (argv: yargs.ArgumentsCamelCase<CreateNxPluginArguments>) => {
await main(argv).catch((error) => {
const { version } = require('../package.json');
Expand All @@ -117,11 +116,11 @@ export const commandsObject: yargs.Argv<CreateNxPluginArguments> = yargs
async function main(parsedArgs: yargs.Arguments<CreateNxPluginArguments>) {
const populatedArguments: CreateNxPluginArguments & CreateWorkspaceOptions = {
...parsedArgs,
name: parsedArgs.pluginName.includes('/')
? parsedArgs.pluginName.split('/')[1]
: parsedArgs.pluginName,
};
await createWorkspace<CreateNxPluginArguments>(
'@nrwl/nx-plugin',
populatedArguments
);
await createWorkspace('@nrwl/nx-plugin', populatedArguments);
}

/**
Expand Down Expand Up @@ -152,3 +151,6 @@ async function normalizeArgsMiddleware(
process.exit(1);
}
}

// Trigger Yargs
commandsObject.argv;
32 changes: 0 additions & 32 deletions packages/create-nx-plugin/bin/detect-invoked-package-manager.ts

This file was deleted.

106 changes: 0 additions & 106 deletions packages/create-nx-plugin/bin/shared.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/create-nx-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"homepage": "https://nx.dev",
"dependencies": {
"create-nx-workspace": "file:../create-nx-workspace",
"yargs-parser": "21.1.1"
"chalk": "^4.1.0",
"enquirer": "~2.3.6",
"yargs": "^17.6.2"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 2 additions & 1 deletion packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { getThirdPartyPreset } from '../src/utils/preset/get-third-party-preset'
import { Framework, frameworkList } from './types/framework-list';
import { Bundler, bundlerList } from './types/bundler-list';
import {
determineCI,
determineDefaultBase,
determineNxCloud,
determinePackageManager,
determineCI,
} from '../src/internal-utils/prompts';
import {
withAllPrompts,
Expand Down Expand Up @@ -74,6 +74,7 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
.option('interactive', {
describe: chalk.dim`Enable interactive mode with presets`,
type: 'boolean',
default: true,
})
.option('style', {
describe: chalk.dim`Style option to be used when a preset with pregenerated app is selected`,
Expand Down
1 change: 1 addition & 0 deletions packages/create-nx-workspace/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './src/create-workspace';
export * from './src/create-workspace-options';
3 changes: 2 additions & 1 deletion packages/create-nx-workspace/src/create-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ export async function createWorkspace<T extends CreateWorkspaceOptions>(

const tmpDir = await createSandbox(packageManager);

// nx new requires preset currently. We should probably make it optional.
const directory = await createEmptyWorkspace<T>(
tmpDir,
name,
packageManager,
options
{ ...options, preset }
);

// If the preset is a third-party preset, we need to call createPreset to install it
Expand Down
Loading

0 comments on commit 78eb03f

Please sign in to comment.