@slicemachine/adapter-sveltekit 0.3.22-dev-next-release.10 → 0.3.22-dev-next-release.11
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 +113 -57
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js +113 -57
- package/dist/hooks/project-init.js.map +1 -1
- package/package.json +3 -3
- package/src/hooks/documentation-read.ts +4 -4
- package/src/hooks/project-init.ts +138 -57
|
@@ -25,8 +25,6 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
25
25
|
dataFileContent = commonTags.source`
|
|
26
26
|
import { createClient } from "$lib/prismicio";
|
|
27
27
|
|
|
28
|
-
export const prerender = true;
|
|
29
|
-
|
|
30
28
|
export async function load({ params, fetch }) {
|
|
31
29
|
const client = createClient({ fetch });
|
|
32
30
|
|
|
@@ -51,8 +49,6 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
51
49
|
dataFileContent = commonTags.source`
|
|
52
50
|
import { createClient } from "$lib/prismicio";
|
|
53
51
|
|
|
54
|
-
export const prerender = true;
|
|
55
|
-
|
|
56
52
|
export async function load({ params, fetch }) {
|
|
57
53
|
const client = createClient({ fetch });
|
|
58
54
|
|
|
@@ -62,6 +58,10 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
62
58
|
page,
|
|
63
59
|
};
|
|
64
60
|
}
|
|
61
|
+
|
|
62
|
+
export async function entries() {
|
|
63
|
+
return [{}]
|
|
64
|
+
}
|
|
65
65
|
`;
|
|
66
66
|
}
|
|
67
67
|
let componentFileContent = commonTags.source(_a || (_a = __template(['\n <script>\n import { SliceZone } from "@prismicio/svelte";\n\n import { components } from "$lib/slices";\n\n export let data;\n <\/script>\n\n <SliceZone slices={data.page.data.slices} {components} />\n '])));
|
|
@@ -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
|
|
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,YA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D,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,6 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
23
23
|
dataFileContent = source`
|
|
24
24
|
import { createClient } from "$lib/prismicio";
|
|
25
25
|
|
|
26
|
-
export const prerender = true;
|
|
27
|
-
|
|
28
26
|
export async function load({ params, fetch }) {
|
|
29
27
|
const client = createClient({ fetch });
|
|
30
28
|
|
|
@@ -49,8 +47,6 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
49
47
|
dataFileContent = source`
|
|
50
48
|
import { createClient } from "$lib/prismicio";
|
|
51
49
|
|
|
52
|
-
export const prerender = true;
|
|
53
|
-
|
|
54
50
|
export async function load({ params, fetch }) {
|
|
55
51
|
const client = createClient({ fetch });
|
|
56
52
|
|
|
@@ -60,6 +56,10 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
60
56
|
page,
|
|
61
57
|
};
|
|
62
58
|
}
|
|
59
|
+
|
|
60
|
+
export async function entries() {
|
|
61
|
+
return [{}]
|
|
62
|
+
}
|
|
63
63
|
`;
|
|
64
64
|
}
|
|
65
65
|
let componentFileContent = source(_a || (_a = __template(['\n <script>\n import { SliceZone } from "@prismicio/svelte";\n\n import { components } from "$lib/slices";\n\n export let data;\n <\/script>\n\n <SliceZone slices={data.page.data.slices} {components} />\n '])));
|
|
@@ -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
|
|
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,U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F;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;"}
|
|
@@ -46,46 +46,11 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
46
46
|
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
let createClientContents;
|
|
50
|
-
if (isTypeScriptProject) {
|
|
51
|
-
createClientContents = commonTags.source`
|
|
52
|
-
/**
|
|
53
|
-
* Creates a Prismic client for the project's repository. The client is used to
|
|
54
|
-
* query content from the Prismic API.
|
|
55
|
-
*
|
|
56
|
-
* @param config - Configuration for the Prismic client.
|
|
57
|
-
*/
|
|
58
|
-
export const createClient = (config: prismic.ClientConfig = {}) => {
|
|
59
|
-
const client = prismic.createClient(repositoryName, {
|
|
60
|
-
routes,
|
|
61
|
-
...config,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return client;
|
|
65
|
-
};
|
|
66
|
-
`;
|
|
67
|
-
} else {
|
|
68
|
-
createClientContents = commonTags.source`
|
|
69
|
-
/**
|
|
70
|
-
* Creates a Prismic client for the project's repository. The client is used to
|
|
71
|
-
* query content from the Prismic API.
|
|
72
|
-
*
|
|
73
|
-
* @param {prismic.ClientConfig} config - Configuration for the Prismic client.
|
|
74
|
-
*/
|
|
75
|
-
export const createClient = (config = {}) => {
|
|
76
|
-
const client = prismic.createClient(repositoryName, {
|
|
77
|
-
routes,
|
|
78
|
-
...config,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return client;
|
|
82
|
-
};
|
|
83
|
-
`;
|
|
84
|
-
}
|
|
85
49
|
let contents;
|
|
86
50
|
if (isTypeScriptProject) {
|
|
87
51
|
contents = commonTags.source`
|
|
88
52
|
import * as prismic from "@prismicio/client";
|
|
53
|
+
import { CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
89
54
|
import config from "../../slicemachine.config.json";
|
|
90
55
|
|
|
91
56
|
/**
|
|
@@ -100,21 +65,38 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
100
65
|
*/
|
|
101
66
|
// TODO: Update the routes array to match your project's route structure.
|
|
102
67
|
const routes: prismic.ClientConfig["routes"] = [
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
68
|
+
// Examples:
|
|
69
|
+
// {
|
|
70
|
+
// type: "homepage",
|
|
71
|
+
// path: "/",
|
|
72
|
+
// },
|
|
73
|
+
// {
|
|
74
|
+
// type: "page",
|
|
75
|
+
// path: "/:uid",
|
|
76
|
+
// },
|
|
111
77
|
];
|
|
112
78
|
|
|
113
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
81
|
+
* query content from the Prismic API.
|
|
82
|
+
*
|
|
83
|
+
* @param config - Configuration for the Prismic client.
|
|
84
|
+
*/
|
|
85
|
+
export const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {
|
|
86
|
+
const client = prismic.createClient(repositoryName, {
|
|
87
|
+
routes,
|
|
88
|
+
...config,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
enableAutoPreviews({ client, cookies });
|
|
92
|
+
|
|
93
|
+
return client;
|
|
94
|
+
};
|
|
114
95
|
`;
|
|
115
96
|
} else {
|
|
116
97
|
contents = commonTags.source`
|
|
117
98
|
import * as prismic from "@prismicio/client";
|
|
99
|
+
import { enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
118
100
|
import config from "../../slicemachine.config.json";
|
|
119
101
|
|
|
120
102
|
/**
|
|
@@ -131,17 +113,33 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
131
113
|
*/
|
|
132
114
|
// TODO: Update the routes array to match your project's route structure.
|
|
133
115
|
const routes = [
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
116
|
+
// Examples:
|
|
117
|
+
// {
|
|
118
|
+
// type: "homepage",
|
|
119
|
+
// path: "/",
|
|
120
|
+
// },
|
|
121
|
+
// {
|
|
122
|
+
// type: "page",
|
|
123
|
+
// path: "/:uid",
|
|
124
|
+
// },
|
|
142
125
|
];
|
|
143
126
|
|
|
144
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
129
|
+
* query content from the Prismic API.
|
|
130
|
+
*
|
|
131
|
+
* @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.
|
|
132
|
+
*/
|
|
133
|
+
export const createClient = ({ cookies, ...config } = {}) => {
|
|
134
|
+
const client = prismic.createClient(repositoryName, {
|
|
135
|
+
routes,
|
|
136
|
+
...config,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
enableAutoPreviews({ client, cookies });
|
|
140
|
+
|
|
141
|
+
return client;
|
|
142
|
+
};
|
|
145
143
|
`;
|
|
146
144
|
}
|
|
147
145
|
await fs.writeProjectFile({
|
|
@@ -170,6 +168,62 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
|
170
168
|
helpers
|
|
171
169
|
});
|
|
172
170
|
};
|
|
171
|
+
const createPreviewRouteMatcherFile = async ({ helpers, options }) => {
|
|
172
|
+
const extension = await getJSFileExtension.getJSFileExtension({ helpers, options });
|
|
173
|
+
const filename = path__namespace.join(`src/params/preview.${extension}`);
|
|
174
|
+
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const contents = commonTags.source`
|
|
178
|
+
export function match(param) {
|
|
179
|
+
return param === 'preview';
|
|
180
|
+
}
|
|
181
|
+
`;
|
|
182
|
+
await fs.writeProjectFile({
|
|
183
|
+
filename,
|
|
184
|
+
contents,
|
|
185
|
+
format: options.format,
|
|
186
|
+
helpers
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const createPreviewRouteDirectory = async ({ helpers, options }) => {
|
|
190
|
+
const filename = path__namespace.join("src", "routes", "[[preview=preview]]", "README.md");
|
|
191
|
+
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const contents = commonTags.source`
|
|
195
|
+
This directory adds support for optional \`/preview\` routes. Do not remove this directory.
|
|
196
|
+
|
|
197
|
+
All routes within this directory will be served using the following URLs:
|
|
198
|
+
|
|
199
|
+
- \`/example-route\` (prerendered)
|
|
200
|
+
- \`/preview/example-route\` (server-rendered)
|
|
201
|
+
|
|
202
|
+
See <https://prismic.io/docs/svelte-preview> for more information.
|
|
203
|
+
`;
|
|
204
|
+
await fs.writeProjectFile({
|
|
205
|
+
filename,
|
|
206
|
+
contents,
|
|
207
|
+
format: options.format,
|
|
208
|
+
helpers
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
const createRootLayoutServerFile = async ({ helpers, options }) => {
|
|
212
|
+
const extension = await getJSFileExtension.getJSFileExtension({ helpers, options });
|
|
213
|
+
const filename = path__namespace.join(`src/routes/+layout.server.${extension}`);
|
|
214
|
+
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const contents = commonTags.source`
|
|
218
|
+
export const prerender = "auto";
|
|
219
|
+
`;
|
|
220
|
+
await fs.writeProjectFile({
|
|
221
|
+
filename,
|
|
222
|
+
contents,
|
|
223
|
+
format: options.format,
|
|
224
|
+
helpers
|
|
225
|
+
});
|
|
226
|
+
};
|
|
173
227
|
const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
174
228
|
var _a2;
|
|
175
229
|
const project = await helpers.getProject();
|
|
@@ -190,12 +244,11 @@ const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
|
190
244
|
});
|
|
191
245
|
};
|
|
192
246
|
const upsertSliceLibraryIndexFiles = async (context) => {
|
|
193
|
-
var _a2;
|
|
194
247
|
const project = await context.helpers.getProject();
|
|
195
248
|
if (!project.config.libraries) {
|
|
196
249
|
return;
|
|
197
250
|
}
|
|
198
|
-
await Promise.all(
|
|
251
|
+
await Promise.all(project.config.libraries.map(async (libraryID) => {
|
|
199
252
|
await upsertSliceLibraryIndexFile.upsertSliceLibraryIndexFile({ libraryID, ...context });
|
|
200
253
|
}));
|
|
201
254
|
};
|
|
@@ -204,7 +257,10 @@ const projectInit = async ({ installDependencies: _installDependencies }, contex
|
|
|
204
257
|
installDependencies({ installDependencies: _installDependencies }),
|
|
205
258
|
modifySliceMachineConfig(context),
|
|
206
259
|
createPrismicIOFile(context),
|
|
207
|
-
createSliceSimulatorPage(context)
|
|
260
|
+
createSliceSimulatorPage(context),
|
|
261
|
+
createPreviewRouteDirectory(context),
|
|
262
|
+
createPreviewRouteMatcherFile(context),
|
|
263
|
+
createRootLayoutServerFile(context)
|
|
208
264
|
]));
|
|
209
265
|
await upsertSliceLibraryIndexFiles(context);
|
|
210
266
|
};
|
|
@@ -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\";\n\nimport type { PluginOptions } from \"../types\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\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 createClientContents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcreateClientContents = source`\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 = (config: prismic.ClientConfig = {}) => {\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\treturn client;\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tcreateClientContents = source`\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 {prismic.ClientConfig} config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = (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\treturn client;\n\t\t\t};\n\t\t`;\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 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 = 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{\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${createClientContents}\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\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 = 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{\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${createClientContents}\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 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]),\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","writeProjectFile","_a","upsertSliceLibraryIndexFile","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA;AAuBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,qBAAqB;AAAA,IACrB;AAA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;AAC9B;AAAA,EACA;AAED,QAAM,QAAQ,KACbG,MAAA,QAAQ,OAAO,cAAf,gBAAAA,IAA0B,IAAI,OAAO,cAAa;AACjD,UAAMC,4BAA4B,4BAAA,EAAE,WAAW,GAAG,QAAS,CAAA;AAAA,EAC3D,EAAC;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,EAChC,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\";\n\nimport type { PluginOptions } from \"../types\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\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 = 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 = 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","writeProjectFile","_a","upsertSliceLibraryIndexFile","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA;AAuBA,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;AAE3D,MAAI,MAAMC,GAAAA,oBAAoB,EAAE,UAAU,QAAS,CAAA,GAAG;AACrD;AAAA,EACA;AAEG,MAAA;AAEJ,MAAI,qBAAqB;AACb,eAAAC,WAAAA;AAAAA;AAAAA;AAAAA;AAA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, options }) => {
|
|
|
27
27
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
let createClientContents;
|
|
31
|
-
if (isTypeScriptProject) {
|
|
32
|
-
createClientContents = source`
|
|
33
|
-
/**
|
|
34
|
-
* Creates a Prismic client for the project's repository. The client is used to
|
|
35
|
-
* query content from the Prismic API.
|
|
36
|
-
*
|
|
37
|
-
* @param config - Configuration for the Prismic client.
|
|
38
|
-
*/
|
|
39
|
-
export const createClient = (config: prismic.ClientConfig = {}) => {
|
|
40
|
-
const client = prismic.createClient(repositoryName, {
|
|
41
|
-
routes,
|
|
42
|
-
...config,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return client;
|
|
46
|
-
};
|
|
47
|
-
`;
|
|
48
|
-
} else {
|
|
49
|
-
createClientContents = source`
|
|
50
|
-
/**
|
|
51
|
-
* Creates a Prismic client for the project's repository. The client is used to
|
|
52
|
-
* query content from the Prismic API.
|
|
53
|
-
*
|
|
54
|
-
* @param {prismic.ClientConfig} config - Configuration for the Prismic client.
|
|
55
|
-
*/
|
|
56
|
-
export const createClient = (config = {}) => {
|
|
57
|
-
const client = prismic.createClient(repositoryName, {
|
|
58
|
-
routes,
|
|
59
|
-
...config,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
return client;
|
|
63
|
-
};
|
|
64
|
-
`;
|
|
65
|
-
}
|
|
66
30
|
let contents;
|
|
67
31
|
if (isTypeScriptProject) {
|
|
68
32
|
contents = source`
|
|
69
33
|
import * as prismic from "@prismicio/client";
|
|
34
|
+
import { CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
70
35
|
import config from "../../slicemachine.config.json";
|
|
71
36
|
|
|
72
37
|
/**
|
|
@@ -81,21 +46,38 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
81
46
|
*/
|
|
82
47
|
// TODO: Update the routes array to match your project's route structure.
|
|
83
48
|
const routes: prismic.ClientConfig["routes"] = [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
49
|
+
// Examples:
|
|
50
|
+
// {
|
|
51
|
+
// type: "homepage",
|
|
52
|
+
// path: "/",
|
|
53
|
+
// },
|
|
54
|
+
// {
|
|
55
|
+
// type: "page",
|
|
56
|
+
// path: "/:uid",
|
|
57
|
+
// },
|
|
92
58
|
];
|
|
93
59
|
|
|
94
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
62
|
+
* query content from the Prismic API.
|
|
63
|
+
*
|
|
64
|
+
* @param config - Configuration for the Prismic client.
|
|
65
|
+
*/
|
|
66
|
+
export const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {
|
|
67
|
+
const client = prismic.createClient(repositoryName, {
|
|
68
|
+
routes,
|
|
69
|
+
...config,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
enableAutoPreviews({ client, cookies });
|
|
73
|
+
|
|
74
|
+
return client;
|
|
75
|
+
};
|
|
95
76
|
`;
|
|
96
77
|
} else {
|
|
97
78
|
contents = source`
|
|
98
79
|
import * as prismic from "@prismicio/client";
|
|
80
|
+
import { enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
99
81
|
import config from "../../slicemachine.config.json";
|
|
100
82
|
|
|
101
83
|
/**
|
|
@@ -112,17 +94,33 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
112
94
|
*/
|
|
113
95
|
// TODO: Update the routes array to match your project's route structure.
|
|
114
96
|
const routes = [
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
97
|
+
// Examples:
|
|
98
|
+
// {
|
|
99
|
+
// type: "homepage",
|
|
100
|
+
// path: "/",
|
|
101
|
+
// },
|
|
102
|
+
// {
|
|
103
|
+
// type: "page",
|
|
104
|
+
// path: "/:uid",
|
|
105
|
+
// },
|
|
123
106
|
];
|
|
124
107
|
|
|
125
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
110
|
+
* query content from the Prismic API.
|
|
111
|
+
*
|
|
112
|
+
* @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.
|
|
113
|
+
*/
|
|
114
|
+
export const createClient = ({ cookies, ...config } = {}) => {
|
|
115
|
+
const client = prismic.createClient(repositoryName, {
|
|
116
|
+
routes,
|
|
117
|
+
...config,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
enableAutoPreviews({ client, cookies });
|
|
121
|
+
|
|
122
|
+
return client;
|
|
123
|
+
};
|
|
126
124
|
`;
|
|
127
125
|
}
|
|
128
126
|
await writeProjectFile({
|
|
@@ -151,6 +149,62 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
|
151
149
|
helpers
|
|
152
150
|
});
|
|
153
151
|
};
|
|
152
|
+
const createPreviewRouteMatcherFile = async ({ helpers, options }) => {
|
|
153
|
+
const extension = await getJSFileExtension({ helpers, options });
|
|
154
|
+
const filename = path.join(`src/params/preview.${extension}`);
|
|
155
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const contents = source`
|
|
159
|
+
export function match(param) {
|
|
160
|
+
return param === 'preview';
|
|
161
|
+
}
|
|
162
|
+
`;
|
|
163
|
+
await writeProjectFile({
|
|
164
|
+
filename,
|
|
165
|
+
contents,
|
|
166
|
+
format: options.format,
|
|
167
|
+
helpers
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
const createPreviewRouteDirectory = async ({ helpers, options }) => {
|
|
171
|
+
const filename = path.join("src", "routes", "[[preview=preview]]", "README.md");
|
|
172
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const contents = source`
|
|
176
|
+
This directory adds support for optional \`/preview\` routes. Do not remove this directory.
|
|
177
|
+
|
|
178
|
+
All routes within this directory will be served using the following URLs:
|
|
179
|
+
|
|
180
|
+
- \`/example-route\` (prerendered)
|
|
181
|
+
- \`/preview/example-route\` (server-rendered)
|
|
182
|
+
|
|
183
|
+
See <https://prismic.io/docs/svelte-preview> for more information.
|
|
184
|
+
`;
|
|
185
|
+
await writeProjectFile({
|
|
186
|
+
filename,
|
|
187
|
+
contents,
|
|
188
|
+
format: options.format,
|
|
189
|
+
helpers
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
const createRootLayoutServerFile = async ({ helpers, options }) => {
|
|
193
|
+
const extension = await getJSFileExtension({ helpers, options });
|
|
194
|
+
const filename = path.join(`src/routes/+layout.server.${extension}`);
|
|
195
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const contents = source`
|
|
199
|
+
export const prerender = "auto";
|
|
200
|
+
`;
|
|
201
|
+
await writeProjectFile({
|
|
202
|
+
filename,
|
|
203
|
+
contents,
|
|
204
|
+
format: options.format,
|
|
205
|
+
helpers
|
|
206
|
+
});
|
|
207
|
+
};
|
|
154
208
|
const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
155
209
|
var _a2;
|
|
156
210
|
const project = await helpers.getProject();
|
|
@@ -171,12 +225,11 @@ const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
|
171
225
|
});
|
|
172
226
|
};
|
|
173
227
|
const upsertSliceLibraryIndexFiles = async (context) => {
|
|
174
|
-
var _a2;
|
|
175
228
|
const project = await context.helpers.getProject();
|
|
176
229
|
if (!project.config.libraries) {
|
|
177
230
|
return;
|
|
178
231
|
}
|
|
179
|
-
await Promise.all(
|
|
232
|
+
await Promise.all(project.config.libraries.map(async (libraryID) => {
|
|
180
233
|
await upsertSliceLibraryIndexFile({ libraryID, ...context });
|
|
181
234
|
}));
|
|
182
235
|
};
|
|
@@ -185,7 +238,10 @@ const projectInit = async ({ installDependencies: _installDependencies }, contex
|
|
|
185
238
|
installDependencies({ installDependencies: _installDependencies }),
|
|
186
239
|
modifySliceMachineConfig(context),
|
|
187
240
|
createPrismicIOFile(context),
|
|
188
|
-
createSliceSimulatorPage(context)
|
|
241
|
+
createSliceSimulatorPage(context),
|
|
242
|
+
createPreviewRouteDirectory(context),
|
|
243
|
+
createPreviewRouteMatcherFile(context),
|
|
244
|
+
createRootLayoutServerFile(context)
|
|
189
245
|
]));
|
|
190
246
|
await upsertSliceLibraryIndexFiles(context);
|
|
191
247
|
};
|
|
@@ -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\";\n\nimport type { PluginOptions } from \"../types\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\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 createClientContents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcreateClientContents = source`\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 = (config: prismic.ClientConfig = {}) => {\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\treturn client;\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tcreateClientContents = source`\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 {prismic.ClientConfig} config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = (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\treturn client;\n\t\t\t};\n\t\t`;\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 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 = 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{\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${createClientContents}\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\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 = 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{\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${createClientContents}\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 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]),\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;AAuBA,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;AACD,2BAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAA,OAgBjB;AACiB,2BAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBvB;AAEG,MAAA;AAEJ,MAAI,qBAAqB;AACb,eAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AC;AAAA,IAAA,CACrC;AAEG,QAAA,aAAa,SAAS,SAAS,GAAG;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,KACbA,MAAA,QAAQ,OAAO,cAAf,gBAAAA,IAA0B,IAAI,OAAO,cAAa;AACjD,UAAM,4BAA4B,EAAE,WAAW,GAAG,QAAS,CAAA;AAAA,EAC3D,EAAC;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,EAChC,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\";\n\nimport type { PluginOptions } from \"../types\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\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 = 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 = 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;AAuBA,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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.
|
|
3
|
+
"version": "0.3.22-dev-next-release.11",
|
|
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.22-dev-next-release.
|
|
67
|
+
"@slicemachine/plugin-kit": "^0.4.22-dev-next-release.11",
|
|
68
68
|
"common-tags": "^1.8.2",
|
|
69
69
|
"fp-ts": "^2.13.1",
|
|
70
70
|
"io-ts": "^2.2.20",
|
|
@@ -109,5 +109,5 @@
|
|
|
109
109
|
"engines": {
|
|
110
110
|
"node": ">=14.15.0"
|
|
111
111
|
},
|
|
112
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "b8bcc6b163fcead72d67763ffbba6de3e8ed6bd1"
|
|
113
113
|
}
|
|
@@ -32,8 +32,6 @@ export const documentationRead: DocumentationReadHook<PluginOptions> = async (
|
|
|
32
32
|
dataFileContent = source`
|
|
33
33
|
import { createClient } from "$lib/prismicio";
|
|
34
34
|
|
|
35
|
-
export const prerender = true;
|
|
36
|
-
|
|
37
35
|
export async function load({ params, fetch }) {
|
|
38
36
|
const client = createClient({ fetch });
|
|
39
37
|
|
|
@@ -58,8 +56,6 @@ export const documentationRead: DocumentationReadHook<PluginOptions> = async (
|
|
|
58
56
|
dataFileContent = source`
|
|
59
57
|
import { createClient } from "$lib/prismicio";
|
|
60
58
|
|
|
61
|
-
export const prerender = true;
|
|
62
|
-
|
|
63
59
|
export async function load({ params, fetch }) {
|
|
64
60
|
const client = createClient({ fetch });
|
|
65
61
|
|
|
@@ -69,6 +65,10 @@ export const documentationRead: DocumentationReadHook<PluginOptions> = async (
|
|
|
69
65
|
page,
|
|
70
66
|
};
|
|
71
67
|
}
|
|
68
|
+
|
|
69
|
+
export async function entries() {
|
|
70
|
+
return [{}]
|
|
71
|
+
}
|
|
72
72
|
`;
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -49,49 +49,12 @@ const createPrismicIOFile = async ({
|
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
let createClientContents: string;
|
|
53
|
-
|
|
54
|
-
if (isTypeScriptProject) {
|
|
55
|
-
createClientContents = source`
|
|
56
|
-
/**
|
|
57
|
-
* Creates a Prismic client for the project's repository. The client is used to
|
|
58
|
-
* query content from the Prismic API.
|
|
59
|
-
*
|
|
60
|
-
* @param config - Configuration for the Prismic client.
|
|
61
|
-
*/
|
|
62
|
-
export const createClient = (config: prismic.ClientConfig = {}) => {
|
|
63
|
-
const client = prismic.createClient(repositoryName, {
|
|
64
|
-
routes,
|
|
65
|
-
...config,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return client;
|
|
69
|
-
};
|
|
70
|
-
`;
|
|
71
|
-
} else {
|
|
72
|
-
createClientContents = source`
|
|
73
|
-
/**
|
|
74
|
-
* Creates a Prismic client for the project's repository. The client is used to
|
|
75
|
-
* query content from the Prismic API.
|
|
76
|
-
*
|
|
77
|
-
* @param {prismic.ClientConfig} config - Configuration for the Prismic client.
|
|
78
|
-
*/
|
|
79
|
-
export const createClient = (config = {}) => {
|
|
80
|
-
const client = prismic.createClient(repositoryName, {
|
|
81
|
-
routes,
|
|
82
|
-
...config,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
return client;
|
|
86
|
-
};
|
|
87
|
-
`;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
52
|
let contents: string;
|
|
91
53
|
|
|
92
54
|
if (isTypeScriptProject) {
|
|
93
55
|
contents = source`
|
|
94
56
|
import * as prismic from "@prismicio/client";
|
|
57
|
+
import { CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
95
58
|
import config from "../../slicemachine.config.json";
|
|
96
59
|
|
|
97
60
|
/**
|
|
@@ -106,21 +69,38 @@ const createPrismicIOFile = async ({
|
|
|
106
69
|
*/
|
|
107
70
|
// TODO: Update the routes array to match your project's route structure.
|
|
108
71
|
const routes: prismic.ClientConfig["routes"] = [
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
72
|
+
// Examples:
|
|
73
|
+
// {
|
|
74
|
+
// type: "homepage",
|
|
75
|
+
// path: "/",
|
|
76
|
+
// },
|
|
77
|
+
// {
|
|
78
|
+
// type: "page",
|
|
79
|
+
// path: "/:uid",
|
|
80
|
+
// },
|
|
117
81
|
];
|
|
118
82
|
|
|
119
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
85
|
+
* query content from the Prismic API.
|
|
86
|
+
*
|
|
87
|
+
* @param config - Configuration for the Prismic client.
|
|
88
|
+
*/
|
|
89
|
+
export const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {
|
|
90
|
+
const client = prismic.createClient(repositoryName, {
|
|
91
|
+
routes,
|
|
92
|
+
...config,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
enableAutoPreviews({ client, cookies });
|
|
96
|
+
|
|
97
|
+
return client;
|
|
98
|
+
};
|
|
120
99
|
`;
|
|
121
100
|
} else {
|
|
122
101
|
contents = source`
|
|
123
102
|
import * as prismic from "@prismicio/client";
|
|
103
|
+
import { enableAutoPreviews } from '@prismicio/svelte/kit';
|
|
124
104
|
import config from "../../slicemachine.config.json";
|
|
125
105
|
|
|
126
106
|
/**
|
|
@@ -137,17 +117,33 @@ const createPrismicIOFile = async ({
|
|
|
137
117
|
*/
|
|
138
118
|
// TODO: Update the routes array to match your project's route structure.
|
|
139
119
|
const routes = [
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
120
|
+
// Examples:
|
|
121
|
+
// {
|
|
122
|
+
// type: "homepage",
|
|
123
|
+
// path: "/",
|
|
124
|
+
// },
|
|
125
|
+
// {
|
|
126
|
+
// type: "page",
|
|
127
|
+
// path: "/:uid",
|
|
128
|
+
// },
|
|
148
129
|
];
|
|
149
130
|
|
|
150
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
133
|
+
* query content from the Prismic API.
|
|
134
|
+
*
|
|
135
|
+
* @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.
|
|
136
|
+
*/
|
|
137
|
+
export const createClient = ({ cookies, ...config } = {}) => {
|
|
138
|
+
const client = prismic.createClient(repositoryName, {
|
|
139
|
+
routes,
|
|
140
|
+
...config,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
enableAutoPreviews({ client, cookies });
|
|
144
|
+
|
|
145
|
+
return client;
|
|
146
|
+
};
|
|
151
147
|
`;
|
|
152
148
|
}
|
|
153
149
|
|
|
@@ -200,6 +196,88 @@ const createSliceSimulatorPage = async ({
|
|
|
200
196
|
});
|
|
201
197
|
};
|
|
202
198
|
|
|
199
|
+
const createPreviewRouteMatcherFile = async ({
|
|
200
|
+
helpers,
|
|
201
|
+
options,
|
|
202
|
+
}: SliceMachineContext<PluginOptions>) => {
|
|
203
|
+
const extension = await getJSFileExtension({ helpers, options });
|
|
204
|
+
const filename = path.join(`src/params/preview.${extension}`);
|
|
205
|
+
|
|
206
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const contents = source`
|
|
211
|
+
export function match(param) {
|
|
212
|
+
return param === 'preview';
|
|
213
|
+
}
|
|
214
|
+
`;
|
|
215
|
+
|
|
216
|
+
await writeProjectFile({
|
|
217
|
+
filename,
|
|
218
|
+
contents,
|
|
219
|
+
format: options.format,
|
|
220
|
+
helpers,
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const createPreviewRouteDirectory = async ({
|
|
225
|
+
helpers,
|
|
226
|
+
options,
|
|
227
|
+
}: SliceMachineContext<PluginOptions>) => {
|
|
228
|
+
const filename = path.join(
|
|
229
|
+
"src",
|
|
230
|
+
"routes",
|
|
231
|
+
"[[preview=preview]]",
|
|
232
|
+
"README.md",
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const contents = source`
|
|
240
|
+
This directory adds support for optional \`/preview\` routes. Do not remove this directory.
|
|
241
|
+
|
|
242
|
+
All routes within this directory will be served using the following URLs:
|
|
243
|
+
|
|
244
|
+
- \`/example-route\` (prerendered)
|
|
245
|
+
- \`/preview/example-route\` (server-rendered)
|
|
246
|
+
|
|
247
|
+
See <https://prismic.io/docs/svelte-preview> for more information.
|
|
248
|
+
`;
|
|
249
|
+
|
|
250
|
+
await writeProjectFile({
|
|
251
|
+
filename,
|
|
252
|
+
contents,
|
|
253
|
+
format: options.format,
|
|
254
|
+
helpers,
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const createRootLayoutServerFile = async ({
|
|
259
|
+
helpers,
|
|
260
|
+
options,
|
|
261
|
+
}: SliceMachineContext<PluginOptions>) => {
|
|
262
|
+
const extension = await getJSFileExtension({ helpers, options });
|
|
263
|
+
const filename = path.join(`src/routes/+layout.server.${extension}`);
|
|
264
|
+
|
|
265
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const contents = source`
|
|
270
|
+
export const prerender = "auto";
|
|
271
|
+
`;
|
|
272
|
+
|
|
273
|
+
await writeProjectFile({
|
|
274
|
+
filename,
|
|
275
|
+
contents,
|
|
276
|
+
format: options.format,
|
|
277
|
+
helpers,
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
|
|
203
281
|
const modifySliceMachineConfig = async ({
|
|
204
282
|
helpers,
|
|
205
283
|
options,
|
|
@@ -251,7 +329,7 @@ const upsertSliceLibraryIndexFiles = async (
|
|
|
251
329
|
}
|
|
252
330
|
|
|
253
331
|
await Promise.all(
|
|
254
|
-
project.config.libraries
|
|
332
|
+
project.config.libraries.map(async (libraryID) => {
|
|
255
333
|
await upsertSliceLibraryIndexFile({ libraryID, ...context });
|
|
256
334
|
}),
|
|
257
335
|
);
|
|
@@ -267,6 +345,9 @@ export const projectInit: ProjectInitHook<PluginOptions> = async (
|
|
|
267
345
|
modifySliceMachineConfig(context),
|
|
268
346
|
createPrismicIOFile(context),
|
|
269
347
|
createSliceSimulatorPage(context),
|
|
348
|
+
createPreviewRouteDirectory(context),
|
|
349
|
+
createPreviewRouteMatcherFile(context),
|
|
350
|
+
createRootLayoutServerFile(context),
|
|
270
351
|
]),
|
|
271
352
|
);
|
|
272
353
|
|