Skip to content

Commit

Permalink
Simplify CNA prompts a bit (#49063)
Browse files Browse the repository at this point in the history
This updates the default CNA prompts a bit to be more straightforward.

x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1681919151818769)
x-ref: [slack thread](https://vercel.slack.com/archives/C04K237UHCP/p1682959312307409)
  • Loading branch information
ijjk authored May 2, 2023
1 parent abc74fb commit 26f69d5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 53 deletions.
4 changes: 2 additions & 2 deletions docs/api-reference/create-next-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ Options:

Initialize with ESLint config.

--experimental-app
--app-dir

Initialize as a `app/` directory project.
Initialize as an `app/` directory project.

--src-dir

Expand Down
6 changes: 3 additions & 3 deletions packages/create-next-app/create-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function createApp({
typescript,
tailwind,
eslint,
experimentalApp,
appDir,
srcDir,
importAlias,
}: {
Expand All @@ -47,13 +47,13 @@ export async function createApp({
typescript: boolean
tailwind: boolean
eslint: boolean
experimentalApp: boolean
appDir: boolean
srcDir: boolean
importAlias: string
}): Promise<void> {
let repoInfo: RepoInfo | undefined
const mode: TemplateMode = typescript ? 'ts' : 'js'
const template: TemplateType = experimentalApp
const template: TemplateType = appDir
? tailwind
? 'app-tw'
: 'app'
Expand Down
58 changes: 36 additions & 22 deletions packages/create-next-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ const program = new Commander.Command(packageJson.name)
`
)
.option(
'--experimental-app',
'--app-dir',
`
Initialize as a \`app/\` directory project.
Initialize as an \`app/\` directory project.
`
)
.option(
Expand Down Expand Up @@ -232,6 +232,7 @@ async function run(): Promise<void> {
tailwind: true,
srcDir: false,
importAlias: '@/*',
customizeImportAlias: false,
}
const getPrefOrDefault = (field: string) =>
preferences[field] ?? defaults[field]
Expand Down Expand Up @@ -340,15 +341,13 @@ async function run(): Promise<void> {
}

if (
!process.argv.includes('--experimental-app') &&
!process.argv.includes('--no-experimental-app')
!process.argv.includes('--app-dir') &&
!process.argv.includes('--no-app-dir')
) {
if (ciInfo.isCI) {
program.experimentalApp = false
program.appDir = false
} else {
const styledAppDir = chalk.hex('#007acc')(
'experimental `app/` directory'
)
const styledAppDir = chalk.hex('#007acc')('`app/` directory')
const { appDir } = await prompts({
onState: onPromptState,
type: 'toggle',
Expand All @@ -358,7 +357,7 @@ async function run(): Promise<void> {
active: 'Yes',
inactive: 'No',
})
program.experimentalApp = Boolean(appDir)
program.appDir = Boolean(appDir)
}
}

Expand All @@ -370,19 +369,34 @@ async function run(): Promise<void> {
program.importAlias = '@/*'
} else {
const styledImportAlias = chalk.hex('#007acc')('import alias')
const { importAlias } = await prompts({

const { customizeImportAlias } = await prompts({
onState: onPromptState,
type: 'text',
name: 'importAlias',
message: `What ${styledImportAlias} would you like configured?`,
initial: getPrefOrDefault('importAlias'),
validate: (value) =>
/.+\/\*/.test(value)
? true
: 'Import alias must follow the pattern <prefix>/*',
type: 'toggle',
name: 'customizeImportAlias',
message: `Would you like to customize the default ${styledImportAlias}?`,
initial: getPrefOrDefault('customizeImportAlias'),
active: 'Yes',
inactive: 'No',
})
program.importAlias = importAlias
preferences.importAlias = importAlias

if (!customizeImportAlias) {
program.importAlias = '@/*'
} else {
const { importAlias } = await prompts({
onState: onPromptState,
type: 'text',
name: 'importAlias',
message: `What ${styledImportAlias} would you like configured?`,
initial: getPrefOrDefault('importAlias'),
validate: (value) =>
/.+\/\*/.test(value)
? true
: 'Import alias must follow the pattern <prefix>/*',
})
program.importAlias = importAlias
preferences.importAlias = importAlias
}
}
}
}
Expand All @@ -396,7 +410,7 @@ async function run(): Promise<void> {
typescript: program.typescript,
tailwind: program.tailwind,
eslint: program.eslint,
experimentalApp: program.experimentalApp,
appDir: program.appDir,
srcDir: program.srcDir,
importAlias: program.importAlias,
})
Expand Down Expand Up @@ -424,7 +438,7 @@ async function run(): Promise<void> {
typescript: program.typescript,
eslint: program.eslint,
tailwind: program.tailwind,
experimentalApp: program.experimentalApp,
appDir: program.appDir,
srcDir: program.srcDir,
importAlias: program.importAlias,
})
Expand Down
22 changes: 11 additions & 11 deletions test/integration/create-next-app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{
Expand All @@ -77,7 +77,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{ cwd }
Expand Down Expand Up @@ -362,7 +362,7 @@ describe('create next app', () => {
'--eslint',
'--example',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{
Expand Down Expand Up @@ -399,7 +399,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{
Expand Down Expand Up @@ -440,7 +440,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{
Expand All @@ -466,7 +466,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{
Expand All @@ -491,7 +491,7 @@ describe('create next app', () => {
'--eslint',
'--use-npm',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{
Expand Down Expand Up @@ -546,7 +546,7 @@ describe('create next app', () => {
'--eslint',
'--use-pnpm',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{
Expand Down Expand Up @@ -618,7 +618,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{
Expand Down Expand Up @@ -686,7 +686,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{
Expand Down Expand Up @@ -761,7 +761,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-experimental-app',
'--no-app-dir',
`--import-alias=@/*`,
],
{
Expand Down
Loading

0 comments on commit 26f69d5

Please sign in to comment.