create-puck-app 0.6.0 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
package/index.js
CHANGED
@@ -5,7 +5,7 @@ import path from "path";
|
|
5
5
|
import { program } from "commander";
|
6
6
|
import inquirer from "inquirer";
|
7
7
|
import Handlebars from "handlebars";
|
8
|
-
import glob from "glob";
|
8
|
+
import { glob } from "glob";
|
9
9
|
import { execSync } from "child_process";
|
10
10
|
import { dirname } from "path";
|
11
11
|
import { fileURLToPath } from "url";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "create-puck-app",
|
3
|
-
"version": "0.6.
|
3
|
+
"version": "0.6.2",
|
4
4
|
"private": false,
|
5
5
|
"license": "MIT",
|
6
6
|
"type": "module",
|
@@ -9,6 +9,7 @@
|
|
9
9
|
},
|
10
10
|
"dependencies": {
|
11
11
|
"commander": "^10.0.1",
|
12
|
+
"glob": "^10.3.4",
|
12
13
|
"handlebars": "^4.7.7",
|
13
14
|
"inquirer": "^9.2.7",
|
14
15
|
"prettier": "^2.8.8"
|
@@ -2,7 +2,17 @@ import { Client } from "./client";
|
|
2
2
|
import { notFound } from "next/navigation";
|
3
3
|
import resolvePuckPath from "./resolve-puck-path";
|
4
4
|
import { Metadata } from "next";
|
5
|
-
import { Data } from "@measured/puck
|
5
|
+
import { Data } from "@measured/puck";
|
6
|
+
import fs from "fs";
|
7
|
+
|
8
|
+
// Replace with call to your database
|
9
|
+
const getPage = (path: string) => {
|
10
|
+
const allData: Record<string, Data> | null = fs.existsSync("database.json")
|
11
|
+
? JSON.parse(fs.readFileSync("database.json", "utf-8"))
|
12
|
+
: null;
|
13
|
+
|
14
|
+
return allData ? allData[path] : null;
|
15
|
+
};
|
6
16
|
|
7
17
|
export async function generateMetadata({
|
8
18
|
params,
|
@@ -17,14 +27,8 @@ export async function generateMetadata({
|
|
17
27
|
};
|
18
28
|
}
|
19
29
|
|
20
|
-
const data: Data = (
|
21
|
-
await fetch("http://localhost:3000/api/puck", {
|
22
|
-
next: { revalidate: 0 },
|
23
|
-
}).then((d) => d.json())
|
24
|
-
)[path];
|
25
|
-
|
26
30
|
return {
|
27
|
-
title:
|
31
|
+
title: getPage(path).root.title,
|
28
32
|
};
|
29
33
|
}
|
30
34
|
|
@@ -35,11 +39,7 @@ export default async function Page({
|
|
35
39
|
}) {
|
36
40
|
const { isEdit, path } = resolvePuckPath(params.puckPath);
|
37
41
|
|
38
|
-
const data = (
|
39
|
-
await fetch("http://localhost:3000/api/puck", {
|
40
|
-
next: { revalidate: 0 },
|
41
|
-
}).then((d) => d.json())
|
42
|
-
)[path];
|
42
|
+
const data = getPage(path);
|
43
43
|
|
44
44
|
if (!data && !isEdit) {
|
45
45
|
return notFound();
|
@@ -1,16 +1,9 @@
|
|
1
|
+
import { revalidatePath } from "next/cache";
|
1
2
|
import { NextResponse } from "next/server";
|
2
3
|
import fs from "fs";
|
3
4
|
|
4
|
-
export async function GET() {
|
5
|
-
const data = fs.existsSync("database.json")
|
6
|
-
? fs.readFileSync("database.json", "utf-8")
|
7
|
-
: null;
|
8
|
-
|
9
|
-
return NextResponse.json(JSON.parse(data || "{}"));
|
10
|
-
}
|
11
|
-
|
12
5
|
export async function POST(request: Request) {
|
13
|
-
const
|
6
|
+
const payload = await request.json();
|
14
7
|
|
15
8
|
const existingData = JSON.parse(
|
16
9
|
fs.existsSync("database.json")
|
@@ -20,12 +13,13 @@ export async function POST(request: Request) {
|
|
20
13
|
|
21
14
|
const updatedData = {
|
22
15
|
...existingData,
|
23
|
-
|
16
|
+
[payload.path]: payload.data,
|
24
17
|
};
|
25
18
|
|
26
19
|
fs.writeFileSync("database.json", JSON.stringify(updatedData));
|
27
20
|
|
21
|
+
// Purge Next.js cache
|
22
|
+
revalidatePath(payload.path);
|
23
|
+
|
28
24
|
return NextResponse.json({ status: "ok" });
|
29
25
|
}
|
30
|
-
|
31
|
-
export const revalidate = 0;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"/":{"content":[{"type":"HeadingBlock","props":{"title":"Edit this page by adding /edit to the end of the URL","id":"HeadingBlock-1694032984497"}}],"root":{"title":""}}}
|