create-puck-app 0.10.0 → 0.10.1-canary.17fc4dc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/package.json +5 -1
- package/scripts/generate.js +72 -0
- package/templates/next/.eslintrc.js +0 -4
- package/templates/next/app/[...puckPath]/client.tsx +0 -32
- package/templates/next/app/[...puckPath]/page.tsx +0 -49
- package/templates/next/app/[...puckPath]/resolve-puck-path.ts +0 -15
- package/templates/next/app/api/puck/route.ts +0 -25
- package/templates/next/app/layout.tsx +0 -14
- package/templates/next/app/page.tsx +0 -1
- package/templates/next/app/styles.css +0 -5
- package/templates/next/database.json +0 -1
- package/templates/next/gitignore +0 -36
- package/templates/next/next-env.d.ts +0 -5
- package/templates/next/next.config.js +0 -4
- package/templates/next/puck.config.tsx +0 -25
- package/templates/next/tsconfig/base.json +0 -20
- package/templates/next/tsconfig/nextjs.json +0 -21
- package/templates/next/tsconfig.json +0 -8
package/index.js
CHANGED
@@ -125,7 +125,7 @@ program
|
|
125
125
|
const targetPath = filePath
|
126
126
|
.replace(templatePath, appPath)
|
127
127
|
.replace(".hbs", "")
|
128
|
-
.replace("gitignore", ".gitignore"); // .gitignore gets ignored by npm during publish
|
128
|
+
.replace("gitignore", ".gitignore"); // Rename gitignore back to .gitignore (.gitignore) gets ignored by npm during publish
|
129
129
|
|
130
130
|
let data;
|
131
131
|
|
package/package.json
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
{
|
2
2
|
"name": "create-puck-app",
|
3
|
-
"version": "0.10.
|
3
|
+
"version": "0.10.1-canary.17fc4dc",
|
4
4
|
"private": false,
|
5
5
|
"license": "MIT",
|
6
6
|
"type": "module",
|
7
7
|
"bin": {
|
8
8
|
"create-puck-app": "./index.js"
|
9
9
|
},
|
10
|
+
"scripts": {
|
11
|
+
"generate": "node scripts/generate.js",
|
12
|
+
"prepublishOnly": "yarn generate"
|
13
|
+
},
|
10
14
|
"dependencies": {
|
11
15
|
"commander": "^10.0.1",
|
12
16
|
"glob": "^10.3.4",
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
import fs from "fs";
|
4
|
+
import path from "path";
|
5
|
+
import { glob } from "glob";
|
6
|
+
import { dirname } from "path";
|
7
|
+
import { fileURLToPath } from "url";
|
8
|
+
|
9
|
+
const verbose = false;
|
10
|
+
|
11
|
+
const run = async () => {
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
13
|
+
const __dirname = dirname(__filename);
|
14
|
+
|
15
|
+
// Copy template files to the new directory
|
16
|
+
const recipePath = path.join(__dirname, "../../../recipes");
|
17
|
+
const templatePath = path.join(__dirname, "../templates");
|
18
|
+
|
19
|
+
if (!fs.existsSync(recipePath)) {
|
20
|
+
console.error(`No recipe directory could be found at ${recipePath}.`);
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
|
24
|
+
if (!fs.existsSync(templatePath)) {
|
25
|
+
console.error(`No template directory could be found at ${templatePath}.`);
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
|
29
|
+
// Compile handlebars templates
|
30
|
+
const recipeFiles = glob.sync(`**/*`, {
|
31
|
+
cwd: recipePath,
|
32
|
+
nodir: true,
|
33
|
+
dot: true,
|
34
|
+
});
|
35
|
+
|
36
|
+
console.warn(
|
37
|
+
`⚠️ The following files use handlebars templates. Please manually update them:`
|
38
|
+
);
|
39
|
+
|
40
|
+
let counter = 0;
|
41
|
+
|
42
|
+
for (const recipeFile of recipeFiles) {
|
43
|
+
const filePath = path.join(recipePath, recipeFile);
|
44
|
+
|
45
|
+
const targetPath = filePath
|
46
|
+
.replace(recipePath, templatePath)
|
47
|
+
.replace(".gitignore", "gitignore"); // rename .gitignore to gitignore so NPM publish doesn't ignore it
|
48
|
+
|
49
|
+
// Don't copy file if it's templated by handlebars
|
50
|
+
if (fs.existsSync(`${targetPath}.hbs`)) {
|
51
|
+
console.warn(`- ${recipeFile}`);
|
52
|
+
} else {
|
53
|
+
if (verbose) {
|
54
|
+
console.log(`Copying ${filePath} -> ${targetPath}`);
|
55
|
+
}
|
56
|
+
|
57
|
+
const data = await fs.readFileSync(filePath, "utf-8");
|
58
|
+
|
59
|
+
const dir = path.dirname(targetPath);
|
60
|
+
|
61
|
+
await fs.mkdirSync(dir, { recursive: true });
|
62
|
+
|
63
|
+
await fs.writeFileSync(targetPath, data);
|
64
|
+
|
65
|
+
counter += 1;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
console.log(`Copied ${counter} files into generator!`);
|
70
|
+
};
|
71
|
+
|
72
|
+
await run();
|
@@ -1,32 +0,0 @@
|
|
1
|
-
"use client";
|
2
|
-
|
3
|
-
import type { Data } from "@measured/puck";
|
4
|
-
import { Puck, Render } from "@measured/puck";
|
5
|
-
import config from "../../puck.config";
|
6
|
-
|
7
|
-
export function Client({
|
8
|
-
path,
|
9
|
-
data,
|
10
|
-
isEdit,
|
11
|
-
}: {
|
12
|
-
path: string;
|
13
|
-
data: Data;
|
14
|
-
isEdit: boolean;
|
15
|
-
}) {
|
16
|
-
if (isEdit) {
|
17
|
-
return (
|
18
|
-
<Puck
|
19
|
-
config={config}
|
20
|
-
data={data}
|
21
|
-
onPublish={async (data: Data) => {
|
22
|
-
await fetch("/api/puck", {
|
23
|
-
method: "post",
|
24
|
-
body: JSON.stringify({ data, path }),
|
25
|
-
});
|
26
|
-
}}
|
27
|
-
/>
|
28
|
-
);
|
29
|
-
}
|
30
|
-
|
31
|
-
return <Render config={config} data={data} />;
|
32
|
-
}
|
@@ -1,49 +0,0 @@
|
|
1
|
-
import { Client } from "./client";
|
2
|
-
import { notFound } from "next/navigation";
|
3
|
-
import resolvePuckPath from "./resolve-puck-path";
|
4
|
-
import { Metadata } from "next";
|
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
|
-
};
|
16
|
-
|
17
|
-
export async function generateMetadata({
|
18
|
-
params,
|
19
|
-
}: {
|
20
|
-
params: { puckPath: string[] };
|
21
|
-
}): Promise<Metadata> {
|
22
|
-
const { isEdit, path } = resolvePuckPath(params.puckPath);
|
23
|
-
|
24
|
-
if (isEdit) {
|
25
|
-
return {
|
26
|
-
title: "Puck: " + path,
|
27
|
-
};
|
28
|
-
}
|
29
|
-
|
30
|
-
return {
|
31
|
-
title: getPage(path)?.root.title,
|
32
|
-
};
|
33
|
-
}
|
34
|
-
|
35
|
-
export default async function Page({
|
36
|
-
params,
|
37
|
-
}: {
|
38
|
-
params: { puckPath: string[] };
|
39
|
-
}) {
|
40
|
-
const { isEdit, path } = resolvePuckPath(params.puckPath);
|
41
|
-
|
42
|
-
const data = getPage(path);
|
43
|
-
|
44
|
-
if (!data && !isEdit) {
|
45
|
-
return notFound();
|
46
|
-
}
|
47
|
-
|
48
|
-
return <Client isEdit={isEdit} path={path} data={data} />;
|
49
|
-
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
const resolvePuckPath = (puckPath: string[] = []) => {
|
2
|
-
const hasPath = puckPath.length > 0;
|
3
|
-
|
4
|
-
const isEdit = hasPath ? puckPath[puckPath.length - 1] === "edit" : false;
|
5
|
-
|
6
|
-
return {
|
7
|
-
isEdit,
|
8
|
-
path: `/${(isEdit
|
9
|
-
? [...puckPath].slice(0, puckPath.length - 1)
|
10
|
-
: [...puckPath]
|
11
|
-
).join("/")}`,
|
12
|
-
};
|
13
|
-
};
|
14
|
-
|
15
|
-
export default resolvePuckPath;
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import { revalidatePath } from "next/cache";
|
2
|
-
import { NextResponse } from "next/server";
|
3
|
-
import fs from "fs";
|
4
|
-
|
5
|
-
export async function POST(request: Request) {
|
6
|
-
const payload = await request.json();
|
7
|
-
|
8
|
-
const existingData = JSON.parse(
|
9
|
-
fs.existsSync("database.json")
|
10
|
-
? fs.readFileSync("database.json", "utf-8")
|
11
|
-
: "{}"
|
12
|
-
);
|
13
|
-
|
14
|
-
const updatedData = {
|
15
|
-
...existingData,
|
16
|
-
[payload.path]: payload.data,
|
17
|
-
};
|
18
|
-
|
19
|
-
fs.writeFileSync("database.json", JSON.stringify(updatedData));
|
20
|
-
|
21
|
-
// Purge Next.js cache
|
22
|
-
revalidatePath(payload.path);
|
23
|
-
|
24
|
-
return NextResponse.json({ status: "ok" });
|
25
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export { default, generateMetadata } from "./[...puckPath]/page";
|
@@ -1 +0,0 @@
|
|
1
|
-
{"/":{"content":[{"type":"HeadingBlock","props":{"title":"Edit this page by adding /edit to the end of the URL","id":"HeadingBlock-1694032984497"}}],"root":{"title":""}}}
|
package/templates/next/gitignore
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
2
|
-
|
3
|
-
# dependencies
|
4
|
-
/node_modules
|
5
|
-
/.pnp
|
6
|
-
.pnp.js
|
7
|
-
|
8
|
-
# testing
|
9
|
-
/coverage
|
10
|
-
|
11
|
-
# next.js
|
12
|
-
/.next/
|
13
|
-
/out/
|
14
|
-
|
15
|
-
# production
|
16
|
-
/build
|
17
|
-
|
18
|
-
# misc
|
19
|
-
.DS_Store
|
20
|
-
*.pem
|
21
|
-
|
22
|
-
# debug
|
23
|
-
npm-debug.log*
|
24
|
-
yarn-debug.log*
|
25
|
-
yarn-error.log*
|
26
|
-
|
27
|
-
# local env files
|
28
|
-
.env.local
|
29
|
-
.env.development.local
|
30
|
-
.env.test.local
|
31
|
-
.env.production.local
|
32
|
-
|
33
|
-
# vercel
|
34
|
-
.vercel
|
35
|
-
|
36
|
-
database.json
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import type { Config } from "@measured/puck";
|
2
|
-
|
3
|
-
type Props = {
|
4
|
-
HeadingBlock: { title: string };
|
5
|
-
};
|
6
|
-
|
7
|
-
export const config: Config<Props> = {
|
8
|
-
components: {
|
9
|
-
HeadingBlock: {
|
10
|
-
fields: {
|
11
|
-
title: { type: "text" },
|
12
|
-
},
|
13
|
-
defaultProps: {
|
14
|
-
title: "Heading",
|
15
|
-
},
|
16
|
-
render: ({ title }) => (
|
17
|
-
<div style={{ padding: 64 }}>
|
18
|
-
<h1>{title}</h1>
|
19
|
-
</div>
|
20
|
-
),
|
21
|
-
},
|
22
|
-
},
|
23
|
-
};
|
24
|
-
|
25
|
-
export default config;
|
@@ -1,20 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
3
|
-
"display": "Default",
|
4
|
-
"compilerOptions": {
|
5
|
-
"composite": false,
|
6
|
-
"declaration": true,
|
7
|
-
"declarationMap": true,
|
8
|
-
"esModuleInterop": true,
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
10
|
-
"inlineSources": false,
|
11
|
-
"isolatedModules": true,
|
12
|
-
"moduleResolution": "node",
|
13
|
-
"noUnusedLocals": false,
|
14
|
-
"noUnusedParameters": false,
|
15
|
-
"preserveWatchOutput": true,
|
16
|
-
"skipLibCheck": true,
|
17
|
-
"strict": true
|
18
|
-
},
|
19
|
-
"exclude": ["node_modules"]
|
20
|
-
}
|
@@ -1,21 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
3
|
-
"display": "Next.js",
|
4
|
-
"extends": "./base.json",
|
5
|
-
"compilerOptions": {
|
6
|
-
"plugins": [{ "name": "next" }],
|
7
|
-
"allowJs": true,
|
8
|
-
"declaration": false,
|
9
|
-
"declarationMap": false,
|
10
|
-
"incremental": true,
|
11
|
-
"jsx": "preserve",
|
12
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
13
|
-
"module": "esnext",
|
14
|
-
"noEmit": true,
|
15
|
-
"resolveJsonModule": true,
|
16
|
-
"strict": false,
|
17
|
-
"target": "es5"
|
18
|
-
},
|
19
|
-
"include": ["src", "next-env.d.ts"],
|
20
|
-
"exclude": ["node_modules"]
|
21
|
-
}
|