@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,16 @@
1
+ import { join } from "node:path";
2
+ import { requireResolve } from "./requireResolve.js";
3
+ const getSvelteMajor = async () => {
4
+ const { readFile } = await import("node:fs/promises");
5
+ const packageJSONPath = requireResolve("svelte/package.json", join(process.cwd(), "package.json"));
6
+ const { version } = JSON.parse(await readFile(packageJSONPath, "utf8"));
7
+ const major = Number.parseInt(version.split(".")[0]);
8
+ if (Number.isNaN(major)) {
9
+ throw new Error(`Unable to parse svelte's installed version number: "${version}"`);
10
+ }
11
+ return major;
12
+ };
13
+ export {
14
+ getSvelteMajor
15
+ };
16
+ //# sourceMappingURL=getSvelteMajor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSvelteMajor.js","sources":["../../../src/lib/getSvelteMajor.ts"],"sourcesContent":["import { join } from \"node:path\";\n\nimport { requireResolve } from \"./requireResolve\";\n\nexport const getSvelteMajor = async (): Promise<number> => {\n\t// A dynamic import lets us easily mock the module.\n\tconst { readFile } = await import(\"node:fs/promises\");\n\n\tconst packageJSONPath = requireResolve(\n\t\t\"svelte/package.json\",\n\t\tjoin(process.cwd(), \"package.json\"),\n\t);\n\tconst { version } = JSON.parse(await readFile(packageJSONPath, \"utf8\"));\n\n\tconst major = Number.parseInt(version.split(\".\")[0]);\n\tif (Number.isNaN(major)) {\n\t\tthrow new Error(\n\t\t\t`Unable to parse svelte's installed version number: \"${version}\"`,\n\t\t);\n\t}\n\n\treturn major;\n};\n"],"names":[],"mappings":";;AAIO,MAAM,iBAAiB,YAA4B;AAEzD,QAAM,EAAE,SAAA,IAAa,MAAM,OAAO,kBAAkB;AAEpD,QAAM,kBAAkB,eACvB,uBACA,KAAK,QAAQ,IAAA,GAAO,cAAc,CAAC;AAEpC,QAAM,EAAE,YAAY,KAAK,MAAM,MAAM,SAAS,iBAAiB,MAAM,CAAC;AAEtE,QAAM,QAAQ,OAAO,SAAS,QAAQ,MAAM,GAAG,EAAE,CAAC,CAAC;AACnD,MAAI,OAAO,MAAM,KAAK,GAAG;AACxB,UAAM,IAAI,MACT,uDAAuD,OAAO,GAAG;AAAA,EAEnE;AAEA,SAAO;AACR;"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converts a string to a Pascal cased string.
3
+ *
4
+ * @param input - String to convert into a Pascal cased string.
5
+ *
6
+ * @returns Pascal cased string version of `input`.
7
+ */
8
+ export declare const pascalCase: (...input: (string | undefined)[]) => string;
@@ -0,0 +1,8 @@
1
+ import { pascalCase as pascalCase$1 } from "pascal-case";
2
+ const pascalCase = (...input) => {
3
+ return pascalCase$1(input.filter(Boolean).join(" "));
4
+ };
5
+ export {
6
+ pascalCase
7
+ };
8
+ //# sourceMappingURL=pascalCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pascalCase.js","sources":["../../../src/lib/pascalCase.ts"],"sourcesContent":["import { pascalCase as basePascalCase } from \"pascal-case\";\n\n/**\n * Converts a string to a Pascal cased string.\n *\n * @param input - String to convert into a Pascal cased string.\n *\n * @returns Pascal cased string version of `input`.\n */\nexport const pascalCase = (...input: (string | undefined)[]): string => {\n\treturn basePascalCase(input.filter(Boolean).join(\" \"));\n};\n"],"names":["basePascalCase"],"mappings":";AASO,MAAM,aAAa,IAAI,UAAyC;AACtE,SAAOA,aAAe,MAAM,OAAO,OAAO,EAAE,KAAK,GAAG,CAAC;AACtD;"}
@@ -0,0 +1 @@
1
+ export declare const rejectIfNecessary: <TPromiseSettledResults extends readonly PromiseSettledResult<any>[]>(promiseSettledResults: TPromiseSettledResults) => void;
@@ -0,0 +1,10 @@
1
+ const rejectIfNecessary = (promiseSettledResults) => {
2
+ const rejectedReasons = promiseSettledResults.filter((result) => result.status === "rejected").map((result) => result.reason);
3
+ if (rejectedReasons.length > 0) {
4
+ throw rejectedReasons[0];
5
+ }
6
+ };
7
+ export {
8
+ rejectIfNecessary
9
+ };
10
+ //# sourceMappingURL=rejectIfNecessary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rejectIfNecessary.js","sources":["../../../src/lib/rejectIfNecessary.ts"],"sourcesContent":["export const rejectIfNecessary = <\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTPromiseSettledResults extends readonly PromiseSettledResult<any>[],\n>(\n\tpromiseSettledResults: TPromiseSettledResults,\n): void => {\n\tconst rejectedReasons = promiseSettledResults\n\t\t.filter(\n\t\t\t(result): result is PromiseRejectedResult => result.status === \"rejected\",\n\t\t)\n\t\t.map((result) => result.reason);\n\n\tif (rejectedReasons.length > 0) {\n\t\tthrow rejectedReasons[0];\n\t}\n};\n"],"names":[],"mappings":"AAAO,MAAM,oBAAoB,CAIhC,0BACS;AACT,QAAM,kBAAkB,sBACtB,OACA,CAAC,WAA4C,OAAO,WAAW,UAAU,EAEzE,IAAI,CAAC,WAAW,OAAO,MAAM;AAE/B,MAAI,gBAAgB,SAAS,GAAG;AAC/B,UAAM,gBAAgB,CAAC;AAAA,EACxB;AACD;"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Resolves a module path with `createRequire().resolve()` with Yarn PnP
3
+ * support.
4
+ *
5
+ * @param id - Module to resolve.
6
+ * @param from - Location to resolve the module from.
7
+ *
8
+ * @returns - Resolved module path.
9
+ */
10
+ export declare const requireResolve: (id: string, from: string) => string;
@@ -0,0 +1,16 @@
1
+ import _module, { createRequire } from "node:module";
2
+ const requireResolve = (id, from) => {
3
+ let resolvedID = id;
4
+ if (process.versions.pnp && "findPnpApi" in _module && typeof _module.findPnpApi === "function") {
5
+ const pnpApi = _module.findPnpApi(from);
6
+ if (pnpApi) {
7
+ resolvedID = pnpApi.resolveRequest(id, from);
8
+ }
9
+ }
10
+ const require2 = createRequire(from);
11
+ return require2.resolve(resolvedID);
12
+ };
13
+ export {
14
+ requireResolve
15
+ };
16
+ //# sourceMappingURL=requireResolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requireResolve.js","sources":["../../../src/lib/requireResolve.ts"],"sourcesContent":["import _module, { createRequire } from \"node:module\";\n\n/**\n * Resolves a module path with `createRequire().resolve()` with Yarn PnP\n * support.\n *\n * @param id - Module to resolve.\n * @param from - Location to resolve the module from.\n *\n * @returns - Resolved module path.\n */\nexport const requireResolve = (id: string, from: string): string => {\n\tlet resolvedID = id;\n\n\t// Support Yarn PnP\n\tif (\n\t\tprocess.versions.pnp &&\n\t\t\"findPnpApi\" in _module &&\n\t\ttypeof _module.findPnpApi === \"function\"\n\t) {\n\t\tconst pnpApi = _module.findPnpApi(from);\n\t\tif (pnpApi) {\n\t\t\tresolvedID = pnpApi.resolveRequest(id, from);\n\t\t}\n\t}\n\n\tconst require = createRequire(from);\n\n\treturn require.resolve(resolvedID);\n};\n"],"names":["require"],"mappings":";AAWO,MAAM,iBAAiB,CAAC,IAAY,SAAwB;AAClE,MAAI,aAAa;AAGjB,MACC,QAAQ,SAAS,OACjB,gBAAgB,WAChB,OAAO,QAAQ,eAAe,YAC7B;AACD,UAAM,SAAS,QAAQ,WAAW,IAAI;AACtC,QAAI,QAAQ;AACX,mBAAa,OAAO,eAAe,IAAI,IAAI;AAAA,IAC5C;AAAA,EACD;AAEA,QAAMA,WAAU,cAAc,IAAI;AAElC,SAAOA,SAAQ,QAAQ,UAAU;AAClC;"}
@@ -0,0 +1,7 @@
1
+ import { PluginSystemContext } from "@prismicio/plugin-kit";
2
+ import { PluginOptions } from "../types.js";
3
+ type UpsertSliceLibraryIndexFileArgs = {
4
+ libraryID: string;
5
+ } & PluginSystemContext<PluginOptions>;
6
+ export declare const upsertSliceLibraryIndexFile: (args: UpsertSliceLibraryIndexFileArgs) => Promise<void>;
7
+ export {};
@@ -0,0 +1,50 @@
1
+ import * as path from "node:path";
2
+ import { buildSliceDirectoryPath, buildSliceLibraryDirectoryPath, writeProjectFile } from "@prismicio/plugin-kit/fs";
3
+ import { stripIndent } from "common-tags";
4
+ import { NON_EDITABLE_FILE_BANNER } from "../constants.js";
5
+ import { getJSFileExtension } from "./getJSFileExtension.js";
6
+ import { pascalCase } from "./pascalCase.js";
7
+ const upsertSliceLibraryIndexFile = async (args) => {
8
+ const slices = await args.actions.readAllSliceModelsForLibrary({
9
+ libraryID: args.libraryID
10
+ });
11
+ const contents = stripIndent`
12
+ ${NON_EDITABLE_FILE_BANNER}
13
+
14
+ ${(await Promise.all(slices.map(async (slice) => {
15
+ const dirName = path.basename(await buildSliceDirectoryPath({
16
+ model: slice.model,
17
+ helpers: args.helpers,
18
+ libraryID: args.libraryID
19
+ }));
20
+ const componentName = pascalCase(slice.model.name);
21
+ return `import ${componentName} from "./${dirName}/index.svelte";`;
22
+ }))).join("\n")}
23
+
24
+ export const components = {
25
+ ${slices.map((slice) => {
26
+ const id = slice.model.id;
27
+ const componentName = pascalCase(slice.model.name);
28
+ return `${id}: ${componentName},`;
29
+ }).join("\n")}
30
+ }
31
+ `;
32
+ const extension = await getJSFileExtension({
33
+ helpers: args.helpers,
34
+ options: args.options
35
+ });
36
+ const filePath = path.join(buildSliceLibraryDirectoryPath({
37
+ libraryID: args.libraryID,
38
+ helpers: args.helpers
39
+ }), `index.${extension}`);
40
+ await writeProjectFile({
41
+ filename: filePath,
42
+ contents,
43
+ format: args.options.format,
44
+ helpers: args.helpers
45
+ });
46
+ };
47
+ export {
48
+ upsertSliceLibraryIndexFile
49
+ };
50
+ //# sourceMappingURL=upsertSliceLibraryIndexFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upsertSliceLibraryIndexFile.js","sources":["../../../src/lib/upsertSliceLibraryIndexFile.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport { PluginSystemContext } from \"@prismicio/plugin-kit\";\nimport {\n\tbuildSliceDirectoryPath,\n\tbuildSliceLibraryDirectoryPath,\n\twriteProjectFile,\n} from \"@prismicio/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\n\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\nimport { PluginOptions } from \"../types\";\n\nimport { getJSFileExtension } from \"./getJSFileExtension\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype UpsertSliceLibraryIndexFileArgs = {\n\tlibraryID: string;\n} & PluginSystemContext<PluginOptions>;\n\nexport const upsertSliceLibraryIndexFile = async (\n\targs: UpsertSliceLibraryIndexFileArgs,\n): Promise<void> => {\n\tconst slices = await args.actions.readAllSliceModelsForLibrary({\n\t\tlibraryID: args.libraryID,\n\t});\n\n\tconst contents = stripIndent`\n\t\t${NON_EDITABLE_FILE_BANNER}\n\n\t\t${(\n\t\t\tawait Promise.all(\n\t\t\t\tslices.map(async (slice) => {\n\t\t\t\t\tconst dirName = path.basename(\n\t\t\t\t\t\tawait buildSliceDirectoryPath({\n\t\t\t\t\t\t\tmodel: slice.model,\n\t\t\t\t\t\t\thelpers: args.helpers,\n\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t\tconst componentName = pascalCase(slice.model.name);\n\n\t\t\t\t\treturn `import ${componentName} from \"./${dirName}/index.svelte\";`;\n\t\t\t\t}),\n\t\t\t)\n\t\t).join(\"\\n\")}\n\n\t\texport const components = {\n\t\t\t${slices\n\t\t\t\t.map((slice) => {\n\t\t\t\t\tconst id = slice.model.id;\n\t\t\t\t\tconst componentName = pascalCase(slice.model.name);\n\n\t\t\t\t\treturn `${id}: ${componentName},`;\n\t\t\t\t})\n\t\t\t\t.join(\"\\n\")}\n\t\t}\n\t`;\n\n\tconst extension = await getJSFileExtension({\n\t\thelpers: args.helpers,\n\t\toptions: args.options,\n\t});\n\tconst filePath = path.join(\n\t\tbuildSliceLibraryDirectoryPath({\n\t\t\tlibraryID: args.libraryID,\n\t\t\thelpers: args.helpers,\n\t\t}),\n\t\t`index.${extension}`,\n\t);\n\n\tawait writeProjectFile({\n\t\tfilename: filePath,\n\t\tcontents,\n\t\tformat: args.options.format,\n\t\thelpers: args.helpers,\n\t});\n};\n"],"names":[],"mappings":";;;;;;AAoBO,MAAM,8BAA8B,OAC1C,SACkB;AAClB,QAAM,SAAS,MAAM,KAAK,QAAQ,6BAA6B;AAAA,IAC9D,WAAW,KAAK;AAAA,EAAA,CAChB;AAED,QAAM,WAAW;AAAA,IACd,wBAAwB;AAAA;AAAA,KAGzB,MAAM,QAAQ,IACb,OAAO,IAAI,OAAO,UAAS;AAC1B,UAAM,UAAU,KAAK,SACpB,MAAM,wBAAwB;AAAA,MAC7B,OAAO,MAAM;AAAA,MACb,SAAS,KAAK;AAAA,MACd,WAAW,KAAK;AAAA,IAAA,CAChB,CAAC;AAEH,UAAM,gBAAgB,WAAW,MAAM,MAAM,IAAI;AAEjD,WAAO,UAAU,aAAa,YAAY,OAAO;AAAA,EAClD,CAAC,CAAC,GAEF,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA,KAGT,OACA,IAAI,CAAC,UAAS;AACd,UAAM,KAAK,MAAM,MAAM;AACvB,UAAM,gBAAgB,WAAW,MAAM,MAAM,IAAI;AAEjD,WAAO,GAAG,EAAE,KAAK,aAAa;AAAA,EAC/B,CAAC,EACA,KAAK,IAAI,CAAC;AAAA;AAAA;AAId,QAAM,YAAY,MAAM,mBAAmB;AAAA,IAC1C,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AAAA,EAAA,CACd;AACD,QAAM,WAAW,KAAK,KACrB,+BAA+B;AAAA,IAC9B,WAAW,KAAK;AAAA,IAChB,SAAS,KAAK;AAAA,EAAA,CACd,GACD,SAAS,SAAS,EAAE;AAGrB,QAAM,iBAAiB;AAAA,IACtB,UAAU;AAAA,IACV;AAAA,IACA,QAAQ,KAAK,QAAQ;AAAA,IACrB,SAAS,KAAK;AAAA,EAAA,CACd;AACF;"}
@@ -0,0 +1,5 @@
1
+ const name = "@prismicio/adapter-sveltekit";
2
+ export {
3
+ name
4
+ };
5
+ //# sourceMappingURL=package.json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,2 @@
1
+ import { PluginOptions } from "./types.js";
2
+ export declare const plugin: import("@prismicio/plugin-kit").Plugin<PluginOptions>;
package/dist/plugin.js ADDED
@@ -0,0 +1,144 @@
1
+ import { definePlugin } from "@prismicio/plugin-kit";
2
+ import { writeSliceModel, upsertGlobalTypeScriptTypes, renameSlice, deleteSliceDirectory, readSliceModel, readSliceLibrary, writeCustomTypeModel, deleteCustomTypeDirectory, readCustomTypeModel, readCustomTypeLibrary } from "@prismicio/plugin-kit/fs";
3
+ import { name } from "./package.json.js";
4
+ import { projectInit } from "./hooks/project-init.js";
5
+ import { sliceCreate } from "./hooks/slice-create.js";
6
+ import { rejectIfNecessary } from "./lib/rejectIfNecessary.js";
7
+ import { upsertSliceLibraryIndexFile } from "./lib/upsertSliceLibraryIndexFile.js";
8
+ const plugin = definePlugin({
9
+ meta: {
10
+ name
11
+ },
12
+ defaultOptions: {
13
+ format: true,
14
+ generatedTypesFilePath: "./src/prismicio-types.d.ts"
15
+ },
16
+ setup({ hook }) {
17
+ hook("project:init", projectInit);
18
+ hook("slice:create", sliceCreate);
19
+ hook("slice:update", async (data, context) => {
20
+ await writeSliceModel({
21
+ libraryID: data.libraryID,
22
+ model: data.model,
23
+ ...context
24
+ });
25
+ await upsertGlobalTypeScriptTypes({
26
+ filename: context.options.generatedTypesFilePath,
27
+ format: context.options.format,
28
+ ...context
29
+ });
30
+ });
31
+ hook("slice:rename", async (data, context) => {
32
+ await renameSlice({
33
+ libraryID: data.libraryID,
34
+ model: data.model,
35
+ format: context.options.format,
36
+ ...context
37
+ });
38
+ rejectIfNecessary(await Promise.allSettled([
39
+ upsertSliceLibraryIndexFile({
40
+ libraryID: data.libraryID,
41
+ ...context
42
+ }),
43
+ upsertGlobalTypeScriptTypes({
44
+ filename: context.options.generatedTypesFilePath,
45
+ format: context.options.format,
46
+ ...context
47
+ })
48
+ ]));
49
+ });
50
+ hook("slice:delete", async (data, context) => {
51
+ await deleteSliceDirectory({
52
+ libraryID: data.libraryID,
53
+ model: data.model,
54
+ ...context
55
+ });
56
+ rejectIfNecessary(await Promise.allSettled([
57
+ upsertSliceLibraryIndexFile({
58
+ libraryID: data.libraryID,
59
+ ...context
60
+ }),
61
+ upsertGlobalTypeScriptTypes({
62
+ filename: context.options.generatedTypesFilePath,
63
+ format: context.options.format,
64
+ ...context
65
+ })
66
+ ]));
67
+ });
68
+ hook("slice:read", async (data, context) => {
69
+ return await readSliceModel({
70
+ libraryID: data.libraryID,
71
+ sliceID: data.sliceID,
72
+ ...context
73
+ });
74
+ });
75
+ hook("slice-library:read", async (data, context) => {
76
+ return await readSliceLibrary({
77
+ libraryID: data.libraryID,
78
+ ...context
79
+ });
80
+ });
81
+ hook("custom-type:create", async (data, context) => {
82
+ await writeCustomTypeModel({
83
+ model: data.model,
84
+ format: context.options.format,
85
+ ...context
86
+ });
87
+ await upsertGlobalTypeScriptTypes({
88
+ filename: context.options.generatedTypesFilePath,
89
+ format: context.options.format,
90
+ ...context
91
+ });
92
+ });
93
+ hook("custom-type:update", async (data, context) => {
94
+ await writeCustomTypeModel({
95
+ model: data.model,
96
+ format: context.options.format,
97
+ ...context
98
+ });
99
+ await upsertGlobalTypeScriptTypes({
100
+ filename: context.options.generatedTypesFilePath,
101
+ format: context.options.format,
102
+ ...context
103
+ });
104
+ });
105
+ hook("custom-type:rename", async (data, context) => {
106
+ await writeCustomTypeModel({
107
+ model: data.model,
108
+ format: context.options.format,
109
+ ...context
110
+ });
111
+ await upsertGlobalTypeScriptTypes({
112
+ filename: context.options.generatedTypesFilePath,
113
+ format: context.options.format,
114
+ ...context
115
+ });
116
+ });
117
+ hook("custom-type:delete", async (data, context) => {
118
+ await deleteCustomTypeDirectory({
119
+ customTypeID: data.model.id,
120
+ ...context
121
+ });
122
+ await upsertGlobalTypeScriptTypes({
123
+ filename: context.options.generatedTypesFilePath,
124
+ format: context.options.format,
125
+ ...context
126
+ });
127
+ });
128
+ hook("custom-type:read", async (data, context) => {
129
+ return await readCustomTypeModel({
130
+ customTypeID: data.id,
131
+ ...context
132
+ });
133
+ });
134
+ hook("custom-type-library:read", async (_data, context) => {
135
+ return await readCustomTypeLibrary({
136
+ helpers: context.helpers
137
+ });
138
+ });
139
+ }
140
+ });
141
+ export {
142
+ plugin
143
+ };
144
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import { definePlugin } from \"@prismicio/plugin-kit\";\nimport {\n\tdeleteCustomTypeDirectory,\n\tdeleteSliceDirectory,\n\treadCustomTypeLibrary,\n\treadCustomTypeModel,\n\treadSliceLibrary,\n\treadSliceModel,\n\trenameSlice,\n\tupsertGlobalTypeScriptTypes,\n\twriteCustomTypeModel,\n\twriteSliceModel,\n} from \"@prismicio/plugin-kit/fs\";\n\nimport { name as pkgName } from \"../package.json\";\n\nimport { projectInit } from \"./hooks/project-init\";\nimport { sliceCreate } from \"./hooks/slice-create\";\nimport { rejectIfNecessary } from \"./lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"./lib/upsertSliceLibraryIndexFile\";\nimport { PluginOptions } from \"./types\";\n\nexport const plugin = definePlugin<PluginOptions>({\n\tmeta: {\n\t\tname: pkgName,\n\t},\n\tdefaultOptions: {\n\t\tformat: true,\n\t\tgeneratedTypesFilePath: \"./src/prismicio-types.d.ts\",\n\t},\n\tsetup({ hook }) {\n\t\t////////////////////////////////////////////////////////////////\n\t\t// project:*\n\t\t////////////////////////////////////////////////////////////////\n\n\t\thook(\"project:init\", projectInit);\n\n\t\t////////////////////////////////////////////////////////////////\n\t\t// slice:*\n\t\t////////////////////////////////////////////////////////////////\n\n\t\thook(\"slice:create\", sliceCreate);\n\t\thook(\"slice:update\", async (data, context) => {\n\t\t\tawait writeSliceModel({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\t...context,\n\t\t\t});\n\n\t\t\tawait upsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\t...context,\n\t\t\t});\n\t\t});\n\t\thook(\"slice:rename\", async (data, context) => {\n\t\t\tawait renameSlice({\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\t...context,\n\t\t\t});\n\n\t\t\trejectIfNecessary(\n\t\t\t\tawait Promise.allSettled([\n\t\t\t\t\tupsertSliceLibraryIndexFile({\n\t\t\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\t\t\t...context,\n\t\t\t\t\t}),\n\t\t\t\t\tupsertGlobalTypeScriptTypes({\n\t\t\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\t\t\tformat: context.options.format,\n\t\t\t\t\t\t...context,\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\t);\n\t\t});\n\t\thook(\"slice:delete\", async (data, context) => {\n\t\t\tawait deleteSliceDirectory({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\t...context,\n\t\t\t});\n\n\t\t\trejectIfNecessary(\n\t\t\t\tawait Promise.allSettled([\n\t\t\t\t\tupsertSliceLibraryIndexFile({\n\t\t\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\t\t\t...context,\n\t\t\t\t\t}),\n\t\t\t\t\tupsertGlobalTypeScriptTypes({\n\t\t\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\t\t\tformat: context.options.format,\n\t\t\t\t\t\t...context,\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\t);\n\t\t});\n\t\thook(\"slice:read\", async (data, context) => {\n\t\t\treturn await readSliceModel({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tsliceID: data.sliceID,\n\t\t\t\t...context,\n\t\t\t});\n\t\t});\n\n\t\t////////////////////////////////////////////////////////////////\n\t\t// slice-library:*\n\t\t////////////////////////////////////////////////////////////////\n\n\t\thook(\"slice-library:read\", async (data, context) => {\n\t\t\treturn await readSliceLibrary({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\t...context,\n\t\t\t});\n\t\t});\n\n\t\t////////////////////////////////////////////////////////////////\n\t\t// custom-type:*\n\t\t////////////////////////////////////////////////////////////////\n\n\t\thook(\"custom-type:create\", async (data, context) => {\n\t\t\tawait writeCustomTypeModel({\n\t\t\t\tmodel: data.model,\n\t\t\t\tformat: context.options.format,\n\t\t\t\t...context,\n\t\t\t});\n\n\t\t\tawait upsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\t...context,\n\t\t\t});\n\t\t});\n\t\thook(\"custom-type:update\", async (data, context) => {\n\t\t\tawait writeCustomTypeModel({\n\t\t\t\tmodel: data.model,\n\t\t\t\tformat: context.options.format,\n\t\t\t\t...context,\n\t\t\t});\n\n\t\t\tawait upsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\t...context,\n\t\t\t});\n\t\t});\n\t\thook(\"custom-type:rename\", async (data, context) => {\n\t\t\tawait writeCustomTypeModel({\n\t\t\t\tmodel: data.model,\n\t\t\t\tformat: context.options.format,\n\t\t\t\t...context,\n\t\t\t});\n\n\t\t\tawait upsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\t...context,\n\t\t\t});\n\t\t});\n\t\thook(\"custom-type:delete\", async (data, context) => {\n\t\t\tawait deleteCustomTypeDirectory({\n\t\t\t\tcustomTypeID: data.model.id,\n\t\t\t\t...context,\n\t\t\t});\n\n\t\t\tawait upsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\t...context,\n\t\t\t});\n\t\t});\n\t\thook(\"custom-type:read\", async (data, context) => {\n\t\t\treturn await readCustomTypeModel({\n\t\t\t\tcustomTypeID: data.id,\n\t\t\t\t...context,\n\t\t\t});\n\t\t});\n\n\t\t////////////////////////////////////////////////////////////////\n\t\t// custom-type-library:*\n\t\t////////////////////////////////////////////////////////////////\n\n\t\thook(\"custom-type-library:read\", async (_data, context) => {\n\t\t\treturn await readCustomTypeLibrary({\n\t\t\t\thelpers: context.helpers,\n\t\t\t});\n\t\t});\n\t},\n});\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,28 @@
1
+ export type PluginOptions = {
2
+ /**
3
+ * Determines if generated files should be formatted using Prettier.
4
+ *
5
+ * @defaultValue `true`
6
+ */
7
+ format?: boolean;
8
+ /**
9
+ * The filepath at which generated TypeScript types will be saved.
10
+ *
11
+ * @defaultValue `prismicio-types.d.ts`
12
+ */
13
+ generatedTypesFilePath?: string;
14
+ /**
15
+ * Determines if generated files should be written in TypeScript or
16
+ * JavaScript.
17
+ *
18
+ * @defaultValue `true` if the project contains a `tsconfig.json`, `false` otherwise.
19
+ */
20
+ typescript?: boolean;
21
+ /**
22
+ * The filepath at which the active Prismic environment is stored as an
23
+ * environment variable.
24
+ *
25
+ * @defaultValue `.env.local`
26
+ */
27
+ environmentVariableFilePath?: string;
28
+ };
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "@prismicio/adapter-sveltekit",
3
+ "version": "0.0.1",
4
+ "description": "Prismic adapter for SvelteKit.",
5
+ "keywords": [
6
+ "typescript",
7
+ "prismic"
8
+ ],
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "ssh://git@github.com/prismicio/devtools.git",
12
+ "directory": "packages/adapter-sveltekit"
13
+ },
14
+ "license": "Apache-2.0",
15
+ "author": "Prismic <contact@prismic.io> (https://prismic.io)",
16
+ "type": "module",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "main": "dist/index.js",
25
+ "module": "dist/index.js",
26
+ "types": "dist/index.d.ts",
27
+ "typesVersions": {
28
+ "*": {
29
+ "*": [
30
+ "dist/index.d.ts"
31
+ ]
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "src"
37
+ ],
38
+ "engines": {
39
+ "node": ">=20.19.0"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "scripts": {
45
+ "build": "vite build",
46
+ "dev": "vite build --watch",
47
+ "types": "tsc --noEmit",
48
+ "format": "prettier --write .",
49
+ "lint": "eslint --max-warnings 0 .",
50
+ "prepack": "$npm_execpath run build",
51
+ "depcheck": "depcheck --config=.depcheckrc",
52
+ "audit": "yarn npm audit --environment production --severity high"
53
+ },
54
+ "dependencies": {
55
+ "@prismicio/plugin-kit": "0.0.1",
56
+ "@prismicio/types-internal": "3.16.1",
57
+ "common-tags": "1.8.2",
58
+ "magicast": "0.5.1",
59
+ "pascal-case": "3.1.2",
60
+ "prettier-plugin-svelte": "3.4.0"
61
+ },
62
+ "devDependencies": {
63
+ "@eslint/js": "9.28.0",
64
+ "@sveltejs/kit": "2.49.0",
65
+ "@sveltejs/vite-plugin-svelte": "6.2.1",
66
+ "@trivago/prettier-plugin-sort-imports": "6.0.0",
67
+ "@types/common-tags": "1.8.4",
68
+ "depcheck": "1.4.7",
69
+ "eslint": "9.39.1",
70
+ "eslint-config-prettier": "10.1.8",
71
+ "eslint-plugin-svelte": "3.13.0",
72
+ "eslint-plugin-tsdoc": "0.5.0",
73
+ "prettier": "3.7.1",
74
+ "prettier-plugin-jsdoc": "1.7.0",
75
+ "svelte": "5.45.2",
76
+ "typescript": "5.9.3",
77
+ "typescript-eslint": "8.33.0",
78
+ "vite": "7.2.4",
79
+ "vite-plugin-sdk": "0.1.5"
80
+ },
81
+ "peerDependencies": {
82
+ "@sveltejs/kit": "^1 || ^2",
83
+ "prettier": ">=3",
84
+ "prettier-plugin-svelte": ">=3",
85
+ "svelte": "^3.54.0 || ^4.0.0-next.0 || ^5.0.0-next.1"
86
+ },
87
+ "peerDependenciesMeta": {
88
+ "prettier": {
89
+ "optional": true
90
+ },
91
+ "prettier-plugin-svelte": {
92
+ "optional": true
93
+ }
94
+ }
95
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Banner text added to files that should not be edited by users.
3
+ */
4
+ export const NON_EDITABLE_FILE_BANNER =
5
+ "// Code generated by Prismic. DO NOT EDIT.";
@@ -0,0 +1,173 @@
1
+ import { source as svelte, source as ts, source as js } from "common-tags";
2
+
3
+ export function prismicIOFileTemplate(args: { typescript: boolean }): string {
4
+ const { typescript } = args;
5
+
6
+ const TS = ts`
7
+ import { createClient as baseCreateClient, type Route } from "@prismicio/client";
8
+ import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
9
+ import prismicConfig from "../../prismic.config.json";
10
+
11
+ /**
12
+ * The project's Prismic repository name.
13
+ */
14
+ export const repositoryName = prismicConfig.repositoryName;
15
+
16
+ /**
17
+ * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
18
+ *
19
+ * {@link https://prismic.io/docs/route-resolver}
20
+ */
21
+ // TODO: Update the routes array to match your project's route structure.
22
+ const routes: Route[] = [
23
+ // Examples:
24
+ // { type: "homepage", path: "/" },
25
+ // { type: "page", path: "/:uid" },
26
+ ];
27
+
28
+ /**
29
+ * Creates a Prismic client for the project's repository. The client is used to
30
+ * query content from the Prismic API.
31
+ *
32
+ * @param config - Configuration for the Prismic client.
33
+ */
34
+ export const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {
35
+ const client = baseCreateClient(repositoryName, {
36
+ routes,
37
+ ...config,
38
+ });
39
+
40
+ enableAutoPreviews({ client, cookies });
41
+
42
+ return client;
43
+ };
44
+ `;
45
+
46
+ const JS = js`
47
+ import { createClient as baseCreateClient } from "@prismicio/client";
48
+ import { enableAutoPreviews } from '@prismicio/svelte/kit';
49
+ import prismicConfig from "../../prismic.config.json";
50
+
51
+ /**
52
+ * The project's Prismic repository name.
53
+ */
54
+ export const repositoryName = prismicConfig.repositoryName;
55
+
56
+ /**
57
+ * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
58
+ *
59
+ * {@link https://prismic.io/docs/route-resolver#route-resolver}
60
+ *
61
+ * @type {import("@prismicio/client").Route[]}
62
+ */
63
+ // TODO: Update the routes array to match your project's route structure.
64
+ const routes = [
65
+ // Examples:
66
+ // { type: "homepage", path: "/" },
67
+ // { type: "page", path: "/:uid" },
68
+ ];
69
+
70
+ /**
71
+ * Creates a Prismic client for the project's repository. The client is used to
72
+ * query content from the Prismic API.
73
+ *
74
+ * @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.
75
+ */
76
+ export const createClient = ({ cookies, ...config } = {}) => {
77
+ const client = prismic.createClient(repositoryName, {
78
+ routes,
79
+ ...config,
80
+ });
81
+
82
+ enableAutoPreviews({ client, cookies });
83
+
84
+ return client;
85
+ };
86
+ `;
87
+
88
+ return typescript ? TS : JS;
89
+ }
90
+
91
+ export function previewAPIRouteTemplate(args: { typescript: boolean }): string {
92
+ const { typescript } = args;
93
+
94
+ const TS = ts`
95
+ import { redirectToPreviewURL } from '@prismicio/svelte/kit';
96
+ import { createClient } from '$lib/prismicio';
97
+ import type { RequestHandler } from "./$types";
98
+
99
+ export const GET: RequestHandler = async ({ fetch, request, cookies }) => {
100
+ const client = createClient({ fetch });
101
+
102
+ return await redirectToPreviewURL({ client, request, cookies });
103
+ }
104
+ `;
105
+
106
+ const JS = js`
107
+ import { redirectToPreviewURL } from '@prismicio/svelte/kit';
108
+ import { createClient } from '$lib/prismicio';
109
+
110
+ /* @type {import("./$types").RequestHandler} */
111
+ export async function GET({ fetch, request, cookies }) {
112
+ const client = createClient({ fetch });
113
+
114
+ return await redirectToPreviewURL({ client, request, cookies });
115
+ }
116
+ `;
117
+
118
+ return typescript ? TS : JS;
119
+ }
120
+
121
+ export function rootLayoutTemplate(args: { version: number }): string {
122
+ const { version } = args;
123
+
124
+ const v5 = svelte`
125
+ <script>
126
+ import { isFilled, asImageSrc } from '@prismicio/client';
127
+ import { PrismicPreview } from '@prismicio/svelte/kit';
128
+ import { page } from '$app/state';
129
+ import { repositoryName } from '$lib/prismicio';
130
+
131
+ const { children } = $props();
132
+ </script>
133
+
134
+ <svelte:head>
135
+ <title>{page.data.page?.data.meta_title}</title>
136
+ <meta property="og:title" content={page.data.page?.data.meta_title} />
137
+ {#if isFilled.keyText(page.data.page?.data.meta_description)}
138
+ <meta name="description" content={page.data.page.data.meta_description} />
139
+ <meta property="og:description" content={page.data.page.data.meta_description} />
140
+ {/if}
141
+ {#if isFilled.image(page.data.page?.data.meta_image)}
142
+ <meta property="og:image" content={asImageSrc(page.data.page.data.meta_image)} />
143
+ {/if}
144
+ </svelte:head>
145
+ {@render children()}
146
+ <PrismicPreview {repositoryName} />
147
+ `;
148
+
149
+ const v4 = svelte`
150
+ <script>
151
+ import { isFilled, asImageSrc } from '@prismicio/client';
152
+ import { PrismicPreview } from '@prismicio/svelte/kit';
153
+ import { page } from '$app/state';
154
+ import { repositoryName } from '$lib/prismicio';
155
+ </script>
156
+
157
+ <svelte:head>
158
+ <title>{page.data.page?.data.meta_title}</title>
159
+ <meta property="og:title" content={page.data.page?.data.meta_title} />
160
+ {#if isFilled.keyText(page.data.page?.data.meta_description)}
161
+ <meta name="description" content={page.data.page.data.meta_description} />
162
+ <meta property="og:description" content={page.data.page.data.meta_description} />
163
+ {/if}
164
+ {#if isFilled.image(page.data.page?.data.meta_image)}
165
+ <meta property="og:image" content={asImageSrc(page.data.page.data.meta_image)} />
166
+ {/if}
167
+ </svelte:head>
168
+ <slot />
169
+ <PrismicPreview {repositoryName} />
170
+ `;
171
+
172
+ return version <= 4 ? v4 : v5;
173
+ }