Skip to content

Commit

Permalink
Update create-next-app App Router question (#49111)
Browse files Browse the repository at this point in the history
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
timneutkens and ijjk authored May 3, 2023
1 parent 2994668 commit 3cb15a0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 58 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.

--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
Loading

0 comments on commit 3cb15a0

Please sign in to comment.