Skip to content

Commit

Permalink
chore(create-next-app): add --empty flag (vercel#65532)
Browse files Browse the repository at this point in the history
## Why?

Adding an `--empty` flag so we can easily create an empty Create Next
App template.

Closes NEXT-3367

---------

Co-authored-by: Ahmed Abdelbaset <A7med3bdulBaset@gmail.com>
  • Loading branch information
samcx and AhmedBaset committed May 9, 2024
1 parent af9ac76 commit c07497e
Show file tree
Hide file tree
Showing 100 changed files with 1,378 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/02-app/02-api-reference/06-create-next-app.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ Options:

Specify import alias to use (default "@/*").

--empty

Initialize an empty project.

--use-npm

Explicitly tell the CLI to bootstrap the app using npm
Expand Down
10 changes: 3 additions & 7 deletions packages/create-next-app/create-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export async function createApp({
srcDir,
importAlias,
skipInstall,
empty,
}: {
appPath: string
packageManager: PackageManager
Expand All @@ -47,16 +48,11 @@ export async function createApp({
srcDir: boolean
importAlias: string
skipInstall: boolean
empty: boolean
}): Promise<void> {
let repoInfo: RepoInfo | undefined
const mode: TemplateMode = typescript ? 'ts' : 'js'
const template: TemplateType = appRouter
? tailwind
? 'app-tw'
: 'app'
: tailwind
? 'default-tw'
: 'default'
const template: TemplateType = `${appRouter ? 'app' : 'default'}${tailwind ? '-tw' : ''}${empty ? '-empty' : ''}`

if (example) {
let repoUrl: URL | undefined
Expand Down
10 changes: 10 additions & 0 deletions packages/create-next-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ const program = new Commander.Command(packageJson.name)
`
Specify import alias to use (default "@/*").
`
)
.option(
'--empty',
`
Initialize an empty project.
`
)
.option(
Expand Down Expand Up @@ -264,6 +271,7 @@ async function run(): Promise<void> {
srcDir: false,
importAlias: '@/*',
customizeImportAlias: false,
empty: false,
}
const getPrefOrDefault = (field: string) =>
preferences[field] ?? defaults[field]
Expand Down Expand Up @@ -446,6 +454,7 @@ async function run(): Promise<void> {
srcDir: program.srcDir,
importAlias: program.importAlias,
skipInstall: program.skipInstall,
empty: program.empty,
})
} catch (reason) {
if (!(reason instanceof DownloadError)) {
Expand Down Expand Up @@ -475,6 +484,7 @@ async function run(): Promise<void> {
srcDir: program.srcDir,
importAlias: program.importAlias,
skipInstall: program.skipInstall,
empty: program.empty,
})
}
conf.set('preferences', preferences)
Expand Down
3 changes: 3 additions & 0 deletions packages/create-next-app/templates/app-empty/js/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Rename this file to `.env.local` to use environment variables locally with `next dev`
# https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
MY_HOST="example.com"
34 changes: 34 additions & 0 deletions packages/create-next-app/templates/app-empty/js/README-template.md
Original file line number Diff line number Diff line change
@@ -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
# or
pnpm dev
# or
bun 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.js`. The page auto-updates as you edit the file.

## 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.
Binary file not shown.
12 changes: 12 additions & 0 deletions packages/create-next-app/templates/app-empty/js/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
7 changes: 7 additions & 0 deletions packages/create-next-app/templates/app-empty/js/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Home() {
return (
<main>
<div>Hello World!</div>
</main>
);
}
3 changes: 3 additions & 0 deletions packages/create-next-app/templates/app-empty/js/eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions packages/create-next-app/templates/app-empty/js/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

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

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
7 changes: 7 additions & 0 deletions packages/create-next-app/templates/app-empty/js/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"@/*": ["./*"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
3 changes: 3 additions & 0 deletions packages/create-next-app/templates/app-empty/ts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Rename this file to `.env.local` to use environment variables locally with `next dev`
# https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
MY_HOST="example.com"
34 changes: 34 additions & 0 deletions packages/create-next-app/templates/app-empty/ts/README-template.md
Original file line number Diff line number Diff line change
@@ -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
# or
pnpm dev
# or
bun 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.

## 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.
18 changes: 18 additions & 0 deletions packages/create-next-app/templates/app-empty/ts/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Metadata } from "next";

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
7 changes: 7 additions & 0 deletions packages/create-next-app/templates/app-empty/ts/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Home() {
return (
<main>
<div>Hello world!</div>
</main>
);
}
3 changes: 3 additions & 0 deletions packages/create-next-app/templates/app-empty/ts/eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions packages/create-next-app/templates/app-empty/ts/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

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

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
5 changes: 5 additions & 0 deletions packages/create-next-app/templates/app-empty/ts/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
27 changes: 27 additions & 0 deletions packages/create-next-app/templates/app-empty/ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Rename this file to `.env.local` to use environment variables locally with `next dev`
# https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
MY_HOST="example.com"
Original file line number Diff line number Diff line change
@@ -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
# or
pnpm dev
# or
bun 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.js`. The page auto-updates as you edit the file.

## 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.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
14 changes: 14 additions & 0 deletions packages/create-next-app/templates/app-tw-empty/js/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import "./globals.css";

export const metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}

0 comments on commit c07497e

Please sign in to comment.