@prismicio/adapter-sveltekit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/constants.d.ts +4 -0
  2. package/dist/constants.js +5 -0
  3. package/dist/constants.js.map +1 -0
  4. package/dist/hooks/project-init.d.ts +3 -0
  5. package/dist/hooks/project-init.js +195 -0
  6. package/dist/hooks/project-init.js.map +1 -0
  7. package/dist/hooks/project-init.templates.d.ts +9 -0
  8. package/dist/hooks/project-init.templates.js +171 -0
  9. package/dist/hooks/project-init.templates.js.map +1 -0
  10. package/dist/hooks/slice-create.d.ts +3 -0
  11. package/dist/hooks/slice-create.js +53 -0
  12. package/dist/hooks/slice-create.js.map +1 -0
  13. package/dist/hooks/slice-create.templates.d.ts +6 -0
  14. package/dist/hooks/slice-create.templates.js +40 -0
  15. package/dist/hooks/slice-create.templates.js.map +1 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +5 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/lib/checkIsTypeScriptProject.d.ts +8 -0
  20. package/dist/lib/checkIsTypeScriptProject.js +8 -0
  21. package/dist/lib/checkIsTypeScriptProject.js.map +1 -0
  22. package/dist/lib/getJSFileExtension.d.ts +5 -0
  23. package/dist/lib/getJSFileExtension.js +12 -0
  24. package/dist/lib/getJSFileExtension.js.map +1 -0
  25. package/dist/lib/getSvelteMajor.d.ts +1 -0
  26. package/dist/lib/getSvelteMajor.js +16 -0
  27. package/dist/lib/getSvelteMajor.js.map +1 -0
  28. package/dist/lib/pascalCase.d.ts +8 -0
  29. package/dist/lib/pascalCase.js +8 -0
  30. package/dist/lib/pascalCase.js.map +1 -0
  31. package/dist/lib/rejectIfNecessary.d.ts +1 -0
  32. package/dist/lib/rejectIfNecessary.js +10 -0
  33. package/dist/lib/rejectIfNecessary.js.map +1 -0
  34. package/dist/lib/requireResolve.d.ts +10 -0
  35. package/dist/lib/requireResolve.js +16 -0
  36. package/dist/lib/requireResolve.js.map +1 -0
  37. package/dist/lib/upsertSliceLibraryIndexFile.d.ts +7 -0
  38. package/dist/lib/upsertSliceLibraryIndexFile.js +50 -0
  39. package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -0
  40. package/dist/package.json.js +5 -0
  41. package/dist/package.json.js.map +1 -0
  42. package/dist/plugin.d.ts +2 -0
  43. package/dist/plugin.js +144 -0
  44. package/dist/plugin.js.map +1 -0
  45. package/dist/types.d.ts +28 -0
  46. package/package.json +95 -0
  47. package/src/constants.ts +5 -0
  48. package/src/hooks/project-init.templates.ts +173 -0
  49. package/src/hooks/project-init.ts +315 -0
  50. package/src/hooks/slice-create.templates.ts +82 -0
  51. package/src/hooks/slice-create.ts +84 -0
  52. package/src/index.ts +3 -0
  53. package/src/lib/checkIsTypeScriptProject.ts +18 -0
  54. package/src/lib/getJSFileExtension.ts +22 -0
  55. package/src/lib/getSvelteMajor.ts +23 -0
  56. package/src/lib/pascalCase.ts +12 -0
  57. package/src/lib/rejectIfNecessary.ts +16 -0
  58. package/src/lib/requireResolve.ts +30 -0
  59. package/src/lib/upsertSliceLibraryIndexFile.ts +78 -0
  60. package/src/plugin.ts +190 -0
  61. package/src/types.ts +31 -0
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Banner text added to files that should not be edited by users.
3
+ */
4
+ export declare const NON_EDITABLE_FILE_BANNER = "// Code generated by Prismic. DO NOT EDIT.";
@@ -0,0 +1,5 @@
1
+ const NON_EDITABLE_FILE_BANNER = "// Code generated by Prismic. DO NOT EDIT.";
2
+ export {
3
+ NON_EDITABLE_FILE_BANNER
4
+ };
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["/**\n * Banner text added to files that should not be edited by users.\n */\nexport const NON_EDITABLE_FILE_BANNER =\n\t\"// Code generated by Prismic. DO NOT EDIT.\";\n"],"names":[],"mappings":"AAGO,MAAM,2BACZ;"}
@@ -0,0 +1,3 @@
1
+ import type { ProjectInitHook } from "@prismicio/plugin-kit";
2
+ import type { PluginOptions } from "../types.js";
3
+ export declare const projectInit: ProjectInitHook<PluginOptions>;
@@ -0,0 +1,195 @@
1
+ import * as path from "node:path";
2
+ import { checkHasProjectFile, writeProjectFile } from "@prismicio/plugin-kit/fs";
3
+ import { source } from "common-tags";
4
+ import { loadFile } from "magicast";
5
+ import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
6
+ import { getJSFileExtension } from "../lib/getJSFileExtension.js";
7
+ import { getSvelteMajor } from "../lib/getSvelteMajor.js";
8
+ import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
9
+ import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
10
+ import { prismicIOFileTemplate, previewAPIRouteTemplate, rootLayoutTemplate } from "./project-init.templates.js";
11
+ const installDependencies = async ({ installDependencies: installDependencies2 }) => {
12
+ await installDependencies2({
13
+ dependencies: {
14
+ "@prismicio/client": "latest",
15
+ "@prismicio/svelte": "latest"
16
+ }
17
+ });
18
+ };
19
+ const createPrismicIOFile = async ({ helpers, options }) => {
20
+ const extension = await getJSFileExtension({ helpers, options });
21
+ const filename = path.join(`src/lib/prismicio.${extension}`);
22
+ if (await checkHasProjectFile({ filename, helpers })) {
23
+ return;
24
+ }
25
+ const typescript = await checkIsTypeScriptProject({ helpers, options });
26
+ const contents = prismicIOFileTemplate({ typescript });
27
+ await writeProjectFile({
28
+ filename,
29
+ contents,
30
+ format: options.format,
31
+ helpers
32
+ });
33
+ };
34
+ const createPreviewRouteMatcherFile = async ({ helpers, options }) => {
35
+ const extension = await getJSFileExtension({ helpers, options });
36
+ const filename = path.join(`src/params/preview.${extension}`);
37
+ if (await checkHasProjectFile({ filename, helpers })) {
38
+ return;
39
+ }
40
+ const contents = source`
41
+ export function match(param) {
42
+ return param === 'preview';
43
+ }
44
+ `;
45
+ await writeProjectFile({
46
+ filename,
47
+ contents,
48
+ format: options.format,
49
+ helpers
50
+ });
51
+ };
52
+ const createPreviewAPIRoute = async ({ helpers, options }) => {
53
+ const extension = await getJSFileExtension({ helpers, options });
54
+ const filename = path.join("src", "routes", "api", "preview", `+server.${extension}`);
55
+ if (await checkHasProjectFile({ filename, helpers })) {
56
+ return;
57
+ }
58
+ const typescript = await checkIsTypeScriptProject({ helpers, options });
59
+ const contents = previewAPIRouteTemplate({ typescript });
60
+ await writeProjectFile({
61
+ filename,
62
+ contents,
63
+ format: options.format,
64
+ helpers
65
+ });
66
+ };
67
+ const createPreviewRouteDirectory = async ({ helpers, options }) => {
68
+ const filename = path.join("src", "routes", "[[preview=preview]]", "README.md");
69
+ if (await checkHasProjectFile({ filename, helpers })) {
70
+ return;
71
+ }
72
+ const contents = source`
73
+ This directory adds support for optional \`/preview\` routes. Do not remove this directory.
74
+
75
+ All routes within this directory will be served using the following URLs:
76
+
77
+ - \`/example-route\` (prerendered)
78
+ - \`/preview/example-route\` (server-rendered)
79
+
80
+ See <https://prismic.io/docs/svelte-preview> for more information.
81
+ `;
82
+ await writeProjectFile({
83
+ filename,
84
+ contents,
85
+ format: options.format,
86
+ helpers
87
+ });
88
+ };
89
+ const createRootLayoutServerFile = async ({ helpers, options }) => {
90
+ const extension = await getJSFileExtension({ helpers, options });
91
+ const filename = path.join(`src/routes/+layout.server.${extension}`);
92
+ if (await checkHasProjectFile({ filename, helpers })) {
93
+ return;
94
+ }
95
+ const contents = source`
96
+ export const prerender = "auto";
97
+ `;
98
+ await writeProjectFile({
99
+ filename,
100
+ contents,
101
+ format: options.format,
102
+ helpers
103
+ });
104
+ };
105
+ const createRootLayoutFile = async ({ helpers, options }) => {
106
+ const filename = path.join("src", "routes", "+layout.svelte");
107
+ if (await checkHasProjectFile({ filename, helpers })) {
108
+ return;
109
+ }
110
+ const contents = rootLayoutTemplate({ version: await getSvelteMajor() });
111
+ await writeProjectFile({
112
+ filename,
113
+ contents,
114
+ format: options.format,
115
+ formatOptions: {
116
+ prettier: {
117
+ plugins: ["prettier-plugin-svelte"],
118
+ parser: "svelte"
119
+ }
120
+ },
121
+ helpers
122
+ });
123
+ };
124
+ const modifyPrismicConfig = async ({ helpers, options, actions }) => {
125
+ const project = await helpers.getProject();
126
+ if (await checkHasProjectFile({
127
+ filename: "./src/lib",
128
+ helpers
129
+ }) && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
130
+ const sliceLibrary = await actions.readSliceLibrary({
131
+ libraryID: project.config.libraries[0]
132
+ });
133
+ if (sliceLibrary.sliceIDs.length < 1) {
134
+ project.config.libraries = ["./src/lib/slices"];
135
+ }
136
+ }
137
+ await helpers.updatePrismicConfig(project.config, {
138
+ format: options.format
139
+ });
140
+ };
141
+ const upsertSliceLibraryIndexFiles = async (context) => {
142
+ const project = await context.helpers.getProject();
143
+ if (!project.config.libraries) {
144
+ return;
145
+ }
146
+ await Promise.all(project.config.libraries.map(async (libraryID) => {
147
+ await upsertSliceLibraryIndexFile({ libraryID, ...context });
148
+ }));
149
+ };
150
+ const modifyViteConfig = async ({ helpers, options }) => {
151
+ let filename = "vite.config.js";
152
+ if (!await checkHasProjectFile({ filename, helpers })) {
153
+ filename = "vite.config.ts";
154
+ }
155
+ if (!await checkHasProjectFile({ filename, helpers })) {
156
+ return;
157
+ }
158
+ const filepath = helpers.joinPathFromRoot(filename);
159
+ const mod = await loadFile(filepath);
160
+ if (mod.exports.default.$type !== "function-call") {
161
+ return;
162
+ }
163
+ const config = mod.exports.default.$args[0];
164
+ config.server ??= {};
165
+ config.server.fs ??= {};
166
+ config.server.fs.allow ??= [];
167
+ if (!config.server.fs.allow.includes("./prismic.config.json")) {
168
+ config.server.fs.allow.push("./prismic.config.json");
169
+ }
170
+ const contents = mod.generate().code.replace(/\n\s*\n(?=\s*server:)/, "\n");
171
+ await writeProjectFile({
172
+ filename,
173
+ contents,
174
+ format: options.format,
175
+ helpers
176
+ });
177
+ };
178
+ const projectInit = async ({ installDependencies: _installDependencies }, context) => {
179
+ rejectIfNecessary(await Promise.allSettled([
180
+ installDependencies({ installDependencies: _installDependencies }),
181
+ modifyPrismicConfig(context),
182
+ createPrismicIOFile(context),
183
+ createPreviewAPIRoute(context),
184
+ createPreviewRouteDirectory(context),
185
+ createPreviewRouteMatcherFile(context),
186
+ createRootLayoutServerFile(context),
187
+ createRootLayoutFile(context),
188
+ modifyViteConfig(context)
189
+ ]));
190
+ await upsertSliceLibraryIndexFiles(context);
191
+ };
192
+ export {
193
+ projectInit
194
+ };
195
+ //# sourceMappingURL=project-init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-init.js","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tPluginSystemContext,\n} from \"@prismicio/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@prismicio/plugin-kit/fs\";\nimport { source } from \"common-tags\";\nimport { loadFile } from \"magicast\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\nimport { getSvelteMajor } from \"../lib/getSvelteMajor\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\nimport type { PluginOptions } from \"../types\";\n\nimport {\n\tpreviewAPIRouteTemplate,\n\tprismicIOFileTemplate,\n\trootLayoutTemplate,\n} from \"./project-init.templates\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/svelte\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = PluginSystemContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/lib/prismicio.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst typescript = await checkIsTypeScriptProject({ helpers, options });\n\tconst contents = prismicIOFileTemplate({ typescript });\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewRouteMatcherFile = async ({\n\thelpers,\n\toptions,\n}: PluginSystemContext<PluginOptions>) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/params/preview.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\texport function match(param) {\n\t\t\treturn param === 'preview';\n\t\t}\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewAPIRoute = async ({\n\thelpers,\n\toptions,\n}: PluginSystemContext<PluginOptions>) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"api\",\n\t\t\"preview\",\n\t\t`+server.${extension}`,\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst typescript = await checkIsTypeScriptProject({ helpers, options });\n\tconst contents = previewAPIRouteTemplate({ typescript });\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewRouteDirectory = async ({\n\thelpers,\n\toptions,\n}: PluginSystemContext<PluginOptions>) => {\n\tconst filename = path.join(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"[[preview=preview]]\",\n\t\t\"README.md\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\tThis directory adds support for optional \\`/preview\\` routes. Do not remove this directory.\n\n\t\tAll routes within this directory will be served using the following URLs:\n\n\t\t- \\`/example-route\\` (prerendered)\n\t\t- \\`/preview/example-route\\` (server-rendered)\n\n\t\tSee <https://prismic.io/docs/svelte-preview> for more information.\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createRootLayoutServerFile = async ({\n\thelpers,\n\toptions,\n}: PluginSystemContext<PluginOptions>) => {\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/routes/+layout.server.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\texport const prerender = \"auto\";\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createRootLayoutFile = async ({\n\thelpers,\n\toptions,\n}: PluginSystemContext<PluginOptions>) => {\n\tconst filename = path.join(\"src\", \"routes\", \"+layout.svelte\");\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = rootLayoutTemplate({ version: await getSvelteMajor() });\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\tformatOptions: {\n\t\t\tprettier: {\n\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t\thelpers,\n\t});\n};\n\nconst modifyPrismicConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: PluginSystemContext<PluginOptions>) => {\n\tconst project = await helpers.getProject();\n\n\t// Nest the default Slice Library in the src directory if it exists and\n\t// is empty.\n\tif (\n\t\t(await checkHasProjectFile({\n\t\t\tfilename: \"./src/lib\",\n\t\t\thelpers,\n\t\t})) &&\n\t\tproject.config.libraries &&\n\t\tJSON.stringify(project.config.libraries) === JSON.stringify([\"./slices\"])\n\t) {\n\t\tconst sliceLibrary = await actions.readSliceLibrary({\n\t\t\tlibraryID: project.config.libraries[0],\n\t\t});\n\n\t\tif (sliceLibrary.sliceIDs.length < 1) {\n\t\t\tproject.config.libraries = [\"./src/lib/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updatePrismicConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst upsertSliceLibraryIndexFiles = async (\n\tcontext: PluginSystemContext<PluginOptions>,\n) => {\n\t// We must use the `getProject()` helper to get the latest version of\n\t// the project config. The config may have been modified in\n\t// `modifyPrismicConfig()` and will not be reflected in\n\t// `context.project`.\n\tconst project = await context.helpers.getProject();\n\n\tif (!project.config.libraries) {\n\t\treturn;\n\t}\n\n\tawait Promise.all(\n\t\tproject.config.libraries.map(async (libraryID) => {\n\t\t\tawait upsertSliceLibraryIndexFile({ libraryID, ...context });\n\t\t}),\n\t);\n};\n\nconst modifyViteConfig = async ({\n\thelpers,\n\toptions,\n}: PluginSystemContext<PluginOptions>) => {\n\tlet filename = \"vite.config.js\";\n\tif (!(await checkHasProjectFile({ filename, helpers }))) {\n\t\tfilename = \"vite.config.ts\";\n\t}\n\tif (!(await checkHasProjectFile({ filename, helpers }))) {\n\t\t// Couldn't find the config file.\n\t\treturn;\n\t}\n\tconst filepath = helpers.joinPathFromRoot(filename);\n\n\tconst mod = await loadFile(filepath);\n\tif (mod.exports.default.$type !== \"function-call\") {\n\t\t// Invalid config file.\n\t\treturn;\n\t}\n\n\t// Add `./prismic.config.json` to allowed files.\n\tconst config = mod.exports.default.$args[0];\n\tconfig.server ??= {};\n\tconfig.server.fs ??= {};\n\tconfig.server.fs.allow ??= [];\n\tif (!config.server.fs.allow.includes(\"./prismic.config.json\")) {\n\t\tconfig.server.fs.allow.push(\"./prismic.config.json\");\n\t}\n\n\t// Remove an empty line above the `server` property.\n\tconst contents = mod.generate().code.replace(/\\n\\s*\\n(?=\\s*server:)/, \"\\n\");\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nexport const projectInit: ProjectInitHook<PluginOptions> = async (\n\t{ installDependencies: _installDependencies },\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tinstallDependencies({ installDependencies: _installDependencies }),\n\t\t\tmodifyPrismicConfig(context),\n\t\t\tcreatePrismicIOFile(context),\n\t\t\tcreatePreviewAPIRoute(context),\n\t\t\tcreatePreviewRouteDirectory(context),\n\t\t\tcreatePreviewRouteMatcherFile(context),\n\t\t\tcreateRootLayoutServerFile(context),\n\t\t\tcreateRootLayoutFile(context),\n\t\t\tmodifyViteConfig(context),\n\t\t]),\n\t);\n\n\t// This must happen after `modifyPrismicConfig()` since the\n\t// location of the default Slice library may change.\n\tawait upsertSliceLibraryIndexFiles(context);\n};\n"],"names":["installDependencies"],"mappings":";;;;;;;;;;AA+BA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,qBAAqB;AAAA,IAAA;AAAA,EACrB,CACD;AACF;AAIA,MAAM,sBAAsB,OAAO,EAClC,SACA,cAC6B;AAC7B,QAAM,YAAY,MAAM,mBAAmB,EAAE,SAAS,SAAS;AAC/D,QAAM,WAAW,KAAK,KAAK,qBAAqB,SAAS,EAAE;AAE3D,MAAI,MAAM,oBAAoB,EAAE,UAAU,QAAA,CAAS,GAAG;AACrD;AAAA,EACD;AAEA,QAAM,aAAa,MAAM,yBAAyB,EAAE,SAAS,SAAS;AACtE,QAAM,WAAW,sBAAsB,EAAE,YAAY;AAErD,QAAM,iBAAiB;AAAA,IACtB;AAAA,IACA;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB;AAAA,EAAA,CACA;AACF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AAoB,OAAO;AAAA,IAC3B,oBAAoB,OAAO;AAAA,IAC3B,sBAAsB,OAAO;AAAA,IAC7B,4BAA4B,OAAO;AAAA,IACnC,8BAA8B,OAAO;AAAA,IACrC,2BAA2B,OAAO;AAAA,IAClC,qBAAqB,OAAO;AAAA,IAC5B,iBAAiB,OAAO;AAAA,EAAA,CACxB,CAAC;AAKH,QAAM,6BAA6B,OAAO;AAC3C;"}
@@ -0,0 +1,9 @@
1
+ export declare function prismicIOFileTemplate(args: {
2
+ typescript: boolean;
3
+ }): string;
4
+ export declare function previewAPIRouteTemplate(args: {
5
+ typescript: boolean;
6
+ }): string;
7
+ export declare function rootLayoutTemplate(args: {
8
+ version: number;
9
+ }): string;
@@ -0,0 +1,171 @@
1
+ import { source } from "common-tags";
2
+ var __freeze = Object.freeze;
3
+ var __defProp = Object.defineProperty;
4
+ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(cooked.slice()) }));
5
+ var _a, _b;
6
+ function prismicIOFileTemplate(args) {
7
+ const { typescript } = args;
8
+ const TS = source`
9
+ import { createClient as baseCreateClient, type Route } from "@prismicio/client";
10
+ import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
11
+ import prismicConfig from "../../prismic.config.json";
12
+
13
+ /**
14
+ * The project's Prismic repository name.
15
+ */
16
+ export const repositoryName = prismicConfig.repositoryName;
17
+
18
+ /**
19
+ * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
20
+ *
21
+ * {@link https://prismic.io/docs/route-resolver}
22
+ */
23
+ // TODO: Update the routes array to match your project's route structure.
24
+ const routes: Route[] = [
25
+ // Examples:
26
+ // { type: "homepage", path: "/" },
27
+ // { type: "page", path: "/:uid" },
28
+ ];
29
+
30
+ /**
31
+ * Creates a Prismic client for the project's repository. The client is used to
32
+ * query content from the Prismic API.
33
+ *
34
+ * @param config - Configuration for the Prismic client.
35
+ */
36
+ export const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {
37
+ const client = baseCreateClient(repositoryName, {
38
+ routes,
39
+ ...config,
40
+ });
41
+
42
+ enableAutoPreviews({ client, cookies });
43
+
44
+ return client;
45
+ };
46
+ `;
47
+ const JS = source`
48
+ import { createClient as baseCreateClient } from "@prismicio/client";
49
+ import { enableAutoPreviews } from '@prismicio/svelte/kit';
50
+ import prismicConfig from "../../prismic.config.json";
51
+
52
+ /**
53
+ * The project's Prismic repository name.
54
+ */
55
+ export const repositoryName = prismicConfig.repositoryName;
56
+
57
+ /**
58
+ * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
59
+ *
60
+ * {@link https://prismic.io/docs/route-resolver#route-resolver}
61
+ *
62
+ * @type {import("@prismicio/client").Route[]}
63
+ */
64
+ // TODO: Update the routes array to match your project's route structure.
65
+ const routes = [
66
+ // Examples:
67
+ // { type: "homepage", path: "/" },
68
+ // { type: "page", path: "/:uid" },
69
+ ];
70
+
71
+ /**
72
+ * Creates a Prismic client for the project's repository. The client is used to
73
+ * query content from the Prismic API.
74
+ *
75
+ * @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.
76
+ */
77
+ export const createClient = ({ cookies, ...config } = {}) => {
78
+ const client = prismic.createClient(repositoryName, {
79
+ routes,
80
+ ...config,
81
+ });
82
+
83
+ enableAutoPreviews({ client, cookies });
84
+
85
+ return client;
86
+ };
87
+ `;
88
+ return typescript ? TS : JS;
89
+ }
90
+ function previewAPIRouteTemplate(args) {
91
+ const { typescript } = args;
92
+ const TS = source`
93
+ import { redirectToPreviewURL } from '@prismicio/svelte/kit';
94
+ import { createClient } from '$lib/prismicio';
95
+ import type { RequestHandler } from "./$types";
96
+
97
+ export const GET: RequestHandler = async ({ fetch, request, cookies }) => {
98
+ const client = createClient({ fetch });
99
+
100
+ return await redirectToPreviewURL({ client, request, cookies });
101
+ }
102
+ `;
103
+ const JS = source`
104
+ import { redirectToPreviewURL } from '@prismicio/svelte/kit';
105
+ import { createClient } from '$lib/prismicio';
106
+
107
+ /* @type {import("./$types").RequestHandler} */
108
+ export async function GET({ fetch, request, cookies }) {
109
+ const client = createClient({ fetch });
110
+
111
+ return await redirectToPreviewURL({ client, request, cookies });
112
+ }
113
+ `;
114
+ return typescript ? TS : JS;
115
+ }
116
+ function rootLayoutTemplate(args) {
117
+ const { version } = args;
118
+ const v5 = source(_a || (_a = __template([`
119
+ <script>
120
+ import { isFilled, asImageSrc } from '@prismicio/client';
121
+ import { PrismicPreview } from '@prismicio/svelte/kit';
122
+ import { page } from '$app/state';
123
+ import { repositoryName } from '$lib/prismicio';
124
+
125
+ const { children } = $props();
126
+ <\/script>
127
+
128
+ <svelte:head>
129
+ <title>{page.data.page?.data.meta_title}</title>
130
+ <meta property="og:title" content={page.data.page?.data.meta_title} />
131
+ {#if isFilled.keyText(page.data.page?.data.meta_description)}
132
+ <meta name="description" content={page.data.page.data.meta_description} />
133
+ <meta property="og:description" content={page.data.page.data.meta_description} />
134
+ {/if}
135
+ {#if isFilled.image(page.data.page?.data.meta_image)}
136
+ <meta property="og:image" content={asImageSrc(page.data.page.data.meta_image)} />
137
+ {/if}
138
+ </svelte:head>
139
+ {@render children()}
140
+ <PrismicPreview {repositoryName} />
141
+ `])));
142
+ const v4 = source(_b || (_b = __template([`
143
+ <script>
144
+ import { isFilled, asImageSrc } from '@prismicio/client';
145
+ import { PrismicPreview } from '@prismicio/svelte/kit';
146
+ import { page } from '$app/state';
147
+ import { repositoryName } from '$lib/prismicio';
148
+ <\/script>
149
+
150
+ <svelte:head>
151
+ <title>{page.data.page?.data.meta_title}</title>
152
+ <meta property="og:title" content={page.data.page?.data.meta_title} />
153
+ {#if isFilled.keyText(page.data.page?.data.meta_description)}
154
+ <meta name="description" content={page.data.page.data.meta_description} />
155
+ <meta property="og:description" content={page.data.page.data.meta_description} />
156
+ {/if}
157
+ {#if isFilled.image(page.data.page?.data.meta_image)}
158
+ <meta property="og:image" content={asImageSrc(page.data.page.data.meta_image)} />
159
+ {/if}
160
+ </svelte:head>
161
+ <slot />
162
+ <PrismicPreview {repositoryName} />
163
+ `])));
164
+ return version <= 4 ? v4 : v5;
165
+ }
166
+ export {
167
+ previewAPIRouteTemplate,
168
+ prismicIOFileTemplate,
169
+ rootLayoutTemplate
170
+ };
171
+ //# sourceMappingURL=project-init.templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-init.templates.js","sources":["../../../src/hooks/project-init.templates.ts"],"sourcesContent":["import { source as svelte, source as ts, source as js } from \"common-tags\";\n\nexport function prismicIOFileTemplate(args: { typescript: boolean }): string {\n\tconst { typescript } = args;\n\n\tconst TS = ts`\n\t\timport { createClient as baseCreateClient, type Route } from \"@prismicio/client\";\n\t\timport { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';\n\t\timport prismicConfig from \"../../prismic.config.json\";\n\n\t\t/**\n\t\t * The project's Prismic repository name.\n\t\t */\n\t\texport const repositoryName = prismicConfig.repositoryName;\n\n\t\t/**\n\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t *\n\t\t * {@link https://prismic.io/docs/route-resolver}\n\t\t */\n\t\t// TODO: Update the routes array to match your project's route structure.\n\t\tconst routes: Route[] = [\n\t\t\t// Examples:\n\t\t\t// { type: \"homepage\", path: \"/\" },\n\t\t\t// { type: \"page\", path: \"/:uid\" },\n\t\t];\n\n\t\t/**\n\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t * query content from the Prismic API.\n\t\t *\n\t\t * @param config - Configuration for the Prismic client.\n\t\t */\n\t\texport const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {\n\t\t\tconst client = baseCreateClient(repositoryName, {\n\t\t\t\troutes,\n\t\t\t\t...config,\n\t\t\t});\n\n\t\t\tenableAutoPreviews({ client, cookies });\n\n\t\t\treturn client;\n\t\t};\n\t`;\n\n\tconst JS = js`\n\t\timport { createClient as baseCreateClient } from \"@prismicio/client\";\n\t\timport { enableAutoPreviews } from '@prismicio/svelte/kit';\n\t\timport prismicConfig from \"../../prismic.config.json\";\n\n\t\t/**\n\t\t * The project's Prismic repository name.\n\t\t */\n\t\texport const repositoryName = prismicConfig.repositoryName;\n\n\t\t/**\n\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t *\n\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t *\n\t\t * @type {import(\"@prismicio/client\").Route[]}\n\t\t */\n\t\t// TODO: Update the routes array to match your project's route structure.\n\t\tconst routes = [\n\t\t\t// Examples:\n\t\t\t// { type: \"homepage\", path: \"/\" },\n\t\t\t// { type: \"page\", path: \"/:uid\" },\n\t\t];\n\n\t\t/**\n\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t * query content from the Prismic API.\n\t\t *\n\t\t * @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.\n\t\t */\n\t\texport const createClient = ({ cookies, ...config } = {}) => {\n\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\troutes,\n\t\t\t\t...config,\n\t\t\t});\n\n\t\t\tenableAutoPreviews({ client, cookies });\n\n\t\t\treturn client;\n\t\t};\n\t`;\n\n\treturn typescript ? TS : JS;\n}\n\nexport function previewAPIRouteTemplate(args: { typescript: boolean }): string {\n\tconst { typescript } = args;\n\n\tconst TS = ts`\n\t\timport { redirectToPreviewURL } from '@prismicio/svelte/kit';\n\t\timport { createClient } from '$lib/prismicio';\n\t\timport type { RequestHandler } from \"./$types\";\n\n\t\texport const GET: RequestHandler = async ({ fetch, request, cookies }) => {\n\t\t\tconst client = createClient({ fetch });\n\n\t\t\treturn await redirectToPreviewURL({ client, request, cookies });\n\t\t}\n\t`;\n\n\tconst JS = js`\n\t\timport { redirectToPreviewURL } from '@prismicio/svelte/kit';\n\t\timport { createClient } from '$lib/prismicio';\n\n\t\t/* @type {import(\"./$types\").RequestHandler} */\n\t\texport async function GET({ fetch, request, cookies }) {\n\t\t\tconst client = createClient({ fetch });\n\n\t\t\treturn await redirectToPreviewURL({ client, request, cookies });\n\t\t}\n\t`;\n\n\treturn typescript ? TS : JS;\n}\n\nexport function rootLayoutTemplate(args: { version: number }): string {\n\tconst { version } = args;\n\n\tconst v5 = svelte`\n\t\t<script>\n\t\t\timport { isFilled, asImageSrc } from '@prismicio/client';\n\t\t\timport { PrismicPreview } from '@prismicio/svelte/kit';\n\t\t\timport { page } from '$app/state';\n\t\t\timport { repositoryName } from '$lib/prismicio';\n\n\t\t\tconst { children } = $props();\n\t\t</script>\n\n\t\t<svelte:head>\n\t\t\t<title>{page.data.page?.data.meta_title}</title>\n\t\t\t<meta property=\"og:title\" content={page.data.page?.data.meta_title} />\n\t\t\t{#if isFilled.keyText(page.data.page?.data.meta_description)}\n\t\t\t\t<meta name=\"description\" content={page.data.page.data.meta_description} />\n\t\t\t\t<meta property=\"og:description\" content={page.data.page.data.meta_description} />\n\t\t\t{/if}\n\t\t\t{#if isFilled.image(page.data.page?.data.meta_image)}\n\t\t\t\t<meta property=\"og:image\" content={asImageSrc(page.data.page.data.meta_image)} />\n\t\t\t{/if}\n\t\t</svelte:head>\n\t\t{@render children()}\n\t\t<PrismicPreview {repositoryName} />\n\t`;\n\n\tconst v4 = svelte`\n\t\t<script>\n\t\t\timport { isFilled, asImageSrc } from '@prismicio/client';\n\t\t\timport { PrismicPreview } from '@prismicio/svelte/kit';\n\t\t\timport { page } from '$app/state';\n\t\t\timport { repositoryName } from '$lib/prismicio';\n\t\t</script>\n\n\t\t<svelte:head>\n\t\t\t<title>{page.data.page?.data.meta_title}</title>\n\t\t\t<meta property=\"og:title\" content={page.data.page?.data.meta_title} />\n\t\t\t{#if isFilled.keyText(page.data.page?.data.meta_description)}\n\t\t\t\t<meta name=\"description\" content={page.data.page.data.meta_description} />\n\t\t\t\t<meta property=\"og:description\" content={page.data.page.data.meta_description} />\n\t\t\t{/if}\n\t\t\t{#if isFilled.image(page.data.page?.data.meta_image)}\n\t\t\t\t<meta property=\"og:image\" content={asImageSrc(page.data.page.data.meta_image)} />\n\t\t\t{/if}\n\t\t</svelte:head>\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAA,CAAA,EAAA;AAyBjB,QAAM,KAAKA,OAAA,OAAA,KAAM,WAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAA,CAAA,EAAA;AAuBjB,SAAO,WAAW,IAAI,KAAK;AAC5B;"}
@@ -0,0 +1,3 @@
1
+ import type { SliceCreateHook } from "@prismicio/plugin-kit";
2
+ import type { PluginOptions } from "../types.js";
3
+ export declare const sliceCreate: SliceCreateHook<PluginOptions>;
@@ -0,0 +1,53 @@
1
+ import { writeSliceModel, upsertGlobalTypeScriptTypes, writeSliceFile } from "@prismicio/plugin-kit/fs";
2
+ import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
3
+ import { getSvelteMajor } from "../lib/getSvelteMajor.js";
4
+ import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
5
+ import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
6
+ import { sliceTemplate } from "./slice-create.templates.js";
7
+ const createComponentFile = async ({ data, helpers, actions, options }) => {
8
+ const { model, componentContents } = data;
9
+ const typescript = await checkIsTypeScriptProject({ helpers, options });
10
+ const contents = componentContents ?? sliceTemplate({ model, typescript, version: await getSvelteMajor() });
11
+ await writeSliceFile({
12
+ libraryID: data.libraryID,
13
+ model: data.model,
14
+ filename: "index.svelte",
15
+ contents,
16
+ format: options.format,
17
+ actions,
18
+ helpers,
19
+ formatOptions: {
20
+ prettier: {
21
+ plugins: ["prettier-plugin-svelte"],
22
+ parser: "svelte"
23
+ }
24
+ }
25
+ });
26
+ };
27
+ const sliceCreate = async (data, context) => {
28
+ rejectIfNecessary(await Promise.allSettled([
29
+ writeSliceModel({
30
+ libraryID: data.libraryID,
31
+ model: data.model,
32
+ format: context.options.format,
33
+ helpers: context.helpers
34
+ }),
35
+ createComponentFile({ data, ...context })
36
+ ]));
37
+ rejectIfNecessary(await Promise.allSettled([
38
+ upsertSliceLibraryIndexFile({
39
+ libraryID: data.libraryID,
40
+ ...context
41
+ }),
42
+ upsertGlobalTypeScriptTypes({
43
+ filename: context.options.generatedTypesFilePath,
44
+ format: context.options.format,
45
+ helpers: context.helpers,
46
+ actions: context.actions
47
+ })
48
+ ]));
49
+ };
50
+ export {
51
+ sliceCreate
52
+ };
53
+ //# sourceMappingURL=slice-create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slice-create.js","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tPluginSystemContext,\n} from \"@prismicio/plugin-kit\";\nimport {\n\tupsertGlobalTypeScriptTypes,\n\twriteSliceFile,\n\twriteSliceModel,\n} from \"@prismicio/plugin-kit/fs\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getSvelteMajor } from \"../lib/getSvelteMajor\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\nimport type { PluginOptions } from \"../types\";\n\nimport { sliceTemplate } from \"./slice-create.templates\";\n\ntype Args = {\n\tdata: SliceCreateHookData;\n} & PluginSystemContext<PluginOptions>;\n\nconst createComponentFile = async ({\n\tdata,\n\thelpers,\n\tactions,\n\toptions,\n}: Args) => {\n\tconst { model, componentContents } = data;\n\n\tconst typescript = await checkIsTypeScriptProject({ helpers, options });\n\tconst contents =\n\t\tcomponentContents ??\n\t\tsliceTemplate({ model, typescript, version: await getSvelteMajor() });\n\n\tawait writeSliceFile({\n\t\tlibraryID: data.libraryID,\n\t\tmodel: data.model,\n\t\tfilename: \"index.svelte\",\n\t\tcontents,\n\t\tformat: options.format,\n\t\tactions,\n\t\thelpers,\n\t\tformatOptions: {\n\t\t\tprettier: {\n\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t});\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\twriteSliceModel({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t}),\n\t\t\tcreateComponentFile({ data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertSliceLibraryIndexFile({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\t...context,\n\t\t\t}),\n\t\t\tupsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t\tactions: context.actions,\n\t\t\t}),\n\t\t]),\n\t);\n};\n"],"names":[],"mappings":";;;;;;AAuBA,MAAM,sBAAsB,OAAO,EAClC,MACA,SACA,SACA,cACU;AACV,QAAM,EAAE,OAAO,kBAAA,IAAsB;AAErC,QAAM,aAAa,MAAM,yBAAyB,EAAE,SAAS,SAAS;AACtE,QAAM,WACL,qBACA,cAAc,EAAE,OAAO,YAAY,SAAS,MAAM,eAAA,GAAkB;AAErE,QAAM,eAAe;AAAA,IACpB,WAAW,KAAK;AAAA,IAChB,OAAO,KAAK;AAAA,IACZ,UAAU;AAAA,IACV;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA;AAAA,IACA,eAAe;AAAA,MACd,UAAU;AAAA,QACT,SAAS,CAAC,wBAAwB;AAAA,QAClC,QAAQ;AAAA,MAAA;AAAA,IACR;AAAA,EACD,CACD;AACF;AAEO,MAAM,cAA8C,OAC1D,MACA,YACG;AACH,oBACC,MAAM,QAAQ,WAAW;AAAA,IACxB,gBAAgB;AAAA,MACf,WAAW,KAAK;AAAA,MAChB,OAAO,KAAK;AAAA,MACZ,QAAQ,QAAQ,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,IACD,oBAAoB,EAAE,MAAM,GAAG,SAAS;AAAA,EAAA,CACxC,CAAC;AAGH,oBACC,MAAM,QAAQ,WAAW;AAAA,IACxB,4BAA4B;AAAA,MAC3B,WAAW,KAAK;AAAA,MAChB,GAAG;AAAA,IAAA,CACH;AAAA,IACD,4BAA4B;AAAA,MAC3B,UAAU,QAAQ,QAAQ;AAAA,MAC1B,QAAQ,QAAQ,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,MACjB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,EAAA,CACD,CAAC;AAEJ;"}
@@ -0,0 +1,6 @@
1
+ import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
2
+ export declare function sliceTemplate(args: {
3
+ model: TypesInternal.SharedSlice;
4
+ typescript: boolean;
5
+ version: number;
6
+ }): string;
@@ -0,0 +1,40 @@
1
+ import { source } from "common-tags";
2
+ import { pascalCase } from "../lib/pascalCase.js";
3
+ var __freeze = Object.freeze;
4
+ var __defProp = Object.defineProperty;
5
+ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(cooked.slice()) }));
6
+ var _a, _b, _c, _d;
7
+ const PLACEHOLDER = `
8
+ Placeholder component for {slice.slice_type} (variation: {slice.variation}) slices.
9
+ <br />
10
+ <strong>You can edit this slice directly in your code editor.</strong>
11
+ <!--
12
+ šŸ’” Use the Prismic MCP server with your code editor
13
+ šŸ“š Docs: https://prismic.io/docs/ai#code-with-prismics-mcp-server
14
+ -->
15
+ `;
16
+ function sliceTemplate(args) {
17
+ const { model, typescript, version } = args;
18
+ const pascalName = pascalCase(model.name);
19
+ const v5TS = source(_a || (_a = __template([`
20
+ <script lang="ts">
21
+ import type { Content } from '@prismicio/client';
22
+ import type { SliceComponentProps } from '@prismicio/svelte';
23
+
24
+ type Props = SliceComponentProps<Content.`, "Slice>;\n\n const { slice }: Props = $props();\n <\/script>\n\n <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n ", "\n </section>\n "])), pascalName, PLACEHOLDER);
25
+ const v5JS = source(_b || (_b = __template(['\n <script>\n /* @typedef {import("@prismicio/client").Content} Content */\n /* @typedef {import("@prismicio/svelte").SliceComponentProps} SliceComponentProps */\n\n /* @type {SliceComponentProps<Content.', "Slice>} */\n const { slice } = $props();\n <\/script>\n\n <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n ", "\n </section>\n "])), pascalName, PLACEHOLDER);
26
+ const v4TS = source(_c || (_c = __template([`
27
+ <script lang="ts">
28
+ import type { Content } from '@prismicio/client';
29
+
30
+ export let slice: Content.`, "Slice;\n <\/script>\n\n <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n ", "\n </section>\n "])), pascalName, PLACEHOLDER);
31
+ const v4JS = source(_d || (_d = __template(['\n <script>\n /** @type {import("@prismicio/client").Content.', "Slice} */\n export let slice;\n <\/script>\n\n <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n ", "\n </section>\n "])), pascalName, PLACEHOLDER);
32
+ if (typescript) {
33
+ return version <= 4 ? v4TS : v5TS;
34
+ }
35
+ return version <= 4 ? v4JS : v5JS;
36
+ }
37
+ export {
38
+ sliceTemplate
39
+ };
40
+ //# sourceMappingURL=slice-create.templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slice-create.templates.js","sources":["../../../src/hooks/slice-create.templates.ts"],"sourcesContent":["import TypesInternal from \"@prismicio/types-internal/lib/customtypes/index.js\";\nimport { source as svelte } from \"common-tags\";\n\nimport { pascalCase } from \"../lib/pascalCase\";\n\nconst PLACEHOLDER = `\nPlaceholder component for {slice.slice_type} (variation: {slice.variation}) slices.\n<br />\n<strong>You can edit this slice directly in your code editor.</strong>\n<!--\nšŸ’” Use the Prismic MCP server with your code editor\nšŸ“š Docs: https://prismic.io/docs/ai#code-with-prismics-mcp-server\n-->\n`;\n\nexport function sliceTemplate(args: {\n\tmodel: TypesInternal.SharedSlice;\n\ttypescript: boolean;\n\tversion: number;\n}): string {\n\tconst { model, typescript, version } = args;\n\n\tconst pascalName = pascalCase(model.name);\n\n\tconst v5TS = svelte`\n\t\t<script lang=\"ts\">\n\t\t\timport type { Content } from '@prismicio/client';\n\t\t\timport type { SliceComponentProps } from '@prismicio/svelte';\n\n\t\t\ttype Props = SliceComponentProps<Content.${pascalName}Slice>;\n\n\t\t\tconst { slice }: Props = $props();\n\t\t</script>\n\n\t\t<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n\t\t\t${PLACEHOLDER}\n\t\t</section>\n\t`;\n\n\tconst v5JS = svelte`\n\t\t<script>\n\t\t\t/* @typedef {import(\"@prismicio/client\").Content} Content */\n\t\t\t/* @typedef {import(\"@prismicio/svelte\").SliceComponentProps} SliceComponentProps */\n\n\t\t\t/* @type {SliceComponentProps<Content.${pascalName}Slice>} */\n\t\t\tconst { slice } = $props();\n\t\t</script>\n\n\t\t<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n\t\t\t${PLACEHOLDER}\n\t\t</section>\n\t`;\n\n\tconst v4TS = svelte`\n\t\t<script lang=\"ts\">\n\t\t\timport type { Content } from '@prismicio/client';\n\n\t\t\texport let slice: Content.${pascalName}Slice;\n\t\t</script>\n\n\t\t<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n\t\t\t${PLACEHOLDER}\n\t\t</section>\n\t`;\n\n\tconst v4JS = svelte`\n\t\t<script>\n\t\t\t/** @type {import(\"@prismicio/client\").Content.${pascalName}Slice} */\n\t\t\texport let slice;\n\t\t</script>\n\n\t\t<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n\t\t\t${PLACEHOLDER}\n\t\t</section>\n\t`;\n\n\tif (typescript) {\n\t\treturn version <= 4 ? v4TS : v5TS;\n\t}\n\n\treturn version <= 4 ? v4JS : v5JS;\n}\n"],"names":["svelte"],"mappings":";;;;;AACA,IAAA,IAAA,IAAA,IAAA;AAIA,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUd,SAAU,cAAc,MAI7B;AACA,QAAM,EAAE,OAAO,YAAY,QAAA,IAAY;AAEvC,QAAM,aAAa,WAAW,MAAM,IAAI;AAExC,QAAM,OAAOA,OAAA,OAAA,KAAM,WAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+CAKoC,gKAMxC,wBAN8B,YAMzC,WAAA;AAIJ,QAAM,OAAOA,OAAA,OAAA,KAAM,WAAA,CAAA,uNAKiC,0JAKrC,wBAL2B,YAKtC,WAAA;AAIJ,QAAM,OAAOA,OAAA,OAAA,KAAM,WAAA,CAAA;AAAA;AAAA;AAAA;AAAA,gCAIqB,sHAIzB,wBAJe,YAI1B,WAAA;AAIJ,QAAM,OAAOA,OAAA,OAAA,KAAM,WAAA,CAAA,oEAE0C,+IAK9C,wBALoC,YAK/C,WAAA;AAIJ,MAAI,YAAY;AACf,WAAO,WAAW,IAAI,OAAO;AAAA,EAC9B;AAEA,SAAO,WAAW,IAAI,OAAO;AAC9B;"}
@@ -0,0 +1,2 @@
1
+ export { plugin as default } from "./plugin.js";
2
+ export type { PluginOptions } from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { plugin } from "./plugin.js";
2
+ export {
3
+ plugin as default
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,8 @@
1
+ import { PluginSystemContext } from "@prismicio/plugin-kit";
2
+ import { PluginOptions } from "../types.js";
3
+ type CheckIsTypeScriptProjectArgs = {
4
+ helpers: PluginSystemContext<PluginOptions>["helpers"];
5
+ options: PluginSystemContext<PluginOptions>["options"];
6
+ };
7
+ export declare const checkIsTypeScriptProject: (args: CheckIsTypeScriptProjectArgs) => Promise<boolean>;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ import { checkIsTypeScriptProject as checkIsTypeScriptProject$1 } from "@prismicio/plugin-kit/fs";
2
+ const checkIsTypeScriptProject = async (args) => {
3
+ return args.options.typescript ?? checkIsTypeScriptProject$1({ helpers: args.helpers });
4
+ };
5
+ export {
6
+ checkIsTypeScriptProject
7
+ };
8
+ //# sourceMappingURL=checkIsTypeScriptProject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkIsTypeScriptProject.js","sources":["../../../src/lib/checkIsTypeScriptProject.ts"],"sourcesContent":["import { PluginSystemContext } from \"@prismicio/plugin-kit\";\nimport { checkIsTypeScriptProject as baseCheckIsTypeScriptProject } from \"@prismicio/plugin-kit/fs\";\n\nimport { PluginOptions } from \"../types\";\n\ntype CheckIsTypeScriptProjectArgs = {\n\thelpers: PluginSystemContext<PluginOptions>[\"helpers\"];\n\toptions: PluginSystemContext<PluginOptions>[\"options\"];\n};\n\nexport const checkIsTypeScriptProject = async (\n\targs: CheckIsTypeScriptProjectArgs,\n): Promise<boolean> => {\n\treturn (\n\t\targs.options.typescript ??\n\t\tbaseCheckIsTypeScriptProject({ helpers: args.helpers })\n\t);\n};\n"],"names":["baseCheckIsTypeScriptProject"],"mappings":";AAUO,MAAM,2BAA2B,OACvC,SACqB;AACrB,SACC,KAAK,QAAQ,cACbA,2BAA6B,EAAE,SAAS,KAAK,SAAS;AAExD;"}
@@ -0,0 +1,5 @@
1
+ import { PluginSystemContext } from "@prismicio/plugin-kit";
2
+ import { PluginOptions } from "../types.js";
3
+ type GetJSFileExtensionArgs = Pick<PluginSystemContext<PluginOptions>, "helpers" | "options">;
4
+ export declare const getJSFileExtension: ({ helpers, options, }: GetJSFileExtensionArgs) => Promise<string>;
5
+ export {};
@@ -0,0 +1,12 @@
1
+ import { checkIsTypeScriptProject } from "./checkIsTypeScriptProject.js";
2
+ const getJSFileExtension = async ({ helpers, options }) => {
3
+ const isTypeScriptProject = await checkIsTypeScriptProject({
4
+ helpers,
5
+ options
6
+ });
7
+ return isTypeScriptProject ? "ts" : "js";
8
+ };
9
+ export {
10
+ getJSFileExtension
11
+ };
12
+ //# sourceMappingURL=getJSFileExtension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getJSFileExtension.js","sources":["../../../src/lib/getJSFileExtension.ts"],"sourcesContent":["import { PluginSystemContext } from \"@prismicio/plugin-kit\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { checkIsTypeScriptProject } from \"./checkIsTypeScriptProject\";\n\ntype GetJSFileExtensionArgs = Pick<\n\tPluginSystemContext<PluginOptions>,\n\t\"helpers\" | \"options\"\n>;\n\nexport const getJSFileExtension = async ({\n\thelpers,\n\toptions,\n}: GetJSFileExtensionArgs): Promise<string> => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\treturn isTypeScriptProject ? \"ts\" : \"js\";\n};\n"],"names":[],"mappings":";AAWO,MAAM,qBAAqB,OAAO,EACxC,SACA,cAC6C;AAC7C,QAAM,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,SAAO,sBAAsB,OAAO;AACrC;"}
@@ -0,0 +1 @@
1
+ export declare const getSvelteMajor: () => Promise<number>;