@slicemachine/adapter-next 0.3.38-beta.1 → 0.3.38-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,252 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SliceMachineContext,
|
|
3
|
-
SliceSimulatorSetupReadHook,
|
|
4
|
-
SliceSimulatorSetupStep,
|
|
5
|
-
} from "@slicemachine/plugin-kit";
|
|
6
|
-
import { source } from "common-tags";
|
|
7
|
-
import { createRequire } from "node:module";
|
|
8
|
-
import fetch, { Response } from "node-fetch";
|
|
9
|
-
|
|
10
|
-
import { getJSFileExtension } from "../lib/getJSFileExtension";
|
|
11
|
-
|
|
12
|
-
import type { PluginOptions } from "../types";
|
|
13
|
-
import { checkHasAppRouter } from "../lib/checkHasAppRouter";
|
|
14
|
-
|
|
15
|
-
const REQUIRED_DEPENDENCIES = ["@prismicio/react"];
|
|
16
|
-
|
|
17
|
-
type Args = SliceMachineContext<PluginOptions>;
|
|
18
|
-
|
|
19
|
-
const createStep1 = async ({
|
|
20
|
-
project,
|
|
21
|
-
helpers,
|
|
22
|
-
}: Args): Promise<SliceSimulatorSetupStep> => {
|
|
23
|
-
const require = createRequire(project.root);
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
title: "Install packages",
|
|
27
|
-
description: "The simulator requires some dependencies.",
|
|
28
|
-
// TODO: Create a plugin runner helper to provide the correct
|
|
29
|
-
// package manager
|
|
30
|
-
body: source`
|
|
31
|
-
The simulator requires extra dependencies. Run the following command to install them.
|
|
32
|
-
|
|
33
|
-
~~~sh
|
|
34
|
-
npm install --save ${REQUIRED_DEPENDENCIES.join(" ")}
|
|
35
|
-
~~~
|
|
36
|
-
`,
|
|
37
|
-
validate: async () => {
|
|
38
|
-
const missingDependencies: string[] = [];
|
|
39
|
-
|
|
40
|
-
for (const dependency of REQUIRED_DEPENDENCIES) {
|
|
41
|
-
try {
|
|
42
|
-
// `require.resolve()` is preferred
|
|
43
|
-
// over `import()` because we don't
|
|
44
|
-
// want to load the module. Loading a
|
|
45
|
-
// module could introduce side-effects.
|
|
46
|
-
require.resolve(dependency, {
|
|
47
|
-
paths: [helpers.joinPathFromRoot("node_modules")],
|
|
48
|
-
});
|
|
49
|
-
} catch {
|
|
50
|
-
missingDependencies.push(dependency);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {
|
|
55
|
-
return {
|
|
56
|
-
title: "Missing all dependencies",
|
|
57
|
-
message: source`
|
|
58
|
-
Install the required dependencies to continue.
|
|
59
|
-
`,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (missingDependencies.length > 0) {
|
|
64
|
-
const formattedMissingDependencies = missingDependencies
|
|
65
|
-
.map((missingDependency) => `\`${missingDependency}\``)
|
|
66
|
-
.join(", ");
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
title: "Missing some dependencies",
|
|
70
|
-
message: source`
|
|
71
|
-
The following dependencies are missing: ${formattedMissingDependencies}
|
|
72
|
-
`,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const createStep2 = async ({
|
|
80
|
-
helpers,
|
|
81
|
-
options,
|
|
82
|
-
}: Args): Promise<SliceSimulatorSetupStep> => {
|
|
83
|
-
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
84
|
-
|
|
85
|
-
const extension = await getJSFileExtension({ helpers, options, jsx: true });
|
|
86
|
-
|
|
87
|
-
if (hasAppRouter) {
|
|
88
|
-
const fileName = `page.${extension}`;
|
|
89
|
-
const filePath = helpers.joinPathFromRoot(
|
|
90
|
-
"app",
|
|
91
|
-
"slice-simulator",
|
|
92
|
-
fileName,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const fileContents = await helpers.format(
|
|
96
|
-
source`
|
|
97
|
-
import {
|
|
98
|
-
SliceSimulator,
|
|
99
|
-
SliceSimulatorParams,
|
|
100
|
-
getSlices,
|
|
101
|
-
} from "@slicemachine/adapter-next/simulator";
|
|
102
|
-
import { SliceZone } from "@prismicio/react";
|
|
103
|
-
|
|
104
|
-
import { components } from "../../slices";
|
|
105
|
-
|
|
106
|
-
export default function SliceSimulatorPage({
|
|
107
|
-
searchParams,
|
|
108
|
-
}: SliceSimulatorParams) {
|
|
109
|
-
const slices = getSlices(searchParams.state);
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<SliceSimulator>
|
|
113
|
-
<SliceZone slices={slices} components={components} />
|
|
114
|
-
</SliceSimulator>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
`,
|
|
118
|
-
filePath,
|
|
119
|
-
{ includeNewlineAtEnd: false },
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
title: "Create a page for the simulator",
|
|
124
|
-
description: `In your \`app\` directory, create a file called \`slice-simulator/${fileName}\` containing this code.`,
|
|
125
|
-
body: source`
|
|
126
|
-
In 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.
|
|
127
|
-
|
|
128
|
-
~~~tsx
|
|
129
|
-
${fileContents}
|
|
130
|
-
~~~
|
|
131
|
-
`,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const fileName = `slice-simulator.${extension}`;
|
|
136
|
-
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
137
|
-
|
|
138
|
-
const fileContents = await helpers.format(
|
|
139
|
-
source`
|
|
140
|
-
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
141
|
-
import { SliceZone } from "@prismicio/react";
|
|
142
|
-
|
|
143
|
-
import { components } from "../slices";
|
|
144
|
-
|
|
145
|
-
export default function SliceSimulatorPage() {
|
|
146
|
-
return (
|
|
147
|
-
<SliceSimulator
|
|
148
|
-
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
149
|
-
/>
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
`,
|
|
153
|
-
filePath,
|
|
154
|
-
{ includeNewlineAtEnd: false },
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
title: "Create a page for the simulator",
|
|
159
|
-
description: `In your \`pages\` directory, create a file called \`${fileName}\` containing this code.`,
|
|
160
|
-
body: source`
|
|
161
|
-
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.
|
|
162
|
-
|
|
163
|
-
~~~tsx
|
|
164
|
-
${fileContents}
|
|
165
|
-
~~~
|
|
166
|
-
`,
|
|
167
|
-
};
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const createStep3 = async ({
|
|
171
|
-
helpers,
|
|
172
|
-
}: Args): Promise<SliceSimulatorSetupStep> => {
|
|
173
|
-
const filePath = helpers.joinPathFromRoot("slicemachine.config.json");
|
|
174
|
-
const fileContents = await helpers.format(
|
|
175
|
-
source`
|
|
176
|
-
{
|
|
177
|
-
"localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
|
|
178
|
-
}
|
|
179
|
-
`,
|
|
180
|
-
filePath,
|
|
181
|
-
{
|
|
182
|
-
includeNewlineAtEnd: false,
|
|
183
|
-
},
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
return {
|
|
187
|
-
title: "Update `slicemachine.config.json`",
|
|
188
|
-
description: `Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.`,
|
|
189
|
-
body: source`
|
|
190
|
-
Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.
|
|
191
|
-
|
|
192
|
-
~~~json
|
|
193
|
-
${fileContents}
|
|
194
|
-
~~~
|
|
195
|
-
`,
|
|
196
|
-
validate: async () => {
|
|
197
|
-
const project = await helpers.getProject();
|
|
198
|
-
|
|
199
|
-
if (!("localSliceSimulatorURL" in project.config)) {
|
|
200
|
-
return {
|
|
201
|
-
title: "Missing `localSliceSimulatorURL` property",
|
|
202
|
-
message: source`
|
|
203
|
-
A \`localSliceSimulatorURL\` property was not found in your \`slicemachine.config.json\` file.
|
|
204
|
-
`,
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Test if the URL is valid.
|
|
209
|
-
try {
|
|
210
|
-
if (project.config.localSliceSimulatorURL) {
|
|
211
|
-
new URL(project.config.localSliceSimulatorURL);
|
|
212
|
-
} else {
|
|
213
|
-
throw new Error("Undefined Slice Simulator URL");
|
|
214
|
-
}
|
|
215
|
-
} catch {
|
|
216
|
-
return {
|
|
217
|
-
title: "An invalid URL was provided",
|
|
218
|
-
message: source`
|
|
219
|
-
The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
|
|
220
|
-
`,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Check if the URL is accessible.
|
|
225
|
-
let res: Response | undefined = undefined;
|
|
226
|
-
try {
|
|
227
|
-
res = await fetch(project.config.localSliceSimulatorURL);
|
|
228
|
-
} catch (error) {
|
|
229
|
-
// Noop, we return if `res` is not defined
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (!res || !res.ok) {
|
|
233
|
-
return {
|
|
234
|
-
title: "Unable to connect to simulator page",
|
|
235
|
-
message: source`
|
|
236
|
-
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.
|
|
237
|
-
`,
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
};
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
export const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<
|
|
245
|
-
PluginOptions
|
|
246
|
-
> = async (_data, context) => {
|
|
247
|
-
return Promise.all([
|
|
248
|
-
createStep1(context),
|
|
249
|
-
createStep2(context),
|
|
250
|
-
createStep3(context),
|
|
251
|
-
]);
|
|
252
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|