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

Simplify CNA prompts a bit #49063

Merged
merged 5 commits into from
May 2, 2023
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
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