feat(misc): rework create-nx-workspace prompts (#17230)
This commit is contained in:
parent
97c3bef658
commit
a722302caf
@ -29,15 +29,13 @@ Show all prompts
|
||||
|
||||
Type: `string`
|
||||
|
||||
The name of the application when a preset with pregenerated app is selected
|
||||
The name of the app when using a monorepo with certain stacks
|
||||
|
||||
### bundler
|
||||
|
||||
Type: `string`
|
||||
|
||||
Choices: [webpack, vite, rspack]
|
||||
|
||||
Bundler to be used to build the application
|
||||
Bundler to be used to build the app
|
||||
|
||||
### ci
|
||||
|
||||
@ -79,15 +77,13 @@ Default base to use for new projects
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Generate a Dockerfile with your node-standalone
|
||||
Generate a Dockerfile for the Node API
|
||||
|
||||
### framework
|
||||
|
||||
Type: `string`
|
||||
|
||||
Choices: [express, fastify, koa, nest]
|
||||
|
||||
Framework option to be used when the node-standalone preset is selected
|
||||
Framework option to be used with certain stacks
|
||||
|
||||
### help
|
||||
|
||||
@ -135,13 +131,13 @@ Package manager to use
|
||||
|
||||
Type: `string`
|
||||
|
||||
Customizes the initial content of your workspace. Default presets include: ["apps", "empty", "core", "npm", "ts", "web-components", "angular-monorepo", "angular-standalone", "react-monorepo", "react-standalone", "nextjs-standalone", "react-native", "expo", "next", "nest", "express", "react", "angular", "node-standalone"]. To build your own see https://nx.dev/packages/nx-plugin#preset
|
||||
Customizes the initial content of your workspace. Default presets include: ["apps", "empty", "core", "npm", "ts", "web-components", "angular-monorepo", "angular-standalone", "react-monorepo", "react-standalone", "next", "nextjs-standalone", "react-native", "expo", "nest", "express", "react", "angular", "node-standalone", "node-monorepo"]. To build your own see https://nx.dev/packages/nx-plugin#preset
|
||||
|
||||
### routing
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Add a routing setup when a preset with pregenerated app is selected
|
||||
Add a routing setup for an Angular app
|
||||
|
||||
### skipGit
|
||||
|
||||
@ -161,10 +157,18 @@ Use Standalone Components if generating an Angular app
|
||||
|
||||
Type: `string`
|
||||
|
||||
Style option to be used when a preset with pregenerated app is selected
|
||||
Stylesheet type to be used with certain stacks
|
||||
|
||||
### version
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Show version number
|
||||
|
||||
### workspaceType
|
||||
|
||||
Type: `string`
|
||||
|
||||
Choices: [integrated, package-based, standalone]
|
||||
|
||||
The type of workspace to create
|
||||
|
||||
@ -29,15 +29,13 @@ Show all prompts
|
||||
|
||||
Type: `string`
|
||||
|
||||
The name of the application when a preset with pregenerated app is selected
|
||||
The name of the app when using a monorepo with certain stacks
|
||||
|
||||
### bundler
|
||||
|
||||
Type: `string`
|
||||
|
||||
Choices: [webpack, vite, rspack]
|
||||
|
||||
Bundler to be used to build the application
|
||||
Bundler to be used to build the app
|
||||
|
||||
### ci
|
||||
|
||||
@ -79,15 +77,13 @@ Default base to use for new projects
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Generate a Dockerfile with your node-standalone
|
||||
Generate a Dockerfile for the Node API
|
||||
|
||||
### framework
|
||||
|
||||
Type: `string`
|
||||
|
||||
Choices: [express, fastify, koa, nest]
|
||||
|
||||
Framework option to be used when the node-standalone preset is selected
|
||||
Framework option to be used with certain stacks
|
||||
|
||||
### help
|
||||
|
||||
@ -135,13 +131,13 @@ Package manager to use
|
||||
|
||||
Type: `string`
|
||||
|
||||
Customizes the initial content of your workspace. Default presets include: ["apps", "empty", "core", "npm", "ts", "web-components", "angular-monorepo", "angular-standalone", "react-monorepo", "react-standalone", "nextjs-standalone", "react-native", "expo", "next", "nest", "express", "react", "angular", "node-standalone"]. To build your own see https://nx.dev/packages/nx-plugin#preset
|
||||
Customizes the initial content of your workspace. Default presets include: ["apps", "empty", "core", "npm", "ts", "web-components", "angular-monorepo", "angular-standalone", "react-monorepo", "react-standalone", "next", "nextjs-standalone", "react-native", "expo", "nest", "express", "react", "angular", "node-standalone", "node-monorepo"]. To build your own see https://nx.dev/packages/nx-plugin#preset
|
||||
|
||||
### routing
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Add a routing setup when a preset with pregenerated app is selected
|
||||
Add a routing setup for an Angular app
|
||||
|
||||
### skipGit
|
||||
|
||||
@ -161,10 +157,18 @@ Use Standalone Components if generating an Angular app
|
||||
|
||||
Type: `string`
|
||||
|
||||
Style option to be used when a preset with pregenerated app is selected
|
||||
Stylesheet type to be used with certain stacks
|
||||
|
||||
### version
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Show version number
|
||||
|
||||
### workspaceType
|
||||
|
||||
Type: `string`
|
||||
|
||||
Choices: [integrated, package-based, standalone]
|
||||
|
||||
The type of workspace to create
|
||||
|
||||
@ -14,12 +14,11 @@ import { writeFileSync } from 'fs';
|
||||
import { createFileSync } from 'fs-extra';
|
||||
|
||||
describe('Storybook generators and executors for standalone workspaces - using React + Vite', () => {
|
||||
const wsName = uniq('react');
|
||||
const appName = uniq('app');
|
||||
const appName = uniq('react');
|
||||
|
||||
beforeAll(() => {
|
||||
// create a workspace with a single react app at the root
|
||||
runCreateWorkspace(wsName, {
|
||||
runCreateWorkspace(appName, {
|
||||
preset: 'react-standalone',
|
||||
appName,
|
||||
style: 'css',
|
||||
@ -80,7 +79,7 @@ describe('Storybook generators and executors for standalone workspaces - using R
|
||||
writeFileSync(
|
||||
tmpProjPath(`src/app/test-button.tsx`),
|
||||
`
|
||||
import { MyLib } from '@${wsName}/my-lib';
|
||||
import { MyLib } from '@${appName}/my-lib';
|
||||
|
||||
export function TestButton() {
|
||||
return (
|
||||
|
||||
@ -135,6 +135,7 @@ export function runCreateWorkspace(
|
||||
bundler,
|
||||
routing,
|
||||
standaloneApi,
|
||||
docker,
|
||||
nextAppDir,
|
||||
}: {
|
||||
preset: string;
|
||||
@ -149,6 +150,7 @@ export function runCreateWorkspace(
|
||||
bundler?: 'webpack' | 'vite';
|
||||
standaloneApi?: boolean;
|
||||
routing?: boolean;
|
||||
docker?: boolean;
|
||||
nextAppDir?: boolean;
|
||||
}
|
||||
) {
|
||||
@ -171,10 +173,14 @@ export function runCreateWorkspace(
|
||||
command += ` --bundler=${bundler}`;
|
||||
}
|
||||
|
||||
if (nextAppDir) {
|
||||
if (nextAppDir !== undefined) {
|
||||
command += ` --nextAppDir=${nextAppDir}`;
|
||||
}
|
||||
|
||||
if (docker !== undefined) {
|
||||
command += ` --docker=${docker}`;
|
||||
}
|
||||
|
||||
if (standaloneApi !== undefined) {
|
||||
command += ` --standaloneApi=${standaloneApi}`;
|
||||
}
|
||||
|
||||
@ -209,6 +209,7 @@ describe('create-nx-workspace', () => {
|
||||
preset: 'next',
|
||||
style: 'css',
|
||||
appName,
|
||||
nextAppDir: false,
|
||||
packageManager,
|
||||
});
|
||||
|
||||
@ -250,7 +251,7 @@ describe('create-nx-workspace', () => {
|
||||
const appName = uniq('app');
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'express',
|
||||
style: 'css',
|
||||
docker: false,
|
||||
appName,
|
||||
packageManager,
|
||||
});
|
||||
@ -309,6 +310,7 @@ describe('create-nx-workspace', () => {
|
||||
const appName = uniq('app');
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'nest',
|
||||
docker: false,
|
||||
appName,
|
||||
packageManager,
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -9,15 +9,16 @@ export enum Preset {
|
||||
AngularStandalone = 'angular-standalone',
|
||||
ReactMonorepo = 'react-monorepo',
|
||||
ReactStandalone = 'react-standalone',
|
||||
NextJs = 'next',
|
||||
NextJsStandalone = 'nextjs-standalone',
|
||||
ReactNative = 'react-native',
|
||||
Expo = 'expo',
|
||||
NextJs = 'next',
|
||||
Nest = 'nest',
|
||||
Express = 'express',
|
||||
React = 'react',
|
||||
Angular = 'angular',
|
||||
NodeStandalone = 'node-standalone',
|
||||
NodeMonorepo = 'node-monorepo',
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -695,6 +695,67 @@ Nx comes with local caching already built-in (check your \`nx.json\`). On CI you
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`@nx/workspace:generateWorkspaceFiles README.md should be created for NodeMonorepo preset 1`] = `
|
||||
"# Proj
|
||||
|
||||
<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>
|
||||
|
||||
✨ **This workspace has been generated by [Nx, a Smart, fast and extensible build system.](https://nx.dev)** ✨
|
||||
|
||||
## Generate code
|
||||
|
||||
If you happen to use Nx plugins, you can leverage code generators that might come with it.
|
||||
|
||||
Run \`nx list\` to get a list of available plugins and whether they have generators. Then run \`nx list <plugin-name>\` to see what generators are available.
|
||||
|
||||
Learn more about [Nx generators on the docs](https://nx.dev/plugin-features/use-code-generators).
|
||||
|
||||
## Running tasks
|
||||
|
||||
To execute tasks with Nx use the following syntax:
|
||||
|
||||
\`\`\`
|
||||
nx <target> <project> <...options>
|
||||
\`\`\`
|
||||
|
||||
You can also run multiple targets:
|
||||
|
||||
\`\`\`
|
||||
nx run-many -t <target1> <target2>
|
||||
\`\`\`
|
||||
|
||||
..or add \`-p\` to filter specific projects
|
||||
|
||||
\`\`\`
|
||||
nx run-many -t <target1> <target2> -p <proj1> <proj2>
|
||||
\`\`\`
|
||||
|
||||
Targets can be defined in the \`package.json\` or \`projects.json\`. Learn more [in the docs](https://nx.dev/core-features/run-tasks).
|
||||
|
||||
## Want better Editor Integration?
|
||||
|
||||
Have a look at the [Nx Console extensions](https://nx.dev/nx-console). It provides autocomplete support, a UI for exploring and running tasks & generators, and more! Available for VSCode, IntelliJ and comes with a LSP for Vim users.
|
||||
|
||||
## Ready to deploy?
|
||||
|
||||
Just run \`nx build demoapp\` to build the application. The build artifacts will be stored in the \`dist/\` directory, ready to be deployed.
|
||||
|
||||
## Set up CI!
|
||||
|
||||
Nx comes with local caching already built-in (check your \`nx.json\`). On CI you might want to go a step further.
|
||||
|
||||
- [Set up remote caching](https://nx.dev/core-features/share-your-cache)
|
||||
- [Set up task distribution across multiple machines](https://nx.dev/core-features/distribute-task-execution)
|
||||
- [Learn more how to setup CI](https://nx.dev/recipes/ci)
|
||||
|
||||
## Connect with us!
|
||||
|
||||
- [Join the community](https://nx.dev/community)
|
||||
- [Subscribe to the Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
|
||||
- [Follow us on Twitter](https://twitter.com/nxdevtools)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`@nx/workspace:generateWorkspaceFiles README.md should be created for NodeStandalone preset 1`] = `
|
||||
"# Proj
|
||||
|
||||
|
||||
@ -149,6 +149,7 @@ function getPresetDependencies({
|
||||
};
|
||||
|
||||
case Preset.NodeStandalone:
|
||||
case Preset.NodeMonorepo:
|
||||
return {
|
||||
dependencies: {},
|
||||
dev: {
|
||||
|
||||
@ -76,7 +76,11 @@ function validateOptions(options: Schema, host: Tree) {
|
||||
throw new Error(`Cannot select nxCloud when skipInstall is set to true.`);
|
||||
}
|
||||
|
||||
if (options.preset === Preset.NodeStandalone && !options.framework) {
|
||||
if (
|
||||
(options.preset === Preset.NodeStandalone ||
|
||||
options.preset === Preset.NodeMonorepo) &&
|
||||
!options.framework
|
||||
) {
|
||||
throw new Error(
|
||||
`Cannot generate ${options.preset} without selecting a framework`
|
||||
);
|
||||
|
||||
@ -161,6 +161,19 @@ async function createPreset(tree: Tree, options: Schema) {
|
||||
rootProject: true,
|
||||
e2eTestRunner: options.e2eTestRunner ?? 'jest',
|
||||
});
|
||||
} else if (options.preset === Preset.NodeMonorepo) {
|
||||
const { applicationGenerator: nodeApplicationGenerator } = require('@nx' +
|
||||
'/node');
|
||||
const bundler = options.bundler === 'webpack' ? 'webpack' : 'esbuild';
|
||||
return nodeApplicationGenerator(tree, {
|
||||
bundler,
|
||||
name: options.name,
|
||||
linter: options.linter,
|
||||
framework: options.framework,
|
||||
docker: options.docker,
|
||||
rootProject: false,
|
||||
e2eTestRunner: options.e2eTestRunner ?? 'jest',
|
||||
});
|
||||
} else {
|
||||
throw new Error(`Invalid preset ${options.preset}`);
|
||||
}
|
||||
|
||||
@ -16,4 +16,5 @@ export enum Preset {
|
||||
Nest = 'nest',
|
||||
Express = 'express',
|
||||
NodeStandalone = 'node-standalone',
|
||||
NodeMonorepo = 'node-monorepo',
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user