Skip to content

Commit

Permalink
Add tailwind, srcDir, and js options for nextjs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclarke committed Jan 3, 2024
1 parent f6c1c13 commit 26ce167
Show file tree
Hide file tree
Showing 53 changed files with 2,163 additions and 25 deletions.
66 changes: 58 additions & 8 deletions packages/create/src/recipes/nextjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { copyTemplateFiles } from "../../utils.js";
const logger = debug("@edgedb/create:recipe:nextjs");

interface NextjsOptions {
lang: "ts" | "js";
router: "app" | "pages";
useTailwind: boolean;
useSrcDir: boolean;
}

const recipe: Recipe<NextjsOptions> = {
Expand All @@ -18,6 +21,17 @@ const recipe: Recipe<NextjsOptions> = {
},
getOptions() {
return p.group({
lang: () =>
p.select<
{ value: NextjsOptions["lang"]; label: string }[],
NextjsOptions["lang"]
>({
message: "Use Typescript?",
options: [
{ value: "ts", label: "Typescript" },
{ value: "js", label: "Javascript" },
],
}),
router: () =>
p.select<
{ value: NextjsOptions["router"]; label: string }[],
Expand All @@ -29,26 +43,55 @@ const recipe: Recipe<NextjsOptions> = {
{ value: "pages", label: "Pages Router" },
],
}),
useTailwind: () =>
p.confirm({
message: "Use Tailwind CSS?",
}),
useSrcDir: () =>
p.confirm({
message: "Use `src/` directory?",
}),
});
},
async apply(
{ projectDir, useEdgeDBAuth }: BaseOptions,
{ router }: NextjsOptions
{ lang, router, useTailwind, useSrcDir }: NextjsOptions
) {
logger("Running nextjs recipe");

const dirname = path.dirname(new URL(import.meta.url).pathname);

const tags = new Set<string>([router]);
const tags = new Set<string>([router, useTailwind ? "tw" : "no-tw"]);

if (useEdgeDBAuth) {
tags.add("auth");
}

await copyTemplateFiles(
path.resolve(dirname, "./template"),
path.resolve(dirname, lang === "js" ? "./template-js" : "./template"),
projectDir,
tags
{
tags,
rewritePath: !useSrcDir
? (p) => (p === path.join(projectDir, "src") ? projectDir : p)
: undefined,
injectVars: [
{
varname: "srcDir",
value: useSrcDir ? "src/" : "",
files: [
"tsconfig.json",
"jsconfig.json",
"tailwind.config.ts",
"tailwind.config.js",
"src/app/page.tsx",
"src/app/page.jsx",
"src/pages/index.tsx",
"src/pages/index.jsx",
],
},
],
}
);

await updatePackage(projectDir, {
Expand All @@ -66,10 +109,17 @@ const recipe: Recipe<NextjsOptions> = {
next: "14.0.4",
},
devDependencies: {
typescript: "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
...(lang === "ts"
? {
typescript: "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
}
: {}),
...(useTailwind
? { autoprefixer: "^10.0.1", postcss: "^8", tailwindcss: "^3.3.0" }
: {}),
},
});
},
Expand Down
35 changes: 35 additions & 0 deletions packages/create/src/recipes/nextjs/template-js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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
36 changes: 36 additions & 0 deletions packages/create/src/recipes/nextjs/template-js/README.__app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## 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.
40 changes: 40 additions & 0 deletions packages/create/src/recipes/nextjs/template-js/README.__pages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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.

[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.js`.

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.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## 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.
9 changes: 9 additions & 0 deletions packages/create/src/recipes/nextjs/template-js/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"paths": {
"@/*": [
"./{{{srcDir}}}*"
]
}
}
}
5 changes: 5 additions & 0 deletions packages/create/src/recipes/nextjs/template-js/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 = {};

module.exports = nextConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};

module.exports = nextConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { redirect } from "next/navigation";
import { auth } from "@/edgedb";

export const { GET, POST } = auth.createAuthRouteHandlers({
async onBuiltinUICallback({ error, tokenData, provider, isSignUp }) {
if (error) {
console.error("sign in failed", error);
}
if (!tokenData) {
console.log("email verification required");
}
if (isSignUp) {
console.log("new sign up");
}
redirect("/");
},
onSignout() {
redirect("/");
},
});
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}
Loading

0 comments on commit 26ce167

Please sign in to comment.