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

Update create-next-app App Router question #49111

Merged
merged 4 commits into from
May 3, 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.
Jump to
Jump to file
Failed to load files.
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.

--app-dir
--app

Initialize as an `app/` directory project.
Initialize as an App Router 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,
appDir,
appRouter,
srcDir,
importAlias,
}: {
Expand All @@ -47,13 +47,13 @@ export async function createApp({
typescript: boolean
tailwind: boolean
eslint: boolean
appDir: boolean
appRouter: boolean
srcDir: boolean
importAlias: string
}): Promise<void> {
let repoInfo: RepoInfo | undefined
const mode: TemplateMode = typescript ? 'ts' : 'js'
const template: TemplateType = appDir
const template: TemplateType = appRouter
? tailwind
? 'app-tw'
: 'app'
Expand Down
31 changes: 14 additions & 17 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(
'--app-dir',
'--app',
`

Initialize as an \`app/\` directory project.
Initialize as an App Router project.
`
)
.option(
Expand All @@ -91,14 +91,14 @@ const program = new Commander.Command(packageJson.name)
'--use-npm',
`

Explicitly tell the CLI to bootstrap the app using npm
Explicitly tell the CLI to bootstrap the application using npm
`
)
.option(
'--use-pnpm',
`

Explicitly tell the CLI to bootstrap the app using pnpm
Explicitly tell the CLI to bootstrap the application using pnpm
`
)
.option(
Expand Down Expand Up @@ -340,24 +340,21 @@ async function run(): Promise<void> {
}
}

if (
!process.argv.includes('--app-dir') &&
!process.argv.includes('--no-app-dir')
) {
if (!process.argv.includes('--app') && !process.argv.includes('--no-app')) {
if (ciInfo.isCI) {
program.appDir = false
program.app = true
} else {
const styledAppDir = chalk.hex('#007acc')('`app/` directory')
const { appDir } = await prompts({
const styledAppDir = chalk.hex('#007acc')('App Router')
const { appRouter } = await prompts({
onState: onPromptState,
type: 'toggle',
name: 'appDir',
message: `Would you like to use ${styledAppDir} with this project?`,
initial: false,
name: 'appRouter',
message: `Use ${styledAppDir} (recommended)?`,
initial: true,
active: 'Yes',
inactive: 'No',
})
program.appDir = Boolean(appDir)
program.app = Boolean(appRouter)
}
}

Expand Down Expand Up @@ -410,7 +407,7 @@ async function run(): Promise<void> {
typescript: program.typescript,
tailwind: program.tailwind,
eslint: program.eslint,
appDir: program.appDir,
appRouter: program.app,
srcDir: program.srcDir,
importAlias: program.importAlias,
})
Expand Down Expand Up @@ -438,7 +435,7 @@ async function run(): Promise<void> {
typescript: program.typescript,
eslint: program.eslint,
tailwind: program.tailwind,
appDir: program.appDir,
appRouter: program.app,
srcDir: program.srcDir,
importAlias: program.importAlias,
})
Expand Down
41 changes: 21 additions & 20 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-app-dir',
'--app',
`--import-alias=@/*`,
],
{
Expand All @@ -77,14 +77,14 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-app-dir',
'--app',
`--import-alias=@/*`,
],
{ cwd }
)

expect(res.exitCode).toBe(0)
shouldBeJavascriptProject({ cwd, projectName, template: 'default' })
shouldBeJavascriptProject({ cwd, projectName, template: 'app' })
})
})
}
Expand Down Expand Up @@ -312,6 +312,7 @@ describe('create next app', () => {
'--js',
'--no-tailwind',
'--eslint',
'--app',
'--example',
'__internal-testing-retry',
'--import-alias=@/*',
Expand All @@ -323,7 +324,7 @@ describe('create next app', () => {
)

expect(res.exitCode).toBe(0)
shouldBeJavascriptProject({ cwd, projectName, template: 'default' })
shouldBeJavascriptProject({ cwd, projectName, template: 'app' })
})
})
}
Expand Down Expand Up @@ -362,7 +363,7 @@ describe('create next app', () => {
'--eslint',
'--example',
'--no-src-dir',
'--no-app-dir',
'--app',
`--import-alias=@/*`,
],
{
Expand Down Expand Up @@ -399,7 +400,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-app-dir',
'--app',
`--import-alias=@/*`,
],
{
Expand Down Expand Up @@ -440,7 +441,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-app-dir',
'--app',
`--import-alias=@/*`,
],
{
Expand All @@ -453,7 +454,7 @@ describe('create next app', () => {
await fs.remove(tmpBin)

expect(res.exitCode).toBe(0)
shouldBeJavascriptProject({ cwd, projectName: '.', template: 'default' })
shouldBeJavascriptProject({ cwd, projectName: '.', template: 'app' })
})
})

Expand All @@ -466,7 +467,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-app-dir',
'--app',
`--import-alias=@/*`,
],
{
Expand All @@ -476,7 +477,7 @@ describe('create next app', () => {
)

expect(res.exitCode).toBe(0)
shouldBeJavascriptProject({ cwd, projectName, template: 'default' })
shouldBeJavascriptProject({ cwd, projectName, template: 'app' })
})
})

Expand All @@ -491,7 +492,7 @@ describe('create next app', () => {
'--eslint',
'--use-npm',
'--no-src-dir',
'--no-app-dir',
'--app',
`--import-alias=@/*`,
],
{
Expand All @@ -500,7 +501,7 @@ describe('create next app', () => {
)

expect(res.exitCode).toBe(0)
shouldBeJavascriptProject({ cwd, projectName, template: 'default' })
shouldBeJavascriptProject({ cwd, projectName, template: 'app' })
})
})

Expand Down Expand Up @@ -546,7 +547,7 @@ describe('create next app', () => {
'--eslint',
'--use-pnpm',
'--no-src-dir',
'--no-app-dir',
'--app',
`--import-alias=@/*`,
],
{
Expand All @@ -560,7 +561,7 @@ describe('create next app', () => {
projectName,
files: [
'package.json',
'pages/index.js',
'app/page.js',
'.gitignore',
'.eslintrc.json',
'pnpm-lock.yaml',
Expand Down Expand Up @@ -618,7 +619,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-app-dir',
'--app',
`--import-alias=@/*`,
],
{
Expand All @@ -629,7 +630,7 @@ describe('create next app', () => {

const files = [
'package.json',
'pages/index.js',
'app/page.js',
'.gitignore',
'.eslintrc.json',
'package-lock.json',
Expand Down Expand Up @@ -686,7 +687,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-app-dir',
'--app',
`--import-alias=@/*`,
],
{
Expand All @@ -697,7 +698,7 @@ describe('create next app', () => {

const files = [
'package.json',
'pages/index.js',
'app/page.js',
'.gitignore',
'.eslintrc.json',
'yarn.lock',
Expand Down Expand Up @@ -761,7 +762,7 @@ describe('create next app', () => {
'--no-tailwind',
'--eslint',
'--no-src-dir',
'--no-app-dir',
'--app',
`--import-alias=@/*`,
],
{
Expand All @@ -772,7 +773,7 @@ describe('create next app', () => {

const files = [
'package.json',
'pages/index.js',
'app/page.js',
'.gitignore',
'.eslintrc.json',
'pnpm-lock.yaml',
Expand Down