Unverified Commit 846ec740 authored by James Mosier's avatar James Mosier Committed by GitHub

Special case default template in CNA (#12109)

This addresses #11910 in which `-e default` was not working because there was no example with the name `default`. This PR checks if a user inputted `default` as the example argument for `create-next-app` and if so it will use the local `default` template in the create-next-app directory.

Closes #11910
parent 9fb2432b
...@@ -165,12 +165,11 @@ async function run(): Promise<void> { ...@@ -165,12 +165,11 @@ async function run(): Promise<void> {
} }
} }
const example = typeof program.example === 'string' && program.example.trim()
await createApp({ await createApp({
appPath: resolvedProjectPath, appPath: resolvedProjectPath,
useNpm: !!program.useNpm, useNpm: !!program.useNpm,
example: example: example && example !== 'default' ? example : undefined,
(typeof program.example === 'string' && program.example.trim()) ||
undefined,
examplePath: program.examplePath, examplePath: program.examplePath,
}) })
} }
......
...@@ -230,4 +230,23 @@ describe('create next app', () => { ...@@ -230,4 +230,23 @@ describe('create next app', () => {
}) })
}) })
} }
it('should allow an example named default', async () => {
await usingTempDir(async (cwd) => {
const projectName = 'default-example'
const res = await run(cwd, projectName, '--example', 'default')
expect(res.exitCode).toBe(0)
expect(
fs.existsSync(path.join(cwd, projectName, 'package.json'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/index.js'))
).toBeTruthy()
// check we copied default `.gitignore`
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
})
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment