Skip to content

Commit

Permalink
feat(cna): add template (#41660)
Browse files Browse the repository at this point in the history
Adds a new template for `app/` via `--experimental-app` flag.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

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

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
balazsorban44 and ijjk committed Oct 22, 2022
1 parent 4ce259f commit e0b04f2
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 11 deletions.
14 changes: 10 additions & 4 deletions packages/create-next-app/create-app.ts
Expand Up @@ -29,15 +29,21 @@ export async function createApp({
example,
examplePath,
typescript,
experimentalApp,
}: {
appPath: string
packageManager: PackageManager
example?: string
examplePath?: string
typescript?: boolean
typescript: boolean
experimentalApp: boolean
}): Promise<void> {
let repoInfo: RepoInfo | undefined
const template = typescript ? 'typescript' : 'default'
const template = experimentalApp
? 'experimental-app'
: typescript
? 'typescript'
: 'default'

if (example) {
let repoUrl: URL | undefined
Expand Down Expand Up @@ -238,7 +244,7 @@ export async function createApp({
/**
* TypeScript projects will have type definitions and other devDependencies.
*/
if (typescript) {
if (template !== 'default') {
devDependencies.push(
'typescript',
'@types/react',
Expand Down Expand Up @@ -273,7 +279,7 @@ export async function createApp({
const devInstallFlags = { devDependencies: true, ...installFlags }
await install(root, devDependencies, devInstallFlags)
}
console.log()
console.log('\nInitializing project with template: ', template, '\n')
/**
* Copy the template files to the target directory.
*/
Expand Down
9 changes: 9 additions & 0 deletions packages/create-next-app/index.ts
Expand Up @@ -24,6 +24,13 @@ const program = new Commander.Command(packageJson.name)
`
Initialize as a TypeScript project.
`
)
.option(
'--experimental-app',
`
Initialize as a \`app/\` directory project.
`
)
.option(
Expand Down Expand Up @@ -136,6 +143,7 @@ async function run(): Promise<void> {
example: example && example !== 'default' ? example : undefined,
examplePath: program.examplePath,
typescript: program.typescript,
experimentalApp: program.experimentalApp,
})
} catch (reason) {
if (!(reason instanceof DownloadError)) {
Expand All @@ -158,6 +166,7 @@ async function run(): Promise<void> {
appPath: resolvedProjectPath,
packageManager,
typescript: program.typescript,
experimentalApp: program.experimentalApp,
})
}
}
Expand Down
@@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
10 changes: 10 additions & 0 deletions packages/create-next-app/templates/experimental-app/app/layout.tsx
@@ -0,0 +1,10 @@
export default function RootLayout({ children }) {
return (
<html lang="en">
<head>
<title>Create Next App</title>
</head>
<body>{children}</body>
</html>
)
}
@@ -0,0 +1,7 @@
export default function Page() {
return (
<h1>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
)
}
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions packages/create-next-app/templates/experimental-app/gitignore
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
@@ -0,0 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
},
}

module.exports = nextConfig
@@ -0,0 +1,13 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'

type Data = {
name: string
}

export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
res.status(200).json({ name: 'John Doe' })
}
25 changes: 25 additions & 0 deletions packages/create-next-app/templates/experimental-app/tsconfig.json
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
4 changes: 1 addition & 3 deletions packages/create-next-app/templates/typescript/pages/_app.tsx
@@ -1,8 +1,6 @@
import '../styles/globals.css'
import type { AppProps } from 'next/app'

function MyApp({ Component, pageProps }: AppProps) {
export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}

export default MyApp
@@ -1,9 +1,8 @@
import type { NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'

const Home: NextPage = () => {
export default function Home() {
return (
<div className={styles.container}>
<Head>
Expand Down Expand Up @@ -70,5 +69,3 @@ const Home: NextPage = () => {
</div>
)
}

export default Home

0 comments on commit e0b04f2

Please sign in to comment.