Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): handle --no-interative for create-nx-workspace #27702

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions e2e/workspace-create/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ describe('create-nx-workspace', () => {
expectCodeIsFormatted();
});

it('should be able to create a react workspace without options and --no-interactive', () => {
const wsName = uniq('react');

runCreateWorkspace(wsName, {
preset: 'react-monorepo',
});

expectNoAngularDevkit();
expectNoTsJestInJestConfig(wsName);
const packageJson = readJson('package.json');
expect(packageJson.devDependencies['@nx/vite']).toBeDefined(); // vite should be default bundler
expectCodeIsFormatted();
});

it('should be able to create an next workspace', () => {
const wsName = uniq('next');
const appName = uniq('app');
Expand Down
23 changes: 21 additions & 2 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { showNxWarning } from '../src/utils/nx/show-nx-warning';
import { messages, recordStat } from '../src/utils/nx/ab-testing';
import { mapErrorToBodyLines } from '../src/utils/error-utils';
import { existsSync } from 'fs';
import { isCI } from '../src/utils/ci/is-ci';

interface BaseArguments extends CreateWorkspaceOptions {
preset: Preset;
Expand Down Expand Up @@ -320,13 +321,13 @@ async function determineFolder(
? parsedArgs._[0].toString()
: parsedArgs.name;
if (folderName) return folderName;

const reply = await enquirer.prompt<{ folderName: string }>([
{
name: 'folderName',
message: `Where would you like to create your workspace?`,
initial: 'org',
type: 'input',
skip: !parsedArgs.interactive || isCI(),
},
]);

Expand Down Expand Up @@ -369,6 +370,7 @@ async function determineStack(
return 'vue';
case Preset.Nest:
case Preset.NodeStandalone:
case Preset.NodeMonorepo:
case Preset.Express:
return 'node';
case Preset.Apps:
Expand Down Expand Up @@ -477,6 +479,7 @@ async function determineNoneOptions(
},
],
initial: 0,
skip: !parsedArgs.interactive || isCI(),
},
]);
js = reply.ts === 'No';
Expand Down Expand Up @@ -578,6 +581,7 @@ async function determineReactOptions(
message: `Default stylesheet format`,
initial: 0,
type: 'autocomplete',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'css',
Expand Down Expand Up @@ -678,6 +682,7 @@ async function determineVueOptions(
message: `Default stylesheet format`,
initial: 0,
type: 'autocomplete',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'css',
Expand Down Expand Up @@ -764,6 +769,7 @@ async function determineAngularOptions(
name: 'bundler',
message: `Which bundler would you like to use?`,
type: 'autocomplete',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'esbuild',
Expand All @@ -789,6 +795,7 @@ async function determineAngularOptions(
message: `Default stylesheet format`,
initial: 0,
type: 'autocomplete',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'css',
Expand Down Expand Up @@ -819,6 +826,7 @@ async function determineAngularOptions(
type: 'autocomplete',
choices: [{ name: 'Yes' }, { name: 'No' }],
initial: 1,
skip: !parsedArgs.interactive || isCI(),
},
]);
ssr = reply.ssr === 'Yes';
Expand Down Expand Up @@ -887,6 +895,7 @@ async function determineNodeOptions(
message:
'Would you like to generate a Dockerfile? [https://docs.docker.com/]',
type: 'autocomplete',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'Yes',
Expand Down Expand Up @@ -1000,6 +1009,7 @@ async function determineAppName(
message: `Application name`,
type: 'input',
initial: parsedArgs.name,
skip: !parsedArgs.interactive || isCI(),
},
]);
invariant(appName, {
Expand Down Expand Up @@ -1059,6 +1069,7 @@ async function determineReactBundler(
name: 'bundler',
message: `Which bundler would you like to use?`,
type: 'autocomplete',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'vite',
Expand All @@ -1073,6 +1084,7 @@ async function determineReactBundler(
message: 'Rspack [ https://www.rspack.dev/ ]',
},
],
initial: 0,
},
]);
return reply.bundler;
Expand All @@ -1087,6 +1099,7 @@ async function determineNextAppDir(
name: 'nextAppDir',
message: 'Would you like to use the App Router (recommended)?',
type: 'autocomplete',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'Yes',
Expand All @@ -1110,6 +1123,7 @@ async function determineNextSrcDir(
name: 'nextSrcDir',
message: 'Would you like to use the src/ directory?',
type: 'autocomplete',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'Yes',
Expand All @@ -1135,6 +1149,7 @@ async function determineVueFramework(
name: 'framework',
message: 'What framework would you like to use?',
type: 'autocomplete',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'none',
Expand All @@ -1155,14 +1170,15 @@ async function determineVueFramework(
async function determineNodeFramework(
parsedArgs: yargs.Arguments<NodeArguments>
): Promise<'express' | 'fastify' | 'koa' | 'nest' | 'none'> {
if (parsedArgs.framework) return parsedArgs.framework;
if (!!parsedArgs.framework) return parsedArgs.framework;
const reply = await enquirer.prompt<{
framework: 'express' | 'fastify' | 'koa' | 'nest' | 'none';
}>([
{
message: 'What framework should be used?',
type: 'autocomplete',
name: 'framework',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'none',
Expand All @@ -1185,6 +1201,7 @@ async function determineNodeFramework(
message: 'NestJs [ https://nestjs.com/ ]',
},
],
initial: 0,
},
]);
return reply.framework;
Expand All @@ -1203,6 +1220,7 @@ async function determineE2eTestRunner(
message: 'Test runner to use for end to end (E2E) tests',
type: 'autocomplete',
name: 'e2eTestRunner',
skip: !parsedArgs.interactive || isCI(),
choices: [
{
name: 'playwright',
Expand All @@ -1217,6 +1235,7 @@ async function determineE2eTestRunner(
message: 'None',
},
],
initial: 0,
},
]);
return reply.e2eTestRunner;
Expand Down