@slicemachine/adapter-next 0.0.3 → 0.0.5

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 (210) hide show
  1. package/dist/SliceSimulator.cjs +14 -41
  2. package/dist/SliceSimulator.cjs.map +1 -1
  3. package/dist/SliceSimulator.js +11 -36
  4. package/dist/SliceSimulator.js.map +1 -1
  5. package/dist/_virtual/_commonjsHelpers.cjs +5 -0
  6. package/dist/_virtual/_commonjsHelpers.cjs.map +1 -0
  7. package/dist/_virtual/_commonjsHelpers.js +5 -0
  8. package/dist/_virtual/_commonjsHelpers.js.map +1 -0
  9. package/dist/_virtual/ponyfill.es2018.cjs +13 -0
  10. package/dist/_virtual/ponyfill.es2018.cjs.map +1 -0
  11. package/dist/_virtual/ponyfill.es2018.js +14 -0
  12. package/dist/_virtual/ponyfill.es2018.js.map +1 -0
  13. package/dist/constants.cjs +5 -0
  14. package/dist/constants.cjs.map +1 -0
  15. package/dist/constants.d.ts +4 -0
  16. package/dist/constants.js +5 -0
  17. package/dist/constants.js.map +1 -0
  18. package/dist/hooks/customType-asset-delete.cjs +3 -5
  19. package/dist/hooks/customType-asset-delete.cjs.map +1 -1
  20. package/dist/hooks/customType-asset-delete.js.map +1 -1
  21. package/dist/hooks/customType-asset-read.cjs +3 -5
  22. package/dist/hooks/customType-asset-read.cjs.map +1 -1
  23. package/dist/hooks/customType-asset-read.js.map +1 -1
  24. package/dist/hooks/customType-asset-update.cjs +4 -6
  25. package/dist/hooks/customType-asset-update.cjs.map +1 -1
  26. package/dist/hooks/customType-asset-update.js.map +1 -1
  27. package/dist/hooks/customType-create.cjs +4 -6
  28. package/dist/hooks/customType-create.cjs.map +1 -1
  29. package/dist/hooks/customType-create.js.map +1 -1
  30. package/dist/hooks/customType-delete.cjs +3 -5
  31. package/dist/hooks/customType-delete.cjs.map +1 -1
  32. package/dist/hooks/customType-delete.js.map +1 -1
  33. package/dist/hooks/customType-read.cjs +1 -1
  34. package/dist/hooks/customType-read.cjs.map +1 -1
  35. package/dist/hooks/customType-read.js.map +1 -1
  36. package/dist/hooks/customType-rename.cjs +1 -1
  37. package/dist/hooks/customType-rename.cjs.map +1 -1
  38. package/dist/hooks/customType-rename.js.map +1 -1
  39. package/dist/hooks/customType-update.cjs +1 -1
  40. package/dist/hooks/customType-update.cjs.map +1 -1
  41. package/dist/hooks/customType-update.js.map +1 -1
  42. package/dist/hooks/customTypeLibrary-read.cjs +4 -6
  43. package/dist/hooks/customTypeLibrary-read.cjs.map +1 -1
  44. package/dist/hooks/customTypeLibrary-read.js.map +1 -1
  45. package/dist/hooks/slice-asset-delete.cjs +3 -5
  46. package/dist/hooks/slice-asset-delete.cjs.map +1 -1
  47. package/dist/hooks/slice-asset-delete.js.map +1 -1
  48. package/dist/hooks/slice-asset-read.cjs +3 -5
  49. package/dist/hooks/slice-asset-read.cjs.map +1 -1
  50. package/dist/hooks/slice-asset-read.js.map +1 -1
  51. package/dist/hooks/slice-asset-update.cjs +4 -6
  52. package/dist/hooks/slice-asset-update.cjs.map +1 -1
  53. package/dist/hooks/slice-asset-update.js.map +1 -1
  54. package/dist/hooks/slice-create.cjs +7 -9
  55. package/dist/hooks/slice-create.cjs.map +1 -1
  56. package/dist/hooks/slice-create.js +3 -3
  57. package/dist/hooks/slice-create.js.map +1 -1
  58. package/dist/hooks/slice-delete.cjs +3 -5
  59. package/dist/hooks/slice-delete.cjs.map +1 -1
  60. package/dist/hooks/slice-delete.js.map +1 -1
  61. package/dist/hooks/slice-read.cjs +4 -6
  62. package/dist/hooks/slice-read.cjs.map +1 -1
  63. package/dist/hooks/slice-read.js.map +1 -1
  64. package/dist/hooks/slice-rename.cjs +3 -5
  65. package/dist/hooks/slice-rename.cjs.map +1 -1
  66. package/dist/hooks/slice-rename.js.map +1 -1
  67. package/dist/hooks/slice-update.cjs +1 -1
  68. package/dist/hooks/slice-update.cjs.map +1 -1
  69. package/dist/hooks/slice-update.js.map +1 -1
  70. package/dist/hooks/sliceLibrary-read.cjs +4 -6
  71. package/dist/hooks/sliceLibrary-read.cjs.map +1 -1
  72. package/dist/hooks/sliceLibrary-read.js.map +1 -1
  73. package/dist/hooks/sliceSimulator-setup-read.cjs +32 -98
  74. package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
  75. package/dist/hooks/sliceSimulator-setup-read.js +32 -79
  76. package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
  77. package/dist/hooks/snippet-read.cjs +33 -18
  78. package/dist/hooks/snippet-read.cjs.map +1 -1
  79. package/dist/hooks/snippet-read.js +30 -13
  80. package/dist/hooks/snippet-read.js.map +1 -1
  81. package/dist/index.cjs +0 -2
  82. package/dist/index.cjs.map +1 -1
  83. package/dist/index.d.ts +0 -2
  84. package/dist/index.js +1 -4
  85. package/dist/index.js.map +1 -1
  86. package/dist/lib/getJSOrTSXFileExtension.cjs +1 -1
  87. package/dist/lib/getJSOrTSXFileExtension.cjs.map +1 -1
  88. package/dist/lib/getJSOrTSXFileExtension.js.map +1 -1
  89. package/dist/lib/isSharedSliceModel.cjs +3 -5
  90. package/dist/lib/isSharedSliceModel.cjs.map +1 -1
  91. package/dist/lib/isSharedSliceModel.js.map +1 -1
  92. package/dist/lib/pascalCase.cjs +1 -1
  93. package/dist/lib/pascalCase.cjs.map +1 -1
  94. package/dist/lib/pascalCase.js.map +1 -1
  95. package/dist/lib/readJSONFile.cjs +3 -5
  96. package/dist/lib/readJSONFile.cjs.map +1 -1
  97. package/dist/lib/readJSONFile.js.map +1 -1
  98. package/dist/lib/rejectIfNecessary.cjs +1 -1
  99. package/dist/lib/rejectIfNecessary.cjs.map +1 -1
  100. package/dist/lib/rejectIfNecessary.js.map +1 -1
  101. package/dist/lib/updateSliceModelFile.cjs +3 -5
  102. package/dist/lib/updateSliceModelFile.cjs.map +1 -1
  103. package/dist/lib/updateSliceModelFile.js.map +1 -1
  104. package/dist/lib/upsertGlobalContentTypes.cjs +8 -6
  105. package/dist/lib/upsertGlobalContentTypes.cjs.map +1 -1
  106. package/dist/lib/upsertGlobalContentTypes.js +4 -0
  107. package/dist/lib/upsertGlobalContentTypes.js.map +1 -1
  108. package/dist/lib/upsertSliceLibraryIndexFile.cjs +9 -8
  109. package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
  110. package/dist/lib/upsertSliceLibraryIndexFile.js +6 -3
  111. package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
  112. package/dist/node_modules/data-uri-to-buffer/dist/index.cjs +41 -0
  113. package/dist/node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -0
  114. package/dist/node_modules/data-uri-to-buffer/dist/index.js +41 -0
  115. package/dist/node_modules/data-uri-to-buffer/dist/index.js.map +1 -0
  116. package/dist/node_modules/fetch-blob/file.cjs +55 -0
  117. package/dist/node_modules/fetch-blob/file.cjs.map +1 -0
  118. package/dist/node_modules/fetch-blob/file.js +55 -0
  119. package/dist/node_modules/fetch-blob/file.js.map +1 -0
  120. package/dist/node_modules/fetch-blob/index.cjs +177 -0
  121. package/dist/node_modules/fetch-blob/index.cjs.map +1 -0
  122. package/dist/node_modules/fetch-blob/index.js +177 -0
  123. package/dist/node_modules/fetch-blob/index.js.map +1 -0
  124. package/dist/node_modules/fetch-blob/streams.cjs +43 -0
  125. package/dist/node_modules/fetch-blob/streams.cjs.map +1 -0
  126. package/dist/node_modules/fetch-blob/streams.js +42 -0
  127. package/dist/node_modules/fetch-blob/streams.js.map +1 -0
  128. package/dist/node_modules/formdata-polyfill/esm.min.cjs +116 -0
  129. package/dist/node_modules/formdata-polyfill/esm.min.cjs.map +1 -0
  130. package/dist/node_modules/formdata-polyfill/esm.min.js +116 -0
  131. package/dist/node_modules/formdata-polyfill/esm.min.js.map +1 -0
  132. package/dist/node_modules/node-domexception/index.cjs +11 -0
  133. package/dist/node_modules/node-domexception/index.cjs.map +1 -0
  134. package/dist/node_modules/node-domexception/index.js +10 -0
  135. package/dist/node_modules/node-domexception/index.js.map +1 -0
  136. package/dist/node_modules/node-fetch/src/body.cjs +237 -0
  137. package/dist/node_modules/node-fetch/src/body.cjs.map +1 -0
  138. package/dist/node_modules/node-fetch/src/body.js +237 -0
  139. package/dist/node_modules/node-fetch/src/body.js.map +1 -0
  140. package/dist/node_modules/node-fetch/src/errors/abort-error.cjs +10 -0
  141. package/dist/node_modules/node-fetch/src/errors/abort-error.cjs.map +1 -0
  142. package/dist/node_modules/node-fetch/src/errors/abort-error.js +10 -0
  143. package/dist/node_modules/node-fetch/src/errors/abort-error.js.map +1 -0
  144. package/dist/node_modules/node-fetch/src/errors/base.cjs +17 -0
  145. package/dist/node_modules/node-fetch/src/errors/base.cjs.map +1 -0
  146. package/dist/node_modules/node-fetch/src/errors/base.js +17 -0
  147. package/dist/node_modules/node-fetch/src/errors/base.js.map +1 -0
  148. package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs +14 -0
  149. package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -0
  150. package/dist/node_modules/node-fetch/src/errors/fetch-error.js +14 -0
  151. package/dist/node_modules/node-fetch/src/errors/fetch-error.js.map +1 -0
  152. package/dist/node_modules/node-fetch/src/headers.cjs +173 -0
  153. package/dist/node_modules/node-fetch/src/headers.cjs.map +1 -0
  154. package/dist/node_modules/node-fetch/src/headers.js +173 -0
  155. package/dist/node_modules/node-fetch/src/headers.js.map +1 -0
  156. package/dist/node_modules/node-fetch/src/index.cjs +292 -0
  157. package/dist/node_modules/node-fetch/src/index.cjs.map +1 -0
  158. package/dist/node_modules/node-fetch/src/index.js +292 -0
  159. package/dist/node_modules/node-fetch/src/index.js.map +1 -0
  160. package/dist/node_modules/node-fetch/src/request.cjs +193 -0
  161. package/dist/node_modules/node-fetch/src/request.cjs.map +1 -0
  162. package/dist/node_modules/node-fetch/src/request.js +193 -0
  163. package/dist/node_modules/node-fetch/src/request.js.map +1 -0
  164. package/dist/node_modules/node-fetch/src/response.cjs +110 -0
  165. package/dist/node_modules/node-fetch/src/response.cjs.map +1 -0
  166. package/dist/node_modules/node-fetch/src/response.js +110 -0
  167. package/dist/node_modules/node-fetch/src/response.js.map +1 -0
  168. package/dist/node_modules/node-fetch/src/utils/get-search.cjs +12 -0
  169. package/dist/node_modules/node-fetch/src/utils/get-search.cjs.map +1 -0
  170. package/dist/node_modules/node-fetch/src/utils/get-search.js +12 -0
  171. package/dist/node_modules/node-fetch/src/utils/get-search.js.map +1 -0
  172. package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs +8 -0
  173. package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs.map +1 -0
  174. package/dist/node_modules/node-fetch/src/utils/is-redirect.js +8 -0
  175. package/dist/node_modules/node-fetch/src/utils/is-redirect.js.map +1 -0
  176. package/dist/node_modules/node-fetch/src/utils/is.cjs +28 -0
  177. package/dist/node_modules/node-fetch/src/utils/is.cjs.map +1 -0
  178. package/dist/node_modules/node-fetch/src/utils/is.js +28 -0
  179. package/dist/node_modules/node-fetch/src/utils/is.js.map +1 -0
  180. package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs +350 -0
  181. package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -0
  182. package/dist/node_modules/node-fetch/src/utils/multipart-parser.js +350 -0
  183. package/dist/node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -0
  184. package/dist/node_modules/node-fetch/src/utils/referrer.cjs +149 -0
  185. package/dist/node_modules/node-fetch/src/utils/referrer.cjs.map +1 -0
  186. package/dist/node_modules/node-fetch/src/utils/referrer.js +149 -0
  187. package/dist/node_modules/node-fetch/src/utils/referrer.js.map +1 -0
  188. package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +3599 -0
  189. package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -0
  190. package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +3599 -0
  191. package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -0
  192. package/dist/package.json.cjs +5 -0
  193. package/dist/package.json.cjs.map +1 -0
  194. package/dist/{package.js → package.json.js} +1 -1
  195. package/dist/package.json.js.map +1 -0
  196. package/dist/plugin.cjs +2 -2
  197. package/dist/plugin.cjs.map +1 -1
  198. package/dist/plugin.js +1 -1
  199. package/dist/plugin.js.map +1 -1
  200. package/package.json +32 -17
  201. package/src/constants.ts +5 -0
  202. package/src/hooks/slice-create.ts +3 -3
  203. package/src/hooks/sliceSimulator-setup-read.ts +38 -80
  204. package/src/hooks/snippet-read.ts +42 -22
  205. package/src/index.ts +0 -6
  206. package/src/lib/upsertGlobalContentTypes.ts +3 -0
  207. package/src/lib/upsertSliceLibraryIndexFile.ts +11 -6
  208. package/dist/package.cjs +0 -5
  209. package/dist/package.cjs.map +0 -1
  210. package/dist/package.js.map +0 -1
@@ -1,60 +1,41 @@
1
1
  "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const pluginKit = require("@slicemachine/plugin-kit");
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
3
  const commonTags = require("common-tags");
5
4
  const node_module = require("node:module");
6
- const http = require("node:http");
5
+ const index = require("../node_modules/node-fetch/src/index.cjs");
7
6
  const getJSOrTSXFileExtension = require("../lib/getJSOrTSXFileExtension.cjs");
8
- function _interopNamespace(e) {
9
- if (e && e.__esModule)
10
- return e;
11
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
12
- if (e) {
13
- for (const k in e) {
14
- if (k !== "default") {
15
- const d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: () => e[k]
19
- });
20
- }
21
- }
22
- }
23
- n.default = e;
24
- return Object.freeze(n);
25
- }
26
- const http__namespace = /* @__PURE__ */ _interopNamespace(http);
27
7
  const REQUIRED_DEPENDENCIES = [
28
8
  "@prismicio/react",
29
- "@prismicio/slice-simulator-react",
30
- "@prismicio/client@latest",
9
+ "@prismicio/client",
31
10
  "@prismicio/helpers"
32
11
  ];
33
- const createStep1 = async ({ project }) => {
12
+ const createStep1 = async ({ project, helpers }) => {
34
13
  const require2 = node_module.createRequire(project.root);
35
14
  return {
36
15
  title: "Install packages",
37
- body: commonTags.stripIndent`
16
+ description: "The simulator requires some dependencies.",
17
+ body: commonTags.source`
38
18
  The simulator requires extra dependencies. Run the following command to install them.
39
19
 
40
20
  ~~~sh
41
- npm install --save @prismicio/react @prismicio/slice-simulator-react @prismicio/client@latest @prismicio/helpers
21
+ npm install --save ${REQUIRED_DEPENDENCIES.join(" ")}
42
22
  ~~~
43
23
  `,
44
24
  validate: async () => {
45
25
  const missingDependencies = [];
46
26
  for (const dependency of REQUIRED_DEPENDENCIES) {
47
27
  try {
48
- require2.resolve(dependency);
28
+ require2.resolve(dependency, {
29
+ paths: [helpers.joinPathFromRoot("node_modules")]
30
+ });
49
31
  } catch {
50
32
  missingDependencies.push(dependency);
51
33
  }
52
34
  }
53
35
  if (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {
54
36
  return {
55
- type: pluginKit.SliceSimulatorSetupStepValidationMessageType.Error,
56
37
  title: "Missing all dependencies",
57
- message: commonTags.stripIndent`
38
+ message: commonTags.source`
58
39
  Install the required dependencies to continue.
59
40
  `
60
41
  };
@@ -62,9 +43,8 @@ const createStep1 = async ({ project }) => {
62
43
  if (missingDependencies.length > 0) {
63
44
  const formattedMissingDependencies = missingDependencies.map((missingDependency) => `\`${missingDependency}\``).join(", ");
64
45
  return {
65
- type: pluginKit.SliceSimulatorSetupStepValidationMessageType.Warning,
66
46
  title: "Missing some dependencies",
67
- message: commonTags.stripIndent`
47
+ message: commonTags.source`
68
48
  The following dependencies are missing: ${formattedMissingDependencies}
69
49
  `
70
50
  };
@@ -73,19 +53,16 @@ const createStep1 = async ({ project }) => {
73
53
  };
74
54
  };
75
55
  const createStep2 = async ({ helpers, options }) => {
76
- const fileName = `slice-simulator.${getJSOrTSXFileExtension.getJSOrTSXFileExtension}`;
56
+ const fileName = `slice-simulator.${getJSOrTSXFileExtension.getJSOrTSXFileExtension(options)}`;
77
57
  const filePath = helpers.joinPathFromRoot("pages", fileName);
78
- let fileContents;
79
- if (options.typescript) {
80
- fileContents = commonTags.stripIndent`
81
- import { GetStaticProps } from "next/types";
58
+ const fileContents = await helpers.format(commonTags.source`
82
59
  import { SliceSimulator } from "@prismicio/slice-simulator-react";
83
60
  import { SliceZone } from "@prismicio/react";
84
61
 
85
62
  import state from "../.slicemachine/libraries-state.json";
86
63
  import { components } from "../slices";
87
64
 
88
- const SliceSimulatorPage = () => {
65
+ export default function SliceSimulatorPage() {
89
66
  return (
90
67
  <SliceSimulator
91
68
  sliceZone={(props) => <SliceZone {...props} components={components} />}
@@ -93,47 +70,13 @@ const createStep2 = async ({ helpers, options }) => {
93
70
  />
94
71
  );
95
72
  };
96
-
97
- export default SliceSimulatorPage;
98
-
99
- export const getStaticProps: GetStaticProps = () => {
100
- return {
101
- // Exclude this page from production builds.
102
- notFound: process.env.NODE_ENV === "production",
103
- };
104
- };
105
- `;
106
- } else {
107
- fileContents = commonTags.stripIndent`
108
- import { SliceSimulator } from "@prismicio/slice-simulator-react";
109
- import { SliceZone } from "@prismicio/react";
110
-
111
- import state from "../.slicemachine/libraries-state.json";
112
- import { components } from "../slices";
113
-
114
- const SliceSimulatorPage = () => {
115
- return (
116
- <SliceSimulator
117
- sliceZone={(props) => <SliceZone {...props} components={components} />}
118
- state={state}
119
- />
120
- );
121
- };
122
-
123
- export default SliceSimulatorPage;
124
-
125
- export const getStaticProps= () => {
126
- return {
127
- // Exclude this page from production builds.
128
- notFound: process.env.NODE_ENV === "production",
129
- };
130
- };
131
- `;
132
- }
133
- fileContents = await helpers.format(fileContents, filePath);
73
+ `, filePath, {
74
+ includeNewlineAtEnd: false
75
+ });
134
76
  return {
135
77
  title: "Create a page for the simulator",
136
- body: commonTags.stripIndent`
78
+ description: `In your \`pages\` directory, create a file called \`${fileName}\` containing this code.`,
79
+ body: commonTags.source`
137
80
  In your \`pages\` directory, create a file called \`${fileName}\` and add the following code. This route will be used to simulate and develop your components.
138
81
 
139
82
  ~~~tsx
@@ -144,15 +87,18 @@ const createStep2 = async ({ helpers, options }) => {
144
87
  };
145
88
  const createStep3 = async ({ helpers }) => {
146
89
  const filePath = helpers.joinPathFromRoot("sm.json");
147
- const fileContents = await helpers.format(`
90
+ const fileContents = await helpers.format(commonTags.source`
148
91
  {
149
92
  "localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
150
93
  }
151
- `, filePath);
94
+ `, filePath, {
95
+ includeNewlineAtEnd: false
96
+ });
152
97
  return {
153
98
  title: "Update `sm.json`",
154
- body: commonTags.stripIndent`
155
- Update your \`sm.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`slice-simulator\` page.
99
+ description: `Update your \`sm.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.`,
100
+ body: commonTags.source`
101
+ Update your \`sm.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.
156
102
 
157
103
  ~~~json
158
104
  ${fileContents}
@@ -162,9 +108,8 @@ const createStep3 = async ({ helpers }) => {
162
108
  const project = await helpers.getProject();
163
109
  if (!("localSliceSimulatorURL" in project.config)) {
164
110
  return {
165
- type: pluginKit.SliceSimulatorSetupStepValidationMessageType.Error,
166
111
  title: "Missing `localSliceSimulatorURL` property",
167
- message: commonTags.stripIndent`
112
+ message: commonTags.source`
168
113
  A \`localSliceSimulatorURL\` property was not found in your \`sm.json\` file.
169
114
  `
170
115
  };
@@ -177,28 +122,17 @@ const createStep3 = async ({ helpers }) => {
177
122
  }
178
123
  } catch {
179
124
  return {
180
- type: pluginKit.SliceSimulatorSetupStepValidationMessageType.Warning,
181
125
  title: "An invalid URL was provided",
182
- message: commonTags.stripIndent`
126
+ message: commonTags.source`
183
127
  The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
184
128
  `
185
129
  };
186
130
  }
187
- const ok = await new Promise((resolve) => {
188
- if (project.config.localSliceSimulatorURL) {
189
- http__namespace.get(project.config.localSliceSimulatorURL, (res) => {
190
- if (res.statusCode) {
191
- resolve(res.statusCode >= 200 && res.statusCode < 300);
192
- }
193
- });
194
- }
195
- resolve(false);
196
- });
197
- if (!ok) {
131
+ const res = await index.default(project.config.localSliceSimulatorURL);
132
+ if (!res.ok) {
198
133
  return {
199
- type: pluginKit.SliceSimulatorSetupStepValidationMessageType.Warning,
200
134
  title: "Unable to connect to simulator page",
201
- message: commonTags.stripIndent`
135
+ message: commonTags.source`
202
136
  Check that the \`localSliceSimulatorURL\` property in \`sm.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-nextjs) for more details.
203
137
  `
204
138
  };
@@ -1 +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 { SliceSimulatorSetupStepValidationMessageType } from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport * as http from \"node:http\";\n\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/slice-simulator-react\",\n\t\"@prismicio/client@latest\",\n\t\"@prismicio/helpers\",\n];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tbody: stripIndent`\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 @prismicio/react @prismicio/slice-simulator-react @prismicio/client@latest @prismicio/helpers\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} 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\ttype: SliceSimulatorSetupStepValidationMessageType.Error,\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: stripIndent`\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\ttype: SliceSimulatorSetupStepValidationMessageType.Warning,\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: stripIndent`\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\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${getJSOrTSXFileExtension}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tlet fileContents: string;\n\n\tif (options.typescript) {\n\t\tfileContents = stripIndent`\n\t\t\timport { GetStaticProps } from \"next/types\";\n\t\t\timport { SliceSimulator } from \"@prismicio/slice-simulator-react\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport state from \"../.slicemachine/libraries-state.json\";\n\t\t\timport { components } from \"../slices\";\n\n\t\t\tconst SliceSimulatorPage = () => {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\tstate={state}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default SliceSimulatorPage;\n\n\t\t\texport const getStaticProps: GetStaticProps = () => {\n\t\t\t\treturn {\n\t\t\t\t\t// Exclude this page from production builds.\n\t\t\t\t\tnotFound: process.env.NODE_ENV === \"production\",\n\t\t\t\t};\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tfileContents = stripIndent`\n\t\t\timport { SliceSimulator } from \"@prismicio/slice-simulator-react\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport state from \"../.slicemachine/libraries-state.json\";\n\t\t\timport { components } from \"../slices\";\n\n\t\t\tconst SliceSimulatorPage = () => {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\tstate={state}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default SliceSimulatorPage;\n\n\t\t\texport const getStaticProps= () => {\n\t\t\t\treturn {\n\t\t\t\t\t// Exclude this page from production builds.\n\t\t\t\t\tnotFound: process.env.NODE_ENV === \"production\",\n\t\t\t\t};\n\t\t\t};\n\t\t`;\n\t}\n\n\tfileContents = await helpers.format(fileContents, filePath);\n\n\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tbody: stripIndent`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\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(\"sm.json\");\n\tconst fileContents = await helpers.format(\n\t\t`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t);\n\n\treturn {\n\t\ttitle: \"Update `sm.json`\",\n\t\tbody: stripIndent`\n\t\t\tUpdate your \\`sm.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\ttype: SliceSimulatorSetupStepValidationMessageType.Error,\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: stripIndent`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`sm.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\ttype: SliceSimulatorSetupStepValidationMessageType.Warning,\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: stripIndent`\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\tconst ok = await new Promise<boolean>((resolve) => {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\thttp.get(project.config.localSliceSimulatorURL, (res) => {\n\t\t\t\t\t\tif (res.statusCode) {\n\t\t\t\t\t\t\tresolve(res.statusCode >= 200 && res.statusCode < 300);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tresolve(false);\n\t\t\t});\n\n\t\t\tif (!ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: SliceSimulatorSetupStepValidationMessageType.Warning,\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: stripIndent`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`sm.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-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 Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require","createRequire","stripIndent","SliceSimulatorSetupStepValidationMessageType","getJSOrTSXFileExtension","http"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,wBAAwB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;;AAKD,MAAM,cAAc,OAAO,EAC1B,cAC4C;AACtC,QAAAA,WAAUC,YAAAA,cAAc,QAAQ,IAAI;AAEnC,SAAA;AAAA,IACN,OAAO;AAAA,IACP,MAAMC,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA,IAON,UAAU,YAAW;AACpB,YAAM,sBAAgC,CAAA;AAEtC,iBAAW,cAAc,uBAAuB;AAC3C,YAAA;AAKH,UAAAF,SAAQ,QAAQ,UAAU;AAAA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AA;AAAA,MAIV;AAAA,IACF;AAAA,EAAA;AAEF;AAEa,MAAA,0BAET,OAAO,OAAO,YAAW;AAC5B,SAAO,QAAQ,IAAI;AAAA,IAClB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,EAAA,CACnB;AACF;;"}
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 from \"node-fetch\";\n\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/client\",\n\t\"@prismicio/helpers\",\n];\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\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${getJSOrTSXFileExtension(options)}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\timport { SliceSimulator } from \"@prismicio/slice-simulator-react\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport state from \"../.slicemachine/libraries-state.json\";\n\t\t\timport { components } from \"../slices\";\n\n\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\tstate={state}\n\t\t\t\t\t/>\n\t\t\t\t);\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: \"Create a page for the simulator\",\n\t\tdescription: `In your \\`pages\\` directory, create a file called \\`${fileName}\\` containing this code.`,\n\t\tbody: source`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\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(\"sm.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/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 `sm.json`\",\n\t\tdescription: `Update your \\`sm.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`sm.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 \\`sm.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\tconst res = await fetch(project.config.localSliceSimulatorURL);\n\n\t\t\tif (!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 \\`sm.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-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 Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require","createRequire","source","getJSOrTSXFileExtension","fetch"],"mappings":";;;;;;AAaA,MAAM,wBAAwB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;;AAKD,MAAM,cAAc,OAAO,EAC1B,SACA,cAC4C;AACtC,QAAAA,WAAUC,YAAAA,cAAc,QAAQ,IAAI;AAEnC,SAAA;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,IAGb,MAAMC,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA,wBAIgB,sBAAsB,KAAK,GAAG;AAAA;AAAA;AAAA,IAGpD,UAAU,YAAW;AACpB,YAAM,sBAAgC,CAAA;AAEtC,iBAAW,cAAc,uBAAuB;AAC3C,YAAA;AAKH,UAAAF,SAAQ,QAAQ,YAAY;AAAA,YAC3B,OAAO,CAAC,QAAQ,iBAAiB,cAAc,CAA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AAA;AAAAA;AAAAA;AAAAA,KAIH;AAAA;AAAA;AAAA,IAGH,UAAU,YAAW;AACd,YAAA,UAAU,MAAM,QAAQ;AAE1B,UAAA,EAAE,4BAA4B,QAAQ,SAAS;AAC3C,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASA,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAGG,UAAA;AACC,YAAA,QAAQ,OAAO,wBAAwB;AACtC,cAAA,IAAI,QAAQ,OAAO,sBAAsB;AAAA,QAAA,OACvC;AACA,gBAAA,IAAI,MAAM,+BAA+B;AAAA,QAC/C;AAAA,MAAA,QACA;AACM,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASA,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAGD,YAAM,MAAM,MAAME,MAAM,QAAA,QAAQ,OAAO,sBAAsB;AAEzD,UAAA,CAAC,IAAI,IAAI;AACL,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASF,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAAA,IACF;AAAA,EAAA;AAEF;AAEa,MAAA,0BAET,OAAO,OAAO,YAAW;AAC5B,SAAO,QAAQ,IAAI;AAAA,IAClB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,EAAA,CACnB;AACF;;"}
@@ -1,39 +1,39 @@
1
- import { SliceSimulatorSetupStepValidationMessageType } from "@slicemachine/plugin-kit";
2
- import { stripIndent } from "common-tags";
1
+ import { source } from "common-tags";
3
2
  import { createRequire } from "node:module";
4
- import * as http from "node:http";
3
+ import fetch from "../node_modules/node-fetch/src/index.js";
5
4
  import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension.js";
6
5
  const REQUIRED_DEPENDENCIES = [
7
6
  "@prismicio/react",
8
- "@prismicio/slice-simulator-react",
9
- "@prismicio/client@latest",
7
+ "@prismicio/client",
10
8
  "@prismicio/helpers"
11
9
  ];
12
- const createStep1 = async ({ project }) => {
10
+ const createStep1 = async ({ project, helpers }) => {
13
11
  const require2 = createRequire(project.root);
14
12
  return {
15
13
  title: "Install packages",
16
- body: stripIndent`
14
+ description: "The simulator requires some dependencies.",
15
+ body: source`
17
16
  The simulator requires extra dependencies. Run the following command to install them.
18
17
 
19
18
  ~~~sh
20
- npm install --save @prismicio/react @prismicio/slice-simulator-react @prismicio/client@latest @prismicio/helpers
19
+ npm install --save ${REQUIRED_DEPENDENCIES.join(" ")}
21
20
  ~~~
22
21
  `,
23
22
  validate: async () => {
24
23
  const missingDependencies = [];
25
24
  for (const dependency of REQUIRED_DEPENDENCIES) {
26
25
  try {
27
- require2.resolve(dependency);
26
+ require2.resolve(dependency, {
27
+ paths: [helpers.joinPathFromRoot("node_modules")]
28
+ });
28
29
  } catch {
29
30
  missingDependencies.push(dependency);
30
31
  }
31
32
  }
32
33
  if (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {
33
34
  return {
34
- type: SliceSimulatorSetupStepValidationMessageType.Error,
35
35
  title: "Missing all dependencies",
36
- message: stripIndent`
36
+ message: source`
37
37
  Install the required dependencies to continue.
38
38
  `
39
39
  };
@@ -41,9 +41,8 @@ const createStep1 = async ({ project }) => {
41
41
  if (missingDependencies.length > 0) {
42
42
  const formattedMissingDependencies = missingDependencies.map((missingDependency) => `\`${missingDependency}\``).join(", ");
43
43
  return {
44
- type: SliceSimulatorSetupStepValidationMessageType.Warning,
45
44
  title: "Missing some dependencies",
46
- message: stripIndent`
45
+ message: source`
47
46
  The following dependencies are missing: ${formattedMissingDependencies}
48
47
  `
49
48
  };
@@ -52,19 +51,16 @@ const createStep1 = async ({ project }) => {
52
51
  };
53
52
  };
54
53
  const createStep2 = async ({ helpers, options }) => {
55
- const fileName = `slice-simulator.${getJSOrTSXFileExtension}`;
54
+ const fileName = `slice-simulator.${getJSOrTSXFileExtension(options)}`;
56
55
  const filePath = helpers.joinPathFromRoot("pages", fileName);
57
- let fileContents;
58
- if (options.typescript) {
59
- fileContents = stripIndent`
60
- import { GetStaticProps } from "next/types";
56
+ const fileContents = await helpers.format(source`
61
57
  import { SliceSimulator } from "@prismicio/slice-simulator-react";
62
58
  import { SliceZone } from "@prismicio/react";
63
59
 
64
60
  import state from "../.slicemachine/libraries-state.json";
65
61
  import { components } from "../slices";
66
62
 
67
- const SliceSimulatorPage = () => {
63
+ export default function SliceSimulatorPage() {
68
64
  return (
69
65
  <SliceSimulator
70
66
  sliceZone={(props) => <SliceZone {...props} components={components} />}
@@ -72,47 +68,13 @@ const createStep2 = async ({ helpers, options }) => {
72
68
  />
73
69
  );
74
70
  };
75
-
76
- export default SliceSimulatorPage;
77
-
78
- export const getStaticProps: GetStaticProps = () => {
79
- return {
80
- // Exclude this page from production builds.
81
- notFound: process.env.NODE_ENV === "production",
82
- };
83
- };
84
- `;
85
- } else {
86
- fileContents = stripIndent`
87
- import { SliceSimulator } from "@prismicio/slice-simulator-react";
88
- import { SliceZone } from "@prismicio/react";
89
-
90
- import state from "../.slicemachine/libraries-state.json";
91
- import { components } from "../slices";
92
-
93
- const SliceSimulatorPage = () => {
94
- return (
95
- <SliceSimulator
96
- sliceZone={(props) => <SliceZone {...props} components={components} />}
97
- state={state}
98
- />
99
- );
100
- };
101
-
102
- export default SliceSimulatorPage;
103
-
104
- export const getStaticProps= () => {
105
- return {
106
- // Exclude this page from production builds.
107
- notFound: process.env.NODE_ENV === "production",
108
- };
109
- };
110
- `;
111
- }
112
- fileContents = await helpers.format(fileContents, filePath);
71
+ `, filePath, {
72
+ includeNewlineAtEnd: false
73
+ });
113
74
  return {
114
75
  title: "Create a page for the simulator",
115
- body: stripIndent`
76
+ description: `In your \`pages\` directory, create a file called \`${fileName}\` containing this code.`,
77
+ body: source`
116
78
  In your \`pages\` directory, create a file called \`${fileName}\` and add the following code. This route will be used to simulate and develop your components.
117
79
 
118
80
  ~~~tsx
@@ -123,15 +85,18 @@ const createStep2 = async ({ helpers, options }) => {
123
85
  };
124
86
  const createStep3 = async ({ helpers }) => {
125
87
  const filePath = helpers.joinPathFromRoot("sm.json");
126
- const fileContents = await helpers.format(`
88
+ const fileContents = await helpers.format(source`
127
89
  {
128
90
  "localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
129
91
  }
130
- `, filePath);
92
+ `, filePath, {
93
+ includeNewlineAtEnd: false
94
+ });
131
95
  return {
132
96
  title: "Update `sm.json`",
133
- body: stripIndent`
134
- Update your \`sm.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`slice-simulator\` page.
97
+ description: `Update your \`sm.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.`,
98
+ body: source`
99
+ Update your \`sm.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.
135
100
 
136
101
  ~~~json
137
102
  ${fileContents}
@@ -141,9 +106,8 @@ const createStep3 = async ({ helpers }) => {
141
106
  const project = await helpers.getProject();
142
107
  if (!("localSliceSimulatorURL" in project.config)) {
143
108
  return {
144
- type: SliceSimulatorSetupStepValidationMessageType.Error,
145
109
  title: "Missing `localSliceSimulatorURL` property",
146
- message: stripIndent`
110
+ message: source`
147
111
  A \`localSliceSimulatorURL\` property was not found in your \`sm.json\` file.
148
112
  `
149
113
  };
@@ -156,28 +120,17 @@ const createStep3 = async ({ helpers }) => {
156
120
  }
157
121
  } catch {
158
122
  return {
159
- type: SliceSimulatorSetupStepValidationMessageType.Warning,
160
123
  title: "An invalid URL was provided",
161
- message: stripIndent`
124
+ message: source`
162
125
  The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
163
126
  `
164
127
  };
165
128
  }
166
- const ok = await new Promise((resolve) => {
167
- if (project.config.localSliceSimulatorURL) {
168
- http.get(project.config.localSliceSimulatorURL, (res) => {
169
- if (res.statusCode) {
170
- resolve(res.statusCode >= 200 && res.statusCode < 300);
171
- }
172
- });
173
- }
174
- resolve(false);
175
- });
176
- if (!ok) {
129
+ const res = await fetch(project.config.localSliceSimulatorURL);
130
+ if (!res.ok) {
177
131
  return {
178
- type: SliceSimulatorSetupStepValidationMessageType.Warning,
179
132
  title: "Unable to connect to simulator page",
180
- message: stripIndent`
133
+ message: source`
181
134
  Check that the \`localSliceSimulatorURL\` property in \`sm.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-nextjs) for more details.
182
135
  `
183
136
  };
@@ -1 +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 { SliceSimulatorSetupStepValidationMessageType } from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport * as http from \"node:http\";\n\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/slice-simulator-react\",\n\t\"@prismicio/client@latest\",\n\t\"@prismicio/helpers\",\n];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tbody: stripIndent`\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 @prismicio/react @prismicio/slice-simulator-react @prismicio/client@latest @prismicio/helpers\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} 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\ttype: SliceSimulatorSetupStepValidationMessageType.Error,\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: stripIndent`\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\ttype: SliceSimulatorSetupStepValidationMessageType.Warning,\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: stripIndent`\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\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${getJSOrTSXFileExtension}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tlet fileContents: string;\n\n\tif (options.typescript) {\n\t\tfileContents = stripIndent`\n\t\t\timport { GetStaticProps } from \"next/types\";\n\t\t\timport { SliceSimulator } from \"@prismicio/slice-simulator-react\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport state from \"../.slicemachine/libraries-state.json\";\n\t\t\timport { components } from \"../slices\";\n\n\t\t\tconst SliceSimulatorPage = () => {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\tstate={state}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default SliceSimulatorPage;\n\n\t\t\texport const getStaticProps: GetStaticProps = () => {\n\t\t\t\treturn {\n\t\t\t\t\t// Exclude this page from production builds.\n\t\t\t\t\tnotFound: process.env.NODE_ENV === \"production\",\n\t\t\t\t};\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tfileContents = stripIndent`\n\t\t\timport { SliceSimulator } from \"@prismicio/slice-simulator-react\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport state from \"../.slicemachine/libraries-state.json\";\n\t\t\timport { components } from \"../slices\";\n\n\t\t\tconst SliceSimulatorPage = () => {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\tstate={state}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default SliceSimulatorPage;\n\n\t\t\texport const getStaticProps= () => {\n\t\t\t\treturn {\n\t\t\t\t\t// Exclude this page from production builds.\n\t\t\t\t\tnotFound: process.env.NODE_ENV === \"production\",\n\t\t\t\t};\n\t\t\t};\n\t\t`;\n\t}\n\n\tfileContents = await helpers.format(fileContents, filePath);\n\n\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tbody: stripIndent`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\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(\"sm.json\");\n\tconst fileContents = await helpers.format(\n\t\t`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t);\n\n\treturn {\n\t\ttitle: \"Update `sm.json`\",\n\t\tbody: stripIndent`\n\t\t\tUpdate your \\`sm.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\ttype: SliceSimulatorSetupStepValidationMessageType.Error,\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: stripIndent`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`sm.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\ttype: SliceSimulatorSetupStepValidationMessageType.Warning,\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: stripIndent`\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\tconst ok = await new Promise<boolean>((resolve) => {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\thttp.get(project.config.localSliceSimulatorURL, (res) => {\n\t\t\t\t\t\tif (res.statusCode) {\n\t\t\t\t\t\t\tresolve(res.statusCode >= 200 && res.statusCode < 300);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tresolve(false);\n\t\t\t});\n\n\t\t\tif (!ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: SliceSimulatorSetupStepValidationMessageType.Warning,\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: stripIndent`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`sm.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-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 Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require"],"mappings":";;;;;AAcA,MAAM,wBAAwB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;;AAKD,MAAM,cAAc,OAAO,EAC1B,cAC4C;AACtC,QAAAA,WAAU,cAAc,QAAQ,IAAI;AAEnC,SAAA;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAON,UAAU,YAAW;AACpB,YAAM,sBAAgC,CAAA;AAEtC,iBAAW,cAAc,uBAAuB;AAC3C,YAAA;AAKH,UAAAA,SAAQ,QAAQ,UAAU;AAAA,QAAA,QACzB;AACD,8BAAoB,KAAK,UAAU;AAAA,QACnC;AAAA,MACD;AAEG,UAAA,oBAAoB,UAAU,sBAAsB,QAAQ;AACxD,eAAA;AAAA,UACN,MAAM,6CAA6C;AAAA,UACnD,OAAO;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAEG,UAAA,oBAAoB,SAAS,GAAG;AAC7B,cAAA,+BAA+B,oBACnC,IAAI,CAAC,sBAAsB,KAAK,qBAAqB,EACrD,KAAK,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AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAGG,UAAA;AACC,YAAA,QAAQ,OAAO,wBAAwB;AACtC,cAAA,IAAI,QAAQ,OAAO,sBAAsB;AAAA,QAAA,OACvC;AACA,gBAAA,IAAI,MAAM,+BAA+B;AAAA,QAC/C;AAAA,MAAA,QACA;AACM,eAAA;AAAA,UACN,MAAM,6CAA6C;AAAA,UACnD,OAAO;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAGD,YAAM,KAAK,MAAM,IAAI,QAAiB,CAAC,YAAW;AAC7C,YAAA,QAAQ,OAAO,wBAAwB;AAC1C,eAAK,IAAI,QAAQ,OAAO,wBAAwB,CAAC,QAAO;AACvD,gBAAI,IAAI,YAAY;AACnB,sBAAQ,IAAI,cAAc,OAAO,IAAI,aAAa,GAAG;AAAA,YACrD;AAAA,UAAA,CACD;AAAA,QACD;AAED,gBAAQ,KAAK;AAAA,MAAA,CACb;AAED,UAAI,CAAC,IAAI;AACD,eAAA;AAAA,UACN,MAAM,6CAA6C;AAAA,UACnD,OAAO;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAAA,IACF;AAAA,EAAA;AAEF;AAEa,MAAA,0BAET,OAAO,OAAO,YAAW;AAC5B,SAAO,QAAQ,IAAI;AAAA,IAClB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,EAAA,CACnB;AACF;"}
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 from \"node-fetch\";\n\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/client\",\n\t\"@prismicio/helpers\",\n];\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\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${getJSOrTSXFileExtension(options)}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\timport { SliceSimulator } from \"@prismicio/slice-simulator-react\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport state from \"../.slicemachine/libraries-state.json\";\n\t\t\timport { components } from \"../slices\";\n\n\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\tstate={state}\n\t\t\t\t\t/>\n\t\t\t\t);\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: \"Create a page for the simulator\",\n\t\tdescription: `In your \\`pages\\` directory, create a file called \\`${fileName}\\` containing this code.`,\n\t\tbody: source`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\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(\"sm.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/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 `sm.json`\",\n\t\tdescription: `Update your \\`sm.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`sm.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 \\`sm.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\tconst res = await fetch(project.config.localSliceSimulatorURL);\n\n\t\t\tif (!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 \\`sm.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-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 Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require"],"mappings":";;;;AAaA,MAAM,wBAAwB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;;AAKD,MAAM,cAAc,OAAO,EAC1B,SACA,cAC4C;AACtC,QAAAA,WAAU,cAAc,QAAQ,IAAI;AAEnC,SAAA;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,IAGb,MAAM;AAAA;AAAA;AAAA;AAAA,wBAIgB,sBAAsB,KAAK,GAAG;AAAA;AAAA;AAAA,IAGpD,UAAU,YAAW;AACpB,YAAM,sBAAgC,CAAA;AAEtC,iBAAW,cAAc,uBAAuB;AAC3C,YAAA;AAKH,UAAAA,SAAQ,QAAQ,YAAY;AAAA,YAC3B,OAAO,CAAC,QAAQ,iBAAiB,cAAc,CAAC;AAAA,UAAA,CAChD;AAAA,QAAA,QACA;AACD,8BAAoB,KAAK,UAAU;AAAA,QACnC;AAAA,MACD;AAEG,UAAA,oBAAoB,UAAU,sBAAsB,QAAQ;AACxD,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAEG,UAAA,oBAAoB,SAAS,GAAG;AAC7B,cAAA,+BAA+B,oBACnC,IAAI,CAAC,sBAAsB,KAAK,qBAAqB,EACrD,KAAK,IAAI;AAEJ,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAAS;AAAA,gDACkC;AAAA;AAAA,QAAA;AAAA,MAG5C;AAAA,IACF;AAAA,EAAA;AAEF;AAEA,MAAM,cAAc,OAAO,EAC1B,SACA,cAC4C;AACtC,QAAA,WAAW,mBAAmB,wBAAwB,OAAO;AACnE,QAAM,WAAW,QAAQ,iBAAiB,SAAS,QAAQ;AAEr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AA,0BAET,OAAO,OAAO,YAAW;AAC5B,SAAO,QAAQ,IAAI;AAAA,IAClB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,EAAA,CACnB;AACF;"}
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const prismicT = require("@prismicio/types");
4
4
  const commonTags = require("common-tags");
5
- function _interopNamespace(e) {
6
- if (e && e.__esModule)
7
- return e;
5
+ function _interopNamespaceDefault(e) {
8
6
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
9
7
  if (e) {
10
8
  for (const k in e) {
@@ -20,22 +18,39 @@ function _interopNamespace(e) {
20
18
  n.default = e;
21
19
  return Object.freeze(n);
22
20
  }
23
- const prismicT__namespace = /* @__PURE__ */ _interopNamespace(prismicT);
24
- const prettierOptions = { parser: "typescript" };
21
+ const prismicT__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismicT);
25
22
  const dotPath = (segments) => {
26
23
  return segments.join(".");
27
24
  };
25
+ const format = async (input, helpers) => {
26
+ const formattedInput = await helpers.format(input, void 0, {
27
+ includeNewlineAtEnd: false,
28
+ prettier: {
29
+ parser: "typescript"
30
+ }
31
+ });
32
+ return formattedInput.endsWith(";") ? formattedInput.substring(0, formattedInput.length - 1) : formattedInput;
33
+ };
28
34
  const snippetRead = async (data, { helpers }) => {
29
35
  const { fieldPath } = data;
30
36
  const label = "React";
31
37
  switch (data.model.type) {
38
+ case prismicT__namespace.CustomTypeModelFieldType.StructuredText: {
39
+ return {
40
+ label,
41
+ language: "tsx",
42
+ code: await format(commonTags.stripIndent`
43
+ <PrismicRichText field={${dotPath(fieldPath)}} />
44
+ `, helpers)
45
+ };
46
+ }
32
47
  case prismicT__namespace.CustomTypeModelFieldType.Link: {
33
48
  return {
34
49
  label,
35
50
  language: "tsx",
36
- code: await helpers.format(commonTags.stripIndent`
51
+ code: await format(commonTags.stripIndent`
37
52
  <PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
38
- `, void 0, { prettier: prettierOptions })
53
+ `, helpers)
39
54
  };
40
55
  }
41
56
  case prismicT__namespace.CustomTypeModelFieldType.Image: {
@@ -43,25 +58,25 @@ const snippetRead = async (data, { helpers }) => {
43
58
  {
44
59
  label: `${label} (next/image)`,
45
60
  language: "tsx",
46
- code: await helpers.format(commonTags.stripIndent`
61
+ code: await format(commonTags.stripIndent`
47
62
  <PrismicNextImage field={${dotPath(fieldPath)}} />
48
- `, void 0, { prettier: prettierOptions })
63
+ `, helpers)
49
64
  },
50
65
  {
51
66
  label,
52
67
  language: "tsx",
53
- code: await helpers.format(commonTags.stripIndent`
68
+ code: await format(commonTags.stripIndent`
54
69
  <PrismicImage field={${dotPath(fieldPath)}} />
55
- `, void 0, { prettier: prettierOptions })
70
+ `, helpers)
56
71
  }
57
72
  ];
58
73
  }
59
74
  case prismicT__namespace.CustomTypeModelFieldType.Group: {
60
- const code = await helpers.format(commonTags.stripIndent`
75
+ const code = await format(commonTags.stripIndent`
61
76
  <>{${dotPath(fieldPath)}.map(item => (
62
77
  <>{/* Render content for item */}</>
63
78
  ))}</>
64
- `, void 0, { prettier: prettierOptions });
79
+ `, helpers);
65
80
  return {
66
81
  label,
67
82
  language: "tsx",
@@ -69,12 +84,12 @@ const snippetRead = async (data, { helpers }) => {
69
84
  };
70
85
  }
71
86
  case prismicT__namespace.CustomTypeModelFieldType.Slices: {
72
- const code = await helpers.format(commonTags.stripIndent`
87
+ const code = await format(commonTags.stripIndent`
73
88
  <SliceZone
74
89
  slices={${dotPath(fieldPath)}}
75
90
  components={components}
76
91
  />
77
- `, void 0, { prettier: prettierOptions });
92
+ `, helpers);
78
93
  return {
79
94
  label,
80
95
  language: "tsx",
@@ -85,9 +100,9 @@ const snippetRead = async (data, { helpers }) => {
85
100
  return {
86
101
  label,
87
102
  language: "tsx",
88
- code: await helpers.format(commonTags.stripIndent`
103
+ code: await format(commonTags.stripIndent`
89
104
  <>{${dotPath(fieldPath)}}</>
90
- `, void 0, { prettier: prettierOptions })
105
+ `, helpers)
91
106
  };
92
107
  }
93
108
  }