@slicemachine/adapter-sveltekit 0.3.30-dev-next-release.2 → 0.3.30-dev-next-release.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/documentation-read.cjs +4 -4
- package/dist/hooks/documentation-read.cjs.map +1 -1
- package/dist/hooks/documentation-read.js +4 -4
- package/dist/hooks/documentation-read.js.map +1 -1
- package/dist/hooks/project-init.cjs +47 -3
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js +47 -3
- package/dist/hooks/project-init.js.map +1 -1
- package/package.json +6 -6
- package/src/hooks/documentation-read.ts +4 -4
- package/src/hooks/project-init.ts +73 -1
|
@@ -25,8 +25,8 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
25
25
|
dataFileContent = commonTags.source`
|
|
26
26
|
import { createClient } from "$lib/prismicio";
|
|
27
27
|
|
|
28
|
-
export async function load({ params, fetch }) {
|
|
29
|
-
const client = createClient({ fetch });
|
|
28
|
+
export async function load({ params, fetch, cookies }) {
|
|
29
|
+
const client = createClient({ fetch, cookies });
|
|
30
30
|
|
|
31
31
|
const page = await client.getByUID("${model.id}", params.uid);
|
|
32
32
|
|
|
@@ -49,8 +49,8 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
49
49
|
dataFileContent = commonTags.source`
|
|
50
50
|
import { createClient } from "$lib/prismicio";
|
|
51
51
|
|
|
52
|
-
export async function load({ params, fetch }) {
|
|
53
|
-
const client = createClient({ fetch });
|
|
52
|
+
export async function load({ params, fetch, cookies }) {
|
|
53
|
+
const client = createClient({ fetch, cookies });
|
|
54
54
|
|
|
55
55
|
const page = await client.getSingle("${model.id}");
|
|
56
56
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentation-read.cjs","sources":["../../../src/hooks/documentation-read.ts"],"sourcesContent":["import { source } from \"common-tags\";\n\nimport type { DocumentationReadHook } from \"@slicemachine/plugin-kit\";\n\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst nestRouteFilePath = (filePath: string, nesting: string): string => {\n\treturn [\n\t\t...filePath.split(\"/\").slice(0, 2),\n\t\tnesting,\n\t\t...filePath.split(\"/\").slice(2),\n\t].join(\"/\");\n};\n\nexport const documentationRead: DocumentationReadHook<PluginOptions> = async (\n\tdata,\n\t{ options, helpers },\n) => {\n\tif (data.kind === \"PageSnippet\") {\n\t\tconst { model } = data.data;\n\n\t\tconst pageDataExtension = await getJSFileExtension({ helpers, options });\n\n\t\tconst routePath = `src/routes/${model.repeatable ? \"[uid]\" : model.id}`;\n\t\tconst dataFilePath = `${routePath}/+page.server.${pageDataExtension}`;\n\t\tconst componentFilePath = `${routePath}/+page.svelte`;\n\n\t\tlet dataFileContent: string;\n\t\tif (model.repeatable) {\n\t\t\tdataFileContent = source`\n\t\t\t\timport { createClient } from \"$lib/prismicio\";\n\n\t\t\t\texport async function load({ params, fetch }) {\n\t\t\t\t\tconst client = createClient({ fetch });\n\n\t\t\t\t\tconst page = await client.getByUID(\"${model.id}\", params.uid);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpage,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\texport async function entries() {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\tconst pages = await client.getAllByType(\"${model.id}\");\n\n\t\t\t\t\treturn pages.map((page) => {\n\t\t\t\t\t\treturn { uid: page.uid };\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tdataFileContent = source`\n\t\t\t\timport { createClient } from \"$lib/prismicio\";\n\n\t\t\t\texport async function load({ params, fetch }) {\n\t\t\t\t\tconst client = createClient({ fetch });\n\n\t\t\t\t\tconst page = await client.getSingle(\"${model.id}\");\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpage,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\texport async function entries() {\n\t\t\t\t\treturn [{}]\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\n\t\tlet componentFileContent = source`\n\t\t\t<script>\n\t\t\t\timport { SliceZone } from \"@prismicio/svelte\";\n\n\t\t\t\timport { components } from \"$lib/slices\";\n\n\t\t\t\texport let data;\n\t\t\t</script>\n\n\t\t\t<SliceZone slices={data.page.data.slices} {components} />\n\t\t`;\n\n\t\tif (options.format) {\n\t\t\tdataFileContent = await helpers.format(\n\t\t\t\tdataFileContent,\n\t\t\t\thelpers.joinPathFromRoot(dataFilePath),\n\t\t\t\t{\n\t\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t\t},\n\t\t\t);\n\t\t\tcomponentFileContent = await helpers.format(\n\t\t\t\tcomponentFileContent,\n\t\t\t\thelpers.joinPathFromRoot(componentFilePath),\n\t\t\t\t{\n\t\t\t\t\tprettier: {\n\t\t\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\t\t\tparser: \"svelte\",\n\t\t\t\t\t},\n\t\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst nestedDataFilePath = nestRouteFilePath(dataFilePath, \"marketing\");\n\t\tconst nestedComponentFilePath = nestRouteFilePath(\n\t\t\tcomponentFilePath,\n\t\t\t\"marketing\",\n\t\t);\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tlabel: \"Default\",\n\t\t\t\tcontent: source`\n\t\t\t\t\t## Create your ${model.label}'s page data fetcher\n\n\t\t\t\t\tAdd a new route by creating a \\`${dataFilePath}\\` file. (If the route should be nested in a child directory, you can create the file in a directory, like \\`${nestedDataFilePath}\\`.)\n\n\t\t\t\t\tPaste in this code:\n\n\t\t\t\t\t${`~~~${pageDataExtension} [${dataFilePath}]\\n${dataFileContent}\\n~~~`}\n\n\t\t\t\t\t## Create your ${model.label}'s page component\n\n\t\t\t\t\tIn the route's directory, create a \\`${componentFilePath}\\` file. (If the route should be nested in a child directory, you can create the file in a directory, like \\`${nestedComponentFilePath}\\`.)\n\n\t\t\t\t\tPaste in this code:\n\n\t\t\t\t\t${`~~~svelte [${componentFilePath}]\\n${componentFileContent}\\n~~~`}\n\n\t\t\t\t\tMake sure all of your import paths are correct. See the [install guide](https://prismic.io/docs/svelte-install) for more information.\n\t\t\t\t`,\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [];\n};\n"],"names":["getJSFileExtension","source"],"mappings":";;;;;;;AAAA,IAAA;AAQA,MAAM,oBAAoB,CAAC,UAAkB,YAA2B;AAChE,SAAA;AAAA,IACN,GAAG,SAAS,MAAM,GAAG,EAAE,MAAM,GAAG,CAAC;AAAA,IACjC;AAAA,IACA,GAAG,SAAS,MAAM,GAAG,EAAE,MAAM,CAAC;AAAA,EAAA,EAC7B,KAAK,GAAG;AACX;AAEO,MAAM,oBAA0D,OACtE,MACA,EAAE,SAAS,cACR;AACC,MAAA,KAAK,SAAS,eAAe;AAC1B,UAAA,EAAE,MAAK,IAAK,KAAK;AAEvB,UAAM,oBAAoB,MAAMA,mBAAA,mBAAmB,EAAE,SAAS,QAAS,CAAA;AAEvE,UAAM,YAAY,cAAc,MAAM,aAAa,UAAU,MAAM;AAC7D,UAAA,eAAe,GAAG,0BAA0B;AAClD,UAAM,oBAAoB,GAAG;AAEzB,QAAA;AACJ,QAAI,MAAM,YAAY;AACH,wBAAAC,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA,2CAMsB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gDAUD,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,OAO7C;AACY,wBAAAA,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA,4CAMuB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAW/C;AAED,QAAI,uBAAuBA,WAAM,OAAA,OAAA,KAAA,WAAA,CAAA,+NAAA,CAAA,EAAA;AAYjC,QAAI,QAAQ,QAAQ;AACnB,wBAAkB,MAAM,QAAQ,OAC/B,iBACA,QAAQ,iBAAiB,YAAY,GACrC;AAAA,QACC,qBAAqB;AAAA,MAAA,CACrB;AAEF,6BAAuB,MAAM,QAAQ,OACpC,sBACA,QAAQ,iBAAiB,iBAAiB,GAC1C;AAAA,QACC,UAAU;AAAA,UACT,SAAS,CAAC,wBAAwB;AAAA,UAClC,QAAQ;AAAA,QACR;AAAA,QACD,qBAAqB;AAAA,MAAA,CACrB;AAAA,IAEF;AAEK,UAAA,qBAAqB,kBAAkB,cAAc,WAAW;AAChE,UAAA,0BAA0B,kBAC/B,mBACA,WAAW;AAGL,WAAA;AAAA,MACN;AAAA,QACC,OAAO;AAAA,QACP,SAASA,WAAAA;AAAAA,sBACS,MAAM;AAAA;AAAA,uCAEW,4HAA4H;AAAA;AAAA;AAAA;AAAA,OAI5J,MAAM,sBAAsB;AAAA,EAAkB;AAAA;AAAA;AAAA,sBAE/B,MAAM;AAAA;AAAA,4CAEgB,iIAAiI;AAAA;AAAA;AAAA;AAAA,OAItK,cAAc;AAAA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA,MAIxC;AAAA,IAAA;AAAA,EAEF;AAED,SAAO;AACR;;"}
|
|
1
|
+
{"version":3,"file":"documentation-read.cjs","sources":["../../../src/hooks/documentation-read.ts"],"sourcesContent":["import { source } from \"common-tags\";\n\nimport type { DocumentationReadHook } from \"@slicemachine/plugin-kit\";\n\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst nestRouteFilePath = (filePath: string, nesting: string): string => {\n\treturn [\n\t\t...filePath.split(\"/\").slice(0, 2),\n\t\tnesting,\n\t\t...filePath.split(\"/\").slice(2),\n\t].join(\"/\");\n};\n\nexport const documentationRead: DocumentationReadHook<PluginOptions> = async (\n\tdata,\n\t{ options, helpers },\n) => {\n\tif (data.kind === \"PageSnippet\") {\n\t\tconst { model } = data.data;\n\n\t\tconst pageDataExtension = await getJSFileExtension({ helpers, options });\n\n\t\tconst routePath = `src/routes/${model.repeatable ? \"[uid]\" : model.id}`;\n\t\tconst dataFilePath = `${routePath}/+page.server.${pageDataExtension}`;\n\t\tconst componentFilePath = `${routePath}/+page.svelte`;\n\n\t\tlet dataFileContent: string;\n\t\tif (model.repeatable) {\n\t\t\tdataFileContent = source`\n\t\t\t\timport { createClient } from \"$lib/prismicio\";\n\n\t\t\t\texport async function load({ params, fetch, cookies }) {\n\t\t\t\t\tconst client = createClient({ fetch, cookies });\n\n\t\t\t\t\tconst page = await client.getByUID(\"${model.id}\", params.uid);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpage,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\texport async function entries() {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\tconst pages = await client.getAllByType(\"${model.id}\");\n\n\t\t\t\t\treturn pages.map((page) => {\n\t\t\t\t\t\treturn { uid: page.uid };\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tdataFileContent = source`\n\t\t\t\timport { createClient } from \"$lib/prismicio\";\n\n\t\t\t\texport async function load({ params, fetch, cookies }) {\n\t\t\t\t\tconst client = createClient({ fetch, cookies });\n\n\t\t\t\t\tconst page = await client.getSingle(\"${model.id}\");\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpage,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\texport async function entries() {\n\t\t\t\t\treturn [{}]\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\n\t\tlet componentFileContent = source`\n\t\t\t<script>\n\t\t\t\timport { SliceZone } from \"@prismicio/svelte\";\n\n\t\t\t\timport { components } from \"$lib/slices\";\n\n\t\t\t\texport let data;\n\t\t\t</script>\n\n\t\t\t<SliceZone slices={data.page.data.slices} {components} />\n\t\t`;\n\n\t\tif (options.format) {\n\t\t\tdataFileContent = await helpers.format(\n\t\t\t\tdataFileContent,\n\t\t\t\thelpers.joinPathFromRoot(dataFilePath),\n\t\t\t\t{\n\t\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t\t},\n\t\t\t);\n\t\t\tcomponentFileContent = await helpers.format(\n\t\t\t\tcomponentFileContent,\n\t\t\t\thelpers.joinPathFromRoot(componentFilePath),\n\t\t\t\t{\n\t\t\t\t\tprettier: {\n\t\t\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\t\t\tparser: \"svelte\",\n\t\t\t\t\t},\n\t\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst nestedDataFilePath = nestRouteFilePath(dataFilePath, \"marketing\");\n\t\tconst nestedComponentFilePath = nestRouteFilePath(\n\t\t\tcomponentFilePath,\n\t\t\t\"marketing\",\n\t\t);\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tlabel: \"Default\",\n\t\t\t\tcontent: source`\n\t\t\t\t\t## Create your ${model.label}'s page data fetcher\n\n\t\t\t\t\tAdd a new route by creating a \\`${dataFilePath}\\` file. (If the route should be nested in a child directory, you can create the file in a directory, like \\`${nestedDataFilePath}\\`.)\n\n\t\t\t\t\tPaste in this code:\n\n\t\t\t\t\t${`~~~${pageDataExtension} [${dataFilePath}]\\n${dataFileContent}\\n~~~`}\n\n\t\t\t\t\t## Create your ${model.label}'s page component\n\n\t\t\t\t\tIn the route's directory, create a \\`${componentFilePath}\\` file. (If the route should be nested in a child directory, you can create the file in a directory, like \\`${nestedComponentFilePath}\\`.)\n\n\t\t\t\t\tPaste in this code:\n\n\t\t\t\t\t${`~~~svelte [${componentFilePath}]\\n${componentFileContent}\\n~~~`}\n\n\t\t\t\t\tMake sure all of your import paths are correct. See the [install guide](https://prismic.io/docs/svelte-install) for more information.\n\t\t\t\t`,\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [];\n};\n"],"names":["getJSFileExtension","source"],"mappings":";;;;;;;AAAA,IAAA;AAQA,MAA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QAAQ;AAAA,QACR;AAAA,QACD,qBAAqB;AAAA,MAAA,CACrB;AAAA,IAEF;AAEK,UAAA,qBAAqB,kBAAkB,cAAc,WAAW;AAChE,UAAA,0BAA0B,kBAC/B,mBACA,WAAW;AAGL,WAAA;AAAA,MACN;AAAA,QACC,OAAO;AAAA,QACP,SAASA,WAAAA;AAAAA,sBACS,MAAM;AAAA;AAAA,uCAEW,4HAA4H;AAAA;AAAA;AAAA;AAAA,OAI5J,MAAM,sBAAsB;AAAA,EAAkB;AAAA;AAAA;AAAA,sBAE/B,MAAM;AAAA;AAAA,4CAEgB,iIAAiI;AAAA;AAAA;AAAA;AAAA,OAItK,cAAc;AAAA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA,MAIxC;AAAA,IAAA;AAAA,EAEF;AAED,SAAO;AACR;;"}
|
|
@@ -23,8 +23,8 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
23
23
|
dataFileContent = source`
|
|
24
24
|
import { createClient } from "$lib/prismicio";
|
|
25
25
|
|
|
26
|
-
export async function load({ params, fetch }) {
|
|
27
|
-
const client = createClient({ fetch });
|
|
26
|
+
export async function load({ params, fetch, cookies }) {
|
|
27
|
+
const client = createClient({ fetch, cookies });
|
|
28
28
|
|
|
29
29
|
const page = await client.getByUID("${model.id}", params.uid);
|
|
30
30
|
|
|
@@ -47,8 +47,8 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
47
47
|
dataFileContent = source`
|
|
48
48
|
import { createClient } from "$lib/prismicio";
|
|
49
49
|
|
|
50
|
-
export async function load({ params, fetch }) {
|
|
51
|
-
const client = createClient({ fetch });
|
|
50
|
+
export async function load({ params, fetch, cookies }) {
|
|
51
|
+
const client = createClient({ fetch, cookies });
|
|
52
52
|
|
|
53
53
|
const page = await client.getSingle("${model.id}");
|
|
54
54
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentation-read.js","sources":["../../../src/hooks/documentation-read.ts"],"sourcesContent":["import { source } from \"common-tags\";\n\nimport type { DocumentationReadHook } from \"@slicemachine/plugin-kit\";\n\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst nestRouteFilePath = (filePath: string, nesting: string): string => {\n\treturn [\n\t\t...filePath.split(\"/\").slice(0, 2),\n\t\tnesting,\n\t\t...filePath.split(\"/\").slice(2),\n\t].join(\"/\");\n};\n\nexport const documentationRead: DocumentationReadHook<PluginOptions> = async (\n\tdata,\n\t{ options, helpers },\n) => {\n\tif (data.kind === \"PageSnippet\") {\n\t\tconst { model } = data.data;\n\n\t\tconst pageDataExtension = await getJSFileExtension({ helpers, options });\n\n\t\tconst routePath = `src/routes/${model.repeatable ? \"[uid]\" : model.id}`;\n\t\tconst dataFilePath = `${routePath}/+page.server.${pageDataExtension}`;\n\t\tconst componentFilePath = `${routePath}/+page.svelte`;\n\n\t\tlet dataFileContent: string;\n\t\tif (model.repeatable) {\n\t\t\tdataFileContent = source`\n\t\t\t\timport { createClient } from \"$lib/prismicio\";\n\n\t\t\t\texport async function load({ params, fetch }) {\n\t\t\t\t\tconst client = createClient({ fetch });\n\n\t\t\t\t\tconst page = await client.getByUID(\"${model.id}\", params.uid);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpage,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\texport async function entries() {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\tconst pages = await client.getAllByType(\"${model.id}\");\n\n\t\t\t\t\treturn pages.map((page) => {\n\t\t\t\t\t\treturn { uid: page.uid };\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tdataFileContent = source`\n\t\t\t\timport { createClient } from \"$lib/prismicio\";\n\n\t\t\t\texport async function load({ params, fetch }) {\n\t\t\t\t\tconst client = createClient({ fetch });\n\n\t\t\t\t\tconst page = await client.getSingle(\"${model.id}\");\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpage,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\texport async function entries() {\n\t\t\t\t\treturn [{}]\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\n\t\tlet componentFileContent = source`\n\t\t\t<script>\n\t\t\t\timport { SliceZone } from \"@prismicio/svelte\";\n\n\t\t\t\timport { components } from \"$lib/slices\";\n\n\t\t\t\texport let data;\n\t\t\t</script>\n\n\t\t\t<SliceZone slices={data.page.data.slices} {components} />\n\t\t`;\n\n\t\tif (options.format) {\n\t\t\tdataFileContent = await helpers.format(\n\t\t\t\tdataFileContent,\n\t\t\t\thelpers.joinPathFromRoot(dataFilePath),\n\t\t\t\t{\n\t\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t\t},\n\t\t\t);\n\t\t\tcomponentFileContent = await helpers.format(\n\t\t\t\tcomponentFileContent,\n\t\t\t\thelpers.joinPathFromRoot(componentFilePath),\n\t\t\t\t{\n\t\t\t\t\tprettier: {\n\t\t\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\t\t\tparser: \"svelte\",\n\t\t\t\t\t},\n\t\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst nestedDataFilePath = nestRouteFilePath(dataFilePath, \"marketing\");\n\t\tconst nestedComponentFilePath = nestRouteFilePath(\n\t\t\tcomponentFilePath,\n\t\t\t\"marketing\",\n\t\t);\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tlabel: \"Default\",\n\t\t\t\tcontent: source`\n\t\t\t\t\t## Create your ${model.label}'s page data fetcher\n\n\t\t\t\t\tAdd a new route by creating a \\`${dataFilePath}\\` file. (If the route should be nested in a child directory, you can create the file in a directory, like \\`${nestedDataFilePath}\\`.)\n\n\t\t\t\t\tPaste in this code:\n\n\t\t\t\t\t${`~~~${pageDataExtension} [${dataFilePath}]\\n${dataFileContent}\\n~~~`}\n\n\t\t\t\t\t## Create your ${model.label}'s page component\n\n\t\t\t\t\tIn the route's directory, create a \\`${componentFilePath}\\` file. (If the route should be nested in a child directory, you can create the file in a directory, like \\`${nestedComponentFilePath}\\`.)\n\n\t\t\t\t\tPaste in this code:\n\n\t\t\t\t\t${`~~~svelte [${componentFilePath}]\\n${componentFileContent}\\n~~~`}\n\n\t\t\t\t\tMake sure all of your import paths are correct. See the [install guide](https://prismic.io/docs/svelte-install) for more information.\n\t\t\t\t`,\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [];\n};\n"],"names":[],"mappings":";;;;;AAAA,IAAA;AAQA,MAAM,oBAAoB,CAAC,UAAkB,YAA2B;AAChE,SAAA;AAAA,IACN,GAAG,SAAS,MAAM,GAAG,EAAE,MAAM,GAAG,CAAC;AAAA,IACjC;AAAA,IACA,GAAG,SAAS,MAAM,GAAG,EAAE,MAAM,CAAC;AAAA,EAAA,EAC7B,KAAK,GAAG;AACX;AAEO,MAAM,oBAA0D,OACtE,MACA,EAAE,SAAS,cACR;AACC,MAAA,KAAK,SAAS,eAAe;AAC1B,UAAA,EAAE,MAAK,IAAK,KAAK;AAEvB,UAAM,oBAAoB,MAAM,mBAAmB,EAAE,SAAS,QAAS,CAAA;AAEvE,UAAM,YAAY,cAAc,MAAM,aAAa,UAAU,MAAM;AAC7D,UAAA,eAAe,GAAG,0BAA0B;AAClD,UAAM,oBAAoB,GAAG;AAEzB,QAAA;AACJ,QAAI,MAAM,YAAY;AACH,wBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2CAMsB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gDAUD,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,OAO7C;AACY,wBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4CAMuB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAW/C;AAED,QAAI,uBAAuB,OAAM,OAAA,KAAA,WAAA,CAAA,+NAAA,CAAA,EAAA;AAYjC,QAAI,QAAQ,QAAQ;AACnB,wBAAkB,MAAM,QAAQ,OAC/B,iBACA,QAAQ,iBAAiB,YAAY,GACrC;AAAA,QACC,qBAAqB;AAAA,MAAA,CACrB;AAEF,6BAAuB,MAAM,QAAQ,OACpC,sBACA,QAAQ,iBAAiB,iBAAiB,GAC1C;AAAA,QACC,UAAU;AAAA,UACT,SAAS,CAAC,wBAAwB;AAAA,UAClC,QAAQ;AAAA,QACR;AAAA,QACD,qBAAqB;AAAA,MAAA,CACrB;AAAA,IAEF;AAEK,UAAA,qBAAqB,kBAAkB,cAAc,WAAW;AAChE,UAAA,0BAA0B,kBAC/B,mBACA,WAAW;AAGL,WAAA;AAAA,MACN;AAAA,QACC,OAAO;AAAA,QACP,SAAS;AAAA,sBACS,MAAM;AAAA;AAAA,uCAEW,4HAA4H;AAAA;AAAA;AAAA;AAAA,OAI5J,MAAM,sBAAsB;AAAA,EAAkB;AAAA;AAAA;AAAA,sBAE/B,MAAM;AAAA;AAAA,4CAEgB,iIAAiI;AAAA;AAAA;AAAA;AAAA,OAItK,cAAc;AAAA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA,MAIxC;AAAA,IAAA;AAAA,EAEF;AAED,SAAO;AACR;"}
|
|
1
|
+
{"version":3,"file":"documentation-read.js","sources":["../../../src/hooks/documentation-read.ts"],"sourcesContent":["import { source } from \"common-tags\";\n\nimport type { DocumentationReadHook } from \"@slicemachine/plugin-kit\";\n\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst nestRouteFilePath = (filePath: string, nesting: string): string => {\n\treturn [\n\t\t...filePath.split(\"/\").slice(0, 2),\n\t\tnesting,\n\t\t...filePath.split(\"/\").slice(2),\n\t].join(\"/\");\n};\n\nexport const documentationRead: DocumentationReadHook<PluginOptions> = async (\n\tdata,\n\t{ options, helpers },\n) => {\n\tif (data.kind === \"PageSnippet\") {\n\t\tconst { model } = data.data;\n\n\t\tconst pageDataExtension = await getJSFileExtension({ helpers, options });\n\n\t\tconst routePath = `src/routes/${model.repeatable ? \"[uid]\" : model.id}`;\n\t\tconst dataFilePath = `${routePath}/+page.server.${pageDataExtension}`;\n\t\tconst componentFilePath = `${routePath}/+page.svelte`;\n\n\t\tlet dataFileContent: string;\n\t\tif (model.repeatable) {\n\t\t\tdataFileContent = source`\n\t\t\t\timport { createClient } from \"$lib/prismicio\";\n\n\t\t\t\texport async function load({ params, fetch, cookies }) {\n\t\t\t\t\tconst client = createClient({ fetch, cookies });\n\n\t\t\t\t\tconst page = await client.getByUID(\"${model.id}\", params.uid);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpage,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\texport async function entries() {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\tconst pages = await client.getAllByType(\"${model.id}\");\n\n\t\t\t\t\treturn pages.map((page) => {\n\t\t\t\t\t\treturn { uid: page.uid };\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tdataFileContent = source`\n\t\t\t\timport { createClient } from \"$lib/prismicio\";\n\n\t\t\t\texport async function load({ params, fetch, cookies }) {\n\t\t\t\t\tconst client = createClient({ fetch, cookies });\n\n\t\t\t\t\tconst page = await client.getSingle(\"${model.id}\");\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpage,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\texport async function entries() {\n\t\t\t\t\treturn [{}]\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\n\t\tlet componentFileContent = source`\n\t\t\t<script>\n\t\t\t\timport { SliceZone } from \"@prismicio/svelte\";\n\n\t\t\t\timport { components } from \"$lib/slices\";\n\n\t\t\t\texport let data;\n\t\t\t</script>\n\n\t\t\t<SliceZone slices={data.page.data.slices} {components} />\n\t\t`;\n\n\t\tif (options.format) {\n\t\t\tdataFileContent = await helpers.format(\n\t\t\t\tdataFileContent,\n\t\t\t\thelpers.joinPathFromRoot(dataFilePath),\n\t\t\t\t{\n\t\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t\t},\n\t\t\t);\n\t\t\tcomponentFileContent = await helpers.format(\n\t\t\t\tcomponentFileContent,\n\t\t\t\thelpers.joinPathFromRoot(componentFilePath),\n\t\t\t\t{\n\t\t\t\t\tprettier: {\n\t\t\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\t\t\tparser: \"svelte\",\n\t\t\t\t\t},\n\t\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst nestedDataFilePath = nestRouteFilePath(dataFilePath, \"marketing\");\n\t\tconst nestedComponentFilePath = nestRouteFilePath(\n\t\t\tcomponentFilePath,\n\t\t\t\"marketing\",\n\t\t);\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tlabel: \"Default\",\n\t\t\t\tcontent: source`\n\t\t\t\t\t## Create your ${model.label}'s page data fetcher\n\n\t\t\t\t\tAdd a new route by creating a \\`${dataFilePath}\\` file. (If the route should be nested in a child directory, you can create the file in a directory, like \\`${nestedDataFilePath}\\`.)\n\n\t\t\t\t\tPaste in this code:\n\n\t\t\t\t\t${`~~~${pageDataExtension} [${dataFilePath}]\\n${dataFileContent}\\n~~~`}\n\n\t\t\t\t\t## Create your ${model.label}'s page component\n\n\t\t\t\t\tIn the route's directory, create a \\`${componentFilePath}\\` file. (If the route should be nested in a child directory, you can create the file in a directory, like \\`${nestedComponentFilePath}\\`.)\n\n\t\t\t\t\tPaste in this code:\n\n\t\t\t\t\t${`~~~svelte [${componentFilePath}]\\n${componentFileContent}\\n~~~`}\n\n\t\t\t\t\tMake sure all of your import paths are correct. See the [install guide](https://prismic.io/docs/svelte-install) for more information.\n\t\t\t\t`,\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [];\n};\n"],"names":[],"mappings":";;;;;AAAA,IAAA;AAQA,MAAM,oBAAoB,CAAC,UAAkB,YAA2B;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,qBAAqB,kBAAkB,cAAc,WAAW;AAChE,UAAA,0BAA0B,kBAC/B,mBACA,WAAW;AAGL,WAAA;AAAA,MACN;AAAA,QACC,OAAO;AAAA,QACP,SAAS;AAAA,sBACS,MAAM;AAAA;AAAA,uCAEW,4HAA4H;AAAA;AAAA;AAAA;AAAA,OAI5J,MAAM,sBAAsB;AAAA,EAAkB;AAAA;AAAA;AAAA,sBAE/B,MAAM;AAAA;AAAA,4CAEgB,iIAAiI;AAAA;AAAA;AAAA;AAAA,OAItK,cAAc;AAAA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA,MAIxC;AAAA,IAAA;AAAA,EAEF;AAED,SAAO;AACR;"}
|
|
@@ -28,7 +28,7 @@ const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
|
28
28
|
var __freeze = Object.freeze;
|
|
29
29
|
var __defProp = Object.defineProperty;
|
|
30
30
|
var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
|
|
31
|
-
var _a;
|
|
31
|
+
var _a, _b;
|
|
32
32
|
const installDependencies = async ({ installDependencies: installDependencies2 }) => {
|
|
33
33
|
await installDependencies2({
|
|
34
34
|
dependencies: {
|
|
@@ -51,7 +51,7 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
51
51
|
if (isTypeScriptProject) {
|
|
52
52
|
contents = commonTags.source`
|
|
53
53
|
import * as prismic from "@prismicio/client";
|
|
54
|
-
import { CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
54
|
+
import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
55
55
|
import config from "../../slicemachine.config.json";
|
|
56
56
|
|
|
57
57
|
/**
|
|
@@ -189,6 +189,29 @@ const createPreviewRouteMatcherFile = async ({ helpers, options }) => {
|
|
|
189
189
|
helpers
|
|
190
190
|
});
|
|
191
191
|
};
|
|
192
|
+
const createPreviewAPIRoute = async ({ helpers, options }) => {
|
|
193
|
+
const extension = await getJSFileExtension.getJSFileExtension({ helpers, options });
|
|
194
|
+
const filename = path__namespace.join("src", "routes", "api", "preview", `+server.${extension}`);
|
|
195
|
+
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const contents = commonTags.source`
|
|
199
|
+
import { redirectToPreviewURL } from '@prismicio/svelte/kit';
|
|
200
|
+
import { createClient } from '$lib/prismicio';
|
|
201
|
+
|
|
202
|
+
export async function GET({ fetch, request, cookies }) {
|
|
203
|
+
const client = createClient({ fetch });
|
|
204
|
+
|
|
205
|
+
return await redirectToPreviewURL({ client, request, cookies });
|
|
206
|
+
}
|
|
207
|
+
`;
|
|
208
|
+
await fs.writeProjectFile({
|
|
209
|
+
filename,
|
|
210
|
+
contents,
|
|
211
|
+
format: options.format,
|
|
212
|
+
helpers
|
|
213
|
+
});
|
|
214
|
+
};
|
|
192
215
|
const createPreviewRouteDirectory = async ({ helpers, options }) => {
|
|
193
216
|
const filename = path__namespace.join("src", "routes", "[[preview=preview]]", "README.md");
|
|
194
217
|
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
@@ -227,6 +250,25 @@ const createRootLayoutServerFile = async ({ helpers, options }) => {
|
|
|
227
250
|
helpers
|
|
228
251
|
});
|
|
229
252
|
};
|
|
253
|
+
const createRootLayoutFile = async ({ helpers, options }) => {
|
|
254
|
+
const filename = path__namespace.join("src", "routes", "+layout.svelte");
|
|
255
|
+
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const contents = commonTags.source(_b || (_b = __template(["\n <script>\n import { PrismicPreview } from '@prismicio/svelte/kit';\n import { repositoryName } from '$lib/prismicio';\n <\/script>\n\n <slot />\n <PrismicPreview {repositoryName} />\n "])));
|
|
259
|
+
await fs.writeProjectFile({
|
|
260
|
+
filename,
|
|
261
|
+
contents,
|
|
262
|
+
format: options.format,
|
|
263
|
+
formatOptions: {
|
|
264
|
+
prettier: {
|
|
265
|
+
plugins: ["prettier-plugin-svelte"],
|
|
266
|
+
parser: "svelte"
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
helpers
|
|
270
|
+
});
|
|
271
|
+
};
|
|
230
272
|
const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
231
273
|
var _a2;
|
|
232
274
|
const project = await helpers.getProject();
|
|
@@ -261,9 +303,11 @@ const projectInit = async ({ installDependencies: _installDependencies }, contex
|
|
|
261
303
|
modifySliceMachineConfig(context),
|
|
262
304
|
createPrismicIOFile(context),
|
|
263
305
|
createSliceSimulatorPage(context),
|
|
306
|
+
createPreviewAPIRoute(context),
|
|
264
307
|
createPreviewRouteDirectory(context),
|
|
265
308
|
createPreviewRouteMatcherFile(context),
|
|
266
|
-
createRootLayoutServerFile(context)
|
|
309
|
+
createRootLayoutServerFile(context),
|
|
310
|
+
createRootLayoutFile(context)
|
|
267
311
|
]));
|
|
268
312
|
await upsertSliceLibraryIndexFiles(context);
|
|
269
313
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-init.cjs","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 { 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 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 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\tcreatePreviewRouteDirectory(context),\n\t\t\tcreatePreviewRouteMatcherFile(context),\n\t\t\tcreateRootLayoutServerFile(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","checkIsTypeScriptProject","getJSFileExtension","path","checkHasProjectFile","source","PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME","writeProjectFile","_a","upsertSliceLibraryIndexFile","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA;AAwBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;A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,OAAO,UAAU,IAAI,OAAO,cAAa;AAChD,UAAMK,4BAA4B,4BAAA,EAAE,WAAW,GAAG,QAAS,CAAA;AAAA,EAC3D,CAAA,CAAC;AAEJ;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEFC,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,yBAAyB,OAAO;AAAA,IAChC,oBAAoB,OAAO;AAAA,IAC3B,yBAAyB,OAAO;AAAA,IAChC,4BAA4B,OAAO;AAAA,IACnC,8BAA8B,OAAO;AAAA,IACrC,2BAA2B,OAAO;AAAA,EAClC,CAAA,CAAC;AAKH,QAAM,6BAA6B,OAAO;AAC3C;;"}
|
|
1
|
+
{"version":3,"file":"project-init.cjs","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 { PrismicPreview } from '@prismicio/svelte/kit';\n\t\t\timport { repositoryName } from '$lib/prismicio';\n\t\t</script>\n\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","checkIsTypeScriptProject","getJSFileExtension","path","checkHasProjectFile","source","PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME","writeProjectFile","_a","upsertSliceLibraryIndexFile","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,IAAA;AAwBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,qBAAqB;AAAA,IACrB;AAAA,EAAA,CACD;AACF;AAIA,MAAM,sBAAsB,OAAO,EAClC,SACA,cAC6B;AACvB,QAAA,sBAAsB,MAAMC,kDAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AACD,QAAM,YAAY,MAAMC,mBAAA,mBAAmB,EAAE,SAAS,QAAS,CAAA;AAC/D,QAAM,WAAWC,gBAAK,KAAK,qBAAqB,WAAW;AAE3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
|
var __freeze = Object.freeze;
|
|
10
10
|
var __defProp = Object.defineProperty;
|
|
11
11
|
var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
|
|
12
|
-
var _a;
|
|
12
|
+
var _a, _b;
|
|
13
13
|
const installDependencies = async ({ installDependencies: installDependencies2 }) => {
|
|
14
14
|
await installDependencies2({
|
|
15
15
|
dependencies: {
|
|
@@ -32,7 +32,7 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
32
32
|
if (isTypeScriptProject) {
|
|
33
33
|
contents = source`
|
|
34
34
|
import * as prismic from "@prismicio/client";
|
|
35
|
-
import { CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
35
|
+
import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
36
36
|
import config from "../../slicemachine.config.json";
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -170,6 +170,29 @@ const createPreviewRouteMatcherFile = async ({ helpers, options }) => {
|
|
|
170
170
|
helpers
|
|
171
171
|
});
|
|
172
172
|
};
|
|
173
|
+
const createPreviewAPIRoute = async ({ helpers, options }) => {
|
|
174
|
+
const extension = await getJSFileExtension({ helpers, options });
|
|
175
|
+
const filename = path.join("src", "routes", "api", "preview", `+server.${extension}`);
|
|
176
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
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
|
+
`;
|
|
189
|
+
await writeProjectFile({
|
|
190
|
+
filename,
|
|
191
|
+
contents,
|
|
192
|
+
format: options.format,
|
|
193
|
+
helpers
|
|
194
|
+
});
|
|
195
|
+
};
|
|
173
196
|
const createPreviewRouteDirectory = async ({ helpers, options }) => {
|
|
174
197
|
const filename = path.join("src", "routes", "[[preview=preview]]", "README.md");
|
|
175
198
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
@@ -208,6 +231,25 @@ const createRootLayoutServerFile = async ({ helpers, options }) => {
|
|
|
208
231
|
helpers
|
|
209
232
|
});
|
|
210
233
|
};
|
|
234
|
+
const createRootLayoutFile = async ({ helpers, options }) => {
|
|
235
|
+
const filename = path.join("src", "routes", "+layout.svelte");
|
|
236
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const contents = source(_b || (_b = __template(["\n <script>\n import { PrismicPreview } from '@prismicio/svelte/kit';\n import { repositoryName } from '$lib/prismicio';\n <\/script>\n\n <slot />\n <PrismicPreview {repositoryName} />\n "])));
|
|
240
|
+
await writeProjectFile({
|
|
241
|
+
filename,
|
|
242
|
+
contents,
|
|
243
|
+
format: options.format,
|
|
244
|
+
formatOptions: {
|
|
245
|
+
prettier: {
|
|
246
|
+
plugins: ["prettier-plugin-svelte"],
|
|
247
|
+
parser: "svelte"
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
helpers
|
|
251
|
+
});
|
|
252
|
+
};
|
|
211
253
|
const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
212
254
|
var _a2;
|
|
213
255
|
const project = await helpers.getProject();
|
|
@@ -242,9 +284,11 @@ const projectInit = async ({ installDependencies: _installDependencies }, contex
|
|
|
242
284
|
modifySliceMachineConfig(context),
|
|
243
285
|
createPrismicIOFile(context),
|
|
244
286
|
createSliceSimulatorPage(context),
|
|
287
|
+
createPreviewAPIRoute(context),
|
|
245
288
|
createPreviewRouteDirectory(context),
|
|
246
289
|
createPreviewRouteMatcherFile(context),
|
|
247
|
-
createRootLayoutServerFile(context)
|
|
290
|
+
createRootLayoutServerFile(context),
|
|
291
|
+
createRootLayoutFile(context)
|
|
248
292
|
]));
|
|
249
293
|
await upsertSliceLibraryIndexFiles(context);
|
|
250
294
|
};
|
|
@@ -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 { 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 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 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\tcreatePreviewRouteDirectory(context),\n\t\t\tcreatePreviewRouteMatcherFile(context),\n\t\t\tcreateRootLayoutServerFile(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;AAwBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,qBAAqB;AAAA,IACrB;AAAA,EAAA,CACD;AACF;AAIA,MAAM,sBAAsB,OAAO,EAClC,SACA,cAC6B;AACvB,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AACD,QAAM,YAAY,MAAM,mBAAmB,EAAE,SAAS,QAAS,CAAA;AAC/D,QAAM,WAAW,KAAK,KAAK,qBAAqB,WAAW;AAE3D,MAAI,MAAM,oBAAoB,EAAE,UAAU,QAAS,CAAA,GAAG;AACrD;AAAA,EACA;AAEG,MAAA;AAEJ,MAAI,qBAAqB;AACb,eAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YASD,UAAU,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAA,OA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AyB,QAAQ,QAAQ;AAAA,IACtD,QAAQ,QAAQ;AAAA,EAAA,CAChB;AACF;AAEA,MAAM,+BAA+B,OACpC,YACG;AAOH,QAAM,UAAU,MAAM,QAAQ,QAAQ,WAAU;AAE5C,MAAA,CAAC,QAAQ,OAAO,WAAW;AAC9B;AAAA,EACA;AAED,QAAM,QAAQ,IACb,QAAQ,OAAO,UAAU,IAAI,OAAO,cAAa;AAChD,UAAM,4BAA4B,EAAE,WAAW,GAAG,QAAS,CAAA;AAAA,EAC3D,CAAA,CAAC;AAEJ;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,yBAAyB,OAAO;AAAA,IAChC,oBAAoB,OAAO;AAAA,IAC3B,yBAAyB,OAAO;AAAA,IAChC,4BAA4B,OAAO;AAAA,IACnC,8BAA8B,OAAO;AAAA,IACrC,2BAA2B,OAAO;AAAA,EAClC,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\";\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 { PrismicPreview } from '@prismicio/svelte/kit';\n\t\t\timport { repositoryName } from '$lib/prismicio';\n\t\t</script>\n\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;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,qBAAqB;AAAA,IACrB;AAAA,EAAA,CACD;AACF;AAIA,MAAM,sBAAsB,OAAO,EAClC,SACA,cAC6B;AACvB,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AACD,QAAM,YAAY,MAAM,mBAAmB,EAAE,SAAS,QAAS,CAAA;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G;AAC7B,cAAA,OAAO,YAAY,CAAC,kBAAkB;AAAA,IAC9C;AAAA,EACD;AAEK,QAAA,QAAQ,yBAAyB,QAAQ,QAAQ;AAAA,IACtD,QAAQ,QAAQ;AAAA,EAAA,CAChB;AACF;AAEA,MAAM,+BAA+B,OACpC,YACG;AAOH,QAAM,UAAU,MAAM,QAAQ,QAAQ,WAAU;AAE5C,MAAA,CAAC,QAAQ,OAAO,WAAW;AAC9B;AAAA,EACA;AAED,QAAM,QAAQ,IACb,QAAQ,OAAO,UAAU,IAAI,OAAO,cAAa;AAChD,UAAM,4BAA4B,EAAE,WAAW,GAAG,QAAS,CAAA;AAAA,EAC3D,CAAA,CAAC;AAEJ;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,yBAAyB,OAAO;AAAA,IAChC,oBAAoB,OAAO;AAAA,IAC3B,yBAAyB,OAAO;AAAA,IAChC,sBAAsB,OAAO;AAAA,IAC7B,4BAA4B,OAAO;AAAA,IACnC,8BAA8B,OAAO;AAAA,IACrC,2BAA2B,OAAO;AAAA,IAClC,qBAAqB,OAAO;AAAA,EAC5B,CAAA,CAAC;AAKH,QAAM,6BAA6B,OAAO;AAC3C;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/adapter-sveltekit",
|
|
3
|
-
"version": "0.3.30-dev-next-release.
|
|
3
|
+
"version": "0.3.30-dev-next-release.4",
|
|
4
4
|
"description": "Slice Machine adapter for SvelteKit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@prismicio/simulator": "^0.1.4",
|
|
66
66
|
"@prismicio/types-internal": "^2.2.0",
|
|
67
|
-
"@slicemachine/plugin-kit": "^0.4.30-dev-next-release.
|
|
67
|
+
"@slicemachine/plugin-kit": "^0.4.30-dev-next-release.4",
|
|
68
68
|
"common-tags": "^1.8.2",
|
|
69
69
|
"fp-ts": "^2.13.1",
|
|
70
70
|
"io-ts": "^2.2.20",
|
|
@@ -79,9 +79,9 @@
|
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@prismicio/mock": "0.2.0",
|
|
81
81
|
"@size-limit/preset-small-lib": "8.2.4",
|
|
82
|
-
"@sveltejs/kit": "
|
|
82
|
+
"@sveltejs/kit": "2.0.0",
|
|
83
83
|
"@sveltejs/package": "2.2.1",
|
|
84
|
-
"@sveltejs/vite-plugin-svelte": "
|
|
84
|
+
"@sveltejs/vite-plugin-svelte": "3.0.1",
|
|
85
85
|
"@types/common-tags": "1.8.1",
|
|
86
86
|
"@typescript-eslint/eslint-plugin": "5.55.0",
|
|
87
87
|
"@typescript-eslint/parser": "5.55.0",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"vitest": "0.32.0"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
|
-
"@sveltejs/kit": "^1",
|
|
106
|
+
"@sveltejs/kit": "^1 || ^2",
|
|
107
107
|
"prettier": ">=3",
|
|
108
108
|
"prettier-plugin-svelte": ">=3",
|
|
109
109
|
"svelte": "^3.54.0 || ^4.0.0-next.0"
|
|
@@ -119,5 +119,5 @@
|
|
|
119
119
|
"engines": {
|
|
120
120
|
"node": ">=14.15.0"
|
|
121
121
|
},
|
|
122
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "33d96d9eba038c228951fed7ae2fb23503b22a73"
|
|
123
123
|
}
|
|
@@ -32,8 +32,8 @@ export const documentationRead: DocumentationReadHook<PluginOptions> = async (
|
|
|
32
32
|
dataFileContent = source`
|
|
33
33
|
import { createClient } from "$lib/prismicio";
|
|
34
34
|
|
|
35
|
-
export async function load({ params, fetch }) {
|
|
36
|
-
const client = createClient({ fetch });
|
|
35
|
+
export async function load({ params, fetch, cookies }) {
|
|
36
|
+
const client = createClient({ fetch, cookies });
|
|
37
37
|
|
|
38
38
|
const page = await client.getByUID("${model.id}", params.uid);
|
|
39
39
|
|
|
@@ -56,8 +56,8 @@ export const documentationRead: DocumentationReadHook<PluginOptions> = async (
|
|
|
56
56
|
dataFileContent = source`
|
|
57
57
|
import { createClient } from "$lib/prismicio";
|
|
58
58
|
|
|
59
|
-
export async function load({ params, fetch }) {
|
|
60
|
-
const client = createClient({ fetch });
|
|
59
|
+
export async function load({ params, fetch, cookies }) {
|
|
60
|
+
const client = createClient({ fetch, cookies });
|
|
61
61
|
|
|
62
62
|
const page = await client.getSingle("${model.id}");
|
|
63
63
|
|
|
@@ -55,7 +55,7 @@ const createPrismicIOFile = async ({
|
|
|
55
55
|
if (isTypeScriptProject) {
|
|
56
56
|
contents = source`
|
|
57
57
|
import * as prismic from "@prismicio/client";
|
|
58
|
-
import { CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
58
|
+
import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
59
59
|
import config from "../../slicemachine.config.json";
|
|
60
60
|
|
|
61
61
|
/**
|
|
@@ -224,6 +224,42 @@ const createPreviewRouteMatcherFile = async ({
|
|
|
224
224
|
});
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
+
const createPreviewAPIRoute = async ({
|
|
228
|
+
helpers,
|
|
229
|
+
options,
|
|
230
|
+
}: SliceMachineContext<PluginOptions>) => {
|
|
231
|
+
const extension = await getJSFileExtension({ helpers, options });
|
|
232
|
+
const filename = path.join(
|
|
233
|
+
"src",
|
|
234
|
+
"routes",
|
|
235
|
+
"api",
|
|
236
|
+
"preview",
|
|
237
|
+
`+server.${extension}`,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const contents = source`
|
|
245
|
+
import { redirectToPreviewURL } from '@prismicio/svelte/kit';
|
|
246
|
+
import { createClient } from '$lib/prismicio';
|
|
247
|
+
|
|
248
|
+
export async function GET({ fetch, request, cookies }) {
|
|
249
|
+
const client = createClient({ fetch });
|
|
250
|
+
|
|
251
|
+
return await redirectToPreviewURL({ client, request, cookies });
|
|
252
|
+
}
|
|
253
|
+
`;
|
|
254
|
+
|
|
255
|
+
await writeProjectFile({
|
|
256
|
+
filename,
|
|
257
|
+
contents,
|
|
258
|
+
format: options.format,
|
|
259
|
+
helpers,
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
|
|
227
263
|
const createPreviewRouteDirectory = async ({
|
|
228
264
|
helpers,
|
|
229
265
|
options,
|
|
@@ -281,6 +317,40 @@ const createRootLayoutServerFile = async ({
|
|
|
281
317
|
});
|
|
282
318
|
};
|
|
283
319
|
|
|
320
|
+
const createRootLayoutFile = async ({
|
|
321
|
+
helpers,
|
|
322
|
+
options,
|
|
323
|
+
}: SliceMachineContext<PluginOptions>) => {
|
|
324
|
+
const filename = path.join("src", "routes", "+layout.svelte");
|
|
325
|
+
|
|
326
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const contents = source`
|
|
331
|
+
<script>
|
|
332
|
+
import { PrismicPreview } from '@prismicio/svelte/kit';
|
|
333
|
+
import { repositoryName } from '$lib/prismicio';
|
|
334
|
+
</script>
|
|
335
|
+
|
|
336
|
+
<slot />
|
|
337
|
+
<PrismicPreview {repositoryName} />
|
|
338
|
+
`;
|
|
339
|
+
|
|
340
|
+
await writeProjectFile({
|
|
341
|
+
filename,
|
|
342
|
+
contents,
|
|
343
|
+
format: options.format,
|
|
344
|
+
formatOptions: {
|
|
345
|
+
prettier: {
|
|
346
|
+
plugins: ["prettier-plugin-svelte"],
|
|
347
|
+
parser: "svelte",
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
helpers,
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
|
|
284
354
|
const modifySliceMachineConfig = async ({
|
|
285
355
|
helpers,
|
|
286
356
|
options,
|
|
@@ -348,9 +418,11 @@ export const projectInit: ProjectInitHook<PluginOptions> = async (
|
|
|
348
418
|
modifySliceMachineConfig(context),
|
|
349
419
|
createPrismicIOFile(context),
|
|
350
420
|
createSliceSimulatorPage(context),
|
|
421
|
+
createPreviewAPIRoute(context),
|
|
351
422
|
createPreviewRouteDirectory(context),
|
|
352
423
|
createPreviewRouteMatcherFile(context),
|
|
353
424
|
createRootLayoutServerFile(context),
|
|
425
|
+
createRootLayoutFile(context),
|
|
354
426
|
]),
|
|
355
427
|
);
|
|
356
428
|
|