Skip to content

Commit

Permalink
fix(core): handle no interative for create-nx-workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Aug 29, 2024
1 parent f950599 commit 41545fc
Showing 1 changed file with 84 additions and 62 deletions.
146 changes: 84 additions & 62 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 @@ -461,23 +462,27 @@ async function determineNoneOptions(
} else if (preset === Preset.TsStandalone) {
// Only standalone TS preset generates a default package, so we need to provide --js and --appName options.
appName = parsedArgs.name;
const reply = await enquirer.prompt<{ ts: 'Yes' | 'No' }>([
{
name: 'ts',
message: `Would you like to use TypeScript with this project?`,
type: 'autocomplete',
choices: [
{
name: 'Yes',
},
{
name: 'No',
},
],
initial: 0,
},
]);
js = reply.ts === 'No';
if (parsedArgs.interactive && !isCI()) {
js = false;
} else {
const reply = await enquirer.prompt<{ ts: 'Yes' | 'No' }>([
{
name: 'ts',
message: `Would you like to use TypeScript with this project?`,
type: 'autocomplete',
choices: [
{
name: 'Yes',
},
{
name: 'No',
},
],
initial: 0,
},
]);
js = reply.ts === 'No';
}
}

return { preset, js, appName };
Expand Down Expand Up @@ -570,48 +575,52 @@ async function determineReactOptions(
preset === Preset.NextJs ||
preset === Preset.NextJsStandalone
) {
const reply = await enquirer.prompt<{ style: string }>([
{
name: 'style',
message: `Default stylesheet format`,
initial: 0,
type: 'autocomplete',
choices: [
{
name: 'css',
message: 'CSS',
},
{
name: 'scss',
message: 'SASS(.scss) [ https://sass-lang.com ]',
},
{
name: 'less',
message: 'LESS [ https://lesscss.org ]',
},
{
name: 'tailwind',
message: 'tailwind [ https://tailwindcss.com ]',
},
{
name: 'styled-components',
message:
'styled-components [ https://styled-components.com ]',
},
{
name: '@emotion/styled',
message:
'emotion [ https://emotion.sh ]',
},
{
name: 'styled-jsx',
message:
'styled-jsx [ https://www.npmjs.com/package/styled-jsx ]',
},
],
},
]);
style = reply.style;
if (parsedArgs.interactive && !isCI()) {
style = 'none';
} else {
const reply = await enquirer.prompt<{ style: string }>([
{
name: 'style',
message: `Default stylesheet format`,
initial: 0,
type: 'autocomplete',
choices: [
{
name: 'css',
message: 'CSS',
},
{
name: 'scss',
message: 'SASS(.scss) [ https://sass-lang.com ]',
},
{
name: 'less',
message: 'LESS [ https://lesscss.org ]',
},
{
name: 'tailwind',
message: 'tailwind [ https://tailwindcss.com ]',
},
{
name: 'styled-components',
message:
'styled-components [ https://styled-components.com ]',
},
{
name: '@emotion/styled',
message:
'emotion [ https://emotion.sh ]',
},
{
name: 'styled-jsx',
message:
'styled-jsx [ https://www.npmjs.com/package/styled-jsx ]',
},
],
},
]);
style = reply.style;
}
}

return {
Expand Down Expand Up @@ -991,6 +1000,7 @@ async function determineAppName(
>
): Promise<string> {
if (parsedArgs.appName) return parsedArgs.appName;
if (!parsedArgs.interactive || isCI()) return parsedArgs.name;

const { appName } = await enquirer.prompt<{ appName: string }>([
{
Expand Down Expand Up @@ -1048,8 +1058,10 @@ async function determineReactFramework(

async function determineReactBundler(
parsedArgs: yargs.Arguments<ReactArguments>
): Promise<'webpack' | 'vite' | 'rspack'> {
): Promise<'webpack' | 'vite' | 'rspack' | undefined> {
if (parsedArgs.bundler) return parsedArgs.bundler;
if (!parsedArgs.interactive || isCI()) return;

const reply = await enquirer.prompt<{
bundler: 'webpack' | 'vite' | 'rspack';
}>([
Expand Down Expand Up @@ -1080,6 +1092,8 @@ async function determineNextAppDir(
parsedArgs: yargs.Arguments<ReactArguments>
): Promise<boolean> {
if (parsedArgs.nextAppDir !== undefined) return parsedArgs.nextAppDir;
if (!parsedArgs.interactive || isCI()) return false;

const reply = await enquirer.prompt<{ nextAppDir: 'Yes' | 'No' }>([
{
name: 'nextAppDir',
Expand All @@ -1103,6 +1117,8 @@ async function determineNextSrcDir(
parsedArgs: yargs.Arguments<ReactArguments>
): Promise<boolean> {
if (parsedArgs.nextSrcDir !== undefined) return parsedArgs.nextSrcDir;
if (!parsedArgs.interactive || isCI()) return false;

const reply = await enquirer.prompt<{ nextSrcDir: 'Yes' | 'No' }>([
{
name: 'nextSrcDir',
Expand All @@ -1126,6 +1142,8 @@ async function determineVueFramework(
parsedArgs: yargs.Arguments<VueArguments>
): Promise<'none' | 'nuxt'> {
if (!!parsedArgs.framework) return parsedArgs.framework;
if (!parsedArgs.interactive || isCI()) return 'none';

const reply = await enquirer.prompt<{
framework: 'none' | 'nuxt';
}>([
Expand Down Expand Up @@ -1153,7 +1171,9 @@ 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;
if (!parsedArgs.interactive || isCI()) return 'none';

const reply = await enquirer.prompt<{
framework: 'express' | 'fastify' | 'koa' | 'nest' | 'none';
}>([
Expand Down Expand Up @@ -1192,8 +1212,10 @@ async function determineE2eTestRunner(
parsedArgs: yargs.Arguments<{
e2eTestRunner?: 'none' | 'cypress' | 'playwright';
}>
): Promise<'none' | 'cypress' | 'playwright'> {
): Promise<'none' | 'cypress' | 'playwright' | undefined> {
if (parsedArgs.e2eTestRunner) return parsedArgs.e2eTestRunner;
if (!parsedArgs.interactive || isCI()) return;

const reply = await enquirer.prompt<{
e2eTestRunner: 'none' | 'cypress' | 'playwright';
}>([
Expand Down

0 comments on commit 41545fc

Please sign in to comment.