@slicemachine/adapter-sveltekit 0.0.0 → 0.3.10-dev-adapter-svelte-kit.3

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 (175) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +98 -0
  3. package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs +41 -0
  4. package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -0
  5. package/dist/_node_modules/data-uri-to-buffer/dist/index.js +41 -0
  6. package/dist/_node_modules/data-uri-to-buffer/dist/index.js.map +1 -0
  7. package/dist/_node_modules/fetch-blob/file.cjs +61 -0
  8. package/dist/_node_modules/fetch-blob/file.cjs.map +1 -0
  9. package/dist/_node_modules/fetch-blob/file.js +61 -0
  10. package/dist/_node_modules/fetch-blob/file.js.map +1 -0
  11. package/dist/_node_modules/fetch-blob/index.cjs +223 -0
  12. package/dist/_node_modules/fetch-blob/index.cjs.map +1 -0
  13. package/dist/_node_modules/fetch-blob/index.js +223 -0
  14. package/dist/_node_modules/fetch-blob/index.js.map +1 -0
  15. package/dist/_node_modules/fetch-blob/streams.cjs +43 -0
  16. package/dist/_node_modules/fetch-blob/streams.cjs.map +1 -0
  17. package/dist/_node_modules/fetch-blob/streams.js +42 -0
  18. package/dist/_node_modules/fetch-blob/streams.js.map +1 -0
  19. package/dist/_node_modules/formdata-polyfill/esm.min.cjs +116 -0
  20. package/dist/_node_modules/formdata-polyfill/esm.min.cjs.map +1 -0
  21. package/dist/_node_modules/formdata-polyfill/esm.min.js +116 -0
  22. package/dist/_node_modules/formdata-polyfill/esm.min.js.map +1 -0
  23. package/dist/_node_modules/node-domexception/index.cjs +11 -0
  24. package/dist/_node_modules/node-domexception/index.cjs.map +1 -0
  25. package/dist/_node_modules/node-domexception/index.js +10 -0
  26. package/dist/_node_modules/node-domexception/index.js.map +1 -0
  27. package/dist/_node_modules/node-fetch/src/body.cjs +262 -0
  28. package/dist/_node_modules/node-fetch/src/body.cjs.map +1 -0
  29. package/dist/_node_modules/node-fetch/src/body.js +262 -0
  30. package/dist/_node_modules/node-fetch/src/body.js.map +1 -0
  31. package/dist/_node_modules/node-fetch/src/errors/abort-error.cjs +10 -0
  32. package/dist/_node_modules/node-fetch/src/errors/abort-error.cjs.map +1 -0
  33. package/dist/_node_modules/node-fetch/src/errors/abort-error.js +10 -0
  34. package/dist/_node_modules/node-fetch/src/errors/abort-error.js.map +1 -0
  35. package/dist/_node_modules/node-fetch/src/errors/base.cjs +17 -0
  36. package/dist/_node_modules/node-fetch/src/errors/base.cjs.map +1 -0
  37. package/dist/_node_modules/node-fetch/src/errors/base.js +17 -0
  38. package/dist/_node_modules/node-fetch/src/errors/base.js.map +1 -0
  39. package/dist/_node_modules/node-fetch/src/errors/fetch-error.cjs +19 -0
  40. package/dist/_node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -0
  41. package/dist/_node_modules/node-fetch/src/errors/fetch-error.js +19 -0
  42. package/dist/_node_modules/node-fetch/src/errors/fetch-error.js.map +1 -0
  43. package/dist/_node_modules/node-fetch/src/headers.cjs +190 -0
  44. package/dist/_node_modules/node-fetch/src/headers.cjs.map +1 -0
  45. package/dist/_node_modules/node-fetch/src/headers.js +190 -0
  46. package/dist/_node_modules/node-fetch/src/headers.js.map +1 -0
  47. package/dist/_node_modules/node-fetch/src/index.cjs +292 -0
  48. package/dist/_node_modules/node-fetch/src/index.cjs.map +1 -0
  49. package/dist/_node_modules/node-fetch/src/index.js +292 -0
  50. package/dist/_node_modules/node-fetch/src/index.js.map +1 -0
  51. package/dist/_node_modules/node-fetch/src/request.cjs +206 -0
  52. package/dist/_node_modules/node-fetch/src/request.cjs.map +1 -0
  53. package/dist/_node_modules/node-fetch/src/request.js +206 -0
  54. package/dist/_node_modules/node-fetch/src/request.js.map +1 -0
  55. package/dist/_node_modules/node-fetch/src/response.cjs +122 -0
  56. package/dist/_node_modules/node-fetch/src/response.cjs.map +1 -0
  57. package/dist/_node_modules/node-fetch/src/response.js +123 -0
  58. package/dist/_node_modules/node-fetch/src/response.js.map +1 -0
  59. package/dist/_node_modules/node-fetch/src/utils/get-search.cjs +12 -0
  60. package/dist/_node_modules/node-fetch/src/utils/get-search.cjs.map +1 -0
  61. package/dist/_node_modules/node-fetch/src/utils/get-search.js +12 -0
  62. package/dist/_node_modules/node-fetch/src/utils/get-search.js.map +1 -0
  63. package/dist/_node_modules/node-fetch/src/utils/is-redirect.cjs +8 -0
  64. package/dist/_node_modules/node-fetch/src/utils/is-redirect.cjs.map +1 -0
  65. package/dist/_node_modules/node-fetch/src/utils/is-redirect.js +8 -0
  66. package/dist/_node_modules/node-fetch/src/utils/is-redirect.js.map +1 -0
  67. package/dist/_node_modules/node-fetch/src/utils/is.cjs +28 -0
  68. package/dist/_node_modules/node-fetch/src/utils/is.cjs.map +1 -0
  69. package/dist/_node_modules/node-fetch/src/utils/is.js +28 -0
  70. package/dist/_node_modules/node-fetch/src/utils/is.js.map +1 -0
  71. package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs +356 -0
  72. package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -0
  73. package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js +356 -0
  74. package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -0
  75. package/dist/_node_modules/node-fetch/src/utils/referrer.cjs +149 -0
  76. package/dist/_node_modules/node-fetch/src/utils/referrer.cjs.map +1 -0
  77. package/dist/_node_modules/node-fetch/src/utils/referrer.js +149 -0
  78. package/dist/_node_modules/node-fetch/src/utils/referrer.js.map +1 -0
  79. package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +3822 -0
  80. package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -0
  81. package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +3822 -0
  82. package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -0
  83. package/dist/_virtual/_commonjsHelpers.cjs +5 -0
  84. package/dist/_virtual/_commonjsHelpers.cjs.map +1 -0
  85. package/dist/_virtual/_commonjsHelpers.js +5 -0
  86. package/dist/_virtual/_commonjsHelpers.js.map +1 -0
  87. package/dist/_virtual/ponyfill.es2018.cjs +5 -0
  88. package/dist/_virtual/ponyfill.es2018.cjs.map +1 -0
  89. package/dist/_virtual/ponyfill.es2018.js +5 -0
  90. package/dist/_virtual/ponyfill.es2018.js.map +1 -0
  91. package/dist/constants.cjs +5 -0
  92. package/dist/constants.cjs.map +1 -0
  93. package/dist/constants.d.ts +4 -0
  94. package/dist/constants.js +5 -0
  95. package/dist/constants.js.map +1 -0
  96. package/dist/hooks/project-init.cjs +211 -0
  97. package/dist/hooks/project-init.cjs.map +1 -0
  98. package/dist/hooks/project-init.d.ts +3 -0
  99. package/dist/hooks/project-init.js +194 -0
  100. package/dist/hooks/project-init.js.map +1 -0
  101. package/dist/hooks/slice-create.cjs +69 -0
  102. package/dist/hooks/slice-create.cjs.map +1 -0
  103. package/dist/hooks/slice-create.d.ts +3 -0
  104. package/dist/hooks/slice-create.js +69 -0
  105. package/dist/hooks/slice-create.js.map +1 -0
  106. package/dist/hooks/sliceSimulator-setup-read.cjs +144 -0
  107. package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -0
  108. package/dist/hooks/sliceSimulator-setup-read.d.ts +3 -0
  109. package/dist/hooks/sliceSimulator-setup-read.js +144 -0
  110. package/dist/hooks/sliceSimulator-setup-read.js.map +1 -0
  111. package/dist/hooks/snippet-read.cjs +114 -0
  112. package/dist/hooks/snippet-read.cjs.map +1 -0
  113. package/dist/hooks/snippet-read.d.ts +3 -0
  114. package/dist/hooks/snippet-read.js +114 -0
  115. package/dist/hooks/snippet-read.js.map +1 -0
  116. package/dist/index.cjs +4 -0
  117. package/dist/index.cjs.map +1 -0
  118. package/dist/index.d.ts +2 -0
  119. package/dist/index.js +5 -0
  120. package/dist/index.js.map +1 -0
  121. package/dist/lib/checkIsTypeScriptProject.cjs +8 -0
  122. package/dist/lib/checkIsTypeScriptProject.cjs.map +1 -0
  123. package/dist/lib/checkIsTypeScriptProject.d.ts +8 -0
  124. package/dist/lib/checkIsTypeScriptProject.js +8 -0
  125. package/dist/lib/checkIsTypeScriptProject.js.map +1 -0
  126. package/dist/lib/getJSFileExtension.cjs +12 -0
  127. package/dist/lib/getJSFileExtension.cjs.map +1 -0
  128. package/dist/lib/getJSFileExtension.d.ts +5 -0
  129. package/dist/lib/getJSFileExtension.js +12 -0
  130. package/dist/lib/getJSFileExtension.js.map +1 -0
  131. package/dist/lib/pascalCase.cjs +8 -0
  132. package/dist/lib/pascalCase.cjs.map +1 -0
  133. package/dist/lib/pascalCase.d.ts +8 -0
  134. package/dist/lib/pascalCase.js +8 -0
  135. package/dist/lib/pascalCase.js.map +1 -0
  136. package/dist/lib/rejectIfNecessary.cjs +10 -0
  137. package/dist/lib/rejectIfNecessary.cjs.map +1 -0
  138. package/dist/lib/rejectIfNecessary.d.ts +1 -0
  139. package/dist/lib/rejectIfNecessary.js +10 -0
  140. package/dist/lib/rejectIfNecessary.js.map +1 -0
  141. package/dist/lib/upsertSliceLibraryIndexFile.cjs +67 -0
  142. package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -0
  143. package/dist/lib/upsertSliceLibraryIndexFile.d.ts +7 -0
  144. package/dist/lib/upsertSliceLibraryIndexFile.js +50 -0
  145. package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -0
  146. package/dist/packages/adapter-sveltekit/package.json.cjs +5 -0
  147. package/dist/packages/adapter-sveltekit/package.json.cjs.map +1 -0
  148. package/dist/packages/adapter-sveltekit/package.json.js +5 -0
  149. package/dist/packages/adapter-sveltekit/package.json.js.map +1 -0
  150. package/dist/plugin.cjs +204 -0
  151. package/dist/plugin.cjs.map +1 -0
  152. package/dist/plugin.d.ts +2 -0
  153. package/dist/plugin.js +204 -0
  154. package/dist/plugin.js.map +1 -0
  155. package/dist/simulator/SliceSimulator.svelte +65 -0
  156. package/dist/simulator/SliceSimulator.svelte.d.ts +35 -0
  157. package/dist/simulator/index.d.ts +1 -0
  158. package/dist/simulator/index.js +1 -0
  159. package/dist/types.d.ts +21 -0
  160. package/package.json +111 -2
  161. package/src/constants.ts +5 -0
  162. package/src/hooks/project-init.ts +265 -0
  163. package/src/hooks/slice-create.ts +120 -0
  164. package/src/hooks/sliceSimulator-setup-read.ts +203 -0
  165. package/src/hooks/snippet-read.ts +163 -0
  166. package/src/index.ts +3 -0
  167. package/src/lib/checkIsTypeScriptProject.ts +18 -0
  168. package/src/lib/getJSFileExtension.ts +22 -0
  169. package/src/lib/pascalCase.ts +12 -0
  170. package/src/lib/rejectIfNecessary.ts +16 -0
  171. package/src/lib/upsertSliceLibraryIndexFile.ts +77 -0
  172. package/src/plugin.ts +275 -0
  173. package/src/simulator/SliceSimulator.svelte +65 -0
  174. package/src/simulator/index.ts +1 -0
  175. package/src/types.ts +23 -0
@@ -0,0 +1,69 @@
1
+ import { writeSliceModel, upsertGlobalTypeScriptTypes, writeSliceFile } from "@slicemachine/plugin-kit/fs";
2
+ import { source } from "common-tags";
3
+ import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
4
+ import { pascalCase } from "../lib/pascalCase.js";
5
+ import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
6
+ import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
7
+ var __freeze = Object.freeze;
8
+ var __defProp = Object.defineProperty;
9
+ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
10
+ var _a, _b;
11
+ const createComponentFile = async ({ data, helpers, actions, options }) => {
12
+ const pascalName = pascalCase(data.model.name);
13
+ let contents;
14
+ const isTypeScriptProject = await checkIsTypeScriptProject({
15
+ helpers,
16
+ options
17
+ });
18
+ if (isTypeScriptProject) {
19
+ contents = source(_a || (_a = __template([`
20
+ <script lang="ts">
21
+ import type { Content, SliceZone } from '@prismicio/client';
22
+
23
+ export let slice: Content.`, "Slice;\n export let slices: SliceZone;\n export let index: number;\n export let context: unknown;\n <\/script>\n\n <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n Placeholder component for {slice.slice_type} (variation: {slice.variation}) Slices\n </section>\n "])), pascalName);
24
+ } else {
25
+ contents = source(_b || (_b = __template(['\n <script>\n /** @type {import("@prismicio/client").Content.', 'Slice} */\n export let slice;\n /** @type {import("@prismicio/client").SliceZone} */\n export let slices;\n /** @type {number} */\n export let index;\n /** @type {unknown} */\n export let context;\n <\/script>\n\n <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n Placeholder component for {slice.slice_type} (variation: {slice.variation}) Slices\n </section>\n '])), pascalName);
26
+ }
27
+ await writeSliceFile({
28
+ libraryID: data.libraryID,
29
+ model: data.model,
30
+ filename: "index.svelte",
31
+ contents,
32
+ format: options.format,
33
+ actions,
34
+ helpers,
35
+ formatOptions: {
36
+ prettier: {
37
+ plugins: ["prettier-plugin-svelte"],
38
+ parser: "svelte"
39
+ }
40
+ }
41
+ });
42
+ };
43
+ const sliceCreate = async (data, context) => {
44
+ rejectIfNecessary(await Promise.allSettled([
45
+ writeSliceModel({
46
+ libraryID: data.libraryID,
47
+ model: data.model,
48
+ format: context.options.format,
49
+ helpers: context.helpers
50
+ }),
51
+ createComponentFile({ data, ...context })
52
+ ]));
53
+ rejectIfNecessary(await Promise.allSettled([
54
+ upsertSliceLibraryIndexFile({
55
+ libraryID: data.libraryID,
56
+ ...context
57
+ }),
58
+ upsertGlobalTypeScriptTypes({
59
+ filename: context.options.generatedTypesFilePath,
60
+ format: context.options.format,
61
+ helpers: context.helpers,
62
+ actions: context.actions
63
+ })
64
+ ]));
65
+ };
66
+ export {
67
+ sliceCreate
68
+ };
69
+ //# 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\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tupsertGlobalTypeScriptTypes,\n\twriteSliceFile,\n\twriteSliceModel,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { source } from \"common-tags\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype Args = {\n\tdata: SliceCreateHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst createComponentFile = async ({\n\tdata,\n\thelpers,\n\tactions,\n\toptions,\n}: Args) => {\n\tconst pascalName = pascalCase(data.model.name);\n\n\tlet contents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tcontents = source`\n\t\t\t<script lang=\"ts\">\n\t\t\t\timport type { Content, SliceZone } from '@prismicio/client';\n\n\t\t\t\texport let slice: Content.${pascalName}Slice;\n\t\t\t\texport let slices: SliceZone;\n\t\t\t\texport let index: number;\n\t\t\t\texport let context: unknown;\n\t\t\t</script>\n\n\t\t\t<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n\t\t\t\tPlaceholder component for {slice.slice_type} (variation: {slice.variation}) Slices\n\t\t\t</section>\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\t<script>\n\t\t\t\t/** @type {import(\"@prismicio/client\").Content.${pascalName}Slice} */\n\t\t\t\texport let slice;\n\t\t\t\t/** @type {import(\"@prismicio/client\").SliceZone} */\n\t\t\t\texport let slices;\n\t\t\t\t/** @type {number} */\n\t\t\t\texport let index;\n\t\t\t\t/** @type {unknown} */\n\t\t\t\texport let context;\n\t\t\t</script>\n\n\t\t\t<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n\t\t\t\tPlaceholder component for {slice.slice_type} (variation: {slice.variation}) Slices\n\t\t\t</section>\n\t\t`;\n\t}\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":";;;;;;;;;AAKA,IAAA,IAAA;AAkBA,MAAM,sBAAsB,OAAO,EAClC,MACA,SACA,SACA,cACU;AACV,QAAM,aAAa,WAAW,KAAK,MAAM,IAAI;AAEzC,MAAA;AAEE,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,MAAI,qBAAqB;AACxB,eAAW,OAAM,OAAA,KAAA,WAAA,CAAA;AAAA;AAAA;AAAA;AAAA,iCAIuB,gUAAV,CAAA,IAAA,UAAA;AAAA,EAAA,OAUxB;AACK,eAAA,OAAA,OAAA,KAAM,kFAE4C,+aAAV,CAAA,IAAA,UAAA;AAAA,EAcnD;AAED,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,MACR;AAAA,IACD;AAAA,EAAA,CACD;AACF;AAEa,MAAA,cAA8C,OAC1D,MACA,YACG;AAEF,oBAAA,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,EACxC,CAAA,CAAC;AAIF,oBAAA,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,EACD,CAAA,CAAC;AAEJ;"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const commonTags = require("common-tags");
4
+ const node_module = require("node:module");
5
+ const index = require('./../_node_modules/node-fetch/src/index.cjs');
6
+ var __freeze = Object.freeze;
7
+ var __defProp = Object.defineProperty;
8
+ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
9
+ var _a;
10
+ const REQUIRED_DEPENDENCIES = ["@prismicio/svelte"];
11
+ const createStep1 = async ({ project, helpers }) => {
12
+ const require2 = node_module.createRequire(project.root);
13
+ return {
14
+ title: "Install packages",
15
+ description: "The simulator requires some dependencies.",
16
+ // TODO: Create a plugin runner helper to provide the correct
17
+ // package manager
18
+ body: commonTags.source`
19
+ The simulator requires extra dependencies. Run the following command to install them.
20
+
21
+ ~~~sh
22
+ npm install --save ${REQUIRED_DEPENDENCIES.join(" ")}
23
+ ~~~
24
+ `,
25
+ validate: async () => {
26
+ const missingDependencies = [];
27
+ for (const dependency of REQUIRED_DEPENDENCIES) {
28
+ try {
29
+ require2.resolve(dependency, {
30
+ paths: [helpers.joinPathFromRoot("node_modules")]
31
+ });
32
+ } catch {
33
+ missingDependencies.push(dependency);
34
+ }
35
+ }
36
+ if (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {
37
+ return {
38
+ title: "Missing all dependencies",
39
+ message: commonTags.source`
40
+ Install the required dependencies to continue.
41
+ `
42
+ };
43
+ }
44
+ if (missingDependencies.length > 0) {
45
+ const formattedMissingDependencies = missingDependencies.map((missingDependency) => `\`${missingDependency}\``).join(", ");
46
+ return {
47
+ title: "Missing some dependencies",
48
+ message: commonTags.source`
49
+ The following dependencies are missing: ${formattedMissingDependencies}
50
+ `
51
+ };
52
+ }
53
+ }
54
+ };
55
+ };
56
+ const createStep2 = async ({ helpers }) => {
57
+ const filePath = helpers.joinPathFromRoot("src", "routes", "slice-simulator", "+page.svelte");
58
+ const fileContents = await helpers.format(commonTags.source(_a || (_a = __template(["\n <script>\n import { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n import { SliceZone } from '@prismicio/svelte';\n import { components } from '$lib/slices';\n <\/script>\n\n <SliceSimulator let:slices>\n <SliceZone {slices} {components} />\n </SliceSimulator>\n "]))), filePath, {
59
+ includeNewlineAtEnd: false,
60
+ prettier: {
61
+ plugins: ["prettier-plugin-svelte"],
62
+ parser: "svelte"
63
+ }
64
+ });
65
+ return {
66
+ title: "Create a page for the simulator",
67
+ description: `Create a file at \`src/routes/slice-simulator/+page.svelte\` containing this code.`,
68
+ body: commonTags.source`
69
+ Create a file at \`src/routes/slice-simulator/+page.svelte\` containing the following code. This route will be used to simulate and develop your components.
70
+
71
+ ~~~svelte
72
+ ${fileContents}
73
+ ~~~
74
+ `
75
+ };
76
+ };
77
+ const createStep3 = async ({ helpers }) => {
78
+ const filePath = helpers.joinPathFromRoot("slicemachine.config.json");
79
+ const fileContents = await helpers.format(commonTags.source`
80
+ {
81
+ "localSliceSimulatorURL": "http://localhost:5173/slice-simulator"
82
+ }
83
+ `, filePath, {
84
+ includeNewlineAtEnd: false
85
+ });
86
+ return {
87
+ title: "Update `slicemachine.config.json`",
88
+ description: `Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.`,
89
+ body: commonTags.source`
90
+ Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.
91
+
92
+ ~~~json
93
+ ${fileContents}
94
+ ~~~
95
+ `,
96
+ validate: async () => {
97
+ const project = await helpers.getProject();
98
+ if (!("localSliceSimulatorURL" in project.config)) {
99
+ return {
100
+ title: "Missing `localSliceSimulatorURL` property",
101
+ message: commonTags.source`
102
+ A \`localSliceSimulatorURL\` property was not found in your \`slicemachine.config.json\` file.
103
+ `
104
+ };
105
+ }
106
+ try {
107
+ if (project.config.localSliceSimulatorURL) {
108
+ new URL(project.config.localSliceSimulatorURL);
109
+ } else {
110
+ throw new Error("Undefined Slice Simulator URL");
111
+ }
112
+ } catch {
113
+ return {
114
+ title: "An invalid URL was provided",
115
+ message: commonTags.source`
116
+ The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
117
+ `
118
+ };
119
+ }
120
+ let res = void 0;
121
+ try {
122
+ res = await index.default(project.config.localSliceSimulatorURL);
123
+ } catch (error) {
124
+ }
125
+ if (!res || !res.ok) {
126
+ return {
127
+ title: "Unable to connect to simulator page",
128
+ message: commonTags.source`
129
+ Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.
130
+ `
131
+ };
132
+ }
133
+ }
134
+ };
135
+ };
136
+ const sliceSimulatorSetupRead = async (_data, context) => {
137
+ return await Promise.all([
138
+ createStep1(context),
139
+ createStep2(context),
140
+ createStep3(context)
141
+ ]);
142
+ };
143
+ exports.sliceSimulatorSetupRead = sliceSimulatorSetupRead;
144
+ //# sourceMappingURL=sliceSimulator-setup-read.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sliceSimulator-setup-read.cjs","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch, { Response } from \"node-fetch\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\"@prismicio/svelte\"];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"slice-simulator\",\n\t\t\"+page.svelte\",\n\t);\n\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t<script>\n\t\t\t\timport { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n\t\t\t\timport { SliceZone } from '@prismicio/svelte';\n\t\t\t\timport { components } from '$lib/slices';\n\t\t\t</script>\n\n\t\t\t<SliceSimulator let:slices>\n\t\t\t\t<SliceZone {slices} {components} />\n\t\t\t</SliceSimulator>\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\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\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tdescription: `Create a file at \\`src/routes/slice-simulator/+page.svelte\\` containing this code.`,\n\t\tbody: source`\n\t\t\tCreate a file at \\`src/routes/slice-simulator/+page.svelte\\` containing the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~svelte\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t};\n};\n\nconst createStep3 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\"slicemachine.config.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:5173/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Update `slicemachine.config.json`\",\n\t\tdescription: `Update your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.\n\n\t\t\t~~~json\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst project = await helpers.getProject();\n\n\t\t\tif (!(\"localSliceSimulatorURL\" in project.config)) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`slicemachine.config.json\\` file.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Test if the URL is valid.\n\t\t\ttry {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\tnew URL(project.config.localSliceSimulatorURL);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Undefined Slice Simulator URL\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe \\`localSliceSimulatorURL\\` property should be of the shape \\`http://localhost:PORT/PATH\\`. See the codeblock for an example.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if the URL is accessible.\n\t\t\tlet res: Response | undefined = undefined;\n\t\t\ttry {\n\t\t\t\tres = await fetch(project.config.localSliceSimulatorURL);\n\t\t\t} catch (error) {\n\t\t\t\t// Noop, we return if `res` is not defined\n\t\t\t}\n\n\t\t\tif (!res || !res.ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`slicemachine.config.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nexport const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<\n\tPluginOptions\n> = async (_data, context) => {\n\treturn await Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require","createRequire","source","fetch"],"mappings":"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"}
@@ -0,0 +1,3 @@
1
+ import type { SliceSimulatorSetupReadHook } from "@slicemachine/plugin-kit";
2
+ import type { PluginOptions } from "../types";
3
+ export declare const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<PluginOptions>;
@@ -0,0 +1,144 @@
1
+ import { source } from "common-tags";
2
+ import { createRequire } from "node:module";
3
+ import fetch from './../_node_modules/node-fetch/src/index.js';
4
+ var __freeze = Object.freeze;
5
+ var __defProp = Object.defineProperty;
6
+ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
7
+ var _a;
8
+ const REQUIRED_DEPENDENCIES = ["@prismicio/svelte"];
9
+ const createStep1 = async ({ project, helpers }) => {
10
+ const require2 = createRequire(project.root);
11
+ return {
12
+ title: "Install packages",
13
+ description: "The simulator requires some dependencies.",
14
+ // TODO: Create a plugin runner helper to provide the correct
15
+ // package manager
16
+ body: source`
17
+ The simulator requires extra dependencies. Run the following command to install them.
18
+
19
+ ~~~sh
20
+ npm install --save ${REQUIRED_DEPENDENCIES.join(" ")}
21
+ ~~~
22
+ `,
23
+ validate: async () => {
24
+ const missingDependencies = [];
25
+ for (const dependency of REQUIRED_DEPENDENCIES) {
26
+ try {
27
+ require2.resolve(dependency, {
28
+ paths: [helpers.joinPathFromRoot("node_modules")]
29
+ });
30
+ } catch {
31
+ missingDependencies.push(dependency);
32
+ }
33
+ }
34
+ if (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {
35
+ return {
36
+ title: "Missing all dependencies",
37
+ message: source`
38
+ Install the required dependencies to continue.
39
+ `
40
+ };
41
+ }
42
+ if (missingDependencies.length > 0) {
43
+ const formattedMissingDependencies = missingDependencies.map((missingDependency) => `\`${missingDependency}\``).join(", ");
44
+ return {
45
+ title: "Missing some dependencies",
46
+ message: source`
47
+ The following dependencies are missing: ${formattedMissingDependencies}
48
+ `
49
+ };
50
+ }
51
+ }
52
+ };
53
+ };
54
+ const createStep2 = async ({ helpers }) => {
55
+ const filePath = helpers.joinPathFromRoot("src", "routes", "slice-simulator", "+page.svelte");
56
+ const fileContents = await helpers.format(source(_a || (_a = __template(["\n <script>\n import { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n import { SliceZone } from '@prismicio/svelte';\n import { components } from '$lib/slices';\n <\/script>\n\n <SliceSimulator let:slices>\n <SliceZone {slices} {components} />\n </SliceSimulator>\n "]))), filePath, {
57
+ includeNewlineAtEnd: false,
58
+ prettier: {
59
+ plugins: ["prettier-plugin-svelte"],
60
+ parser: "svelte"
61
+ }
62
+ });
63
+ return {
64
+ title: "Create a page for the simulator",
65
+ description: `Create a file at \`src/routes/slice-simulator/+page.svelte\` containing this code.`,
66
+ body: source`
67
+ Create a file at \`src/routes/slice-simulator/+page.svelte\` containing the following code. This route will be used to simulate and develop your components.
68
+
69
+ ~~~svelte
70
+ ${fileContents}
71
+ ~~~
72
+ `
73
+ };
74
+ };
75
+ const createStep3 = async ({ helpers }) => {
76
+ const filePath = helpers.joinPathFromRoot("slicemachine.config.json");
77
+ const fileContents = await helpers.format(source`
78
+ {
79
+ "localSliceSimulatorURL": "http://localhost:5173/slice-simulator"
80
+ }
81
+ `, filePath, {
82
+ includeNewlineAtEnd: false
83
+ });
84
+ return {
85
+ title: "Update `slicemachine.config.json`",
86
+ description: `Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.`,
87
+ body: source`
88
+ Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.
89
+
90
+ ~~~json
91
+ ${fileContents}
92
+ ~~~
93
+ `,
94
+ validate: async () => {
95
+ const project = await helpers.getProject();
96
+ if (!("localSliceSimulatorURL" in project.config)) {
97
+ return {
98
+ title: "Missing `localSliceSimulatorURL` property",
99
+ message: source`
100
+ A \`localSliceSimulatorURL\` property was not found in your \`slicemachine.config.json\` file.
101
+ `
102
+ };
103
+ }
104
+ try {
105
+ if (project.config.localSliceSimulatorURL) {
106
+ new URL(project.config.localSliceSimulatorURL);
107
+ } else {
108
+ throw new Error("Undefined Slice Simulator URL");
109
+ }
110
+ } catch {
111
+ return {
112
+ title: "An invalid URL was provided",
113
+ message: source`
114
+ The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
115
+ `
116
+ };
117
+ }
118
+ let res = void 0;
119
+ try {
120
+ res = await fetch(project.config.localSliceSimulatorURL);
121
+ } catch (error) {
122
+ }
123
+ if (!res || !res.ok) {
124
+ return {
125
+ title: "Unable to connect to simulator page",
126
+ message: source`
127
+ Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.
128
+ `
129
+ };
130
+ }
131
+ }
132
+ };
133
+ };
134
+ const sliceSimulatorSetupRead = async (_data, context) => {
135
+ return await Promise.all([
136
+ createStep1(context),
137
+ createStep2(context),
138
+ createStep3(context)
139
+ ]);
140
+ };
141
+ export {
142
+ sliceSimulatorSetupRead
143
+ };
144
+ //# sourceMappingURL=sliceSimulator-setup-read.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sliceSimulator-setup-read.js","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch, { Response } from \"node-fetch\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\"@prismicio/svelte\"];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"slice-simulator\",\n\t\t\"+page.svelte\",\n\t);\n\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t<script>\n\t\t\t\timport { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n\t\t\t\timport { SliceZone } from '@prismicio/svelte';\n\t\t\t\timport { components } from '$lib/slices';\n\t\t\t</script>\n\n\t\t\t<SliceSimulator let:slices>\n\t\t\t\t<SliceZone {slices} {components} />\n\t\t\t</SliceSimulator>\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\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\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tdescription: `Create a file at \\`src/routes/slice-simulator/+page.svelte\\` containing this code.`,\n\t\tbody: source`\n\t\t\tCreate a file at \\`src/routes/slice-simulator/+page.svelte\\` containing the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~svelte\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t};\n};\n\nconst createStep3 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\"slicemachine.config.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:5173/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Update `slicemachine.config.json`\",\n\t\tdescription: `Update your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.\n\n\t\t\t~~~json\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst project = await helpers.getProject();\n\n\t\t\tif (!(\"localSliceSimulatorURL\" in project.config)) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`slicemachine.config.json\\` file.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Test if the URL is valid.\n\t\t\ttry {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\tnew URL(project.config.localSliceSimulatorURL);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Undefined Slice Simulator URL\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe \\`localSliceSimulatorURL\\` property should be of the shape \\`http://localhost:PORT/PATH\\`. See the codeblock for an example.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if the URL is accessible.\n\t\t\tlet res: Response | undefined = undefined;\n\t\t\ttry {\n\t\t\t\tres = await fetch(project.config.localSliceSimulatorURL);\n\t\t\t} catch (error) {\n\t\t\t\t// Noop, we return if `res` is not defined\n\t\t\t}\n\n\t\t\tif (!res || !res.ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`slicemachine.config.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nexport const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<\n\tPluginOptions\n> = async (_data, context) => {\n\treturn await Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require"],"mappings":"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"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const commonTags = require("common-tags");
4
+ const dotPath = (...segments) => {
5
+ return segments.flat().join(".");
6
+ };
7
+ const format = async (input, helpers) => {
8
+ const formattedInput = await helpers.format(input, void 0, {
9
+ includeNewlineAtEnd: false,
10
+ prettier: {
11
+ plugins: ["prettier-plugin-svelte"],
12
+ parser: "svelte"
13
+ }
14
+ });
15
+ return formattedInput;
16
+ };
17
+ const snippetRead = async (data, { helpers }) => {
18
+ const { fieldPath } = data;
19
+ const label = "Svelte";
20
+ switch (data.model.type) {
21
+ case "StructuredText": {
22
+ return [
23
+ {
24
+ label: `${label} (components)`,
25
+ language: "svelte",
26
+ code: await format(commonTags.stripIndent`
27
+ <PrismicRichText field={${dotPath(fieldPath)}} />
28
+ `, helpers)
29
+ },
30
+ {
31
+ label: `${label} (plain text)`,
32
+ language: "svelte",
33
+ code: await format(commonTags.stripIndent`
34
+ <PrismicText field={${dotPath(fieldPath)}} />
35
+ `, helpers)
36
+ }
37
+ ];
38
+ }
39
+ case "Link": {
40
+ return {
41
+ label,
42
+ language: "svelte",
43
+ code: await format(commonTags.stripIndent`
44
+ <PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
45
+ `, helpers)
46
+ };
47
+ }
48
+ case "Image": {
49
+ return {
50
+ label,
51
+ language: "svelte",
52
+ code: await format(commonTags.stripIndent`
53
+ <PrismicImage field={${dotPath(fieldPath)}} />
54
+ `, helpers)
55
+ };
56
+ }
57
+ case "Group": {
58
+ const code = await format(commonTags.stripIndent`
59
+ {#each ${dotPath(fieldPath)} as item}
60
+ <!-- Render content for item -->
61
+ {/each}
62
+ `, helpers);
63
+ return {
64
+ label,
65
+ language: "svelte",
66
+ code
67
+ };
68
+ }
69
+ case "Slices": {
70
+ const code = await format(commonTags.stripIndent`
71
+ <SliceZone
72
+ slices={${dotPath(fieldPath)}}
73
+ {components}
74
+ />
75
+ `, helpers);
76
+ return {
77
+ label,
78
+ language: "svelte",
79
+ code
80
+ };
81
+ }
82
+ case "GeoPoint": {
83
+ const code = await format(commonTags.stripIndent`
84
+ {${dotPath(fieldPath, "latitude")}}, {${dotPath(fieldPath, "longitude")}}
85
+ `, helpers);
86
+ return {
87
+ label,
88
+ language: "svelte",
89
+ code
90
+ };
91
+ }
92
+ case "Embed": {
93
+ const code = await format(commonTags.stripIndent`
94
+ {@html ${dotPath(fieldPath, "html")}}
95
+ `, helpers);
96
+ return {
97
+ label,
98
+ language: "svelte",
99
+ code
100
+ };
101
+ }
102
+ default: {
103
+ return {
104
+ label,
105
+ language: "svelte",
106
+ code: await format(commonTags.stripIndent`
107
+ {${dotPath(fieldPath)}}
108
+ `, helpers)
109
+ };
110
+ }
111
+ }
112
+ };
113
+ exports.snippetRead = snippetRead;
114
+ //# sourceMappingURL=snippet-read.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snippet-read.cjs","sources":["../../../src/hooks/snippet-read.ts"],"sourcesContent":["import type {\n\tSliceMachineHelpers,\n\tSnippetReadHook,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (...segments: (string | string[])[]): string => {\n\treturn segments.flat().join(\".\");\n};\n\nconst format = async (input: string, helpers: SliceMachineHelpers) => {\n\tconst formattedInput = await helpers.format(input, undefined, {\n\t\tincludeNewlineAtEnd: false,\n\t\tprettier: {\n\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\tparser: \"svelte\",\n\t\t},\n\t});\n\n\treturn formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath } = data;\n\n\tconst label = \"Svelte\";\n\n\tswitch (data.model.type) {\n\t\tcase \"StructuredText\": {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (components)`,\n\t\t\t\t\tlanguage: \"svelte\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicRichText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (plain text)`,\n\t\t\t\t\tlanguage: \"svelte\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tcase \"Link\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"svelte\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase \"Image\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"svelte\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t{#each ${dotPath(fieldPath)} as item}\n\t\t\t\t\t\t<!-- Render content for item -->\n\t\t\t\t\t{/each}\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"svelte\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"Slices\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t slices={${dotPath(fieldPath)}}\n\t\t\t\t\t {components}\n\t\t\t\t\t/>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"svelte\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"GeoPoint\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t{${dotPath(fieldPath, \"latitude\")}}, {${dotPath(fieldPath, \"longitude\")}}\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"svelte\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"Embed\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t{@html ${dotPath(fieldPath, \"html\")}}\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"svelte\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"svelte\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t{${dotPath(fieldPath)}}\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t}\n};\n"],"names":["stripIndent"],"mappings":";;;AAQA,MAAM,UAAU,IAAI,aAA2C;AAC9D,SAAO,SAAS,KAAA,EAAO,KAAK,GAAG;AAChC;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,SAAS,CAAC,wBAAwB;AAAA,MAClC,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAEM,SAAA;AACR;AAEO,MAAM,cAA8C,OAC1D,MACA,EAAE,cACC;AACG,QAAA,EAAE,UAAc,IAAA;AAEtB,QAAM,QAAQ;AAEN,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAK,kBAAkB;AACf,aAAA;AAAA,QACN;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACXA;iCAC2B,QAAQ,SAAS;AAAA,SAE5C,OAAO;AAAA,QAER;AAAA,QACD;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACXA;6BACuB,QAAQ,SAAS;AAAA,SAExC,OAAO;AAAA,QAER;AAAA,MAAA;AAAA,IAEF;AAAA,IAED,KAAK,QAAQ;AACL,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;4BACuB,QAAQ,SAAS;AAAA,QAExC,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;8BACyB,QAAQ,SAAS;AAAA,SAE1C,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClBA;cACU,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI3B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,UAAU;AACR,YAAA,OAAO,MAAM,OAClBA;;iBAEa,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI9B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,YAAY;AACV,YAAA,OAAO,MAAM,OAClBA;QACI,QAAQ,WAAW,UAAU,QAAQ,QAAQ,WAAW,WAAW;AAAA,OAEvE,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClBA;cACU,QAAQ,WAAW,MAAM;AAAA,OAEnC,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;SACI,QAAQ,SAAS;AAAA,QAErB,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,EACD;AACF;;"}
@@ -0,0 +1,3 @@
1
+ import type { SnippetReadHook } from "@slicemachine/plugin-kit";
2
+ import type { PluginOptions } from "../types";
3
+ export declare const snippetRead: SnippetReadHook<PluginOptions>;
@@ -0,0 +1,114 @@
1
+ import { stripIndent } from "common-tags";
2
+ const dotPath = (...segments) => {
3
+ return segments.flat().join(".");
4
+ };
5
+ const format = async (input, helpers) => {
6
+ const formattedInput = await helpers.format(input, void 0, {
7
+ includeNewlineAtEnd: false,
8
+ prettier: {
9
+ plugins: ["prettier-plugin-svelte"],
10
+ parser: "svelte"
11
+ }
12
+ });
13
+ return formattedInput;
14
+ };
15
+ const snippetRead = async (data, { helpers }) => {
16
+ const { fieldPath } = data;
17
+ const label = "Svelte";
18
+ switch (data.model.type) {
19
+ case "StructuredText": {
20
+ return [
21
+ {
22
+ label: `${label} (components)`,
23
+ language: "svelte",
24
+ code: await format(stripIndent`
25
+ <PrismicRichText field={${dotPath(fieldPath)}} />
26
+ `, helpers)
27
+ },
28
+ {
29
+ label: `${label} (plain text)`,
30
+ language: "svelte",
31
+ code: await format(stripIndent`
32
+ <PrismicText field={${dotPath(fieldPath)}} />
33
+ `, helpers)
34
+ }
35
+ ];
36
+ }
37
+ case "Link": {
38
+ return {
39
+ label,
40
+ language: "svelte",
41
+ code: await format(stripIndent`
42
+ <PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
43
+ `, helpers)
44
+ };
45
+ }
46
+ case "Image": {
47
+ return {
48
+ label,
49
+ language: "svelte",
50
+ code: await format(stripIndent`
51
+ <PrismicImage field={${dotPath(fieldPath)}} />
52
+ `, helpers)
53
+ };
54
+ }
55
+ case "Group": {
56
+ const code = await format(stripIndent`
57
+ {#each ${dotPath(fieldPath)} as item}
58
+ <!-- Render content for item -->
59
+ {/each}
60
+ `, helpers);
61
+ return {
62
+ label,
63
+ language: "svelte",
64
+ code
65
+ };
66
+ }
67
+ case "Slices": {
68
+ const code = await format(stripIndent`
69
+ <SliceZone
70
+ slices={${dotPath(fieldPath)}}
71
+ {components}
72
+ />
73
+ `, helpers);
74
+ return {
75
+ label,
76
+ language: "svelte",
77
+ code
78
+ };
79
+ }
80
+ case "GeoPoint": {
81
+ const code = await format(stripIndent`
82
+ {${dotPath(fieldPath, "latitude")}}, {${dotPath(fieldPath, "longitude")}}
83
+ `, helpers);
84
+ return {
85
+ label,
86
+ language: "svelte",
87
+ code
88
+ };
89
+ }
90
+ case "Embed": {
91
+ const code = await format(stripIndent`
92
+ {@html ${dotPath(fieldPath, "html")}}
93
+ `, helpers);
94
+ return {
95
+ label,
96
+ language: "svelte",
97
+ code
98
+ };
99
+ }
100
+ default: {
101
+ return {
102
+ label,
103
+ language: "svelte",
104
+ code: await format(stripIndent`
105
+ {${dotPath(fieldPath)}}
106
+ `, helpers)
107
+ };
108
+ }
109
+ }
110
+ };
111
+ export {
112
+ snippetRead
113
+ };
114
+ //# sourceMappingURL=snippet-read.js.map