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 20, 2023
1 parent c733d3c commit 8600a0b
Show file tree
Hide file tree
Showing 32 changed files with 254 additions and 228 deletions.
8 changes: 8 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -5487,6 +5487,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": "preset generator",
"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": "preset generator",
"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": "Preset for @nrwl/nx-plugin",
"description": "Initializes a workspace with an nx-plugin inside of it. Use as: `create-nx-workspace --preset @nrwl/nx-plugin`.",
"type": "object",
"properties": {
"pluginName": {
"type": "string",
"description": "Plugin name",
"aliases": ["name"]
}
},
"required": ["pluginName"],
"presets": []
},
"description": "preset generator",
"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"
}
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
39 changes: 21 additions & 18 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 Down Expand Up @@ -38,8 +39,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 +65,7 @@ function determinePluginName(parsedArgs: CreateNxPluginArguments) {
}

interface CreateNxPluginArguments {
name: string;
importPath: string;
pluginName: string;
packageManager: PackageManager;
ci: CI;
allPrompts: boolean;
Expand All @@ -82,19 +82,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 +117,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 +152,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
5 changes: 1 addition & 4 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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,
Expand Down Expand Up @@ -722,7 +723,3 @@ async function determineBundler(

return Promise.resolve(parsedArgs.bundler);
}

function determineCI(argv: yargs.Arguments<Arguments>, nxCloud: boolean) {
throw new Error('Function not implemented.');
}
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 @@ -35,11 +35,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
2 changes: 1 addition & 1 deletion packages/create-nx-workspace/src/internal-utils/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function determineNxCloud(
}

export async function determineCI(
parsedArgs: yargs.Arguments<{ ci: CI; allPrompts?: boolean }>,
parsedArgs: yargs.Arguments<{ ci?: CI; allPrompts?: boolean }>,
nxCloud: boolean
): Promise<string> {
if (!nxCloud) {
Expand Down
Loading

0 comments on commit 8600a0b

Please sign in to comment.