Unverified Commit e0b04f22 authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

feat(cna): add template (#41660)

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: 's avatarJJ Kasper <jj@jjsweb.site>
parent 4ce259fa
......@@ -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
......@@ -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',
......@@ -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.
*/
......
......@@ -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(
......@@ -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)) {
......@@ -158,6 +166,7 @@ async function run(): Promise<void> {
appPath: resolvedProjectPath,
packageManager,
typescript: program.typescript,
experimentalApp: program.experimentalApp,
})
}
}
......
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.
export default function RootLayout({ children }) {
return (
<html lang="en">
<head>
<title>Create Next App</title>
</head>
<body>{children}</body>
</html>
)
}
export default function Page() {
return (
<h1>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
)
}
# 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
/// <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.
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
},
}
module.exports = nextConfig
// 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' })
}
{
"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"]
}
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
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>
......@@ -70,5 +69,3 @@ const Home: NextPage = () => {
</div>
)
}
export default Home
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