From 922a83913ae2cb402d0e8fa075cbcc0c906b61cc Mon Sep 17 00:00:00 2001 From: Chris Villa Date: Thu, 19 Oct 2023 11:05:17 +0100 Subject: [PATCH] chore: add duplicated template code to .gitignore --- packages/create-puck-app/templates/.gitignore | 8 +++ .../templates/next/.eslintrc.js | 4 -- .../create-puck-app/templates/next/README.md | 39 --------------- .../next/app/[...puckPath]/client.tsx | 32 ------------ .../templates/next/app/[...puckPath]/page.tsx | 49 ------------------- .../app/[...puckPath]/resolve-puck-path.ts | 15 ------ .../templates/next/app/api/puck/route.ts | 25 ---------- .../templates/next/app/layout.tsx | 14 ------ .../templates/next/app/page.tsx | 1 - .../templates/next/app/styles.css | 5 -- .../templates/next/database.json | 1 - .../create-puck-app/templates/next/gitignore | 36 -------------- .../templates/next/next-env.d.ts | 5 -- .../templates/next/next.config.js | 4 -- .../templates/next/puck.config.tsx | 25 ---------- .../templates/next/tsconfig.json | 8 --- .../templates/next/tsconfig/base.json | 20 -------- .../templates/next/tsconfig/nextjs.json | 21 -------- 18 files changed, 8 insertions(+), 304 deletions(-) create mode 100644 packages/create-puck-app/templates/.gitignore delete mode 100644 packages/create-puck-app/templates/next/.eslintrc.js delete mode 100644 packages/create-puck-app/templates/next/README.md delete mode 100644 packages/create-puck-app/templates/next/app/[...puckPath]/client.tsx delete mode 100644 packages/create-puck-app/templates/next/app/[...puckPath]/page.tsx delete mode 100644 packages/create-puck-app/templates/next/app/[...puckPath]/resolve-puck-path.ts delete mode 100644 packages/create-puck-app/templates/next/app/api/puck/route.ts delete mode 100644 packages/create-puck-app/templates/next/app/layout.tsx delete mode 100644 packages/create-puck-app/templates/next/app/page.tsx delete mode 100644 packages/create-puck-app/templates/next/app/styles.css delete mode 100644 packages/create-puck-app/templates/next/database.json delete mode 100644 packages/create-puck-app/templates/next/gitignore delete mode 100644 packages/create-puck-app/templates/next/next-env.d.ts delete mode 100644 packages/create-puck-app/templates/next/next.config.js delete mode 100644 packages/create-puck-app/templates/next/puck.config.tsx delete mode 100644 packages/create-puck-app/templates/next/tsconfig.json delete mode 100644 packages/create-puck-app/templates/next/tsconfig/base.json delete mode 100644 packages/create-puck-app/templates/next/tsconfig/nextjs.json diff --git a/packages/create-puck-app/templates/.gitignore b/packages/create-puck-app/templates/.gitignore new file mode 100644 index 0000000000..c21e65c0f3 --- /dev/null +++ b/packages/create-puck-app/templates/.gitignore @@ -0,0 +1,8 @@ +# Ignore everything +*.* + +# Explicitly ignore gitignore without extension +gitignore + +# Except for handlebars files +!*.hbs diff --git a/packages/create-puck-app/templates/next/.eslintrc.js b/packages/create-puck-app/templates/next/.eslintrc.js deleted file mode 100644 index c8df607506..0000000000 --- a/packages/create-puck-app/templates/next/.eslintrc.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - root: true, - extends: ["custom"], -}; diff --git a/packages/create-puck-app/templates/next/README.md b/packages/create-puck-app/templates/next/README.md deleted file mode 100644 index 45cf5e8c28..0000000000 --- a/packages/create-puck-app/templates/next/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# `next` recipe - -The `next` recipe showcases one of the most powerful ways to implement Puck using to provide an authoring tool for any route in your Next app. - -## Demonstrates - -- Next.js 13 App Router implementation -- JSON database implementation with HTTP API -- Catch-all routes to use puck for any route on the platform - -## Usage - -Run the generator and enter `next` when prompted - -``` -npx create-puck-app my-app -``` - -Start the server - -``` -yarn dev -``` - -Navigate to the homepage at https://localhost:3000. To edit the homepage, access the Puck editor at https://localhost:3000/edit. - -You can do this for any route on the application, **even if the page doesn't exist**. For example, visit https://localhost:3000/hello/world and you'll receive a 404. You can author and publish a page by visiting https://localhost:3000/hello/world/edit. After publishing, go back to the original URL to see your page. - -## Using this recipe - -To adopt this recipe you will need to: - -- **IMPORTANT** Add authentication to `/edit` routes. This can be done by modifying the example API routes in `/app/api/puck/route.ts` and server component in `/app/[...puckPath]/page.tsx`. **If you don't do this, Puck will be completely public.** -- Integrate your database into the API calls in `/app/api/puck/route.ts` -- Implement a custom puck configuration in `puck.config.tsx` - -## License - -MIT © [Measured Co.](https://github.com/measuredco) diff --git a/packages/create-puck-app/templates/next/app/[...puckPath]/client.tsx b/packages/create-puck-app/templates/next/app/[...puckPath]/client.tsx deleted file mode 100644 index f2ba2ffc47..0000000000 --- a/packages/create-puck-app/templates/next/app/[...puckPath]/client.tsx +++ /dev/null @@ -1,32 +0,0 @@ -"use client"; - -import type { Data } from "@measured/puck"; -import { Puck, Render } from "@measured/puck"; -import config from "../../puck.config"; - -export function Client({ - path, - data, - isEdit, -}: { - path: string; - data: Data; - isEdit: boolean; -}) { - if (isEdit) { - return ( - { - await fetch("/api/puck", { - method: "post", - body: JSON.stringify({ data, path }), - }); - }} - /> - ); - } - - return ; -} diff --git a/packages/create-puck-app/templates/next/app/[...puckPath]/page.tsx b/packages/create-puck-app/templates/next/app/[...puckPath]/page.tsx deleted file mode 100644 index 40700a8bb7..0000000000 --- a/packages/create-puck-app/templates/next/app/[...puckPath]/page.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { Client } from "./client"; -import { notFound } from "next/navigation"; -import resolvePuckPath from "./resolve-puck-path"; -import { Metadata } from "next"; -import { Data } from "@measured/puck"; -import fs from "fs"; - -// Replace with call to your database -const getPage = (path: string) => { - const allData: Record | null = fs.existsSync("database.json") - ? JSON.parse(fs.readFileSync("database.json", "utf-8")) - : null; - - return allData ? allData[path] : null; -}; - -export async function generateMetadata({ - params, -}: { - params: { puckPath: string[] }; -}): Promise { - const { isEdit, path } = resolvePuckPath(params.puckPath); - - if (isEdit) { - return { - title: "Puck: " + path, - }; - } - - return { - title: getPage(path)?.root.title, - }; -} - -export default async function Page({ - params, -}: { - params: { puckPath: string[] }; -}) { - const { isEdit, path } = resolvePuckPath(params.puckPath); - - const data = getPage(path); - - if (!data && !isEdit) { - return notFound(); - } - - return ; -} diff --git a/packages/create-puck-app/templates/next/app/[...puckPath]/resolve-puck-path.ts b/packages/create-puck-app/templates/next/app/[...puckPath]/resolve-puck-path.ts deleted file mode 100644 index 5ee031aab0..0000000000 --- a/packages/create-puck-app/templates/next/app/[...puckPath]/resolve-puck-path.ts +++ /dev/null @@ -1,15 +0,0 @@ -const resolvePuckPath = (puckPath: string[] = []) => { - const hasPath = puckPath.length > 0; - - const isEdit = hasPath ? puckPath[puckPath.length - 1] === "edit" : false; - - return { - isEdit, - path: `/${(isEdit - ? [...puckPath].slice(0, puckPath.length - 1) - : [...puckPath] - ).join("/")}`, - }; -}; - -export default resolvePuckPath; diff --git a/packages/create-puck-app/templates/next/app/api/puck/route.ts b/packages/create-puck-app/templates/next/app/api/puck/route.ts deleted file mode 100644 index 21f424f2b5..0000000000 --- a/packages/create-puck-app/templates/next/app/api/puck/route.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { revalidatePath } from "next/cache"; -import { NextResponse } from "next/server"; -import fs from "fs"; - -export async function POST(request: Request) { - const payload = await request.json(); - - const existingData = JSON.parse( - fs.existsSync("database.json") - ? fs.readFileSync("database.json", "utf-8") - : "{}" - ); - - const updatedData = { - ...existingData, - [payload.path]: payload.data, - }; - - fs.writeFileSync("database.json", JSON.stringify(updatedData)); - - // Purge Next.js cache - revalidatePath(payload.path); - - return NextResponse.json({ status: "ok" }); -} diff --git a/packages/create-puck-app/templates/next/app/layout.tsx b/packages/create-puck-app/templates/next/app/layout.tsx deleted file mode 100644 index 080b7671b4..0000000000 --- a/packages/create-puck-app/templates/next/app/layout.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import "@measured/puck/dist/index.css"; -import "./styles.css"; - -export default function RootLayout({ - children, -}: { - children: React.ReactNode; -}) { - return ( - - {children} - - ); -} diff --git a/packages/create-puck-app/templates/next/app/page.tsx b/packages/create-puck-app/templates/next/app/page.tsx deleted file mode 100644 index bf62683fb7..0000000000 --- a/packages/create-puck-app/templates/next/app/page.tsx +++ /dev/null @@ -1 +0,0 @@ -export { default, generateMetadata } from "./[...puckPath]/page"; diff --git a/packages/create-puck-app/templates/next/app/styles.css b/packages/create-puck-app/templates/next/app/styles.css deleted file mode 100644 index 4dc4eebc1e..0000000000 --- a/packages/create-puck-app/templates/next/app/styles.css +++ /dev/null @@ -1,5 +0,0 @@ -html, -body { - margin: 0; - padding: 0; -} diff --git a/packages/create-puck-app/templates/next/database.json b/packages/create-puck-app/templates/next/database.json deleted file mode 100644 index 7bfd4eb182..0000000000 --- a/packages/create-puck-app/templates/next/database.json +++ /dev/null @@ -1 +0,0 @@ -{"/":{"content":[{"type":"HeadingBlock","props":{"title":"Edit this page by adding /edit to the end of the URL","id":"HeadingBlock-1694032984497"}}],"root":{"title":""}}} \ No newline at end of file diff --git a/packages/create-puck-app/templates/next/gitignore b/packages/create-puck-app/templates/next/gitignore deleted file mode 100644 index cb9850fbef..0000000000 --- a/packages/create-puck-app/templates/next/gitignore +++ /dev/null @@ -1,36 +0,0 @@ -# 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* - -# local env files -.env.local -.env.development.local -.env.test.local -.env.production.local - -# vercel -.vercel - -database.json \ No newline at end of file diff --git a/packages/create-puck-app/templates/next/next-env.d.ts b/packages/create-puck-app/templates/next/next-env.d.ts deleted file mode 100644 index 4f11a03dc6..0000000000 --- a/packages/create-puck-app/templates/next/next-env.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/// -/// - -// NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/packages/create-puck-app/templates/next/next.config.js b/packages/create-puck-app/templates/next/next.config.js deleted file mode 100644 index fdda6aa12c..0000000000 --- a/packages/create-puck-app/templates/next/next.config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - reactStrictMode: true, - transpilePackages: ["ui"], -}; diff --git a/packages/create-puck-app/templates/next/puck.config.tsx b/packages/create-puck-app/templates/next/puck.config.tsx deleted file mode 100644 index f000285a95..0000000000 --- a/packages/create-puck-app/templates/next/puck.config.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import type { Config } from "@measured/puck"; - -type Props = { - HeadingBlock: { title: string }; -}; - -export const config: Config = { - components: { - HeadingBlock: { - fields: { - title: { type: "text" }, - }, - defaultProps: { - title: "Heading", - }, - render: ({ title }) => ( -
-

{title}

-
- ), - }, - }, -}; - -export default config; diff --git a/packages/create-puck-app/templates/next/tsconfig.json b/packages/create-puck-app/templates/next/tsconfig.json deleted file mode 100644 index 508804435d..0000000000 --- a/packages/create-puck-app/templates/next/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "./tsconfig/nextjs.json", - "compilerOptions": { - "plugins": [{ "name": "next" }] - }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], - "exclude": ["node_modules"] -} diff --git a/packages/create-puck-app/templates/next/tsconfig/base.json b/packages/create-puck-app/templates/next/tsconfig/base.json deleted file mode 100644 index d72a9f3a27..0000000000 --- a/packages/create-puck-app/templates/next/tsconfig/base.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "display": "Default", - "compilerOptions": { - "composite": false, - "declaration": true, - "declarationMap": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "inlineSources": false, - "isolatedModules": true, - "moduleResolution": "node", - "noUnusedLocals": false, - "noUnusedParameters": false, - "preserveWatchOutput": true, - "skipLibCheck": true, - "strict": true - }, - "exclude": ["node_modules"] -} diff --git a/packages/create-puck-app/templates/next/tsconfig/nextjs.json b/packages/create-puck-app/templates/next/tsconfig/nextjs.json deleted file mode 100644 index d5010a1bbc..0000000000 --- a/packages/create-puck-app/templates/next/tsconfig/nextjs.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "display": "Next.js", - "extends": "./base.json", - "compilerOptions": { - "plugins": [{ "name": "next" }], - "allowJs": true, - "declaration": false, - "declarationMap": false, - "incremental": true, - "jsx": "preserve", - "lib": ["dom", "dom.iterable", "esnext"], - "module": "esnext", - "noEmit": true, - "resolveJsonModule": true, - "strict": false, - "target": "es5" - }, - "include": ["src", "next-env.d.ts"], - "exclude": ["node_modules"] -}