Skip to content

Commit

Permalink
fix(core): handle --no-interative for create-nx-workspace (nrwl#27702)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
xiongemi authored Sep 11, 2024
1 parent 2eb5592 commit 24edc5a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
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

0 comments on commit 24edc5a

Please sign in to comment.