@slicemachine/adapter-sveltekit 0.3.78-beta.9 → 0.3.78

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 (70) hide show
  1. package/dist/AlternateGrid/javascript.4.svelte +227 -0
  2. package/dist/AlternateGrid/javascript.svelte +6 -5
  3. package/dist/AlternateGrid/typescript.4.svelte +224 -0
  4. package/dist/AlternateGrid/typescript.svelte +9 -4
  5. package/dist/CallToAction/javascript.4.svelte +127 -0
  6. package/dist/CallToAction/javascript.svelte +6 -5
  7. package/dist/CallToAction/typescript.4.svelte +124 -0
  8. package/dist/CallToAction/typescript.svelte +4 -2
  9. package/dist/CustomerLogos/javascript.4.svelte +124 -0
  10. package/dist/CustomerLogos/javascript.svelte +6 -5
  11. package/dist/CustomerLogos/typescript.4.svelte +121 -0
  12. package/dist/CustomerLogos/typescript.svelte +4 -2
  13. package/dist/Hero/javascript.4.svelte +190 -0
  14. package/dist/Hero/javascript.svelte +5 -4
  15. package/dist/Hero/typescript.4.svelte +187 -0
  16. package/dist/Hero/typescript.svelte +4 -2
  17. package/dist/hooks/documentation-read.cjs +14 -51
  18. package/dist/hooks/documentation-read.cjs.map +1 -1
  19. package/dist/hooks/documentation-read.js +14 -51
  20. package/dist/hooks/documentation-read.js.map +1 -1
  21. package/dist/hooks/documentation-read.templates.cjs +114 -0
  22. package/dist/hooks/documentation-read.templates.cjs.map +1 -0
  23. package/dist/hooks/documentation-read.templates.d.ts +9 -0
  24. package/dist/hooks/documentation-read.templates.js +114 -0
  25. package/dist/hooks/documentation-read.templates.js.map +1 -0
  26. package/dist/hooks/project-init.cjs +44 -143
  27. package/dist/hooks/project-init.cjs.map +1 -1
  28. package/dist/hooks/project-init.js +44 -143
  29. package/dist/hooks/project-init.js.map +1 -1
  30. package/dist/hooks/project-init.templates.cjs +181 -0
  31. package/dist/hooks/project-init.templates.cjs.map +1 -0
  32. package/dist/hooks/project-init.templates.d.ts +12 -0
  33. package/dist/hooks/project-init.templates.js +181 -0
  34. package/dist/hooks/project-init.templates.js.map +1 -0
  35. package/dist/hooks/slice-create.cjs +5 -52
  36. package/dist/hooks/slice-create.cjs.map +1 -1
  37. package/dist/hooks/slice-create.js +5 -52
  38. package/dist/hooks/slice-create.js.map +1 -1
  39. package/dist/hooks/slice-create.templates.cjs +61 -0
  40. package/dist/hooks/slice-create.templates.cjs.map +1 -0
  41. package/dist/hooks/slice-create.templates.d.ts +6 -0
  42. package/dist/hooks/slice-create.templates.js +61 -0
  43. package/dist/hooks/slice-create.templates.js.map +1 -0
  44. package/dist/lib/getSvelteMajor.cjs +38 -0
  45. package/dist/lib/getSvelteMajor.cjs.map +1 -0
  46. package/dist/lib/getSvelteMajor.d.ts +1 -0
  47. package/dist/lib/getSvelteMajor.js +16 -0
  48. package/dist/lib/getSvelteMajor.js.map +1 -0
  49. package/dist/lib/requireResolve.cjs +16 -0
  50. package/dist/lib/requireResolve.cjs.map +1 -0
  51. package/dist/lib/requireResolve.d.ts +10 -0
  52. package/dist/lib/requireResolve.js +16 -0
  53. package/dist/lib/requireResolve.js.map +1 -0
  54. package/dist/plugin.cjs +4 -2
  55. package/dist/plugin.cjs.map +1 -1
  56. package/dist/plugin.js +4 -2
  57. package/dist/plugin.js.map +1 -1
  58. package/dist/simulator/SliceSimulator.svelte +3 -2
  59. package/dist/simulator/SliceSimulator.svelte.d.ts +7 -19
  60. package/package.json +8 -8
  61. package/src/hooks/documentation-read.templates.ts +170 -0
  62. package/src/hooks/documentation-read.ts +21 -59
  63. package/src/hooks/project-init.templates.ts +208 -0
  64. package/src/hooks/project-init.ts +57 -147
  65. package/src/hooks/slice-create.templates.ts +103 -0
  66. package/src/hooks/slice-create.ts +7 -66
  67. package/src/lib/getSvelteMajor.ts +23 -0
  68. package/src/lib/requireResolve.ts +30 -0
  69. package/src/plugin.ts +5 -2
  70. package/src/simulator/SliceSimulator.svelte +3 -2
@@ -1,15 +1,13 @@
1
1
  import * as path from "node:path";
2
2
  import { checkHasProjectFile, writeProjectFile } from "@slicemachine/plugin-kit/fs";
3
3
  import { source } from "common-tags";
4
+ import { loadFile } from "magicast";
4
5
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
5
6
  import { getJSFileExtension } from "../lib/getJSFileExtension.js";
7
+ import { getSvelteMajor } from "../lib/getSvelteMajor.js";
6
8
  import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
7
9
  import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
8
- import { PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME } from "../constants.js";
9
- var __freeze = Object.freeze;
10
- var __defProp = Object.defineProperty;
11
- var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
12
- var _a, _b;
10
+ import { prismicIOFileTemplate, sliceSimulatorPageTemplate, previewAPIRouteTemplate, rootLayoutTemplate } from "./project-init.templates.js";
13
11
  const installDependencies = async ({ installDependencies: installDependencies2 }) => {
14
12
  await installDependencies2({
15
13
  dependencies: {
@@ -19,113 +17,13 @@ const installDependencies = async ({ installDependencies: installDependencies2 }
19
17
  });
20
18
  };
21
19
  const createPrismicIOFile = async ({ helpers, options }) => {
22
- const isTypeScriptProject = await checkIsTypeScriptProject({
23
- helpers,
24
- options
25
- });
26
20
  const extension = await getJSFileExtension({ helpers, options });
27
21
  const filename = path.join(`src/lib/prismicio.${extension}`);
28
22
  if (await checkHasProjectFile({ filename, helpers })) {
29
23
  return;
30
24
  }
31
- let contents;
32
- if (isTypeScriptProject) {
33
- contents = source`
34
- import * as prismic from "@prismicio/client";
35
- import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
36
- import config from "../../slicemachine.config.json";
37
-
38
- /**
39
- * The project's Prismic repository name.
40
- */
41
- export const repositoryName =
42
- import${"."}meta${"."}env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;
43
-
44
- /**
45
- * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
46
- *
47
- * {@link https://prismic.io/docs/route-resolver#route-resolver}
48
- */
49
- // TODO: Update the routes array to match your project's route structure.
50
- const routes: prismic.ClientConfig["routes"] = [
51
- // Examples:
52
- // {
53
- // type: "homepage",
54
- // path: "/",
55
- // },
56
- // {
57
- // type: "page",
58
- // path: "/:uid",
59
- // },
60
- ];
61
-
62
- /**
63
- * Creates a Prismic client for the project's repository. The client is used to
64
- * query content from the Prismic API.
65
- *
66
- * @param config - Configuration for the Prismic client.
67
- */
68
- export const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {
69
- const client = prismic.createClient(repositoryName, {
70
- routes,
71
- ...config,
72
- });
73
-
74
- enableAutoPreviews({ client, cookies });
75
-
76
- return client;
77
- };
78
- `;
79
- } else {
80
- contents = source`
81
- import * as prismic from "@prismicio/client";
82
- import { enableAutoPreviews } from '@prismicio/svelte/kit';
83
- import config from "../../slicemachine.config.json";
84
-
85
- /**
86
- * The project's Prismic repository name.
87
- */
88
- export const repositoryName =
89
- import${"."}meta${"."}env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;
90
-
91
- /**
92
- * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
93
- *
94
- * {@link https://prismic.io/docs/route-resolver#route-resolver}
95
- *
96
- * @type {prismic.ClientConfig["routes"]}
97
- */
98
- // TODO: Update the routes array to match your project's route structure.
99
- const routes = [
100
- // Examples:
101
- // {
102
- // type: "homepage",
103
- // path: "/",
104
- // },
105
- // {
106
- // type: "page",
107
- // path: "/:uid",
108
- // },
109
- ];
110
-
111
- /**
112
- * Creates a Prismic client for the project's repository. The client is used to
113
- * query content from the Prismic API.
114
- *
115
- * @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.
116
- */
117
- export const createClient = ({ cookies, ...config } = {}) => {
118
- const client = prismic.createClient(repositoryName, {
119
- routes,
120
- ...config,
121
- });
122
-
123
- enableAutoPreviews({ client, cookies });
124
-
125
- return client;
126
- };
127
- `;
128
- }
25
+ const typescript = await checkIsTypeScriptProject({ helpers, options });
26
+ const contents = prismicIOFileTemplate({ typescript });
129
27
  await writeProjectFile({
130
28
  filename,
131
29
  contents,
@@ -138,7 +36,9 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
138
36
  if (await checkHasProjectFile({ filename, helpers })) {
139
37
  return;
140
38
  }
141
- const contents = source(_a || (_a = __template(["\n <script>\n import { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n import { SliceZone } from '@prismicio/svelte';\n import { components } from '$lib/slices';\n <\/script>\n\n <SliceSimulator let:slices>\n <SliceZone {slices} {components} />\n </SliceSimulator>\n "])));
39
+ const contents = sliceSimulatorPageTemplate({
40
+ version: await getSvelteMajor()
41
+ });
142
42
  await writeProjectFile({
143
43
  filename,
144
44
  contents,
@@ -176,16 +76,8 @@ const createPreviewAPIRoute = async ({ helpers, options }) => {
176
76
  if (await checkHasProjectFile({ filename, helpers })) {
177
77
  return;
178
78
  }
179
- const contents = source`
180
- import { redirectToPreviewURL } from '@prismicio/svelte/kit';
181
- import { createClient } from '$lib/prismicio';
182
-
183
- export async function GET({ fetch, request, cookies }) {
184
- const client = createClient({ fetch });
185
-
186
- return await redirectToPreviewURL({ client, request, cookies });
187
- }
188
- `;
79
+ const typescript = await checkIsTypeScriptProject({ helpers, options });
80
+ const contents = previewAPIRouteTemplate({ typescript });
189
81
  await writeProjectFile({
190
82
  filename,
191
83
  contents,
@@ -236,28 +128,7 @@ const createRootLayoutFile = async ({ helpers, options }) => {
236
128
  if (await checkHasProjectFile({ filename, helpers })) {
237
129
  return;
238
130
  }
239
- const contents = source(_b || (_b = __template([`
240
- <script>
241
- import { isFilled, asImageSrc } from '@prismicio/client';
242
- import { PrismicPreview } from '@prismicio/svelte/kit';
243
- import { page } from '$app/state';
244
- import { repositoryName } from '$lib/prismicio';
245
- <\/script>
246
-
247
- <svelte:head>
248
- <title>{page.data.page?.data.meta_title}</title>
249
- <meta property="og:title" content={page.data.page?.data.meta_title} />
250
- {#if isFilled.keyText(page.data.page?.data.meta_description)}
251
- <meta name="description" content={page.data.page.data.meta_description} />
252
- <meta property="og:description" content={page.data.page.data.meta_description} />
253
- {/if}
254
- {#if isFilled.image(page.data.page?.data.meta_image)}
255
- <meta property="og:image" content={asImageSrc(page.data.page.data.meta_image)} />
256
- {/if}
257
- </svelte:head>
258
- <slot />
259
- <PrismicPreview {repositoryName} />
260
- `])));
131
+ const contents = rootLayoutTemplate({ version: await getSvelteMajor() });
261
132
  await writeProjectFile({
262
133
  filename,
263
134
  contents,
@@ -272,9 +143,9 @@ const createRootLayoutFile = async ({ helpers, options }) => {
272
143
  });
273
144
  };
274
145
  const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
275
- var _a2;
146
+ var _a;
276
147
  const project = await helpers.getProject();
277
- (_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://localhost:5173/slice-simulator");
148
+ (_a = project.config).localSliceSimulatorURL || (_a.localSliceSimulatorURL = "http://localhost:5173/slice-simulator");
278
149
  if (await checkHasProjectFile({
279
150
  filename: "./src/lib",
280
151
  helpers
@@ -299,6 +170,35 @@ const upsertSliceLibraryIndexFiles = async (context) => {
299
170
  await upsertSliceLibraryIndexFile({ libraryID, ...context });
300
171
  }));
301
172
  };
173
+ const modifyViteConfig = async ({ helpers, options }) => {
174
+ var _a, _b;
175
+ let filename = "vite.config.js";
176
+ if (!await checkHasProjectFile({ filename, helpers })) {
177
+ filename = "vite.config.ts";
178
+ }
179
+ if (!await checkHasProjectFile({ filename, helpers })) {
180
+ return;
181
+ }
182
+ const filepath = helpers.joinPathFromRoot(filename);
183
+ const mod = await loadFile(filepath);
184
+ if (mod.exports.default.$type !== "function-call") {
185
+ return;
186
+ }
187
+ const config = mod.exports.default.$args[0];
188
+ config.server ?? (config.server = {});
189
+ (_a = config.server).fs ?? (_a.fs = {});
190
+ (_b = config.server.fs).allow ?? (_b.allow = []);
191
+ if (!config.server.fs.allow.includes("./slicemachine.config.json")) {
192
+ config.server.fs.allow.push("./slicemachine.config.json");
193
+ }
194
+ const contents = mod.generate().code.replace(/\n\s*\n(?=\s*server:)/, "\n");
195
+ await writeProjectFile({
196
+ filename,
197
+ contents,
198
+ format: options.format,
199
+ helpers
200
+ });
201
+ };
302
202
  const projectInit = async ({ installDependencies: _installDependencies }, context) => {
303
203
  rejectIfNecessary(await Promise.allSettled([
304
204
  installDependencies({ installDependencies: _installDependencies }),
@@ -309,7 +209,8 @@ const projectInit = async ({ installDependencies: _installDependencies }, contex
309
209
  createPreviewRouteDirectory(context),
310
210
  createPreviewRouteMatcherFile(context),
311
211
  createRootLayoutServerFile(context),
312
- createRootLayoutFile(context)
212
+ createRootLayoutFile(context),
213
+ modifyViteConfig(context)
313
214
  ]));
314
215
  await upsertSliceLibraryIndexFiles(context);
315
216
  };
@@ -1 +1 @@
1
- {"version":3,"file":"project-init.js","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { source } from \"common-tags\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\nimport type { PluginOptions } from \"../types\";\nimport { PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME } from \"../constants\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/svelte\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/lib/prismicio.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';\n\t\t\timport config from \"../../slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName =\n\t\t\t\timport${\".\"}meta${\".\"}env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes: prismic.ClientConfig[\"routes\"] = [\n\t\t\t\t// Examples:\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"homepage\",\n\t\t\t\t// \tpath: \"/\",\n\t\t\t\t// },\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"page\",\n\t\t\t\t// \tpath: \"/:uid\",\n\t\t\t\t// },\n\t\t\t];\n\n\t\t\t/**\n\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t * query content from the Prismic API.\n\t\t\t *\n\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {\n\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\troutes,\n\t\t\t\t\t...config,\n\t\t\t\t});\n\n\t\t\t\tenableAutoPreviews({ client, cookies });\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport { enableAutoPreviews } from '@prismicio/svelte/kit';\n\t\t\timport config from \"../../slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName =\n\t\t\t\timport${\".\"}meta${\".\"}env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t *\n\t\t\t * @type {prismic.ClientConfig[\"routes\"]}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes = [\n\t\t\t\t// Examples:\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"homepage\",\n\t\t\t\t// \tpath: \"/\",\n\t\t\t\t// },\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"page\",\n\t\t\t\t// \tpath: \"/:uid\",\n\t\t\t\t// },\n\t\t\t];\n\n\t\t\t/**\n\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t * query content from the Prismic API.\n\t\t\t *\n\t\t\t * @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = ({ cookies, ...config } = {}) => {\n\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\troutes,\n\t\t\t\t\t...config,\n\t\t\t\t});\n\n\t\t\t\tenableAutoPreviews({ client, cookies });\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst filename = path.join(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"slice-simulator\",\n\t\t\"+page.svelte\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\t<script>\n\t\t\timport { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n\t\t\timport { SliceZone } from '@prismicio/svelte';\n\t\t\timport { components } from '$lib/slices';\n\t\t</script>\n\n\t\t<SliceSimulator let:slices>\n\t\t\t<SliceZone {slices} {components} />\n\t\t</SliceSimulator>\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\tformatOptions: {\n\t\t\tprettier: {\n\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t\thelpers,\n\t});\n};\n\nconst createPreviewRouteMatcherFile = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/params/preview.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\texport function match(param) {\n\t\t\treturn param === 'preview';\n\t\t}\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewAPIRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"api\",\n\t\t\"preview\",\n\t\t`+server.${extension}`,\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\timport { redirectToPreviewURL } from '@prismicio/svelte/kit';\n\t\timport { createClient } from '$lib/prismicio';\n\n\t\texport async function GET({ fetch, request, cookies }) {\n\t\t\tconst client = createClient({ fetch });\n\n\t\t\treturn await redirectToPreviewURL({ client, request, cookies });\n\t\t}\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewRouteDirectory = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst filename = path.join(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"[[preview=preview]]\",\n\t\t\"README.md\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\tThis directory adds support for optional \\`/preview\\` routes. Do not remove this directory.\n\n\t\tAll routes within this directory will be served using the following URLs:\n\n\t\t- \\`/example-route\\` (prerendered)\n\t\t- \\`/preview/example-route\\` (server-rendered)\n\n\t\tSee <https://prismic.io/docs/svelte-preview> for more information.\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createRootLayoutServerFile = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/routes/+layout.server.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\texport const prerender = \"auto\";\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createRootLayoutFile = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst filename = path.join(\"src\", \"routes\", \"+layout.svelte\");\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\t<script>\n\t\t\timport { isFilled, asImageSrc } from '@prismicio/client';\n\t\t\timport { PrismicPreview } from '@prismicio/svelte/kit';\n\t\t\timport { page } from '$app/state';\n\t\t\timport { repositoryName } from '$lib/prismicio';\n\t\t</script>\n\n\t\t<svelte:head>\n\t\t\t<title>{page.data.page?.data.meta_title}</title>\n\t\t\t<meta property=\"og:title\" content={page.data.page?.data.meta_title} />\n\t\t\t{#if isFilled.keyText(page.data.page?.data.meta_description)}\n\t\t\t\t<meta name=\"description\" content={page.data.page.data.meta_description} />\n\t\t\t\t<meta property=\"og:description\" content={page.data.page.data.meta_description} />\n\t\t\t{/if}\n\t\t\t{#if isFilled.image(page.data.page?.data.meta_image)}\n\t\t\t\t<meta property=\"og:image\" content={asImageSrc(page.data.page.data.meta_image)} />\n\t\t\t{/if}\n\t\t</svelte:head>\n\t\t<slot />\n\t\t<PrismicPreview {repositoryName} />\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\tformatOptions: {\n\t\t\tprettier: {\n\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst project = await helpers.getProject();\n\n\t// Add Slice Simulator URL.\n\tproject.config.localSliceSimulatorURL ||=\n\t\t\"http://localhost:5173/slice-simulator\";\n\n\t// Nest the default Slice Library in the src directory if it exists and\n\t// is empty.\n\tif (\n\t\t(await checkHasProjectFile({\n\t\t\tfilename: \"./src/lib\",\n\t\t\thelpers,\n\t\t})) &&\n\t\tproject.config.libraries &&\n\t\tJSON.stringify(project.config.libraries) === JSON.stringify([\"./slices\"])\n\t) {\n\t\tconst sliceLibrary = await actions.readSliceLibrary({\n\t\t\tlibraryID: project.config.libraries[0],\n\t\t});\n\n\t\tif (sliceLibrary.sliceIDs.length < 1) {\n\t\t\tproject.config.libraries = [\"./src/lib/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst upsertSliceLibraryIndexFiles = async (\n\tcontext: SliceMachineContext<PluginOptions>,\n) => {\n\t// We must use the `getProject()` helper to get the latest version of\n\t// the project config. The config may have been modified in\n\t// `modifySliceMachineConfig()` and will not be relfected in\n\t// `context.project`.\n\t// TODO: Automatically update the plugin runner's in-memory `project`\n\t// object when `updateSliceMachineConfig()` is called.\n\tconst project = await context.helpers.getProject();\n\n\tif (!project.config.libraries) {\n\t\treturn;\n\t}\n\n\tawait Promise.all(\n\t\tproject.config.libraries.map(async (libraryID) => {\n\t\t\tawait upsertSliceLibraryIndexFile({ libraryID, ...context });\n\t\t}),\n\t);\n};\n\nexport const projectInit: ProjectInitHook<PluginOptions> = async (\n\t{ installDependencies: _installDependencies },\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tinstallDependencies({ installDependencies: _installDependencies }),\n\t\t\tmodifySliceMachineConfig(context),\n\t\t\tcreatePrismicIOFile(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tcreatePreviewAPIRoute(context),\n\t\t\tcreatePreviewRouteDirectory(context),\n\t\t\tcreatePreviewRouteMatcherFile(context),\n\t\t\tcreateRootLayoutServerFile(context),\n\t\t\tcreateRootLayoutFile(context),\n\t\t]),\n\t);\n\n\t// This must happen after `modifySliceMachineConfig()` since the\n\t// location of the default Slice library may change.\n\tawait upsertSliceLibraryIndexFiles(context);\n};\n"],"names":["installDependencies","_a"],"mappings":";;;;;;;;;;;AAAA,IAAA,IAAA;AAwBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;A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BAA2B,OAAO;AAAA,IAClC,qBAAqB,OAAO;AAAA,EAC5B,CAAA,CAAC;AAKH,QAAM,6BAA6B,OAAO;AAC3C;"}
1
+ {"version":3,"file":"project-init.js","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { source } from \"common-tags\";\nimport { loadFile } from \"magicast\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\nimport { getSvelteMajor } from \"../lib/getSvelteMajor\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\nimport type { PluginOptions } from \"../types\";\nimport {\n\tpreviewAPIRouteTemplate,\n\tprismicIOFileTemplate,\n\trootLayoutTemplate,\n\tsliceSimulatorPageTemplate,\n} from \"./project-init.templates\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/svelte\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/lib/prismicio.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst typescript = await checkIsTypeScriptProject({ helpers, options });\n\tconst contents = prismicIOFileTemplate({ typescript });\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst filename = path.join(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"slice-simulator\",\n\t\t\"+page.svelte\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = sliceSimulatorPageTemplate({\n\t\tversion: await getSvelteMajor(),\n\t});\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\tformatOptions: {\n\t\t\tprettier: {\n\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t\thelpers,\n\t});\n};\n\nconst createPreviewRouteMatcherFile = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/params/preview.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\texport function match(param) {\n\t\t\treturn param === 'preview';\n\t\t}\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewAPIRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"api\",\n\t\t\"preview\",\n\t\t`+server.${extension}`,\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst typescript = await checkIsTypeScriptProject({ helpers, options });\n\tconst contents = previewAPIRouteTemplate({ typescript });\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewRouteDirectory = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst filename = path.join(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"[[preview=preview]]\",\n\t\t\"README.md\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\tThis directory adds support for optional \\`/preview\\` routes. Do not remove this directory.\n\n\t\tAll routes within this directory will be served using the following URLs:\n\n\t\t- \\`/example-route\\` (prerendered)\n\t\t- \\`/preview/example-route\\` (server-rendered)\n\n\t\tSee <https://prismic.io/docs/svelte-preview> for more information.\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createRootLayoutServerFile = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/routes/+layout.server.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\texport const prerender = \"auto\";\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createRootLayoutFile = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst filename = path.join(\"src\", \"routes\", \"+layout.svelte\");\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = rootLayoutTemplate({ version: await getSvelteMajor() });\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\tformatOptions: {\n\t\t\tprettier: {\n\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst project = await helpers.getProject();\n\n\t// Add Slice Simulator URL.\n\tproject.config.localSliceSimulatorURL ||=\n\t\t\"http://localhost:5173/slice-simulator\";\n\n\t// Nest the default Slice Library in the src directory if it exists and\n\t// is empty.\n\tif (\n\t\t(await checkHasProjectFile({\n\t\t\tfilename: \"./src/lib\",\n\t\t\thelpers,\n\t\t})) &&\n\t\tproject.config.libraries &&\n\t\tJSON.stringify(project.config.libraries) === JSON.stringify([\"./slices\"])\n\t) {\n\t\tconst sliceLibrary = await actions.readSliceLibrary({\n\t\t\tlibraryID: project.config.libraries[0],\n\t\t});\n\n\t\tif (sliceLibrary.sliceIDs.length < 1) {\n\t\t\tproject.config.libraries = [\"./src/lib/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst upsertSliceLibraryIndexFiles = async (\n\tcontext: SliceMachineContext<PluginOptions>,\n) => {\n\t// We must use the `getProject()` helper to get the latest version of\n\t// the project config. The config may have been modified in\n\t// `modifySliceMachineConfig()` and will not be relfected in\n\t// `context.project`.\n\t// TODO: Automatically update the plugin runner's in-memory `project`\n\t// object when `updateSliceMachineConfig()` is called.\n\tconst project = await context.helpers.getProject();\n\n\tif (!project.config.libraries) {\n\t\treturn;\n\t}\n\n\tawait Promise.all(\n\t\tproject.config.libraries.map(async (libraryID) => {\n\t\t\tawait upsertSliceLibraryIndexFile({ libraryID, ...context });\n\t\t}),\n\t);\n};\n\nconst modifyViteConfig = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tlet filename = \"vite.config.js\";\n\tif (!(await checkHasProjectFile({ filename, helpers }))) {\n\t\tfilename = \"vite.config.ts\";\n\t}\n\tif (!(await checkHasProjectFile({ filename, helpers }))) {\n\t\t// Couldn't find the config file.\n\t\treturn;\n\t}\n\tconst filepath = helpers.joinPathFromRoot(filename);\n\n\tconst mod = await loadFile(filepath);\n\tif (mod.exports.default.$type !== \"function-call\") {\n\t\t// Invalid config file.\n\t\treturn;\n\t}\n\n\t// Add `./slicemachine.config.json` to allowed files.\n\tconst config = mod.exports.default.$args[0];\n\tconfig.server ??= {};\n\tconfig.server.fs ??= {};\n\tconfig.server.fs.allow ??= [];\n\tif (!config.server.fs.allow.includes(\"./slicemachine.config.json\")) {\n\t\tconfig.server.fs.allow.push(\"./slicemachine.config.json\");\n\t}\n\n\t// Remove an empty line above the `server` property.\n\tconst contents = mod.generate().code.replace(/\\n\\s*\\n(?=\\s*server:)/, \"\\n\");\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nexport const projectInit: ProjectInitHook<PluginOptions> = async (\n\t{ installDependencies: _installDependencies },\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tinstallDependencies({ installDependencies: _installDependencies }),\n\t\t\tmodifySliceMachineConfig(context),\n\t\t\tcreatePrismicIOFile(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tcreatePreviewAPIRoute(context),\n\t\t\tcreatePreviewRouteDirectory(context),\n\t\t\tcreatePreviewRouteMatcherFile(context),\n\t\t\tcreateRootLayoutServerFile(context),\n\t\t\tcreateRootLayoutFile(context),\n\t\t\tmodifyViteConfig(context),\n\t\t]),\n\t);\n\n\t// This must happen after `modifySliceMachineConfig()` since the\n\t// location of the default Slice library may change.\n\tawait upsertSliceLibraryIndexFiles(context);\n};\n"],"names":["installDependencies"],"mappings":";;;;;;;;;;AA+BA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,qBAAqB;AAAA,IACrB;AAAA,EAAA,C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,QAAM,6BAA6B,OAAO;AAC3C;"}
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const commonTags = require("common-tags");
4
+ const constants = require("../constants.cjs");
5
+ var __freeze = Object.freeze;
6
+ var __defProp = Object.defineProperty;
7
+ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
8
+ var _a, _b, _c, _d;
9
+ function prismicIOFileTemplate(args) {
10
+ const { typescript } = args;
11
+ const TS = commonTags.source`
12
+ import { createClient as baseCreateClient, type Route } from "@prismicio/client";
13
+ import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
14
+ import sm from "../../slicemachine.config.json";
15
+
16
+ /**
17
+ * The project's Prismic repository name.
18
+ */
19
+ export const repositoryName =
20
+ import${"."}meta${"."}env.${constants.PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || sm.repositoryName;
21
+
22
+ /**
23
+ * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
24
+ *
25
+ * {@link https://prismic.io/docs/route-resolver}
26
+ */
27
+ // TODO: Update the routes array to match your project's route structure.
28
+ const routes: Route[] = [
29
+ // Examples:
30
+ // { type: "homepage", path: "/" },
31
+ // { type: "page", path: "/:uid" },
32
+ ];
33
+
34
+ /**
35
+ * Creates a Prismic client for the project's repository. The client is used to
36
+ * query content from the Prismic API.
37
+ *
38
+ * @param config - Configuration for the Prismic client.
39
+ */
40
+ export const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {
41
+ const client = baseCreateClient(repositoryName, {
42
+ routes,
43
+ ...config,
44
+ });
45
+
46
+ enableAutoPreviews({ client, cookies });
47
+
48
+ return client;
49
+ };
50
+ `;
51
+ const JS = commonTags.source`
52
+ import { createClient as baseCreateClient } from "@prismicio/client";
53
+ import { enableAutoPreviews } from '@prismicio/svelte/kit';
54
+ import sm from "../../slicemachine.config.json";
55
+
56
+ /**
57
+ * The project's Prismic repository name.
58
+ */
59
+ export const repositoryName =
60
+ import${"."}meta${"."}env.${constants.PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || sm.repositoryName;
61
+
62
+ /**
63
+ * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
64
+ *
65
+ * {@link https://prismic.io/docs/route-resolver#route-resolver}
66
+ *
67
+ * @type {import("@prismicio/client").Route[]}
68
+ */
69
+ // TODO: Update the routes array to match your project's route structure.
70
+ const routes = [
71
+ // Examples:
72
+ // { type: "homepage", path: "/" },
73
+ // { type: "page", path: "/:uid" },
74
+ ];
75
+
76
+ /**
77
+ * Creates a Prismic client for the project's repository. The client is used to
78
+ * query content from the Prismic API.
79
+ *
80
+ * @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.
81
+ */
82
+ export const createClient = ({ cookies, ...config } = {}) => {
83
+ const client = prismic.createClient(repositoryName, {
84
+ routes,
85
+ ...config,
86
+ });
87
+
88
+ enableAutoPreviews({ client, cookies });
89
+
90
+ return client;
91
+ };
92
+ `;
93
+ return typescript ? TS : JS;
94
+ }
95
+ function sliceSimulatorPageTemplate(args) {
96
+ const { version } = args;
97
+ const v5 = commonTags.source(_a || (_a = __template(["\n <script>\n import { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n import { SliceZone } from '@prismicio/svelte';\n import { components } from '$lib/slices';\n <\/script>\n\n <!-- Slot syntax is used for backward compatibility with Svelte <=4. -->\n <SliceSimulator let:slices>\n <SliceZone {slices} {components} />\n </SliceSimulator>\n "])));
98
+ const v4 = commonTags.source(_b || (_b = __template(["\n <script>\n import { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n import { SliceZone } from '@prismicio/svelte';\n import { components } from '$lib/slices';\n <\/script>\n\n <SliceSimulator let:slices>\n <SliceZone {slices} {components} />\n </SliceSimulator>\n "])));
99
+ return version <= 4 ? v4 : v5;
100
+ }
101
+ function previewAPIRouteTemplate(args) {
102
+ const { typescript } = args;
103
+ const TS = commonTags.source`
104
+ import { redirectToPreviewURL } from '@prismicio/svelte/kit';
105
+ import { createClient } from '$lib/prismicio';
106
+ import type { RequestHandler } from "./$types";
107
+
108
+ export const GET: RequestHandler = async ({ fetch, request, cookies }) => {
109
+ const client = createClient({ fetch });
110
+
111
+ return await redirectToPreviewURL({ client, request, cookies });
112
+ }
113
+ `;
114
+ const JS = commonTags.source`
115
+ import { redirectToPreviewURL } from '@prismicio/svelte/kit';
116
+ import { createClient } from '$lib/prismicio';
117
+
118
+ /* @type {import("./$types").RequestHandler} */
119
+ export async function GET({ fetch, request, cookies }) {
120
+ const client = createClient({ fetch });
121
+
122
+ return await redirectToPreviewURL({ client, request, cookies });
123
+ }
124
+ `;
125
+ return typescript ? TS : JS;
126
+ }
127
+ function rootLayoutTemplate(args) {
128
+ const { version } = args;
129
+ const v5 = commonTags.source(_c || (_c = __template([`
130
+ <script>
131
+ import { isFilled, asImageSrc } from '@prismicio/client';
132
+ import { PrismicPreview } from '@prismicio/svelte/kit';
133
+ import { page } from '$app/state';
134
+ import { repositoryName } from '$lib/prismicio';
135
+
136
+ const { children } = $props();
137
+ <\/script>
138
+
139
+ <svelte:head>
140
+ <title>{page.data.page?.data.meta_title}</title>
141
+ <meta property="og:title" content={page.data.page?.data.meta_title} />
142
+ {#if isFilled.keyText(page.data.page?.data.meta_description)}
143
+ <meta name="description" content={page.data.page.data.meta_description} />
144
+ <meta property="og:description" content={page.data.page.data.meta_description} />
145
+ {/if}
146
+ {#if isFilled.image(page.data.page?.data.meta_image)}
147
+ <meta property="og:image" content={asImageSrc(page.data.page.data.meta_image)} />
148
+ {/if}
149
+ </svelte:head>
150
+ {@render children()}
151
+ <PrismicPreview {repositoryName} />
152
+ `])));
153
+ const v4 = commonTags.source(_d || (_d = __template([`
154
+ <script>
155
+ import { isFilled, asImageSrc } from '@prismicio/client';
156
+ import { PrismicPreview } from '@prismicio/svelte/kit';
157
+ import { page } from '$app/state';
158
+ import { repositoryName } from '$lib/prismicio';
159
+ <\/script>
160
+
161
+ <svelte:head>
162
+ <title>{page.data.page?.data.meta_title}</title>
163
+ <meta property="og:title" content={page.data.page?.data.meta_title} />
164
+ {#if isFilled.keyText(page.data.page?.data.meta_description)}
165
+ <meta name="description" content={page.data.page.data.meta_description} />
166
+ <meta property="og:description" content={page.data.page.data.meta_description} />
167
+ {/if}
168
+ {#if isFilled.image(page.data.page?.data.meta_image)}
169
+ <meta property="og:image" content={asImageSrc(page.data.page.data.meta_image)} />
170
+ {/if}
171
+ </svelte:head>
172
+ <slot />
173
+ <PrismicPreview {repositoryName} />
174
+ `])));
175
+ return version <= 4 ? v4 : v5;
176
+ }
177
+ exports.previewAPIRouteTemplate = previewAPIRouteTemplate;
178
+ exports.prismicIOFileTemplate = prismicIOFileTemplate;
179
+ exports.rootLayoutTemplate = rootLayoutTemplate;
180
+ exports.sliceSimulatorPageTemplate = sliceSimulatorPageTemplate;
181
+ //# sourceMappingURL=project-init.templates.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-init.templates.cjs","sources":["../../../src/hooks/project-init.templates.ts"],"sourcesContent":["import { source as svelte, source as ts, source as js } from \"common-tags\";\n\nimport { PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME } from \"../constants\";\n\nexport function prismicIOFileTemplate(args: { typescript: boolean }): string {\n\tconst { typescript } = args;\n\n\tconst TS = ts`\n\t\timport { createClient as baseCreateClient, type Route } from \"@prismicio/client\";\n\t\timport { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';\n\t\timport sm from \"../../slicemachine.config.json\";\n\n\t\t/**\n\t\t * The project's Prismic repository name.\n\t\t */\n\t\texport const repositoryName =\n\t\t\timport${\".\"}meta${\".\"}env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || sm.repositoryName;\n\n\t\t/**\n\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t *\n\t\t * {@link https://prismic.io/docs/route-resolver}\n\t\t */\n\t\t// TODO: Update the routes array to match your project's route structure.\n\t\tconst routes: Route[] = [\n\t\t\t// Examples:\n\t\t\t// { type: \"homepage\", path: \"/\" },\n\t\t\t// { type: \"page\", path: \"/:uid\" },\n\t\t];\n\n\t\t/**\n\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t * query content from the Prismic API.\n\t\t *\n\t\t * @param config - Configuration for the Prismic client.\n\t\t */\n\t\texport const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {\n\t\t\tconst client = baseCreateClient(repositoryName, {\n\t\t\t\troutes,\n\t\t\t\t...config,\n\t\t\t});\n\n\t\t\tenableAutoPreviews({ client, cookies });\n\n\t\t\treturn client;\n\t\t};\n\t`;\n\n\tconst JS = js`\n\t\timport { createClient as baseCreateClient } from \"@prismicio/client\";\n\t\timport { enableAutoPreviews } from '@prismicio/svelte/kit';\n\t\timport sm from \"../../slicemachine.config.json\";\n\n\t\t/**\n\t\t * The project's Prismic repository name.\n\t\t */\n\t\texport const repositoryName =\n\t\t\timport${\".\"}meta${\".\"}env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || sm.repositoryName;\n\n\t\t/**\n\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t *\n\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t *\n\t\t * @type {import(\"@prismicio/client\").Route[]}\n\t\t */\n\t\t// TODO: Update the routes array to match your project's route structure.\n\t\tconst routes = [\n\t\t\t// Examples:\n\t\t\t// { type: \"homepage\", path: \"/\" },\n\t\t\t// { type: \"page\", path: \"/:uid\" },\n\t\t];\n\n\t\t/**\n\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t * query content from the Prismic API.\n\t\t *\n\t\t * @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.\n\t\t */\n\t\texport const createClient = ({ cookies, ...config } = {}) => {\n\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\troutes,\n\t\t\t\t...config,\n\t\t\t});\n\n\t\t\tenableAutoPreviews({ client, cookies });\n\n\t\t\treturn client;\n\t\t};\n\t`;\n\n\treturn typescript ? TS : JS;\n}\n\nexport function sliceSimulatorPageTemplate(args: { version: number }): string {\n\tconst { version } = args;\n\n\tconst v5 = svelte`\n\t\t<script>\n\t\t\timport { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n\t\t\timport { SliceZone } from '@prismicio/svelte';\n\t\t\timport { components } from '$lib/slices';\n\t\t</script>\n\n\t\t<!-- Slot syntax is used for backward compatibility with Svelte <=4. -->\n\t\t<SliceSimulator let:slices>\n\t\t\t<SliceZone {slices} {components} />\n\t\t</SliceSimulator>\n\t`;\n\n\tconst v4 = svelte`\n\t\t<script>\n\t\t\timport { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n\t\t\timport { SliceZone } from '@prismicio/svelte';\n\t\t\timport { components } from '$lib/slices';\n\t\t</script>\n\n\t\t<SliceSimulator let:slices>\n\t\t\t<SliceZone {slices} {components} />\n\t\t</SliceSimulator>\n\t`;\n\n\treturn version <= 4 ? v4 : v5;\n}\n\nexport function previewAPIRouteTemplate(args: { typescript: boolean }): string {\n\tconst { typescript } = args;\n\n\tconst TS = ts`\n\t\timport { redirectToPreviewURL } from '@prismicio/svelte/kit';\n\t\timport { createClient } from '$lib/prismicio';\n\t\timport type { RequestHandler } from \"./$types\";\n\n\t\texport const GET: RequestHandler = async ({ fetch, request, cookies }) => {\n\t\t\tconst client = createClient({ fetch });\n\n\t\t\treturn await redirectToPreviewURL({ client, request, cookies });\n\t\t}\n\t`;\n\n\tconst JS = js`\n\t\timport { redirectToPreviewURL } from '@prismicio/svelte/kit';\n\t\timport { createClient } from '$lib/prismicio';\n\n\t\t/* @type {import(\"./$types\").RequestHandler} */\n\t\texport async function GET({ fetch, request, cookies }) {\n\t\t\tconst client = createClient({ fetch });\n\n\t\t\treturn await redirectToPreviewURL({ client, request, cookies });\n\t\t}\n\t`;\n\n\treturn typescript ? TS : JS;\n}\n\nexport function rootLayoutTemplate(args: { version: number }): string {\n\tconst { version } = args;\n\n\tconst v5 = svelte`\n\t\t<script>\n\t\t\timport { isFilled, asImageSrc } from '@prismicio/client';\n\t\t\timport { PrismicPreview } from '@prismicio/svelte/kit';\n\t\t\timport { page } from '$app/state';\n\t\t\timport { repositoryName } from '$lib/prismicio';\n\n\t\t\tconst { children } = $props();\n\t\t</script>\n\n\t\t<svelte:head>\n\t\t\t<title>{page.data.page?.data.meta_title}</title>\n\t\t\t<meta property=\"og:title\" content={page.data.page?.data.meta_title} />\n\t\t\t{#if isFilled.keyText(page.data.page?.data.meta_description)}\n\t\t\t\t<meta name=\"description\" content={page.data.page.data.meta_description} />\n\t\t\t\t<meta property=\"og:description\" content={page.data.page.data.meta_description} />\n\t\t\t{/if}\n\t\t\t{#if isFilled.image(page.data.page?.data.meta_image)}\n\t\t\t\t<meta property=\"og:image\" content={asImageSrc(page.data.page.data.meta_image)} />\n\t\t\t{/if}\n\t\t</svelte:head>\n\t\t{@render children()}\n\t\t<PrismicPreview {repositoryName} />\n\t`;\n\n\tconst v4 = svelte`\n\t\t<script>\n\t\t\timport { isFilled, asImageSrc } from '@prismicio/client';\n\t\t\timport { PrismicPreview } from '@prismicio/svelte/kit';\n\t\t\timport { page } from '$app/state';\n\t\t\timport { repositoryName } from '$lib/prismicio';\n\t\t</script>\n\n\t\t<svelte:head>\n\t\t\t<title>{page.data.page?.data.meta_title}</title>\n\t\t\t<meta property=\"og:title\" content={page.data.page?.data.meta_title} />\n\t\t\t{#if isFilled.keyText(page.data.page?.data.meta_description)}\n\t\t\t\t<meta name=\"description\" content={page.data.page.data.meta_description} />\n\t\t\t\t<meta property=\"og:description\" content={page.data.page.data.meta_description} />\n\t\t\t{/if}\n\t\t\t{#if isFilled.image(page.data.page?.data.meta_image)}\n\t\t\t\t<meta property=\"og:image\" content={asImageSrc(page.data.page.data.meta_image)} />\n\t\t\t{/if}\n\t\t</svelte:head>\n\t\t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AEvB,QAAM,KAAKH,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAYX,QAAM,KAAKE,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAYX,SAAO,aAAa,KAAK;AAC1B;AAEM,SAAU,mBAAmB,MAAyB;AACrD,QAAA,EAAE,QAAY,IAAA;AAEpB,QAAM,KAAKC,WAAAA,OAAM,OAAA,KAAA,WAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAA,CAAA,EAAA;AAyBjB,QAAM,KAAKA,WAAAA,OAAM,OAAA,KAAA,WAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAA,CAAA,EAAA;AAuBV,SAAA,WAAW,IAAI,KAAK;AAC5B;;;;;"}
@@ -0,0 +1,12 @@
1
+ export declare function prismicIOFileTemplate(args: {
2
+ typescript: boolean;
3
+ }): string;
4
+ export declare function sliceSimulatorPageTemplate(args: {
5
+ version: number;
6
+ }): string;
7
+ export declare function previewAPIRouteTemplate(args: {
8
+ typescript: boolean;
9
+ }): string;
10
+ export declare function rootLayoutTemplate(args: {
11
+ version: number;
12
+ }): string;