Unverified Commit c07497eb authored by Sam Ko's avatar Sam Ko Committed by GitHub

chore(create-next-app): add --empty flag (#65532)

## Why?

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

Closes NEXT-3367

---------
Co-authored-by: 's avatarAhmed Abdelbaset <A7med3bdulBaset@gmail.com>
parent af9ac76a
...@@ -84,6 +84,10 @@ Options: ...@@ -84,6 +84,10 @@ Options:
Specify import alias to use (default "@/*"). Specify import alias to use (default "@/*").
--empty
Initialize an empty project.
--use-npm --use-npm
Explicitly tell the CLI to bootstrap the app using npm Explicitly tell the CLI to bootstrap the app using npm
......
...@@ -35,6 +35,7 @@ export async function createApp({ ...@@ -35,6 +35,7 @@ export async function createApp({
srcDir, srcDir,
importAlias, importAlias,
skipInstall, skipInstall,
empty,
}: { }: {
appPath: string appPath: string
packageManager: PackageManager packageManager: PackageManager
...@@ -47,16 +48,11 @@ export async function createApp({ ...@@ -47,16 +48,11 @@ export async function createApp({
srcDir: boolean srcDir: boolean
importAlias: string importAlias: string
skipInstall: boolean skipInstall: boolean
empty: boolean
}): Promise<void> { }): Promise<void> {
let repoInfo: RepoInfo | undefined let repoInfo: RepoInfo | undefined
const mode: TemplateMode = typescript ? 'ts' : 'js' const mode: TemplateMode = typescript ? 'ts' : 'js'
const template: TemplateType = appRouter const template: TemplateType = `${appRouter ? 'app' : 'default'}${tailwind ? '-tw' : ''}${empty ? '-empty' : ''}`
? tailwind
? 'app-tw'
: 'app'
: tailwind
? 'default-tw'
: 'default'
if (example) { if (example) {
let repoUrl: URL | undefined let repoUrl: URL | undefined
......
...@@ -90,6 +90,13 @@ const program = new Commander.Command(packageJson.name) ...@@ -90,6 +90,13 @@ const program = new Commander.Command(packageJson.name)
` `
Specify import alias to use (default "@/*"). Specify import alias to use (default "@/*").
`
)
.option(
'--empty',
`
Initialize an empty project.
` `
) )
.option( .option(
...@@ -264,6 +271,7 @@ async function run(): Promise<void> { ...@@ -264,6 +271,7 @@ async function run(): Promise<void> {
srcDir: false, srcDir: false,
importAlias: '@/*', importAlias: '@/*',
customizeImportAlias: false, customizeImportAlias: false,
empty: false,
} }
const getPrefOrDefault = (field: string) => const getPrefOrDefault = (field: string) =>
preferences[field] ?? defaults[field] preferences[field] ?? defaults[field]
...@@ -446,6 +454,7 @@ async function run(): Promise<void> { ...@@ -446,6 +454,7 @@ async function run(): Promise<void> {
srcDir: program.srcDir, srcDir: program.srcDir,
importAlias: program.importAlias, importAlias: program.importAlias,
skipInstall: program.skipInstall, skipInstall: program.skipInstall,
empty: program.empty,
}) })
} catch (reason) { } catch (reason) {
if (!(reason instanceof DownloadError)) { if (!(reason instanceof DownloadError)) {
...@@ -475,6 +484,7 @@ async function run(): Promise<void> { ...@@ -475,6 +484,7 @@ async function run(): Promise<void> {
srcDir: program.srcDir, srcDir: program.srcDir,
importAlias: program.importAlias, importAlias: program.importAlias,
skipInstall: program.skipInstall, skipInstall: program.skipInstall,
empty: program.empty,
}) })
} }
conf.set('preferences', preferences) conf.set('preferences', preferences)
......
# 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"
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.
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>
);
}
export default function Home() {
return (
<main>
<div>Hello World!</div>
</main>
);
}
# 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
{
"compilerOptions": {
"paths": {
"@/*": ["./*"]
}
}
}
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default nextConfig;
# 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"
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.
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>
);
}
export default function Home() {
return (
<main>
<div>Hello world!</div>
</main>
);
}
# 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
/// <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 = {};
export default nextConfig;
{
"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"]
}
# 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"
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.
@tailwind base;
@tailwind components;
@tailwind utilities;
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>
);
}
export default function Home() {
return (
<main>
<div>Hello world!</div>
</main>
);
}
# 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
{
"compilerOptions": {
"paths": {
"@/*": ["./*"]
}
}
}
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default nextConfig;
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};
export default config;
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./app/**/*.{js,jsx,mdx}"],
theme: {},
plugins: [],
};
# 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"
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.
@tailwind base;
@tailwind components;
@tailwind utilities;
import type { Metadata } from "next";
import "./globals.css";
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>
);
}
export default function Home() {
return (
<main>
<div>Hello world!</div>
</main>
);
}
# 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
/// <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 = {};
export default nextConfig;
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};
export default config;
import type { Config } from "tailwindcss";
const config: Config = {
content: ["./app/**/*.{ts,tsx,mdx}"],
theme: {},
plugins: [],
};
export default config;
{
"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"]
}
# Rename this file to `.env.local` to use environment variables locally with `next dev`
# https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
MY_HOST="example.com"
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 `pages/index.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.
# 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
{
"compilerOptions": {
"paths": {
"@/*": ["./*"]
}
}
}
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};
export default nextConfig;
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />;
}
import { Html, Head, Main, NextScript } from "next/document";
export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
import Head from "next/head";
export default function Home() {
return (
<>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<div>Hello World!</div>
</main>
</>
);
}
# Rename this file to `.env.local` to use environment variables locally with `next dev`
# https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
MY_HOST="example.com"
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 `pages/index.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.
# 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
/// <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 = {
reactStrictMode: true,
};
export default nextConfig;
import type { AppProps } from "next/app";
export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
}
import { Html, Head, Main, NextScript } from "next/document";
export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
import Head from "next/head";
export default function Home() {
return (
<>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<div>Hello world!</div>
</main>
</>
);
}
{
"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,
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
# Rename this file to `.env.local` to use environment variables locally with `next dev`
# https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
MY_HOST="example.com"
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 `pages/index.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.
# 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
{
"compilerOptions": {
"paths": {
"@/*": ["./*"]
}
}
}
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};
export default nextConfig;
import "@/styles/globals.css";
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />;
}
import { Html, Head, Main, NextScript } from "next/document";
export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
export default function Home() {
return (
<main>
<div>Hello world!</div>
</main>
);
}
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};
export default config;
@tailwind base;
@tailwind components;
@tailwind utilities;
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./pages/**/*.{js,jsx,mdx}"],
theme: {},
plugins: [],
};
# Rename this file to `.env.local` to use environment variables locally with `next dev`
# https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
MY_HOST="example.com"
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 `pages/index.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.
# 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
/// <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 = {
reactStrictMode: true,
};
export default nextConfig;
import type { AppProps } from "next/app";
import "@/styles/globals.css";
export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
}
import { Html, Head, Main, NextScript } from "next/document";
export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
export default function Home() {
return (
<main>
<div>Hello world!</div>
</main>
);
}
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};
export default config;
@tailwind base;
@tailwind components;
@tailwind utilities;
import type { Config } from "tailwindcss";
const config: Config = {
content: ["./pages/**/*.{ts,tsx,mdx}"],
theme: {},
plugins: [],
};
export default config;
{
"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,
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
import { PackageManager } from "../helpers/get-pkg-manager"; import { PackageManager } from "../helpers/get-pkg-manager";
export type TemplateType = "default" | "app" | "default-tw" | "app-tw"; export type TemplateType =
| "app"
| "app-empty"
| "app-tw"
| "app-tw-empty"
| "default"
| "default-empty"
| "default-tw"
| "default-tw-empty";
export type TemplateMode = "js" | "ts"; export type TemplateMode = "js" | "ts";
export interface GetTemplateFileArgs { export interface GetTemplateFileArgs {
...@@ -14,7 +22,6 @@ export interface InstallTemplateArgs { ...@@ -14,7 +22,6 @@ export interface InstallTemplateArgs {
root: string; root: string;
packageManager: PackageManager; packageManager: PackageManager;
isOnline: boolean; isOnline: boolean;
template: TemplateType; template: TemplateType;
mode: TemplateMode; mode: TemplateMode;
eslint: boolean; eslint: boolean;
......
...@@ -61,6 +61,28 @@ export const projectSpecification: ProjectSpecification = { ...@@ -61,6 +61,28 @@ export const projectSpecification: ProjectSpecification = {
], ],
}, },
}, },
'default-empty': {
js: {
files: ['pages/index.js', 'pages/_app.js', 'jsconfig.json'],
deps: [],
devDeps: [],
},
ts: {
files: [
'pages/index.tsx',
'pages/_app.tsx',
'tsconfig.json',
'next-env.d.ts',
],
deps: [],
devDeps: [
'@types/node',
'@types/react',
'@types/react-dom',
'typescript',
],
},
},
'default-tw': { 'default-tw': {
js: { js: {
files: [ files: [
...@@ -95,6 +117,38 @@ export const projectSpecification: ProjectSpecification = { ...@@ -95,6 +117,38 @@ export const projectSpecification: ProjectSpecification = {
], ],
}, },
}, },
'default-tw-empty': {
js: {
files: [
'jsconfig.json',
'pages/_app.js',
'pages/index.js',
'postcss.config.mjs',
'tailwind.config.js',
],
deps: [],
devDeps: ['postcss', 'tailwindcss'],
},
ts: {
files: [
'next-env.d.ts',
'pages/_app.tsx',
'pages/index.tsx',
'postcss.config.mjs',
'tailwind.config.ts',
'tsconfig.json',
],
deps: [],
devDeps: [
'@types/node',
'@types/react-dom',
'@types/react',
'postcss',
'tailwindcss',
'typescript',
],
},
},
app: { app: {
js: { js: {
deps: [], deps: [],
...@@ -117,6 +171,28 @@ export const projectSpecification: ProjectSpecification = { ...@@ -117,6 +171,28 @@ export const projectSpecification: ProjectSpecification = {
], ],
}, },
}, },
'app-empty': {
js: {
deps: [],
devDeps: [],
files: ['app/page.js', 'app/layout.js', 'jsconfig.json'],
},
ts: {
deps: [],
devDeps: [
'@types/node',
'@types/react',
'@types/react-dom',
'typescript',
],
files: [
'app/page.tsx',
'app/layout.tsx',
'tsconfig.json',
'next-env.d.ts',
],
},
},
'app-tw': { 'app-tw': {
js: { js: {
deps: [], deps: [],
...@@ -149,6 +225,38 @@ export const projectSpecification: ProjectSpecification = { ...@@ -149,6 +225,38 @@ export const projectSpecification: ProjectSpecification = {
], ],
}, },
}, },
'app-tw-empty': {
js: {
deps: [],
devDeps: ['postcss', 'tailwindcss'],
files: [
'app/layout.js',
'app/page.js',
'jsconfig.json',
'postcss.config.mjs',
'tailwind.config.js',
],
},
ts: {
deps: [],
devDeps: [
'@types/node',
'@types/react-dom',
'@types/react',
'postcss',
'tailwindcss',
'typescript',
],
files: [
'app/layout.tsx',
'app/page.tsx',
'next-env.d.ts',
'postcss.config.mjs',
'tailwind.config.ts',
'tsconfig.json',
],
},
},
} }
export type GetProjectSettingsArgs = { export type GetProjectSettingsArgs = {
......
...@@ -157,7 +157,11 @@ export const shouldBeTemplateProject = ({ ...@@ -157,7 +157,11 @@ export const shouldBeTemplateProject = ({
}) })
// Tailwind templates share the same files (tailwind.config.js, postcss.config.mjs) // Tailwind templates share the same files (tailwind.config.js, postcss.config.mjs)
if (template !== 'app-tw' && template !== 'default-tw') { if (
!['app-tw', 'app-tw-empty', 'default-tw', 'default-tw-empty'].includes(
template
)
) {
projectFilesShouldNotExist({ projectFilesShouldNotExist({
cwd, cwd,
projectName, projectName,
......
...@@ -72,7 +72,7 @@ describe('create-next-app --app (App Router)', () => { ...@@ -72,7 +72,7 @@ describe('create-next-app --app (App Router)', () => {
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'ts' }) shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'ts' })
await tryNextDev({ cwd, projectName }) await tryNextDev({ cwd, projectName })
await projectShouldHaveNoGitChanges({ cwd, projectName }) projectShouldHaveNoGitChanges({ cwd, projectName })
}) })
}) })
...@@ -146,4 +146,80 @@ describe('create-next-app --app (App Router)', () => { ...@@ -146,4 +146,80 @@ describe('create-next-app --app (App Router)', () => {
}) })
}) })
}) })
it('should create an empty project with --empty flag', async () => {
await useTempDir(async (cwd) => {
const projectName = 'app-empty'
const childProcess = createNextApp(
[
projectName,
'--ts',
'--app',
'--eslint',
'--src-dir',
'--empty',
'--no-tailwind',
'--no-import-alias',
],
{
cwd,
},
testVersion
)
const exitCode = await spawnExitPromise(childProcess)
const isEmpty = true
expect(exitCode).toBe(0)
shouldBeTemplateProject({
cwd,
projectName,
template: 'app-empty',
mode: 'ts',
srcDir: true,
})
await tryNextDev({
cwd,
projectName,
isEmpty,
})
})
})
it('should create an empty TailwindCSS project with --empty flag', async () => {
await useTempDir(async (cwd) => {
const projectName = 'app-tw-empty'
const childProcess = createNextApp(
[
projectName,
'--ts',
'--app',
'--eslint',
'--src-dir',
'--tailwind',
'--empty',
'--no-import-alias',
],
{
cwd,
},
testVersion
)
const exitCode = await spawnExitPromise(childProcess)
const isEmpty = true
expect(exitCode).toBe(0)
shouldBeTemplateProject({
cwd,
projectName,
template: 'app-tw-empty',
mode: 'ts',
srcDir: true,
})
await tryNextDev({
cwd,
projectName,
isEmpty,
})
})
})
}) })
...@@ -154,4 +154,82 @@ describe('create-next-app --no-app (Pages Router)', () => { ...@@ -154,4 +154,82 @@ describe('create-next-app --no-app (Pages Router)', () => {
}) })
}) })
}) })
it('should create an empty project with --empty flag', async () => {
await useTempDir(async (cwd) => {
const projectName = 'pages-empty'
const childProcess = createNextApp(
[
projectName,
'--ts',
'--no-app',
'--eslint',
'--src-dir',
'--no-tailwind',
'--empty',
'--no-import-alias',
],
{
cwd,
},
testVersion
)
const exitCode = await spawnExitPromise(childProcess)
const isEmpty = true
expect(exitCode).toBe(0)
shouldBeTemplateProject({
cwd,
projectName,
template: 'default-empty',
mode: 'ts',
srcDir: true,
})
await tryNextDev({
cwd,
projectName,
isApp: false,
isEmpty,
})
})
})
it('should create an empty TailwindCSS project with --empty flag', async () => {
await useTempDir(async (cwd) => {
const projectName = 'pages-tw-empty'
const childProcess = createNextApp(
[
projectName,
'--ts',
'--no-app',
'--eslint',
'--src-dir',
'--tailwind',
'--empty',
'--no-import-alias',
],
{
cwd,
},
testVersion
)
const exitCode = await spawnExitPromise(childProcess)
const isEmpty = true
expect(exitCode).toBe(0)
shouldBeTemplateProject({
cwd,
projectName,
template: 'default-tw-empty',
mode: 'ts',
srcDir: true,
})
await tryNextDev({
cwd,
projectName,
isApp: false,
isEmpty,
})
})
})
}) })
...@@ -44,10 +44,12 @@ export async function tryNextDev({ ...@@ -44,10 +44,12 @@ export async function tryNextDev({
cwd, cwd,
projectName, projectName,
isApp = true, isApp = true,
isEmpty = false,
}: { }: {
cwd: string cwd: string
projectName: string projectName: string
isApp?: boolean isApp?: boolean
isEmpty?: boolean
}) { }) {
const dir = join(cwd, projectName) const dir = join(cwd, projectName)
const port = await findPort() const port = await findPort()
...@@ -57,10 +59,14 @@ export async function tryNextDev({ ...@@ -57,10 +59,14 @@ export async function tryNextDev({
try { try {
const res = await fetchViaHTTP(port, '/') const res = await fetchViaHTTP(port, '/')
expect(await res.text()).toContain('Get started by editing') if (isEmpty) {
expect(await res.text()).toContain('Hello world!')
} else {
expect(await res.text()).toContain('Get started by editing')
}
expect(res.status).toBe(200) expect(res.status).toBe(200)
if (!isApp) { if (!isApp && !isEmpty) {
const apiRes = await fetchViaHTTP(port, '/api/hello') const apiRes = await fetchViaHTTP(port, '/api/hello')
expect(await apiRes.json()).toEqual({ name: 'John Doe' }) expect(await apiRes.json()).toEqual({ name: 'John Doe' })
expect(apiRes.status).toBe(200) expect(apiRes.status).toBe(200)
......
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