prismic 1.1.0 → 1.2.0
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/dist/{builders-hKD4IrLX-ClhMQQkN.mjs → builders-hKD4IrLX-BrpqCAS2.mjs} +1 -1
- package/dist/index.mjs +115 -101
- package/dist/nextjs-HiDO_p-p.mjs +318 -0
- package/dist/nuxt-CDrqbn0o.mjs +59 -0
- package/dist/string-BUjs_2AH.mjs +7 -0
- package/dist/{sveltekit-BMDXAfYz.mjs → sveltekit-Qx8xJZOd.mjs} +45 -35
- package/package.json +1 -1
- package/src/adapters/index.ts +177 -0
- package/src/{frameworks → adapters}/nextjs.templates.ts +102 -102
- package/src/adapters/nextjs.ts +211 -0
- package/src/adapters/nuxt.ts +232 -0
- package/src/adapters/sveltekit.ts +226 -0
- package/src/clients/core.ts +104 -0
- package/src/clients/wroom.ts +111 -0
- package/src/commands/init.ts +57 -69
- package/src/commands/login.ts +12 -29
- package/src/commands/logout.ts +8 -28
- package/src/commands/preview-add.ts +57 -0
- package/src/commands/preview-list.ts +54 -0
- package/src/commands/preview-remove.ts +51 -0
- package/src/commands/preview-set-simulator.ts +60 -0
- package/src/commands/preview.ts +28 -0
- package/src/commands/sync.ts +49 -87
- package/src/commands/webhook-create.ts +89 -0
- package/src/commands/webhook-disable.ts +60 -0
- package/src/commands/webhook-enable.ts +60 -0
- package/src/commands/webhook-list.ts +43 -0
- package/src/commands/webhook-remove.ts +52 -0
- package/src/commands/webhook-set-triggers.ts +93 -0
- package/src/commands/webhook-view.ts +65 -0
- package/src/commands/webhook.ts +43 -0
- package/src/commands/whoami.ts +7 -28
- package/src/config.ts +2 -11
- package/src/index.ts +122 -105
- package/src/lib/command.ts +188 -0
- package/src/lib/file.ts +13 -1
- package/src/lib/packageJson.ts +70 -1
- package/src/lib/segment.ts +26 -30
- package/src/project.ts +54 -0
- package/dist/frameworks-DtGBrEuY.mjs +0 -17
- package/dist/nextjs-2qjzSaQI.mjs +0 -312
- package/dist/nuxt-DKsgbqpV.mjs +0 -59
- package/src/frameworks/index.ts +0 -398
- package/src/frameworks/nextjs.ts +0 -211
- package/src/frameworks/nuxt.ts +0 -252
- package/src/frameworks/sveltekit.ts +0 -234
- /package/src/{frameworks → adapters}/nuxt.templates.ts +0 -0
- /package/src/{frameworks → adapters}/sveltekit.templates.ts +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{C as e,T as t,a as n,b as r,n as i,o as a,t as o,v as s,w as c,y as l,z as u}from"./string-BUjs_2AH.mjs";import{n as d}from"./builders-hKD4IrLX-BrpqCAS2.mjs";import{createRequire as f}from"node:module";import{writeFile as p}from"node:fs/promises";import{fileURLToPath as m}from"node:url";import{relative as h}from"node:path";function g(e){let{typescript:t}=e;return t?o`
|
|
2
2
|
import { createClient as baseCreateClient, type Route } from "@prismicio/client";
|
|
3
3
|
import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
4
4
|
import prismicConfig from "../../prismic.config.json";
|
|
@@ -39,7 +39,7 @@ import{_ as e,a as t,b as n,o as r,t as i,y as a}from"./frameworks-DtGBrEuY.mjs"
|
|
|
39
39
|
|
|
40
40
|
return client;
|
|
41
41
|
};
|
|
42
|
-
`:
|
|
42
|
+
`:o`
|
|
43
43
|
import { createClient as baseCreateClient } from "@prismicio/client";
|
|
44
44
|
import { enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
45
45
|
import prismicConfig from "../../prismic.config.json";
|
|
@@ -82,7 +82,7 @@ import{_ as e,a as t,b as n,o as r,t as i,y as a}from"./frameworks-DtGBrEuY.mjs"
|
|
|
82
82
|
|
|
83
83
|
return client;
|
|
84
84
|
};
|
|
85
|
-
`}function
|
|
85
|
+
`}function _(e){let{version:t}=e,n=o`
|
|
86
86
|
<script>
|
|
87
87
|
import { SliceSimulator, SliceZone } from '@prismicio/svelte';
|
|
88
88
|
import { components } from '$lib/slices';
|
|
@@ -92,7 +92,7 @@ import{_ as e,a as t,b as n,o as r,t as i,y as a}from"./frameworks-DtGBrEuY.mjs"
|
|
|
92
92
|
<SliceSimulator let:slices>
|
|
93
93
|
<SliceZone {slices} {components} />
|
|
94
94
|
</SliceSimulator>
|
|
95
|
-
`,
|
|
95
|
+
`,r=o`
|
|
96
96
|
<script>
|
|
97
97
|
import { SliceSimulator, SliceZone } from '@prismicio/svelte';
|
|
98
98
|
import { components } from '$lib/slices';
|
|
@@ -101,7 +101,7 @@ import{_ as e,a as t,b as n,o as r,t as i,y as a}from"./frameworks-DtGBrEuY.mjs"
|
|
|
101
101
|
<SliceSimulator let:slices>
|
|
102
102
|
<SliceZone {slices} {components} />
|
|
103
103
|
</SliceSimulator>
|
|
104
|
-
`;return
|
|
104
|
+
`;return t<=4?r:n}function v(e){let{typescript:t}=e;return t?o`
|
|
105
105
|
import { redirectToPreviewURL } from '@prismicio/svelte/kit';
|
|
106
106
|
import { createClient } from '$lib/prismicio';
|
|
107
107
|
import type { RequestHandler } from "./$types";
|
|
@@ -111,7 +111,7 @@ import{_ as e,a as t,b as n,o as r,t as i,y as a}from"./frameworks-DtGBrEuY.mjs"
|
|
|
111
111
|
|
|
112
112
|
return await redirectToPreviewURL({ client, request, cookies });
|
|
113
113
|
}
|
|
114
|
-
`:
|
|
114
|
+
`:o`
|
|
115
115
|
import { redirectToPreviewURL } from '@prismicio/svelte/kit';
|
|
116
116
|
import { createClient } from '$lib/prismicio';
|
|
117
117
|
|
|
@@ -121,7 +121,7 @@ import{_ as e,a as t,b as n,o as r,t as i,y as a}from"./frameworks-DtGBrEuY.mjs"
|
|
|
121
121
|
|
|
122
122
|
return await redirectToPreviewURL({ client, request, cookies });
|
|
123
123
|
}
|
|
124
|
-
`}function
|
|
124
|
+
`}function y(e){let{version:t}=e,n=o`
|
|
125
125
|
<script>
|
|
126
126
|
import { isFilled, asImageSrc } from '@prismicio/client';
|
|
127
127
|
import { PrismicPreview } from '@prismicio/svelte/kit';
|
|
@@ -144,7 +144,7 @@ import{_ as e,a as t,b as n,o as r,t as i,y as a}from"./frameworks-DtGBrEuY.mjs"
|
|
|
144
144
|
</svelte:head>
|
|
145
145
|
{@render children()}
|
|
146
146
|
<PrismicPreview {repositoryName} />
|
|
147
|
-
`,
|
|
147
|
+
`,r=o`
|
|
148
148
|
<script>
|
|
149
149
|
import { isFilled, asImageSrc } from '@prismicio/client';
|
|
150
150
|
import { PrismicPreview } from '@prismicio/svelte/kit';
|
|
@@ -165,62 +165,72 @@ import{_ as e,a as t,b as n,o as r,t as i,y as a}from"./frameworks-DtGBrEuY.mjs"
|
|
|
165
165
|
</svelte:head>
|
|
166
166
|
<slot />
|
|
167
167
|
<PrismicPreview {repositoryName} />
|
|
168
|
-
`;return
|
|
168
|
+
`;return t<=4?r:n}const b=o`
|
|
169
169
|
<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
|
|
170
170
|
Placeholder component for {slice.slice_type} (variation: {slice.variation}) slices.
|
|
171
171
|
<br />
|
|
172
172
|
<strong>You can edit this slice directly in your code editor.</strong>
|
|
173
173
|
</section>
|
|
174
|
-
`;function
|
|
174
|
+
`;function x(e){let{name:t,typescript:n,version:r}=e,i=u(t),a=o`
|
|
175
175
|
<script lang="ts">
|
|
176
176
|
import type { Content } from '@prismicio/client';
|
|
177
177
|
import type { SliceComponentProps } from '@prismicio/svelte';
|
|
178
178
|
|
|
179
|
-
type Props = SliceComponentProps<Content.${
|
|
179
|
+
type Props = SliceComponentProps<Content.${i}Slice>;
|
|
180
180
|
|
|
181
181
|
const { slice }: Props = $props();
|
|
182
182
|
<\/script>
|
|
183
183
|
|
|
184
|
-
${
|
|
185
|
-
`,
|
|
184
|
+
${b}
|
|
185
|
+
`,s=o`
|
|
186
186
|
<script>
|
|
187
187
|
/* @typedef {import("@prismicio/client").Content} Content */
|
|
188
188
|
/* @typedef {import("@prismicio/svelte").SliceComponentProps} SliceComponentProps */
|
|
189
189
|
|
|
190
|
-
/* @type {SliceComponentProps<Content.${
|
|
190
|
+
/* @type {SliceComponentProps<Content.${i}Slice>} */
|
|
191
191
|
const { slice } = $props();
|
|
192
192
|
<\/script>
|
|
193
193
|
|
|
194
|
-
${
|
|
195
|
-
`,
|
|
194
|
+
${b}
|
|
195
|
+
`,c=o`
|
|
196
196
|
<script lang="ts">
|
|
197
197
|
import type { Content } from '@prismicio/client';
|
|
198
198
|
|
|
199
|
-
export let slice: Content.${
|
|
199
|
+
export let slice: Content.${i}Slice;
|
|
200
200
|
<\/script>
|
|
201
201
|
|
|
202
|
-
${
|
|
203
|
-
`,
|
|
202
|
+
${b}
|
|
203
|
+
`,l=o`
|
|
204
204
|
<script>
|
|
205
|
-
/** @type {import("@prismicio/client").Content.${
|
|
205
|
+
/** @type {import("@prismicio/client").Content.${i}Slice} */
|
|
206
206
|
export let slice;
|
|
207
207
|
<\/script>
|
|
208
208
|
|
|
209
|
-
${
|
|
210
|
-
`;return
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
209
|
+
${b}
|
|
210
|
+
`;return n?r<=4?c:a:r<=4?l:s}var S=class extends i{id=`sveltekit`;async onProjectInitialized(){await s({"@prismicio/client":`^${await r(`@prismicio/client`)}`,"@prismicio/svelte":`^${await r(`@prismicio/svelte`)}`}),await C(),await w(),await T(),await E(),await D(),await O(),await k(),await A()}async onSliceCreated(e,r){let i=u(e.name),a=new URL(i,t(r));await c(new URL(`index.svelte`,a),x({name:e.name,typescript:await n(),version:await M()}))}onSliceUpdated(){}onSliceDeleted(){}onCustomTypeCreated(){}onCustomTypeUpdated(){}onCustomTypeDeleted(){}async createSliceIndexFile(e){let t=(await this.getSlices()).filter(t=>t.library.href===e.href),n=t.map(t=>`import ${u(t.model.name)} from "./${h(m(e),m(t.directory))}/index.svelte";`),r=t.map(e=>{let t=u(e.model.name);return`${e.model.id}: ${t}`}),i=o`
|
|
211
|
+
// Code generated by Prismic. DO NOT EDIT.
|
|
212
|
+
|
|
213
|
+
${n.join(`
|
|
214
|
+
`)}
|
|
215
|
+
|
|
216
|
+
export const components = {
|
|
217
|
+
${r.join(`,
|
|
218
|
+
`)}
|
|
219
|
+
};
|
|
220
|
+
`,a=`index.${await j()}`;await c(new URL(a,e),i)}async getDefaultSliceLibrary(){let e=await a();return new URL(`src/lib/slices/`,e)}};async function C(){let t=await j(),r=await a(),i=new URL(`src/lib/prismicio.${t}`,r);await e(i)||await c(i,g({typescript:await n()}))}async function w(){let t=await a(),n=new URL(`src/routes/slice-simulator/+page.svelte`,t);await e(n)||await c(n,_({version:await M()}))}async function T(){let t=await j(),n=await a(),r=new URL(`src/params/preview.${t}`,n);await e(r)||await c(r,o`
|
|
221
|
+
export function match(param) {
|
|
222
|
+
return param === 'preview';
|
|
223
|
+
}
|
|
224
|
+
`)}async function E(){let t=await j(),r=await a(),i=new URL(`src/routes/api/preview/+server.${t}`,r);await e(i)||await c(i,v({typescript:await n()}))}async function D(){let t=await a(),n=new URL(`src/routes/[[preview=preview]]/README.md`,t);await e(n)||await c(n,o`
|
|
225
|
+
This directory adds support for optional \`/preview\` routes. Do not remove this directory.
|
|
216
226
|
|
|
217
|
-
|
|
227
|
+
All routes within this directory will be served using the following URLs:
|
|
218
228
|
|
|
219
|
-
|
|
220
|
-
|
|
229
|
+
- \`/example-route\` (prerendered)
|
|
230
|
+
- \`/preview/example-route\` (server-rendered)
|
|
221
231
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
`);await
|
|
232
|
+
See <https://prismic.io/docs/svelte-preview> for more information.
|
|
233
|
+
`)}async function O(){let t=await j(),n=await a(),r=new URL(`src/routes/+layout.server.${t}`,n);await e(r)||await c(r,o`
|
|
234
|
+
export const prerender = "auto";
|
|
235
|
+
`)}async function k(){let t=await a(),n=new URL(`src/routes/+layout.svelte`,t);await e(n)||await c(n,y({version:await M()}))}async function A(){let t=await a(),n=new URL(`vite.config.js`,t);if(await e(n)||(n=new URL(`vite.config.ts`,t)),!await e(n))return;let r=n.pathname,i=await d(r);if(i.exports.default.$type!==`function-call`)return;let o=i.exports.default.$args[0];o.server??={},o.server.fs??={},o.server.fs.allow??=[],o.server.fs.allow.includes(`./prismic.config.json`)||o.server.fs.allow.push(`./prismic.config.json`);let s=i.generate().code.replace(/\n\s*\n(?=\s*server:)/,`
|
|
236
|
+
`);await p(n,s)}async function j(){return await n()?`ts`:`js`}async function M(){let{version:e}=f(await l())(`svelte/package.json`),t=Number.parseInt(e.split(`.`)[0]);return Number.isNaN(t)?1/0:t}export{S as SvelteKitAdapter};
|
package/package.json
CHANGED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { CustomType, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
+
|
|
3
|
+
import { pascalCase } from "change-case";
|
|
4
|
+
import { rm } from "node:fs/promises";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import { glob } from "tinyglobby";
|
|
7
|
+
|
|
8
|
+
import { readJsonFile, writeFileRecursive } from "../lib/file";
|
|
9
|
+
import { stringify } from "../lib/json";
|
|
10
|
+
import { readPackageJson } from "../lib/packageJson";
|
|
11
|
+
import { appendTrailingSlash } from "../lib/url";
|
|
12
|
+
import { findProjectRoot, getLibraries } from "../project";
|
|
13
|
+
|
|
14
|
+
type CustomTypeMeta = { model: CustomType; directory: URL };
|
|
15
|
+
type SharedSliceMeta = { model: SharedSlice; directory: URL; library: URL };
|
|
16
|
+
|
|
17
|
+
export async function getAdapter(): Promise<Adapter> {
|
|
18
|
+
const { dependencies, devDependencies, peerDependencies } = await readPackageJson();
|
|
19
|
+
const allDependencies = { ...dependencies, ...devDependencies, ...peerDependencies };
|
|
20
|
+
if ("next" in allDependencies) {
|
|
21
|
+
const { NextJsAdapter } = await import("./nextjs");
|
|
22
|
+
return new NextJsAdapter();
|
|
23
|
+
}
|
|
24
|
+
if ("nuxt" in allDependencies) {
|
|
25
|
+
const { NuxtAdapter } = await import("./nuxt");
|
|
26
|
+
return new NuxtAdapter();
|
|
27
|
+
}
|
|
28
|
+
if ("@sveltejs/kit" in allDependencies) {
|
|
29
|
+
const { SvelteKitAdapter } = await import("./sveltekit");
|
|
30
|
+
return new SvelteKitAdapter();
|
|
31
|
+
}
|
|
32
|
+
throw new NoSupportedFrameworkError();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class NoSupportedFrameworkError extends Error {
|
|
36
|
+
message = "No supported framework found (Next.js, Nuxt, or SvelteKit required)";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export abstract class Adapter {
|
|
40
|
+
abstract readonly id: string;
|
|
41
|
+
|
|
42
|
+
abstract onProjectInitialized(): Promise<void> | void;
|
|
43
|
+
abstract onSliceCreated(model: SharedSlice, library: URL): Promise<void> | void;
|
|
44
|
+
abstract onSliceUpdated(model: SharedSlice): Promise<void> | void;
|
|
45
|
+
abstract onSliceDeleted(id: string): Promise<void> | void;
|
|
46
|
+
abstract onCustomTypeCreated(model: CustomType): Promise<void> | void;
|
|
47
|
+
abstract onCustomTypeUpdated(model: CustomType): Promise<void> | void;
|
|
48
|
+
abstract onCustomTypeDeleted(id: string): Promise<void> | void;
|
|
49
|
+
|
|
50
|
+
abstract createSliceIndexFile(library: URL): Promise<void>;
|
|
51
|
+
abstract getDefaultSliceLibrary(): Promise<URL>;
|
|
52
|
+
|
|
53
|
+
async initProject(): Promise<void> {
|
|
54
|
+
const libraries = await this.getSliceLibraries();
|
|
55
|
+
for (const library of libraries) {
|
|
56
|
+
await this.createSliceIndexFile(library);
|
|
57
|
+
}
|
|
58
|
+
await this.onProjectInitialized();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getSliceLibraries(): Promise<URL[]> {
|
|
62
|
+
let libraries = await getLibraries();
|
|
63
|
+
if (libraries) return libraries;
|
|
64
|
+
const defaultSliceLibrary = await this.getDefaultSliceLibrary();
|
|
65
|
+
return [defaultSliceLibrary];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async getSlices(): Promise<SharedSliceMeta[]> {
|
|
69
|
+
const allSlices: SharedSliceMeta[] = [];
|
|
70
|
+
|
|
71
|
+
const libraries = await this.getSliceLibraries();
|
|
72
|
+
for (const library of libraries) {
|
|
73
|
+
const modelGlob = new URL("*/model.json", library);
|
|
74
|
+
const sliceModelPaths = Array.from(
|
|
75
|
+
await glob(fileURLToPath(modelGlob), { absolute: true }),
|
|
76
|
+
(path) => pathToFileURL(path),
|
|
77
|
+
);
|
|
78
|
+
const slices = await Promise.all(
|
|
79
|
+
sliceModelPaths.map(async (sliceModelPath) => {
|
|
80
|
+
const directory = new URL(".", sliceModelPath);
|
|
81
|
+
const model = await readJsonFile<SharedSlice>(sliceModelPath);
|
|
82
|
+
return { library, directory, model };
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
allSlices.push(...slices);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return allSlices.sort((a, b) =>
|
|
89
|
+
a.model.id.toLowerCase().localeCompare(b.model.id.toLowerCase()),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async getSlice(id: string): Promise<SharedSliceMeta> {
|
|
94
|
+
const slices = await this.getSlices();
|
|
95
|
+
const slice = slices.find((s) => s.model.id === id);
|
|
96
|
+
if (!slice) throw new Error(`No slice found with ID: ${id}`);
|
|
97
|
+
return slice;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async createSlice(model: SharedSlice, library?: URL): Promise<void> {
|
|
101
|
+
library ??= await this.getDefaultSliceLibrary();
|
|
102
|
+
await upsertSliceModel(model, library);
|
|
103
|
+
await this.onSliceCreated(model, library);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async updateSlice(model: SharedSlice): Promise<void> {
|
|
107
|
+
const slice = await this.getSlice(model.id);
|
|
108
|
+
await upsertSliceModel(model, slice.library);
|
|
109
|
+
await this.onSliceUpdated(model);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async deleteSlice(id: string): Promise<void> {
|
|
113
|
+
const slice = await this.getSlice(id);
|
|
114
|
+
await rm(slice.directory, { recursive: true });
|
|
115
|
+
await this.createSliceIndexFile(slice.library);
|
|
116
|
+
await this.onSliceDeleted(id);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async getCustomTypes(): Promise<CustomTypeMeta[]> {
|
|
120
|
+
const projectRoot = await findProjectRoot();
|
|
121
|
+
const customTypesDirectory = new URL("customtypes/", projectRoot);
|
|
122
|
+
const modelGlob = new URL("*/index.json", customTypesDirectory);
|
|
123
|
+
const customTypeModelPaths = Array.from(
|
|
124
|
+
await glob(fileURLToPath(modelGlob), { absolute: true }),
|
|
125
|
+
(path) => pathToFileURL(path),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const customTypes = await Promise.all(
|
|
129
|
+
customTypeModelPaths.map(async (customTypeModelPath) => {
|
|
130
|
+
const directory = new URL(".", customTypeModelPath);
|
|
131
|
+
const model = await readJsonFile<CustomType>(customTypeModelPath);
|
|
132
|
+
return { directory, model };
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
return customTypes.sort((a, b) =>
|
|
137
|
+
a.model.id.toLowerCase().localeCompare(b.model.id.toLowerCase()),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async getCustomType(id: string): Promise<CustomTypeMeta> {
|
|
142
|
+
const customTypes = await this.getCustomTypes();
|
|
143
|
+
const customType = customTypes.find((s) => s.model.id === id);
|
|
144
|
+
if (!customType) throw new Error(`No custom type found with ID: ${id}`);
|
|
145
|
+
return customType;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async createCustomType(model: CustomType): Promise<void> {
|
|
149
|
+
await upsertCustomTypeModel(model);
|
|
150
|
+
await this.onCustomTypeCreated(model);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async updateCustomType(model: CustomType): Promise<void> {
|
|
154
|
+
await upsertCustomTypeModel(model);
|
|
155
|
+
await this.onCustomTypeUpdated(model);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async deleteCustomType(id: string): Promise<void> {
|
|
159
|
+
const customType = await this.getCustomType(id);
|
|
160
|
+
await rm(customType.directory, { recursive: true });
|
|
161
|
+
await this.onCustomTypeDeleted(id);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function upsertSliceModel(model: SharedSlice, library: URL): Promise<void> {
|
|
166
|
+
const sliceDirectoryName = pascalCase(model.name);
|
|
167
|
+
const sliceDirectory = new URL(sliceDirectoryName, appendTrailingSlash(library));
|
|
168
|
+
const modelPath = new URL("model.json", appendTrailingSlash(sliceDirectory));
|
|
169
|
+
await writeFileRecursive(modelPath, stringify(model));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function upsertCustomTypeModel(model: CustomType): Promise<void> {
|
|
173
|
+
const projectRoot = await findProjectRoot();
|
|
174
|
+
const customTypesDirectory = new URL("customtypes/", projectRoot);
|
|
175
|
+
const modelPath = new URL(`${model.id}/index.json`, customTypesDirectory);
|
|
176
|
+
await writeFileRecursive(modelPath, stringify(model));
|
|
177
|
+
}
|
|
@@ -3,16 +3,16 @@ import { pascalCase } from "change-case";
|
|
|
3
3
|
import { dedent } from "../lib/string";
|
|
4
4
|
|
|
5
5
|
const SLICE_MARKUP = dedent`
|
|
6
|
-
return (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
)
|
|
6
|
+
return (
|
|
7
|
+
<section
|
|
8
|
+
data-slice-type={slice.slice_type}
|
|
9
|
+
data-slice-variation={slice.variation}
|
|
10
|
+
>
|
|
11
|
+
Placeholder component for {slice.slice_type} (variation: {slice.variation}) slices.
|
|
12
|
+
<br />
|
|
13
|
+
<strong>You can edit this slice directly in your code editor.</strong>
|
|
14
|
+
</section>
|
|
15
|
+
)
|
|
16
16
|
`;
|
|
17
17
|
|
|
18
18
|
export function sliceTemplate(args: { name: string; typescript: boolean }): string {
|
|
@@ -248,53 +248,45 @@ export function sliceSimulatorPageTemplate(args: {
|
|
|
248
248
|
}): string {
|
|
249
249
|
const { typescript, appRouter } = args;
|
|
250
250
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
return (
|
|
270
|
-
<SliceSimulator>
|
|
271
|
-
<SliceZone slices={slices} components={components} />
|
|
272
|
-
</SliceSimulator>
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
`;
|
|
251
|
+
const appTS = dedent`
|
|
252
|
+
import { SliceSimulator, SliceSimulatorParams, getSlices } from "@prismicio/next";
|
|
253
|
+
import { SliceZone } from "@prismicio/react";
|
|
254
|
+
|
|
255
|
+
import { components } from "../../slices";
|
|
256
|
+
|
|
257
|
+
export default async function SliceSimulatorPage({
|
|
258
|
+
searchParams,
|
|
259
|
+
}: SliceSimulatorParams) {
|
|
260
|
+
const { state } = await searchParams
|
|
261
|
+
const slices = getSlices(state);
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
<SliceSimulator>
|
|
265
|
+
<SliceZone slices={slices} components={components} />
|
|
266
|
+
</SliceSimulator>
|
|
267
|
+
);
|
|
276
268
|
}
|
|
269
|
+
`;
|
|
277
270
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
271
|
+
const appJS = dedent`
|
|
272
|
+
import { SliceSimulator, getSlices } from "@prismicio/next";
|
|
273
|
+
import { SliceZone } from "@prismicio/react";
|
|
281
274
|
|
|
282
|
-
|
|
275
|
+
import { components } from "../../slices";
|
|
283
276
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
277
|
+
export default async function SliceSimulatorPage({ searchParams }) {
|
|
278
|
+
const { state } = await searchParams
|
|
279
|
+
const slices = getSlices(state);
|
|
287
280
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
281
|
+
return (
|
|
282
|
+
<SliceSimulator>
|
|
283
|
+
<SliceZone slices={slices} components={components} />
|
|
284
|
+
</SliceSimulator>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
`;
|
|
296
288
|
|
|
297
|
-
|
|
289
|
+
const pages = dedent`
|
|
298
290
|
import { SliceSimulator } from "@prismicio/next/pages";
|
|
299
291
|
import { SliceZone } from "@prismicio/react";
|
|
300
292
|
|
|
@@ -308,58 +300,58 @@ export function sliceSimulatorPageTemplate(args: {
|
|
|
308
300
|
);
|
|
309
301
|
}
|
|
310
302
|
`;
|
|
303
|
+
|
|
304
|
+
if (appRouter) {
|
|
305
|
+
return typescript ? appTS : appJS;
|
|
306
|
+
} else {
|
|
307
|
+
return pages;
|
|
308
|
+
}
|
|
311
309
|
}
|
|
312
310
|
|
|
313
311
|
export function previewRouteTemplate(args: { typescript: boolean; appRouter: boolean }): string {
|
|
314
312
|
const { typescript, appRouter } = args;
|
|
315
313
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
import { NextRequest } from "next/server";
|
|
320
|
-
import { redirectToPreviewURL } from "@prismicio/next";
|
|
314
|
+
const appTS = dedent`
|
|
315
|
+
import { NextRequest } from "next/server";
|
|
316
|
+
import { redirectToPreviewURL } from "@prismicio/next";
|
|
321
317
|
|
|
322
|
-
|
|
318
|
+
import { createClient } from "../../../prismicio";
|
|
323
319
|
|
|
324
|
-
|
|
325
|
-
|
|
320
|
+
export async function GET(request: NextRequest) {
|
|
321
|
+
const client = createClient();
|
|
326
322
|
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
`;
|
|
323
|
+
return await redirectToPreviewURL({ client, request });
|
|
330
324
|
}
|
|
325
|
+
`;
|
|
331
326
|
|
|
332
|
-
|
|
333
|
-
|
|
327
|
+
const appJS = dedent`
|
|
328
|
+
import { redirectToPreviewURL } from "@prismicio/next";
|
|
334
329
|
|
|
335
|
-
|
|
330
|
+
import { createClient } from "../../../prismicio";
|
|
336
331
|
|
|
337
|
-
|
|
338
|
-
|
|
332
|
+
export async function GET(request) {
|
|
333
|
+
const client = createClient();
|
|
339
334
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
335
|
+
return await redirectToPreviewURL({ client, request });
|
|
336
|
+
}
|
|
337
|
+
`;
|
|
344
338
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
import { setPreviewData, redirectToPreviewURL } from "@prismicio/next/pages";
|
|
339
|
+
const pagesTS = dedent`
|
|
340
|
+
import { NextApiRequest, NextApiResponse } from "next";
|
|
341
|
+
import { setPreviewData, redirectToPreviewURL } from "@prismicio/next/pages";
|
|
349
342
|
|
|
350
|
-
|
|
343
|
+
import { createClient } from "../../prismicio";
|
|
351
344
|
|
|
352
|
-
|
|
353
|
-
|
|
345
|
+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
346
|
+
const client = createClient({ req });
|
|
354
347
|
|
|
355
|
-
|
|
348
|
+
setPreviewData({ req, res });
|
|
356
349
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
350
|
+
return await redirectToPreviewURL({ req, res, client });
|
|
351
|
+
};
|
|
352
|
+
`;
|
|
361
353
|
|
|
362
|
-
|
|
354
|
+
const pagesJS = dedent`
|
|
363
355
|
import { setPreviewData, redirectToPreviewURL } from "@prismicio/next/pages";
|
|
364
356
|
|
|
365
357
|
import { createClient } from "../../prismicio";
|
|
@@ -372,6 +364,12 @@ export function previewRouteTemplate(args: { typescript: boolean; appRouter: boo
|
|
|
372
364
|
return await redirectToPreviewURL({ req, res, client });
|
|
373
365
|
};
|
|
374
366
|
`;
|
|
367
|
+
|
|
368
|
+
if (appRouter) {
|
|
369
|
+
return typescript ? appTS : appJS;
|
|
370
|
+
} else {
|
|
371
|
+
return typescript ? pagesTS : pagesJS;
|
|
372
|
+
}
|
|
375
373
|
}
|
|
376
374
|
|
|
377
375
|
export function exitPreviewRouteTemplate(args: {
|
|
@@ -380,34 +378,36 @@ export function exitPreviewRouteTemplate(args: {
|
|
|
380
378
|
}): string {
|
|
381
379
|
const { typescript, appRouter } = args;
|
|
382
380
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
import { exitPreview } from "@prismicio/next";
|
|
381
|
+
const app = dedent`
|
|
382
|
+
import { exitPreview } from "@prismicio/next";
|
|
386
383
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
384
|
+
export function GET() {
|
|
385
|
+
return exitPreview();
|
|
386
|
+
}
|
|
387
|
+
`;
|
|
392
388
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
import { exitPreview } from "@prismicio/next/pages";
|
|
389
|
+
const pagesTS = dedent`
|
|
390
|
+
import { NextApiRequest, NextApiResponse } from "next";
|
|
391
|
+
import { exitPreview } from "@prismicio/next/pages";
|
|
397
392
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
393
|
+
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
394
|
+
return exitPreview({ req, res });
|
|
395
|
+
}
|
|
396
|
+
`;
|
|
403
397
|
|
|
404
|
-
|
|
398
|
+
const pagesJS = dedent`
|
|
405
399
|
import { exitPreview } from "@prismicio/next/pages";
|
|
406
400
|
|
|
407
401
|
export default function handler(req, res) {
|
|
408
402
|
return exitPreview({ req, res });
|
|
409
403
|
}
|
|
410
404
|
`;
|
|
405
|
+
|
|
406
|
+
if (appRouter) {
|
|
407
|
+
return app;
|
|
408
|
+
} else {
|
|
409
|
+
return typescript ? pagesTS : pagesJS;
|
|
410
|
+
}
|
|
411
411
|
}
|
|
412
412
|
|
|
413
413
|
export function revalidateRouteTemplate(args: { supportsCacheLife: boolean }): string {
|