@prismicio/adapter-sveltekit 0.0.3-beta.16 → 0.0.3-beta.18

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.
@@ -2,12 +2,13 @@ import * as path from "node:path";
2
2
  import { checkHasProjectFile, writeProjectFile } from "@prismicio/plugin-kit/fs";
3
3
  import { source } from "common-tags";
4
4
  import { loadFile } from "magicast";
5
+ import * as prettierPluginSvelte from "prettier-plugin-svelte";
5
6
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
6
7
  import { getJSFileExtension } from "../lib/getJSFileExtension.js";
7
8
  import { getSvelteMajor } from "../lib/getSvelteMajor.js";
8
9
  import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
9
10
  import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
10
- import { prismicIOFileTemplate, previewAPIRouteTemplate, rootLayoutTemplate } from "./project-init.templates.js";
11
+ import { prismicIOFileTemplate, sliceSimulatorPageTemplate, previewAPIRouteTemplate, rootLayoutTemplate } from "./project-init.templates.js";
11
12
  const installDependencies = async ({ installDependencies: installDependencies2 }) => {
12
13
  await installDependencies2({
13
14
  dependencies: {
@@ -31,6 +32,27 @@ const createPrismicIOFile = async ({ helpers, options }) => {
31
32
  helpers
32
33
  });
33
34
  };
35
+ const createSliceSimulatorPage = async ({ helpers, options }) => {
36
+ const filename = path.join("src", "routes", "slice-simulator", "+page.svelte");
37
+ if (await checkHasProjectFile({ filename, helpers })) {
38
+ return;
39
+ }
40
+ const contents = sliceSimulatorPageTemplate({
41
+ version: await getSvelteMajor()
42
+ });
43
+ await writeProjectFile({
44
+ filename,
45
+ contents,
46
+ format: options.format,
47
+ formatOptions: {
48
+ prettier: {
49
+ plugins: [prettierPluginSvelte],
50
+ parser: "svelte"
51
+ }
52
+ },
53
+ helpers
54
+ });
55
+ };
34
56
  const createPreviewRouteMatcherFile = async ({ helpers, options }) => {
35
57
  const extension = await getJSFileExtension({ helpers, options });
36
58
  const filename = path.join(`src/params/preview.${extension}`);
@@ -114,7 +136,7 @@ const createRootLayoutFile = async ({ helpers, options }) => {
114
136
  format: options.format,
115
137
  formatOptions: {
116
138
  prettier: {
117
- plugins: ["prettier-plugin-svelte"],
139
+ plugins: [prettierPluginSvelte],
118
140
  parser: "svelte"
119
141
  }
120
142
  },
@@ -180,6 +202,7 @@ const projectInit = async ({ installDependencies: _installDependencies }, contex
180
202
  installDependencies({ installDependencies: _installDependencies }),
181
203
  modifyPrismicConfig(context),
182
204
  createPrismicIOFile(context),
205
+ createSliceSimulatorPage(context),
183
206
  createPreviewAPIRoute(context),
184
207
  createPreviewRouteDirectory(context),
185
208
  createPreviewRouteMatcherFile(context),
@@ -1 +1 @@
1
- {"version":3,"file":"project-init.js","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tPluginSystemContext,\n} from \"@prismicio/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@prismicio/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\";\nimport type { PluginOptions } from \"../types\";\n\nimport {\n\tpreviewAPIRouteTemplate,\n\tprismicIOFileTemplate,\n\trootLayoutTemplate,\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 = PluginSystemContext<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 createPreviewRouteMatcherFile = async ({\n\thelpers,\n\toptions,\n}: PluginSystemContext<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}: PluginSystemContext<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}: PluginSystemContext<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}: PluginSystemContext<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}: PluginSystemContext<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 modifyPrismicConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: PluginSystemContext<PluginOptions>) => {\n\tconst project = await helpers.getProject();\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.updatePrismicConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst upsertSliceLibraryIndexFiles = async (\n\tcontext: PluginSystemContext<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// `modifyPrismicConfig()` and will not be reflected in\n\t// `context.project`.\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}: PluginSystemContext<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 `./prismic.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(\"./prismic.config.json\")) {\n\t\tconfig.server.fs.allow.push(\"./prismic.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\tmodifyPrismicConfig(context),\n\t\t\tcreatePrismicIOFile(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 `modifyPrismicConfig()` 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,IAAA;AAAA,EACrB,CACD;AACF;AAIA,MAAM,sBAAsB,OAAO,EAClC,SACA,cAC6B;AAC7B,QAAM,YAAY,MAAM,mBAAmB,EAAE,SAAS,SAAS;AAC/D,QAAM,WAAW,KAAK,KAAK,qBAAqB,SAAS,EAAE;AAE3D,MAAI,MAAM,oBAAoB,EAAE,UAAU,QAAA,CAAS,GAAG;AACrD;AAAA,EACD;AAEA,QAAM,aAAa,MAAM,yBAAyB,EAAE,SAAS,SAAS;AACtE,QAAM,WAAW,sBAAsB,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BAAqB,qBAAA,GACvB,YACG;AACH,oBACC,MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,oBAAoB,OAAO;AAAA,IAC3B,oBAAoB,OAAO;AAAA,IAC3B,sBAAsB,OAAO;AAAA,IAC7B,4BAA4B,OAAO;AAAA,IACnC,8BAA8B,OAAO;AAAA,IACrC,2BAA2B,OAAO;AAAA,IAClC,qBAAqB,OAAO;AAAA,IAC5B,iBAAiB,OAAO;AAAA,EAAA,CACxB,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\";\n\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tPluginSystemContext,\n} from \"@prismicio/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@prismicio/plugin-kit/fs\";\nimport { source } from \"common-tags\";\nimport { loadFile } from \"magicast\";\nimport * as prettierPluginSvelte from \"prettier-plugin-svelte\";\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\";\nimport type { PluginOptions } from \"../types\";\n\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 = PluginSystemContext<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}: PluginSystemContext<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: [prettierPluginSvelte],\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}: PluginSystemContext<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}: PluginSystemContext<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}: PluginSystemContext<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}: PluginSystemContext<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}: PluginSystemContext<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: [prettierPluginSvelte],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t\thelpers,\n\t});\n};\n\nconst modifyPrismicConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: PluginSystemContext<PluginOptions>) => {\n\tconst project = await helpers.getProject();\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.updatePrismicConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst upsertSliceLibraryIndexFiles = async (\n\tcontext: PluginSystemContext<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// `modifyPrismicConfig()` and will not be reflected in\n\t// `context.project`.\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}: PluginSystemContext<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 `./prismic.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(\"./prismic.config.json\")) {\n\t\tconfig.server.fs.allow.push(\"./prismic.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\tmodifyPrismicConfig(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 `modifyPrismicConfig()` since the\n\t// location of the default Slice library may change.\n\tawait upsertSliceLibraryIndexFiles(context);\n};\n"],"names":["installDependencies"],"mappings":";;;;;;;;;;;AAiCA,MAAM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C5B,iBAAiB,OAAO;AAAA,EAAA,CACxB,CAAC;AAKH,QAAM,6BAA6B,OAAO;AAC3C;"}
@@ -1,6 +1,9 @@
1
1
  export declare function prismicIOFileTemplate(args: {
2
2
  typescript: boolean;
3
3
  }): string;
4
+ export declare function sliceSimulatorPageTemplate(args: {
5
+ version: number;
6
+ }): string;
4
7
  export declare function previewAPIRouteTemplate(args: {
5
8
  typescript: boolean;
6
9
  }): string;
@@ -2,7 +2,7 @@ import { source } from "common-tags";
2
2
  var __freeze = Object.freeze;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(cooked.slice()) }));
5
- var _a, _b;
5
+ var _a, _b, _c, _d;
6
6
  function prismicIOFileTemplate(args) {
7
7
  const { typescript } = args;
8
8
  const TS = source`
@@ -87,6 +87,12 @@ function prismicIOFileTemplate(args) {
87
87
  `;
88
88
  return typescript ? TS : JS;
89
89
  }
90
+ function sliceSimulatorPageTemplate(args) {
91
+ const { version } = args;
92
+ const v5 = source(_a || (_a = __template(["\n <script>\n import { SliceSimulator, 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 "])));
93
+ const v4 = source(_b || (_b = __template(["\n <script>\n import { SliceSimulator, SliceZone } from '@prismicio/svelte';\n import { components } from '$lib/slices';\n <\/script>\n\n <SliceSimulator let:slices>\n <SliceZone {slices} {components} />\n </SliceSimulator>\n "])));
94
+ return version <= 4 ? v4 : v5;
95
+ }
90
96
  function previewAPIRouteTemplate(args) {
91
97
  const { typescript } = args;
92
98
  const TS = source`
@@ -115,7 +121,7 @@ function previewAPIRouteTemplate(args) {
115
121
  }
116
122
  function rootLayoutTemplate(args) {
117
123
  const { version } = args;
118
- const v5 = source(_a || (_a = __template([`
124
+ const v5 = source(_c || (_c = __template([`
119
125
  <script>
120
126
  import { isFilled, asImageSrc } from '@prismicio/client';
121
127
  import { PrismicPreview } from '@prismicio/svelte/kit';
@@ -139,7 +145,7 @@ function rootLayoutTemplate(args) {
139
145
  {@render children()}
140
146
  <PrismicPreview {repositoryName} />
141
147
  `])));
142
- const v4 = source(_b || (_b = __template([`
148
+ const v4 = source(_d || (_d = __template([`
143
149
  <script>
144
150
  import { isFilled, asImageSrc } from '@prismicio/client';
145
151
  import { PrismicPreview } from '@prismicio/svelte/kit';
@@ -166,6 +172,7 @@ function rootLayoutTemplate(args) {
166
172
  export {
167
173
  previewAPIRouteTemplate,
168
174
  prismicIOFileTemplate,
169
- rootLayoutTemplate
175
+ rootLayoutTemplate,
176
+ sliceSimulatorPageTemplate
170
177
  };
171
178
  //# sourceMappingURL=project-init.templates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"project-init.templates.js","sources":["../../../src/hooks/project-init.templates.ts"],"sourcesContent":["import { source as svelte, source as ts, source as js } from \"common-tags\";\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 prismicConfig from \"../../prismic.config.json\";\n\n\t\t/**\n\t\t * The project's Prismic repository name.\n\t\t */\n\t\texport const repositoryName = prismicConfig.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 prismicConfig from \"../../prismic.config.json\";\n\n\t\t/**\n\t\t * The project's Prismic repository name.\n\t\t */\n\t\texport const repositoryName = prismicConfig.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 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<slot />\n\t\t<PrismicPreview {repositoryName} />\n\t`;\n\n\treturn version <= 4 ? v4 : v5;\n}\n"],"names":["ts","js","svelte"],"mappings":";;;;AAAA,IAAA,IAAA;AAEM,SAAU,sBAAsB,MAA6B;AAClE,QAAM,EAAE,eAAe;AAEvB,QAAM,KAAKA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAwCX,QAAM,KAAKC;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AA0CX,SAAO,aAAa,KAAK;AAC1B;AAEM,SAAU,wBAAwB,MAA6B;AACpE,QAAM,EAAE,eAAe;AAEvB,QAAM,KAAKD;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAYX,QAAM,KAAKC;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAYX,SAAO,aAAa,KAAK;AAC1B;AAEM,SAAU,mBAAmB,MAAyB;AAC3D,QAAM,EAAE,YAAY;AAEpB,QAAM,KAAKC,OAAA,OAAA,KAAM,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,OAAA,OAAA,KAAM,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;AAuBjB,SAAO,WAAW,IAAI,KAAK;AAC5B;"}
1
+ {"version":3,"file":"project-init.templates.js","sources":["../../../src/hooks/project-init.templates.ts"],"sourcesContent":["import { source as svelte, source as ts, source as js } from \"common-tags\";\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 prismicConfig from \"../../prismic.config.json\";\n\n\t\t/**\n\t\t * The project's Prismic repository name.\n\t\t */\n\t\texport const repositoryName = prismicConfig.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 prismicConfig from \"../../prismic.config.json\";\n\n\t\t/**\n\t\t * The project's Prismic repository name.\n\t\t */\n\t\texport const repositoryName = prismicConfig.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, 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, 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<slot />\n\t\t<PrismicPreview {repositoryName} />\n\t`;\n\n\treturn version <= 4 ? v4 : v5;\n}\n"],"names":["ts","js","svelte"],"mappings":";;;;AAAA,IAAA,IAAA,IAAA,IAAA;AAEM,SAAU,sBAAsB,MAA6B;AAClE,QAAM,EAAE,eAAe;AAEvB,QAAM,KAAKA;AAAAA;AAAAA;AAAAA;AAAAA;A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A;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAA,CAAA,EAAA;AAyBjB,QAAM,KAAKA,OAAA,OAAA,KAAM,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;AAuBjB,SAAO,WAAW,IAAI,KAAK;AAC5B;"}
@@ -1,4 +1,5 @@
1
1
  import { writeSliceModel, upsertGlobalTypeScriptTypes, writeSliceFile } from "@prismicio/plugin-kit/fs";
2
+ import * as prettierPluginSvelte from "prettier-plugin-svelte";
2
3
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
3
4
  import { getSvelteMajor } from "../lib/getSvelteMajor.js";
4
5
  import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
@@ -18,7 +19,7 @@ const createComponentFile = async ({ data, helpers, actions, options }) => {
18
19
  helpers,
19
20
  formatOptions: {
20
21
  prettier: {
21
- plugins: ["prettier-plugin-svelte"],
22
+ plugins: [prettierPluginSvelte],
22
23
  parser: "svelte"
23
24
  }
24
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"slice-create.js","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tPluginSystemContext,\n} from \"@prismicio/plugin-kit\";\nimport {\n\tupsertGlobalTypeScriptTypes,\n\twriteSliceFile,\n\twriteSliceModel,\n} from \"@prismicio/plugin-kit/fs\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getSvelteMajor } from \"../lib/getSvelteMajor\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\nimport type { PluginOptions } from \"../types\";\n\nimport { sliceTemplate } from \"./slice-create.templates\";\n\ntype Args = {\n\tdata: SliceCreateHookData;\n} & PluginSystemContext<PluginOptions>;\n\nconst createComponentFile = async ({\n\tdata,\n\thelpers,\n\tactions,\n\toptions,\n}: Args) => {\n\tconst { model, componentContents } = data;\n\n\tconst typescript = await checkIsTypeScriptProject({ helpers, options });\n\tconst contents =\n\t\tcomponentContents ??\n\t\tsliceTemplate({ model, typescript, version: await getSvelteMajor() });\n\n\tawait writeSliceFile({\n\t\tlibraryID: data.libraryID,\n\t\tmodel: data.model,\n\t\tfilename: \"index.svelte\",\n\t\tcontents,\n\t\tformat: options.format,\n\t\tactions,\n\t\thelpers,\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});\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\twriteSliceModel({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t}),\n\t\t\tcreateComponentFile({ data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertSliceLibraryIndexFile({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\t...context,\n\t\t\t}),\n\t\t\tupsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t\tactions: context.actions,\n\t\t\t}),\n\t\t]),\n\t);\n};\n"],"names":[],"mappings":";;;;;;AAuBA,MAAM,sBAAsB,OAAO,EAClC,MACA,SACA,SACA,cACU;AACV,QAAM,EAAE,OAAO,kBAAA,IAAsB;AAErC,QAAM,aAAa,MAAM,yBAAyB,EAAE,SAAS,SAAS;AACtE,QAAM,WACL,qBACA,cAAc,EAAE,OAAO,YAAY,SAAS,MAAM,eAAA,GAAkB;AAErE,QAAM,eAAe;AAAA,IACpB,WAAW,KAAK;AAAA,IAChB,OAAO,KAAK;AAAA,IACZ,UAAU;AAAA,IACV;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA;AAAA,IACA,eAAe;AAAA,MACd,UAAU;AAAA,QACT,SAAS,CAAC,wBAAwB;AAAA,QAClC,QAAQ;AAAA,MAAA;AAAA,IACR;AAAA,EACD,CACD;AACF;AAEO,MAAM,cAA8C,OAC1D,MACA,YACG;AACH,oBACC,MAAM,QAAQ,WAAW;AAAA,IACxB,gBAAgB;AAAA,MACf,WAAW,KAAK;AAAA,MAChB,OAAO,KAAK;AAAA,MACZ,QAAQ,QAAQ,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,IACD,oBAAoB,EAAE,MAAM,GAAG,SAAS;AAAA,EAAA,CACxC,CAAC;AAGH,oBACC,MAAM,QAAQ,WAAW;AAAA,IACxB,4BAA4B;AAAA,MAC3B,WAAW,KAAK;AAAA,MAChB,GAAG;AAAA,IAAA,CACH;AAAA,IACD,4BAA4B;AAAA,MAC3B,UAAU,QAAQ,QAAQ;AAAA,MAC1B,QAAQ,QAAQ,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,MACjB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,EAAA,CACD,CAAC;AAEJ;"}
1
+ {"version":3,"file":"slice-create.js","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tPluginSystemContext,\n} from \"@prismicio/plugin-kit\";\nimport {\n\tupsertGlobalTypeScriptTypes,\n\twriteSliceFile,\n\twriteSliceModel,\n} from \"@prismicio/plugin-kit/fs\";\nimport * as prettierPluginSvelte from \"prettier-plugin-svelte\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getSvelteMajor } from \"../lib/getSvelteMajor\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\nimport type { PluginOptions } from \"../types\";\n\nimport { sliceTemplate } from \"./slice-create.templates\";\n\ntype Args = {\n\tdata: SliceCreateHookData;\n} & PluginSystemContext<PluginOptions>;\n\nconst createComponentFile = async ({\n\tdata,\n\thelpers,\n\tactions,\n\toptions,\n}: Args) => {\n\tconst { model, componentContents } = data;\n\n\tconst typescript = await checkIsTypeScriptProject({ helpers, options });\n\tconst contents =\n\t\tcomponentContents ??\n\t\tsliceTemplate({ model, typescript, version: await getSvelteMajor() });\n\n\tawait writeSliceFile({\n\t\tlibraryID: data.libraryID,\n\t\tmodel: data.model,\n\t\tfilename: \"index.svelte\",\n\t\tcontents,\n\t\tformat: options.format,\n\t\tactions,\n\t\thelpers,\n\t\tformatOptions: {\n\t\t\tprettier: {\n\t\t\t\tplugins: [prettierPluginSvelte],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t});\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\twriteSliceModel({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t}),\n\t\t\tcreateComponentFile({ data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertSliceLibraryIndexFile({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\t...context,\n\t\t\t}),\n\t\t\tupsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t\tactions: context.actions,\n\t\t\t}),\n\t\t]),\n\t);\n};\n"],"names":[],"mappings":";;;;;;;AAwBA,MAAM,sBAAsB,OAAO,EAClC,MACA,SACA,SACA,cACU;AACV,QAAM,EAAE,OAAO,kBAAA,IAAsB;AAErC,QAAM,aAAa,MAAM,yBAAyB,EAAE,SAAS,SAAS;AACtE,QAAM,WACL,qBACA,cAAc,EAAE,OAAO,YAAY,SAAS,MAAM,eAAA,GAAkB;AAErE,QAAM,eAAe;AAAA,IACpB,WAAW,KAAK;AAAA,IAChB,OAAO,KAAK;AAAA,IACZ,UAAU;AAAA,IACV;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA;AAAA,IACA,eAAe;AAAA,MACd,UAAU;AAAA,QACT,SAAS,CAAC,oBAAoB;AAAA,QAC9B,QAAQ;AAAA,MAAA;AAAA,IACR;AAAA,EACD,CACD;AACF;AAEO,MAAM,cAA8C,OAC1D,MACA,YACG;AACH,oBACC,MAAM,QAAQ,WAAW;AAAA,IACxB,gBAAgB;AAAA,MACf,WAAW,KAAK;AAAA,MAChB,OAAO,KAAK;AAAA,MACZ,QAAQ,QAAQ,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,IACD,oBAAoB,EAAE,MAAM,GAAG,SAAS;AAAA,EAAA,CACxC,CAAC;AAGH,oBACC,MAAM,QAAQ,WAAW;AAAA,IACxB,4BAA4B;AAAA,MAC3B,WAAW,KAAK;AAAA,MAChB,GAAG;AAAA,IAAA,CACH;AAAA,IACD,4BAA4B;AAAA,MAC3B,UAAU,QAAQ,QAAQ;AAAA,MAC1B,QAAQ,QAAQ,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,MACjB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,EAAA,CACD,CAAC;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/adapter-sveltekit",
3
- "version": "0.0.3-beta.16",
3
+ "version": "0.0.3-beta.18",
4
4
  "description": "Prismic adapter for SvelteKit.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -52,7 +52,7 @@
52
52
  "audit": "yarn npm audit --environment production --severity high"
53
53
  },
54
54
  "dependencies": {
55
- "@prismicio/plugin-kit": "0.0.3-beta.18",
55
+ "@prismicio/plugin-kit": "0.0.3-beta.20",
56
56
  "@prismicio/types-internal": "3.16.1",
57
57
  "change-case": "5.4.4",
58
58
  "common-tags": "1.8.2",
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@eslint/js": "9.39.2",
64
- "@sveltejs/kit": "2.50.0",
64
+ "@sveltejs/kit": "2.50.1",
65
65
  "@sveltejs/vite-plugin-svelte": "6.2.4",
66
66
  "@trivago/prettier-plugin-sort-imports": "6.0.2",
67
67
  "@types/common-tags": "1.8.4",
@@ -88,6 +88,35 @@ export function prismicIOFileTemplate(args: { typescript: boolean }): string {
88
88
  return typescript ? TS : JS;
89
89
  }
90
90
 
91
+ export function sliceSimulatorPageTemplate(args: { version: number }): string {
92
+ const { version } = args;
93
+
94
+ const v5 = svelte`
95
+ <script>
96
+ import { SliceSimulator, SliceZone } from '@prismicio/svelte';
97
+ import { components } from '$lib/slices';
98
+ </script>
99
+
100
+ <!-- Slot syntax is used for backward compatibility with Svelte <=4. -->
101
+ <SliceSimulator let:slices>
102
+ <SliceZone {slices} {components} />
103
+ </SliceSimulator>
104
+ `;
105
+
106
+ const v4 = svelte`
107
+ <script>
108
+ import { SliceSimulator, SliceZone } from '@prismicio/svelte';
109
+ import { components } from '$lib/slices';
110
+ </script>
111
+
112
+ <SliceSimulator let:slices>
113
+ <SliceZone {slices} {components} />
114
+ </SliceSimulator>
115
+ `;
116
+
117
+ return version <= 4 ? v4 : v5;
118
+ }
119
+
91
120
  export function previewAPIRouteTemplate(args: { typescript: boolean }): string {
92
121
  const { typescript } = args;
93
122
 
@@ -11,6 +11,7 @@ import {
11
11
  } from "@prismicio/plugin-kit/fs";
12
12
  import { source } from "common-tags";
13
13
  import { loadFile } from "magicast";
14
+ import * as prettierPluginSvelte from "prettier-plugin-svelte";
14
15
 
15
16
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
16
17
  import { getJSFileExtension } from "../lib/getJSFileExtension";
@@ -23,6 +24,7 @@ import {
23
24
  previewAPIRouteTemplate,
24
25
  prismicIOFileTemplate,
25
26
  rootLayoutTemplate,
27
+ sliceSimulatorPageTemplate,
26
28
  } from "./project-init.templates";
27
29
 
28
30
  type InstallDependenciesArgs = {
@@ -64,6 +66,39 @@ const createPrismicIOFile = async ({
64
66
  });
65
67
  };
66
68
 
69
+ const createSliceSimulatorPage = async ({
70
+ helpers,
71
+ options,
72
+ }: PluginSystemContext<PluginOptions>) => {
73
+ const filename = path.join(
74
+ "src",
75
+ "routes",
76
+ "slice-simulator",
77
+ "+page.svelte",
78
+ );
79
+
80
+ if (await checkHasProjectFile({ filename, helpers })) {
81
+ return;
82
+ }
83
+
84
+ const contents = sliceSimulatorPageTemplate({
85
+ version: await getSvelteMajor(),
86
+ });
87
+
88
+ await writeProjectFile({
89
+ filename,
90
+ contents,
91
+ format: options.format,
92
+ formatOptions: {
93
+ prettier: {
94
+ plugins: [prettierPluginSvelte],
95
+ parser: "svelte",
96
+ },
97
+ },
98
+ helpers,
99
+ });
100
+ };
101
+
67
102
  const createPreviewRouteMatcherFile = async ({
68
103
  helpers,
69
104
  options,
@@ -192,7 +227,7 @@ const createRootLayoutFile = async ({
192
227
  format: options.format,
193
228
  formatOptions: {
194
229
  prettier: {
195
- plugins: ["prettier-plugin-svelte"],
230
+ plugins: [prettierPluginSvelte],
196
231
  parser: "svelte",
197
232
  },
198
233
  },
@@ -300,6 +335,7 @@ export const projectInit: ProjectInitHook<PluginOptions> = async (
300
335
  installDependencies({ installDependencies: _installDependencies }),
301
336
  modifyPrismicConfig(context),
302
337
  createPrismicIOFile(context),
338
+ createSliceSimulatorPage(context),
303
339
  createPreviewAPIRoute(context),
304
340
  createPreviewRouteDirectory(context),
305
341
  createPreviewRouteMatcherFile(context),
@@ -8,6 +8,7 @@ import {
8
8
  writeSliceFile,
9
9
  writeSliceModel,
10
10
  } from "@prismicio/plugin-kit/fs";
11
+ import * as prettierPluginSvelte from "prettier-plugin-svelte";
11
12
 
12
13
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
13
14
  import { getSvelteMajor } from "../lib/getSvelteMajor";
@@ -44,7 +45,7 @@ const createComponentFile = async ({
44
45
  helpers,
45
46
  formatOptions: {
46
47
  prettier: {
47
- plugins: ["prettier-plugin-svelte"],
48
+ plugins: [prettierPluginSvelte],
48
49
  parser: "svelte",
49
50
  },
50
51
  },