@slicemachine/adapter-next 0.3.38-beta.1 → 0.3.38-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin.cjs +1 -3
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -3
- package/dist/plugin.js.map +1 -1
- package/package.json +2 -3
- package/src/plugin.ts +0 -7
- package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs +0 -41
- package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs.map +0 -1
- package/dist/_node_modules/data-uri-to-buffer/dist/index.js +0 -41
- package/dist/_node_modules/data-uri-to-buffer/dist/index.js.map +0 -1
- package/dist/_node_modules/fetch-blob/file.cjs +0 -61
- package/dist/_node_modules/fetch-blob/file.cjs.map +0 -1
- package/dist/_node_modules/fetch-blob/file.js +0 -61
- package/dist/_node_modules/fetch-blob/file.js.map +0 -1
- package/dist/_node_modules/fetch-blob/index.cjs +0 -223
- package/dist/_node_modules/fetch-blob/index.cjs.map +0 -1
- package/dist/_node_modules/fetch-blob/index.js +0 -223
- package/dist/_node_modules/fetch-blob/index.js.map +0 -1
- package/dist/_node_modules/fetch-blob/streams.cjs +0 -43
- package/dist/_node_modules/fetch-blob/streams.cjs.map +0 -1
- package/dist/_node_modules/fetch-blob/streams.js +0 -42
- package/dist/_node_modules/fetch-blob/streams.js.map +0 -1
- package/dist/_node_modules/formdata-polyfill/esm.min.cjs +0 -116
- package/dist/_node_modules/formdata-polyfill/esm.min.cjs.map +0 -1
- package/dist/_node_modules/formdata-polyfill/esm.min.js +0 -116
- package/dist/_node_modules/formdata-polyfill/esm.min.js.map +0 -1
- package/dist/_node_modules/node-domexception/index.cjs +0 -11
- package/dist/_node_modules/node-domexception/index.cjs.map +0 -1
- package/dist/_node_modules/node-domexception/index.js +0 -10
- package/dist/_node_modules/node-domexception/index.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/body.cjs +0 -262
- package/dist/_node_modules/node-fetch/src/body.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/body.js +0 -262
- package/dist/_node_modules/node-fetch/src/body.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/errors/abort-error.cjs +0 -10
- package/dist/_node_modules/node-fetch/src/errors/abort-error.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/errors/abort-error.js +0 -10
- package/dist/_node_modules/node-fetch/src/errors/abort-error.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/errors/base.cjs +0 -17
- package/dist/_node_modules/node-fetch/src/errors/base.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/errors/base.js +0 -17
- package/dist/_node_modules/node-fetch/src/errors/base.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.cjs +0 -19
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.js +0 -19
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/headers.cjs +0 -190
- package/dist/_node_modules/node-fetch/src/headers.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/headers.js +0 -190
- package/dist/_node_modules/node-fetch/src/headers.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/index.cjs +0 -292
- package/dist/_node_modules/node-fetch/src/index.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/index.js +0 -292
- package/dist/_node_modules/node-fetch/src/index.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/request.cjs +0 -206
- package/dist/_node_modules/node-fetch/src/request.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/request.js +0 -206
- package/dist/_node_modules/node-fetch/src/request.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/response.cjs +0 -122
- package/dist/_node_modules/node-fetch/src/response.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/response.js +0 -123
- package/dist/_node_modules/node-fetch/src/response.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/utils/get-search.cjs +0 -12
- package/dist/_node_modules/node-fetch/src/utils/get-search.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/utils/get-search.js +0 -12
- package/dist/_node_modules/node-fetch/src/utils/get-search.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.cjs +0 -8
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.js +0 -8
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/utils/is.cjs +0 -28
- package/dist/_node_modules/node-fetch/src/utils/is.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/utils/is.js +0 -28
- package/dist/_node_modules/node-fetch/src/utils/is.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs +0 -356
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js +0 -356
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js.map +0 -1
- package/dist/_node_modules/node-fetch/src/utils/referrer.cjs +0 -149
- package/dist/_node_modules/node-fetch/src/utils/referrer.cjs.map +0 -1
- package/dist/_node_modules/node-fetch/src/utils/referrer.js +0 -149
- package/dist/_node_modules/node-fetch/src/utils/referrer.js.map +0 -1
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +0 -3822
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +0 -1
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +0 -3822
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +0 -1
- package/dist/_virtual/_commonjsHelpers.cjs +0 -5
- package/dist/_virtual/_commonjsHelpers.cjs.map +0 -1
- package/dist/_virtual/_commonjsHelpers.js +0 -5
- package/dist/_virtual/_commonjsHelpers.js.map +0 -1
- package/dist/_virtual/ponyfill.es2018.cjs +0 -5
- package/dist/_virtual/ponyfill.es2018.cjs.map +0 -1
- package/dist/_virtual/ponyfill.es2018.js +0 -5
- package/dist/_virtual/ponyfill.es2018.js.map +0 -1
- package/dist/hooks/sliceSimulator-setup-read.cjs +0 -189
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +0 -1
- package/dist/hooks/sliceSimulator-setup-read.d.ts +0 -3
- package/dist/hooks/sliceSimulator-setup-read.js +0 -189
- package/dist/hooks/sliceSimulator-setup-read.js.map +0 -1
- package/src/hooks/sliceSimulator-setup-read.ts +0 -252
- /package/dist/{packages/adapter-next/package.json.cjs → package.json.cjs} +0 -0
- /package/dist/{packages/adapter-next/package.json.cjs.map → package.json.cjs.map} +0 -0
- /package/dist/{packages/adapter-next/package.json.js → package.json.js} +0 -0
- /package/dist/{packages/adapter-next/package.json.js.map → package.json.js.map} +0 -0
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
4
|
-
exports.commonjsGlobal = commonjsGlobal;
|
|
5
|
-
//# sourceMappingURL=_commonjsHelpers.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_commonjsHelpers.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
2
|
-
export {
|
|
3
|
-
commonjsGlobal
|
|
4
|
-
};
|
|
5
|
-
//# sourceMappingURL=_commonjsHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_commonjsHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ponyfill.es2018.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ponyfill.es2018.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,189 +0,0 @@
|
|
|
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
|
-
const getJSFileExtension = require("../lib/getJSFileExtension.cjs");
|
|
7
|
-
const checkHasAppRouter = require("../lib/checkHasAppRouter.cjs");
|
|
8
|
-
const REQUIRED_DEPENDENCIES = ["@prismicio/react"];
|
|
9
|
-
const createStep1 = async ({ project, helpers }) => {
|
|
10
|
-
const require2 = node_module.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: commonTags.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: commonTags.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: commonTags.source`
|
|
47
|
-
The following dependencies are missing: ${formattedMissingDependencies}
|
|
48
|
-
`
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
const createStep2 = async ({ helpers, options }) => {
|
|
55
|
-
const hasAppRouter = await checkHasAppRouter.checkHasAppRouter({ helpers });
|
|
56
|
-
const extension = await getJSFileExtension.getJSFileExtension({ helpers, options, jsx: true });
|
|
57
|
-
if (hasAppRouter) {
|
|
58
|
-
const fileName2 = `page.${extension}`;
|
|
59
|
-
const filePath2 = helpers.joinPathFromRoot("app", "slice-simulator", fileName2);
|
|
60
|
-
const fileContents2 = await helpers.format(commonTags.source`
|
|
61
|
-
import {
|
|
62
|
-
SliceSimulator,
|
|
63
|
-
SliceSimulatorParams,
|
|
64
|
-
getSlices,
|
|
65
|
-
} from "@slicemachine/adapter-next/simulator";
|
|
66
|
-
import { SliceZone } from "@prismicio/react";
|
|
67
|
-
|
|
68
|
-
import { components } from "../../slices";
|
|
69
|
-
|
|
70
|
-
export default function SliceSimulatorPage({
|
|
71
|
-
searchParams,
|
|
72
|
-
}: SliceSimulatorParams) {
|
|
73
|
-
const slices = getSlices(searchParams.state);
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<SliceSimulator>
|
|
77
|
-
<SliceZone slices={slices} components={components} />
|
|
78
|
-
</SliceSimulator>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
`, filePath2, { includeNewlineAtEnd: false });
|
|
82
|
-
return {
|
|
83
|
-
title: "Create a page for the simulator",
|
|
84
|
-
description: `In your \`app\` directory, create a file called \`slice-simulator/${fileName2}\` containing this code.`,
|
|
85
|
-
body: commonTags.source`
|
|
86
|
-
In your \`app\` directory, create a file called \`slice-simulator/${fileName2}\` and add the following code. This route will be used to simulate and develop your components.
|
|
87
|
-
|
|
88
|
-
~~~tsx
|
|
89
|
-
${fileContents2}
|
|
90
|
-
~~~
|
|
91
|
-
`
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
const fileName = `slice-simulator.${extension}`;
|
|
95
|
-
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
96
|
-
const fileContents = await helpers.format(commonTags.source`
|
|
97
|
-
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
98
|
-
import { SliceZone } from "@prismicio/react";
|
|
99
|
-
|
|
100
|
-
import { components } from "../slices";
|
|
101
|
-
|
|
102
|
-
export default function SliceSimulatorPage() {
|
|
103
|
-
return (
|
|
104
|
-
<SliceSimulator
|
|
105
|
-
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
106
|
-
/>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
`, filePath, { includeNewlineAtEnd: false });
|
|
110
|
-
return {
|
|
111
|
-
title: "Create a page for the simulator",
|
|
112
|
-
description: `In your \`pages\` directory, create a file called \`${fileName}\` containing this code.`,
|
|
113
|
-
body: commonTags.source`
|
|
114
|
-
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.
|
|
115
|
-
|
|
116
|
-
~~~tsx
|
|
117
|
-
${fileContents}
|
|
118
|
-
~~~
|
|
119
|
-
`
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
const createStep3 = async ({ helpers }) => {
|
|
123
|
-
const filePath = helpers.joinPathFromRoot("slicemachine.config.json");
|
|
124
|
-
const fileContents = await helpers.format(commonTags.source`
|
|
125
|
-
{
|
|
126
|
-
"localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
|
|
127
|
-
}
|
|
128
|
-
`, filePath, {
|
|
129
|
-
includeNewlineAtEnd: false
|
|
130
|
-
});
|
|
131
|
-
return {
|
|
132
|
-
title: "Update `slicemachine.config.json`",
|
|
133
|
-
description: `Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.`,
|
|
134
|
-
body: commonTags.source`
|
|
135
|
-
Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.
|
|
136
|
-
|
|
137
|
-
~~~json
|
|
138
|
-
${fileContents}
|
|
139
|
-
~~~
|
|
140
|
-
`,
|
|
141
|
-
validate: async () => {
|
|
142
|
-
const project = await helpers.getProject();
|
|
143
|
-
if (!("localSliceSimulatorURL" in project.config)) {
|
|
144
|
-
return {
|
|
145
|
-
title: "Missing `localSliceSimulatorURL` property",
|
|
146
|
-
message: commonTags.source`
|
|
147
|
-
A \`localSliceSimulatorURL\` property was not found in your \`slicemachine.config.json\` file.
|
|
148
|
-
`
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
try {
|
|
152
|
-
if (project.config.localSliceSimulatorURL) {
|
|
153
|
-
new URL(project.config.localSliceSimulatorURL);
|
|
154
|
-
} else {
|
|
155
|
-
throw new Error("Undefined Slice Simulator URL");
|
|
156
|
-
}
|
|
157
|
-
} catch {
|
|
158
|
-
return {
|
|
159
|
-
title: "An invalid URL was provided",
|
|
160
|
-
message: commonTags.source`
|
|
161
|
-
The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
|
|
162
|
-
`
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
let res = void 0;
|
|
166
|
-
try {
|
|
167
|
-
res = await index.default(project.config.localSliceSimulatorURL);
|
|
168
|
-
} catch (error) {
|
|
169
|
-
}
|
|
170
|
-
if (!res || !res.ok) {
|
|
171
|
-
return {
|
|
172
|
-
title: "Unable to connect to simulator page",
|
|
173
|
-
message: commonTags.source`
|
|
174
|
-
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.
|
|
175
|
-
`
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
const sliceSimulatorSetupRead = async (_data, context) => {
|
|
182
|
-
return Promise.all([
|
|
183
|
-
createStep1(context),
|
|
184
|
-
createStep2(context),
|
|
185
|
-
createStep3(context)
|
|
186
|
-
]);
|
|
187
|
-
};
|
|
188
|
-
exports.sliceSimulatorSetupRead = sliceSimulatorSetupRead;
|
|
189
|
-
//# sourceMappingURL=sliceSimulator-setup-read.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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 { getJSFileExtension } from \"../lib/getJSFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkHasAppRouter } from \"../lib/checkHasAppRouter\";\n\nconst REQUIRED_DEPENDENCIES = [\"@prismicio/react\"];\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 hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options, jsx: true });\n\n\tif (hasAppRouter) {\n\t\tconst fileName = `page.${extension}`;\n\t\tconst filePath = helpers.joinPathFromRoot(\n\t\t\t\"app\",\n\t\t\t\"slice-simulator\",\n\t\t\tfileName,\n\t\t);\n\n\t\tconst fileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport {\n\t\t\t\t\tSliceSimulator,\n\t\t\t\t\tSliceSimulatorParams,\n\t\t\t\t\tgetSlices,\n\t\t\t\t} from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage({\n\t\t\t\t\tsearchParams,\n\t\t\t\t}: SliceSimulatorParams) {\n\t\t\t\t\tconst slices = getSlices(searchParams.state);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator>\n\t\t\t\t\t\t\t<SliceZone slices={slices} components={components} />\n\t\t\t\t\t\t</SliceSimulator>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{ includeNewlineAtEnd: false },\n\t\t);\n\n\t\treturn {\n\t\t\ttitle: \"Create a page for the simulator\",\n\t\t\tdescription: `In your \\`app\\` directory, create a file called \\`slice-simulator/${fileName}\\` containing this code.`,\n\t\t\tbody: source`\n\t\t\t\tIn your \\`app\\` directory, create a file called \\`slice-simulator/${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\t};\n\t}\n\n\tconst fileName = `slice-simulator.${extension}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`,\n\t\tfilePath,\n\t\t{ includeNewlineAtEnd: false },\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(\"slicemachine.config.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 `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 Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require","createRequire","source","checkHasAppRouter","getJSFileExtension","fileName","filePath","fileContents","fetch"],"mappings":";;;;;;;AAcA,MAAM,wBAAwB,CAAC,kBAAkB;AAIjD,MAAM,cAAc,OAAO,EAC1B,SACA,cAC4C;AACtC,QAAAA,WAAUC,YAAAA,cAAc,QAAQ,IAAI;AAEnC,SAAA;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA;AAAA;AAAA,IAGb,MAAMC,WAAAA;AAAAA;AAA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ACM,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASA,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAGD,UAAI,MAA4B;AAC5B,UAAA;AACH,cAAM,MAAMM,MAAA,QAAM,QAAQ,OAAO,sBAAsB;AAAA,eAC/C;MAER;AAED,UAAI,CAAC,OAAO,CAAC,IAAI,IAAI;AACb,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASN,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,189 +0,0 @@
|
|
|
1
|
-
import { source } from "common-tags";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import fetch from './../_node_modules/node-fetch/src/index.js';
|
|
4
|
-
import { getJSFileExtension } from "../lib/getJSFileExtension.js";
|
|
5
|
-
import { checkHasAppRouter } from "../lib/checkHasAppRouter.js";
|
|
6
|
-
const REQUIRED_DEPENDENCIES = ["@prismicio/react"];
|
|
7
|
-
const createStep1 = async ({ project, helpers }) => {
|
|
8
|
-
const require2 = createRequire(project.root);
|
|
9
|
-
return {
|
|
10
|
-
title: "Install packages",
|
|
11
|
-
description: "The simulator requires some dependencies.",
|
|
12
|
-
// TODO: Create a plugin runner helper to provide the correct
|
|
13
|
-
// package manager
|
|
14
|
-
body: source`
|
|
15
|
-
The simulator requires extra dependencies. Run the following command to install them.
|
|
16
|
-
|
|
17
|
-
~~~sh
|
|
18
|
-
npm install --save ${REQUIRED_DEPENDENCIES.join(" ")}
|
|
19
|
-
~~~
|
|
20
|
-
`,
|
|
21
|
-
validate: async () => {
|
|
22
|
-
const missingDependencies = [];
|
|
23
|
-
for (const dependency of REQUIRED_DEPENDENCIES) {
|
|
24
|
-
try {
|
|
25
|
-
require2.resolve(dependency, {
|
|
26
|
-
paths: [helpers.joinPathFromRoot("node_modules")]
|
|
27
|
-
});
|
|
28
|
-
} catch {
|
|
29
|
-
missingDependencies.push(dependency);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {
|
|
33
|
-
return {
|
|
34
|
-
title: "Missing all dependencies",
|
|
35
|
-
message: source`
|
|
36
|
-
Install the required dependencies to continue.
|
|
37
|
-
`
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (missingDependencies.length > 0) {
|
|
41
|
-
const formattedMissingDependencies = missingDependencies.map((missingDependency) => `\`${missingDependency}\``).join(", ");
|
|
42
|
-
return {
|
|
43
|
-
title: "Missing some dependencies",
|
|
44
|
-
message: source`
|
|
45
|
-
The following dependencies are missing: ${formattedMissingDependencies}
|
|
46
|
-
`
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
const createStep2 = async ({ helpers, options }) => {
|
|
53
|
-
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
54
|
-
const extension = await getJSFileExtension({ helpers, options, jsx: true });
|
|
55
|
-
if (hasAppRouter) {
|
|
56
|
-
const fileName2 = `page.${extension}`;
|
|
57
|
-
const filePath2 = helpers.joinPathFromRoot("app", "slice-simulator", fileName2);
|
|
58
|
-
const fileContents2 = await helpers.format(source`
|
|
59
|
-
import {
|
|
60
|
-
SliceSimulator,
|
|
61
|
-
SliceSimulatorParams,
|
|
62
|
-
getSlices,
|
|
63
|
-
} from "@slicemachine/adapter-next/simulator";
|
|
64
|
-
import { SliceZone } from "@prismicio/react";
|
|
65
|
-
|
|
66
|
-
import { components } from "../../slices";
|
|
67
|
-
|
|
68
|
-
export default function SliceSimulatorPage({
|
|
69
|
-
searchParams,
|
|
70
|
-
}: SliceSimulatorParams) {
|
|
71
|
-
const slices = getSlices(searchParams.state);
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<SliceSimulator>
|
|
75
|
-
<SliceZone slices={slices} components={components} />
|
|
76
|
-
</SliceSimulator>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
`, filePath2, { includeNewlineAtEnd: false });
|
|
80
|
-
return {
|
|
81
|
-
title: "Create a page for the simulator",
|
|
82
|
-
description: `In your \`app\` directory, create a file called \`slice-simulator/${fileName2}\` containing this code.`,
|
|
83
|
-
body: source`
|
|
84
|
-
In your \`app\` directory, create a file called \`slice-simulator/${fileName2}\` and add the following code. This route will be used to simulate and develop your components.
|
|
85
|
-
|
|
86
|
-
~~~tsx
|
|
87
|
-
${fileContents2}
|
|
88
|
-
~~~
|
|
89
|
-
`
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const fileName = `slice-simulator.${extension}`;
|
|
93
|
-
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
94
|
-
const fileContents = await helpers.format(source`
|
|
95
|
-
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
96
|
-
import { SliceZone } from "@prismicio/react";
|
|
97
|
-
|
|
98
|
-
import { components } from "../slices";
|
|
99
|
-
|
|
100
|
-
export default function SliceSimulatorPage() {
|
|
101
|
-
return (
|
|
102
|
-
<SliceSimulator
|
|
103
|
-
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
104
|
-
/>
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
`, filePath, { includeNewlineAtEnd: false });
|
|
108
|
-
return {
|
|
109
|
-
title: "Create a page for the simulator",
|
|
110
|
-
description: `In your \`pages\` directory, create a file called \`${fileName}\` containing this code.`,
|
|
111
|
-
body: source`
|
|
112
|
-
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.
|
|
113
|
-
|
|
114
|
-
~~~tsx
|
|
115
|
-
${fileContents}
|
|
116
|
-
~~~
|
|
117
|
-
`
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
const createStep3 = async ({ helpers }) => {
|
|
121
|
-
const filePath = helpers.joinPathFromRoot("slicemachine.config.json");
|
|
122
|
-
const fileContents = await helpers.format(source`
|
|
123
|
-
{
|
|
124
|
-
"localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
|
|
125
|
-
}
|
|
126
|
-
`, filePath, {
|
|
127
|
-
includeNewlineAtEnd: false
|
|
128
|
-
});
|
|
129
|
-
return {
|
|
130
|
-
title: "Update `slicemachine.config.json`",
|
|
131
|
-
description: `Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.`,
|
|
132
|
-
body: source`
|
|
133
|
-
Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.
|
|
134
|
-
|
|
135
|
-
~~~json
|
|
136
|
-
${fileContents}
|
|
137
|
-
~~~
|
|
138
|
-
`,
|
|
139
|
-
validate: async () => {
|
|
140
|
-
const project = await helpers.getProject();
|
|
141
|
-
if (!("localSliceSimulatorURL" in project.config)) {
|
|
142
|
-
return {
|
|
143
|
-
title: "Missing `localSliceSimulatorURL` property",
|
|
144
|
-
message: source`
|
|
145
|
-
A \`localSliceSimulatorURL\` property was not found in your \`slicemachine.config.json\` file.
|
|
146
|
-
`
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
try {
|
|
150
|
-
if (project.config.localSliceSimulatorURL) {
|
|
151
|
-
new URL(project.config.localSliceSimulatorURL);
|
|
152
|
-
} else {
|
|
153
|
-
throw new Error("Undefined Slice Simulator URL");
|
|
154
|
-
}
|
|
155
|
-
} catch {
|
|
156
|
-
return {
|
|
157
|
-
title: "An invalid URL was provided",
|
|
158
|
-
message: source`
|
|
159
|
-
The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
|
|
160
|
-
`
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
let res = void 0;
|
|
164
|
-
try {
|
|
165
|
-
res = await fetch(project.config.localSliceSimulatorURL);
|
|
166
|
-
} catch (error) {
|
|
167
|
-
}
|
|
168
|
-
if (!res || !res.ok) {
|
|
169
|
-
return {
|
|
170
|
-
title: "Unable to connect to simulator page",
|
|
171
|
-
message: source`
|
|
172
|
-
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.
|
|
173
|
-
`
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
const sliceSimulatorSetupRead = async (_data, context) => {
|
|
180
|
-
return Promise.all([
|
|
181
|
-
createStep1(context),
|
|
182
|
-
createStep2(context),
|
|
183
|
-
createStep3(context)
|
|
184
|
-
]);
|
|
185
|
-
};
|
|
186
|
-
export {
|
|
187
|
-
sliceSimulatorSetupRead
|
|
188
|
-
};
|
|
189
|
-
//# sourceMappingURL=sliceSimulator-setup-read.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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 { getJSFileExtension } from \"../lib/getJSFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkHasAppRouter } from \"../lib/checkHasAppRouter\";\n\nconst REQUIRED_DEPENDENCIES = [\"@prismicio/react\"];\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 hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options, jsx: true });\n\n\tif (hasAppRouter) {\n\t\tconst fileName = `page.${extension}`;\n\t\tconst filePath = helpers.joinPathFromRoot(\n\t\t\t\"app\",\n\t\t\t\"slice-simulator\",\n\t\t\tfileName,\n\t\t);\n\n\t\tconst fileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport {\n\t\t\t\t\tSliceSimulator,\n\t\t\t\t\tSliceSimulatorParams,\n\t\t\t\t\tgetSlices,\n\t\t\t\t} from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage({\n\t\t\t\t\tsearchParams,\n\t\t\t\t}: SliceSimulatorParams) {\n\t\t\t\t\tconst slices = getSlices(searchParams.state);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator>\n\t\t\t\t\t\t\t<SliceZone slices={slices} components={components} />\n\t\t\t\t\t\t</SliceSimulator>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{ includeNewlineAtEnd: false },\n\t\t);\n\n\t\treturn {\n\t\t\ttitle: \"Create a page for the simulator\",\n\t\t\tdescription: `In your \\`app\\` directory, create a file called \\`slice-simulator/${fileName}\\` containing this code.`,\n\t\t\tbody: source`\n\t\t\t\tIn your \\`app\\` directory, create a file called \\`slice-simulator/${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\t};\n\t}\n\n\tconst fileName = `slice-simulator.${extension}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`,\n\t\tfilePath,\n\t\t{ includeNewlineAtEnd: false },\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(\"slicemachine.config.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 `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 Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require","fileName","filePath","fileContents"],"mappings":";;;;;AAcA,MAAM,wBAAwB,CAAC,kBAAkB;AAIjD,MAAM,cAAc,OAAO,EAC1B,SACA,cAC4C;AACtC,QAAAA,WAAU,cAAc,QAAQ,IAAI;AAEnC,SAAA;AAAA,IACN,OAAO;AAAA,IAC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