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.
Files changed (48) hide show
  1. package/dist/{builders-hKD4IrLX-ClhMQQkN.mjs → builders-hKD4IrLX-BrpqCAS2.mjs} +1 -1
  2. package/dist/index.mjs +115 -101
  3. package/dist/nextjs-HiDO_p-p.mjs +318 -0
  4. package/dist/nuxt-CDrqbn0o.mjs +59 -0
  5. package/dist/string-BUjs_2AH.mjs +7 -0
  6. package/dist/{sveltekit-BMDXAfYz.mjs → sveltekit-Qx8xJZOd.mjs} +45 -35
  7. package/package.json +1 -1
  8. package/src/adapters/index.ts +177 -0
  9. package/src/{frameworks → adapters}/nextjs.templates.ts +102 -102
  10. package/src/adapters/nextjs.ts +211 -0
  11. package/src/adapters/nuxt.ts +232 -0
  12. package/src/adapters/sveltekit.ts +226 -0
  13. package/src/clients/core.ts +104 -0
  14. package/src/clients/wroom.ts +111 -0
  15. package/src/commands/init.ts +57 -69
  16. package/src/commands/login.ts +12 -29
  17. package/src/commands/logout.ts +8 -28
  18. package/src/commands/preview-add.ts +57 -0
  19. package/src/commands/preview-list.ts +54 -0
  20. package/src/commands/preview-remove.ts +51 -0
  21. package/src/commands/preview-set-simulator.ts +60 -0
  22. package/src/commands/preview.ts +28 -0
  23. package/src/commands/sync.ts +49 -87
  24. package/src/commands/webhook-create.ts +89 -0
  25. package/src/commands/webhook-disable.ts +60 -0
  26. package/src/commands/webhook-enable.ts +60 -0
  27. package/src/commands/webhook-list.ts +43 -0
  28. package/src/commands/webhook-remove.ts +52 -0
  29. package/src/commands/webhook-set-triggers.ts +93 -0
  30. package/src/commands/webhook-view.ts +65 -0
  31. package/src/commands/webhook.ts +43 -0
  32. package/src/commands/whoami.ts +7 -28
  33. package/src/config.ts +2 -11
  34. package/src/index.ts +122 -105
  35. package/src/lib/command.ts +188 -0
  36. package/src/lib/file.ts +13 -1
  37. package/src/lib/packageJson.ts +70 -1
  38. package/src/lib/segment.ts +26 -30
  39. package/src/project.ts +54 -0
  40. package/dist/frameworks-DtGBrEuY.mjs +0 -17
  41. package/dist/nextjs-2qjzSaQI.mjs +0 -312
  42. package/dist/nuxt-DKsgbqpV.mjs +0 -59
  43. package/src/frameworks/index.ts +0 -398
  44. package/src/frameworks/nextjs.ts +0 -211
  45. package/src/frameworks/nuxt.ts +0 -252
  46. package/src/frameworks/sveltekit.ts +0 -234
  47. /package/src/{frameworks → adapters}/nuxt.templates.ts +0 -0
  48. /package/src/{frameworks → adapters}/sveltekit.templates.ts +0 -0
@@ -1,312 +0,0 @@
1
- import{_ as e,a as t,b as n,o as r,t as i,y as a}from"./frameworks-DtGBrEuY.mjs";import{createRequire as o}from"node:module";const s=t`
2
- return (
3
- <section
4
- data-slice-type={slice.slice_type}
5
- data-slice-variation={slice.variation}
6
- >
7
- Placeholder component for {slice.slice_type} (variation: {slice.variation}) slices.
8
- <br />
9
- <strong>You can edit this slice directly in your code editor.</strong>
10
- </section>
11
- )
12
- `;function c(e){let{name:n,typescript:i}=e,a=r(n),o=t`
13
- import { FC } from "react";
14
- import { Content } from "@prismicio/client";
15
- import { SliceComponentProps } from "@prismicio/react";
16
-
17
- /**
18
- * Props for \`${a}\`.
19
- */
20
- export type ${a}Props = SliceComponentProps<Content.${a}Slice>;
21
-
22
- /**
23
- * Component for "${n}" Slices.
24
- */
25
- const ${a}: FC<${a}Props> = ({ slice }) => {
26
- ${s}
27
- };
28
-
29
- export default ${a}
30
- `,c=t`
31
- /**
32
- * @typedef {import("@prismicio/client").Content.${a}Slice} ${a}Slice
33
- * @typedef {import("@prismicio/react").SliceComponentProps<${a}Slice>} ${a}Props
34
- * @type {import("react").FC<${a}Props>}
35
- */
36
- const ${a} = ({ slice }) => {
37
- ${s}
38
- };
39
-
40
- export default ${a};
41
- `;return i?o:c}function l(e){let{typescript:n,appRouter:r,hasSrcDirectory:i}=e,a=`${i?`..`:`.`}/prismic.config.json`,o,s;return r?n?(o=t`
42
- import {
43
- createClient as baseCreateClient,
44
- type ClientConfig,
45
- type Route,
46
- } from "@prismicio/client";
47
- import { enableAutoPreviews } from "@prismicio/next";
48
- import prismicConfig from "${a}";
49
- `,s=t`
50
- /**
51
- * Creates a Prismic client for the project's repository. The client is used to
52
- * query content from the Prismic API.
53
- *
54
- * @param config - Configuration for the Prismic client.
55
- */
56
- export const createClient = (config: ClientConfig = {}) => {
57
- const client = baseCreateClient(repositoryName, {
58
- routes,
59
- fetchOptions:
60
- process.env.NODE_ENV === 'production'
61
- ? { next: { tags: ['prismic'] }, cache: 'force-cache' }
62
- : { next: { revalidate: 5 } },
63
- ...config,
64
- });
65
-
66
- enableAutoPreviews({ client });
67
-
68
- return client;
69
- };
70
- `):(o=t`
71
- import { createClient as baseCreateClient } from "@prismicio/client";
72
- import { enableAutoPreviews } from "@prismicio/next";
73
- import prismicConfig from "${a}";
74
- `,s=t`
75
- /**
76
- * Creates a Prismic client for the project's repository. The client is used to
77
- * query content from the Prismic API.
78
- *
79
- * @param {import("@prismicio/client").ClientConfig} config - Configuration for the Prismic client.
80
- */
81
- export const createClient = (config = {}) => {
82
- const client = baseCreateClient(repositoryName, {
83
- routes,
84
- fetchOptions:
85
- process.env.NODE_ENV === 'production'
86
- ? { next: { tags: ['prismic'] }, cache: 'force-cache' }
87
- : { next: { revalidate: 5 } },
88
- ...config,
89
- });
90
-
91
- enableAutoPreviews({ client });
92
-
93
- return client;
94
- };
95
- `):n?(o=t`
96
- import { createClient as baseCreateClient, type Routes } from "@prismicio/client";
97
- import { enableAutoPreviews, type CreateClientConfig } from "@prismicio/next/pages";
98
- import prismicConfig from "${a}";
99
- `,s=t`
100
- /**
101
- * Creates a Prismic client for the project's repository. The client is used to
102
- * query content from the Prismic API.
103
- *
104
- * @param config - Configuration for the Prismic client.
105
- */
106
- export const createClient = ({ previewData, req, ...config }: CreateClientConfig = {}) => {
107
- const client = baseCreateClient(repositoryName, {
108
- routes,
109
- ...config,
110
- });
111
-
112
- enableAutoPreviews({ client, previewData, req });
113
-
114
- return client;
115
- };
116
- `):(o=t`
117
- import { createClient as baseCreateClient } from "@prismicio/client";
118
- import { enableAutoPreviews } from "@prismicio/next/pages";
119
- import prismicConfig from "${a}";
120
- `,s=t`
121
- /**
122
- * Creates a Prismic client for the project's repository. The client is used to
123
- * query content from the Prismic API.
124
- *
125
- * @param {import("@prismicio/next/pages").CreateClientConfig} config - Configuration for the Prismic client.
126
- */
127
- export const createClient = ({ previewData, req, ...config } = {}) => {
128
- const client = baseCreateClient(repositoryName, {
129
- routes,
130
- ...config,
131
- });
132
-
133
- enableAutoPreviews({ client, previewData, req });
134
-
135
- return client;
136
- };
137
- `),n?t`
138
- ${o}
139
-
140
- /**
141
- * The project's Prismic repository name.
142
- */
143
- export const repositoryName = prismicConfig.repositoryName;
144
-
145
- /**
146
- * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
147
- *
148
- * {@link https://prismic.io/docs/route-resolver#route-resolver}
149
- *
150
- * Note: \`prismic sync\` may append new default routes for Page Types. Feel free
151
- * to edit these to match your site's routing structure.
152
- */
153
- // TODO: Update the routes array to match your project's route structure.
154
- const routes: Route[] = [
155
- // Examples:
156
- // { type: "homepage", path: "/" },
157
- // { type: "page", path: "/:uid" },
158
- ];
159
-
160
- ${s}
161
- `:t`
162
- ${o}
163
-
164
- /**
165
- * The project's Prismic repository name.
166
- */
167
- export const repositoryName = prismicConfig.repositoryName;
168
-
169
- /**
170
- * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
171
- *
172
- * {@link https://prismic.io/docs/route-resolver#route-resolver}
173
- *
174
- * Note: \`prismic sync\` may append new default routes for Page Types. Feel free
175
- * to edit these to match your site's routing structure.
176
- *
177
- * @type {import("@prismicio/client").Route[]}
178
- */
179
- // TODO: Update the routes array to match your project's route structure.
180
- const routes = [
181
- // Examples:
182
- // { type: "homepage", path: "/" },
183
- // { type: "page", path: "/:uid" },
184
- ];
185
-
186
- ${s}
187
- `}function u(e){let{typescript:n,appRouter:r}=e;return r?n?t`
188
- import {
189
- SliceSimulator,
190
- SliceSimulatorParams,
191
- getSlices,
192
- } from "@prismicio/next";
193
- import { SliceZone } from "@prismicio/react";
194
-
195
- import { components } from "../../slices";
196
-
197
- export default async function SliceSimulatorPage({
198
- searchParams,
199
- }: SliceSimulatorParams) {
200
- const { state } = await searchParams
201
- const slices = getSlices(state);
202
-
203
- return (
204
- <SliceSimulator>
205
- <SliceZone slices={slices} components={components} />
206
- </SliceSimulator>
207
- );
208
- }
209
- `:t`
210
- import { SliceSimulator, getSlices } from "@prismicio/next";
211
- import { SliceZone } from "@prismicio/react";
212
-
213
- import { components } from "../../slices";
214
-
215
- export default async function SliceSimulatorPage({ searchParams }) {
216
- const { state } = await searchParams
217
- const slices = getSlices(state);
218
-
219
- return (
220
- <SliceSimulator>
221
- <SliceZone slices={slices} components={components} />
222
- </SliceSimulator>
223
- );
224
- }
225
- `:t`
226
- import { SliceSimulator } from "@prismicio/next/pages";
227
- import { SliceZone } from "@prismicio/react";
228
-
229
- import { components } from "../slices";
230
-
231
- export default function SliceSimulatorPage() {
232
- return (
233
- <SliceSimulator
234
- sliceZone={(props) => <SliceZone {...props} components={components} />}
235
- />
236
- );
237
- }
238
- `}function d(e){let{typescript:n,appRouter:r}=e;return r?n?t`
239
- import { NextRequest } from "next/server";
240
- import { redirectToPreviewURL } from "@prismicio/next";
241
-
242
- import { createClient } from "../../../prismicio";
243
-
244
- export async function GET(request: NextRequest) {
245
- const client = createClient();
246
-
247
- return await redirectToPreviewURL({ client, request });
248
- }
249
- `:t`
250
- import { redirectToPreviewURL } from "@prismicio/next";
251
-
252
- import { createClient } from "../../../prismicio";
253
-
254
- export async function GET(request) {
255
- const client = createClient();
256
-
257
- return await redirectToPreviewURL({ client, request });
258
- }
259
- `:n?t`
260
- import { NextApiRequest, NextApiResponse } from "next";
261
- import { setPreviewData, redirectToPreviewURL } from "@prismicio/next/pages";
262
-
263
- import { createClient } from "../../prismicio";
264
-
265
- export default async function handler(req: NextApiRequest, res: NextApiResponse) {
266
- const client = createClient({ req });
267
-
268
- setPreviewData({ req, res });
269
-
270
- return await redirectToPreviewURL({ req, res, client });
271
- };
272
- `:t`
273
- import { setPreviewData, redirectToPreviewURL } from "@prismicio/next/pages";
274
-
275
- import { createClient } from "../../prismicio";
276
-
277
- export default async function handler(req, res) {
278
- const client = createClient({ req });
279
-
280
- setPreviewData({ req, res });
281
-
282
- return await redirectToPreviewURL({ req, res, client });
283
- };
284
- `}function f(e){let{typescript:n,appRouter:r}=e;return r?t`
285
- import { exitPreview } from "@prismicio/next";
286
-
287
- export function GET() {
288
- return exitPreview();
289
- }
290
- `:n?t`
291
- import { NextApiRequest, NextApiResponse } from "next";
292
- import { exitPreview } from "@prismicio/next/pages";
293
-
294
- export default function handler(req: NextApiRequest, res: NextApiResponse) {
295
- return exitPreview({ req, res });
296
- }
297
- `:t`
298
- import { exitPreview } from "@prismicio/next/pages";
299
-
300
- export default function handler(req, res) {
301
- return exitPreview({ req, res });
302
- }
303
- `}function p(e){let{supportsCacheLife:n}=e;return t`
304
- import { NextResponse } from "next/server";
305
- import { revalidateTag } from "next/cache";
306
-
307
- export async function POST() {
308
- revalidateTag("prismic"${n?`, "max"`:``});
309
-
310
- return NextResponse.json({ revalidated: true, now: Date.now() });
311
- }
312
- `}var m=class extends i{id=`next`;async getDependencies(){return{"@prismicio/client":`^${await e(`@prismicio/client`)}`,"@prismicio/react":`^${await e(`@prismicio/react`)}`,"@prismicio/next":`^${await e(`@prismicio/next`)}`}}async initProject(){await super.initProject(),await this.#i(),await this.#a(),await this.#o(),await this.#s(),await this.#c()}async createSliceComponent(e,t){let r=await this.getJsFileExtension(),i=new URL(`index.${r}x`,t);return await n(i,c({name:e.name,typescript:await this.checkIsTypeScriptProject()})),{componentPath:i}}getSliceImportPath(e){return`./${e}`}async getDefaultSliceLibraryPath(e){let t=new URL(`src/`,e),n=await a(t)?t:e;return new URL(`slices/`,n)}async getClientFilePath(){return await this.#t()?`src/prismicio.ts`:`prismicio.ts`}async getSlicesDirectoryPath(){return await this.#t()?`src/slices/`:`slices/`}getSliceComponentExtensions(){return[`.tsx`,`.ts`,`.jsx`,`.js`]}async getRoutePath(e){let t=await this.#t()?`src/app`:`app`;switch(e){case`/slice-simulator`:return{path:`${t}/slice-simulator/page`,extensions:[`.tsx`,`.ts`,`.jsx`,`.js`]};case`/api/preview`:return{path:`${t}/api/preview/route`,extensions:[`.ts`,`.js`]};case`/api/exit-preview`:return{path:`${t}/api/exit-preview/route`,extensions:[`.ts`,`.js`]};case`/api/revalidate`:return{path:`${t}/api/revalidate/route`,extensions:[`.ts`,`.js`]};default:return null}}async#e(){return await a(await this.#r(`app`))}async#t(){let e=await this.getProjectRoot();return await a(new URL(`src/`,e))}async#n(){let e=await this.getProjectRoot(),{version:t}=o(new URL(`package.json`,e))(`next/package.json`);return t}async#r(e){let t=await this.getProjectRoot(),n=await this.#t()?`src/`:``;return new URL(`${n}${e}`,t)}async#i(){let e=await this.getJsFileExtension(),t=await this.#r(`prismicio.${e}`);await a(t)||await n(t,l({typescript:await this.checkIsTypeScriptProject(),appRouter:await this.#e(),hasSrcDirectory:await this.#t()}))}async#a(){let e=await this.#e(),t=await this.checkIsTypeScriptProject(),r=`${await this.getJsFileExtension()}x`,i=e?`app/slice-simulator/page.${r}`:`pages/slice-simulator.${r}`,o=await this.#r(i);await a(o)||await n(o,u({typescript:t,appRouter:e}))}async#o(){let e=await this.#e(),t=await this.checkIsTypeScriptProject(),r=await this.getJsFileExtension(),i=e?`app/api/preview/route.${r}`:`pages/api/preview.${r}`,o=await this.#r(i);await a(o)||await n(o,d({typescript:t,appRouter:e}))}async#s(){let e=await this.#e(),t=await this.checkIsTypeScriptProject(),r=await this.getJsFileExtension(),i=e?`app/api/exit-preview/route.${r}`:`pages/api/exit-preview.${r}`,o=await this.#r(i);await a(o)||await n(o,f({typescript:t,appRouter:e}))}async#c(){if(!await this.#e())return;let e=await this.getJsFileExtension(),t=await this.#r(`app/api/revalidate/route.${e}`);if(await a(t))return;let r=await this.#n();await n(t,p({supportsCacheLife:Number.parseInt(r.split(`.`)[0])>=16}))}};export{m as NextJsFramework};
@@ -1,59 +0,0 @@
1
- import{_ as e,a as t,b as n,g as r,o as i,p as a,t as o,y as s}from"./frameworks-DtGBrEuY.mjs";import{n as c,r as l,t as u}from"./builders-hKD4IrLX-ClhMQQkN.mjs";import{readFile as d,rm as f}from"node:fs/promises";import{fileURLToPath as p}from"node:url";import{relative as m}from"node:path";function h(e){let{name:n,typescript:r}=e,a=i(n);return r?t`
2
- <script setup lang="ts">
3
- import type { Content } from "@prismicio/client";
4
-
5
- // The array passed to \`getSliceComponentProps\` is purely optional.
6
- // Consider it as a visual hint for you when templating your slice.
7
- defineProps(getSliceComponentProps<Content.${a}Slice>(
8
- ["slice", "index", "slices", "context"]
9
- ));
10
- <\/script>
11
-
12
- <template>
13
- <section
14
- :data-slice-type="slice.slice_type"
15
- :data-slice-variation="slice.variation"
16
- >
17
- Placeholder component for {{ slice.slice_type }} (variation: {{ slice.variation }}) slices.
18
- <br />
19
- <strong>You can edit this slice directly in your code editor.</strong>
20
- </section>
21
- </template>
22
- `:t`
23
- <script setup>
24
- // The array passed to \`getSliceComponentProps\` is purely optional.
25
- // Consider it as a visual hint for you when templating your slice.
26
- defineProps(getSliceComponentProps(["slice", "index", "slices", "context"]));
27
- <\/script>
28
-
29
- <template>
30
- <section
31
- :data-slice-type="slice.slice_type"
32
- :data-slice-variation="slice.variation"
33
- >
34
- Placeholder component for {{ slice.slice_type }} (variation: {{ slice.variation }}) slices.
35
- <br />
36
- <strong>You can edit this slice directly in your code editor.</strong>
37
- </section>
38
- </template>
39
- `}function g(e){let{typescript:n}=e,r=[`setup`];return n&&r.push(`lang="ts"`),t`
40
- <script ${r.join(` `)}>
41
- import { components } from "~/slices";
42
- <\/script>
43
-
44
- <template>
45
- <SliceSimulator #default="{ slices }">
46
- <SliceZone :slices="slices" :components="components" />
47
- </SliceSimulator>
48
- </template>
49
- `}const _=`@nuxtjs/prismic`;var v=class extends o{id=`nuxt`;async getDependencies(){return{"@prismicio/client":`^${await e(`@prismicio/client`)}`,[_]:`^${await e(_)}`}}async initProject(){await super.initProject(),await this.#t(),await this.#n(),await this.#r(),await this.#i()}async createSliceComponent(e,t){let r=new URL(`index.vue`,t);return await n(r,h({name:e.name,typescript:await this.checkIsTypeScriptProject()})),{componentPath:r}}getSliceImportPath(e){return`./${e}/index.vue`}async getDefaultSliceLibraryPath(e){let t=await this.#e();return new URL(`slices/`,t)}async getClientFilePath(){return null}async getSlicesDirectoryPath(){let e=await this.getProjectRoot();return await s(new URL(`app/`,e))?`app/slices/`:await s(new URL(`src/`,e))?`src/slices/`:`slices/`}getSliceComponentExtensions(){return[`.vue`]}async getRoutePath(e){return e===`/slice-simulator`?{path:`pages/slice-simulator`,extensions:[`.vue`]}:null}async generateSliceLibraryIndexContents(e){return t`
50
- // Code generated by Prismic. DO NOT EDIT.
51
-
52
- import { defineAsyncComponent } from "vue";
53
- import { defineSliceZoneComponents } from "@prismicio/vue";
54
-
55
- export const components = defineSliceZoneComponents({
56
- ${(await Promise.all(e.map(async e=>{let t=m(p(e.library),p(e.directory));return`${e.model.id}: defineAsyncComponent(() => import("./${t}/index.vue"))`}))).join(`,
57
- `)}
58
- });
59
- `}async#e(){let e=await this.getProjectRoot(),t=new URL(`app/`,e);if(await s(t))return t;let n=new URL(`src/`,e);return await s(n)?n:e}async#t(){let e=await this.getProjectRoot(),t=new URL(`nuxt.config.js`,e);if(await s(t)||(t=new URL(`nuxt.config.ts`,e)),!await s(t))return;let n=p(t),r=await c(n),i=r.exports.default.$type===`function-call`?r.exports.default.$args[0]:r.exports.default,a=!1;(i.modules||[]).find(e=>typeof e==`string`?e===_:Array.isArray(e)?(a=!!e[1],e[0]===_):!1)||(i.modules||=[],i.modules.push(_)),a||(r.imports.$prepend({from:`./prismic.config.json`,imported:`repositoryName`}),i.prismic||={},i.prismic.endpoint=u.raw(`repositoryName`)),await l(r,n)}async#n(){let e=await this.getProjectRoot(),t=await this.checkIsTypeScriptProject(),r=new URL(`app/pages/`,e),i=new URL(`src/pages/`,e),a=new URL(`pages/`,e),o;o=await s(r)?r:await s(i)?i:await s(a)?a:new URL(`pages/`,await this.#e());let c=new URL(`slice-simulator.vue`,o);await s(c)||await n(c,g({typescript:t}))}async#r(){let e=await this.#e(),t=new URL(`app.vue`,e);if(!await s(t))return;let r=await d(t,`utf8`);if(!r.includes(`<NuxtWelcome`))return;let i=new URL(`pages/index.vue`,e);await s(i)||await n(i,r),await f(t)}async#i(){let e=await this.getProjectRoot(),t=await s(new URL(`app/`,e)),n=await s(new URL(`src/`,e));if(!t&&!n)return;let i;try{i=await a()}catch{return}let o=i.libraries;!o||JSON.stringify(o)!==JSON.stringify([`./slices`])||(await this.getSlices()).length>0||await r({libraries:[t?`./app/slices`:`./src/slices`]})}};export{v as NuxtFramework};