@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.
- package/dist/SliceSimulator.cjs +14 -41
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.js +11 -36
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/_virtual/_commonjsHelpers.cjs +5 -0
- package/dist/_virtual/_commonjsHelpers.cjs.map +1 -0
- package/dist/_virtual/_commonjsHelpers.js +5 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/ponyfill.es2018.cjs +13 -0
- package/dist/_virtual/ponyfill.es2018.cjs.map +1 -0
- package/dist/_virtual/ponyfill.es2018.js +14 -0
- package/dist/_virtual/ponyfill.es2018.js.map +1 -0
- package/dist/constants.cjs +5 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/hooks/customType-asset-delete.cjs +3 -5
- package/dist/hooks/customType-asset-delete.cjs.map +1 -1
- package/dist/hooks/customType-asset-delete.js.map +1 -1
- package/dist/hooks/customType-asset-read.cjs +3 -5
- package/dist/hooks/customType-asset-read.cjs.map +1 -1
- package/dist/hooks/customType-asset-read.js.map +1 -1
- package/dist/hooks/customType-asset-update.cjs +4 -6
- package/dist/hooks/customType-asset-update.cjs.map +1 -1
- package/dist/hooks/customType-asset-update.js.map +1 -1
- package/dist/hooks/customType-create.cjs +4 -6
- package/dist/hooks/customType-create.cjs.map +1 -1
- package/dist/hooks/customType-create.js.map +1 -1
- package/dist/hooks/customType-delete.cjs +3 -5
- package/dist/hooks/customType-delete.cjs.map +1 -1
- package/dist/hooks/customType-delete.js.map +1 -1
- package/dist/hooks/customType-read.cjs +1 -1
- package/dist/hooks/customType-read.cjs.map +1 -1
- package/dist/hooks/customType-read.js.map +1 -1
- package/dist/hooks/customType-rename.cjs +1 -1
- package/dist/hooks/customType-rename.cjs.map +1 -1
- package/dist/hooks/customType-rename.js.map +1 -1
- package/dist/hooks/customType-update.cjs +1 -1
- package/dist/hooks/customType-update.cjs.map +1 -1
- package/dist/hooks/customType-update.js.map +1 -1
- package/dist/hooks/customTypeLibrary-read.cjs +4 -6
- package/dist/hooks/customTypeLibrary-read.cjs.map +1 -1
- package/dist/hooks/customTypeLibrary-read.js.map +1 -1
- package/dist/hooks/slice-asset-delete.cjs +3 -5
- package/dist/hooks/slice-asset-delete.cjs.map +1 -1
- package/dist/hooks/slice-asset-delete.js.map +1 -1
- package/dist/hooks/slice-asset-read.cjs +3 -5
- package/dist/hooks/slice-asset-read.cjs.map +1 -1
- package/dist/hooks/slice-asset-read.js.map +1 -1
- package/dist/hooks/slice-asset-update.cjs +4 -6
- package/dist/hooks/slice-asset-update.cjs.map +1 -1
- package/dist/hooks/slice-asset-update.js.map +1 -1
- package/dist/hooks/slice-create.cjs +7 -9
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +3 -3
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/hooks/slice-delete.cjs +3 -5
- package/dist/hooks/slice-delete.cjs.map +1 -1
- package/dist/hooks/slice-delete.js.map +1 -1
- package/dist/hooks/slice-read.cjs +4 -6
- package/dist/hooks/slice-read.cjs.map +1 -1
- package/dist/hooks/slice-read.js.map +1 -1
- package/dist/hooks/slice-rename.cjs +3 -5
- package/dist/hooks/slice-rename.cjs.map +1 -1
- package/dist/hooks/slice-rename.js.map +1 -1
- package/dist/hooks/slice-update.cjs +1 -1
- package/dist/hooks/slice-update.cjs.map +1 -1
- package/dist/hooks/slice-update.js.map +1 -1
- package/dist/hooks/sliceLibrary-read.cjs +4 -6
- package/dist/hooks/sliceLibrary-read.cjs.map +1 -1
- package/dist/hooks/sliceLibrary-read.js.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.cjs +32 -98
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.js +32 -79
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
- package/dist/hooks/snippet-read.cjs +33 -18
- package/dist/hooks/snippet-read.cjs.map +1 -1
- package/dist/hooks/snippet-read.js +30 -13
- package/dist/hooks/snippet-read.js.map +1 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.js.map +1 -1
- package/dist/lib/isSharedSliceModel.cjs +3 -5
- package/dist/lib/isSharedSliceModel.cjs.map +1 -1
- package/dist/lib/isSharedSliceModel.js.map +1 -1
- package/dist/lib/pascalCase.cjs +1 -1
- package/dist/lib/pascalCase.cjs.map +1 -1
- package/dist/lib/pascalCase.js.map +1 -1
- package/dist/lib/readJSONFile.cjs +3 -5
- package/dist/lib/readJSONFile.cjs.map +1 -1
- package/dist/lib/readJSONFile.js.map +1 -1
- package/dist/lib/rejectIfNecessary.cjs +1 -1
- package/dist/lib/rejectIfNecessary.cjs.map +1 -1
- package/dist/lib/rejectIfNecessary.js.map +1 -1
- package/dist/lib/updateSliceModelFile.cjs +3 -5
- package/dist/lib/updateSliceModelFile.cjs.map +1 -1
- package/dist/lib/updateSliceModelFile.js.map +1 -1
- package/dist/lib/upsertGlobalContentTypes.cjs +8 -6
- package/dist/lib/upsertGlobalContentTypes.cjs.map +1 -1
- package/dist/lib/upsertGlobalContentTypes.js +4 -0
- package/dist/lib/upsertGlobalContentTypes.js.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +9 -8
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.js +6 -3
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs +41 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.js +41 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.js.map +1 -0
- package/dist/node_modules/fetch-blob/file.cjs +55 -0
- package/dist/node_modules/fetch-blob/file.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/file.js +55 -0
- package/dist/node_modules/fetch-blob/file.js.map +1 -0
- package/dist/node_modules/fetch-blob/index.cjs +177 -0
- package/dist/node_modules/fetch-blob/index.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/index.js +177 -0
- package/dist/node_modules/fetch-blob/index.js.map +1 -0
- package/dist/node_modules/fetch-blob/streams.cjs +43 -0
- package/dist/node_modules/fetch-blob/streams.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/streams.js +42 -0
- package/dist/node_modules/fetch-blob/streams.js.map +1 -0
- package/dist/node_modules/formdata-polyfill/esm.min.cjs +116 -0
- package/dist/node_modules/formdata-polyfill/esm.min.cjs.map +1 -0
- package/dist/node_modules/formdata-polyfill/esm.min.js +116 -0
- package/dist/node_modules/formdata-polyfill/esm.min.js.map +1 -0
- package/dist/node_modules/node-domexception/index.cjs +11 -0
- package/dist/node_modules/node-domexception/index.cjs.map +1 -0
- package/dist/node_modules/node-domexception/index.js +10 -0
- package/dist/node_modules/node-domexception/index.js.map +1 -0
- package/dist/node_modules/node-fetch/src/body.cjs +237 -0
- package/dist/node_modules/node-fetch/src/body.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/body.js +237 -0
- package/dist/node_modules/node-fetch/src/body.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.cjs +10 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.js +10 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/base.cjs +17 -0
- package/dist/node_modules/node-fetch/src/errors/base.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/base.js +17 -0
- package/dist/node_modules/node-fetch/src/errors/base.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs +14 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js +14 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js.map +1 -0
- package/dist/node_modules/node-fetch/src/headers.cjs +173 -0
- package/dist/node_modules/node-fetch/src/headers.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/headers.js +173 -0
- package/dist/node_modules/node-fetch/src/headers.js.map +1 -0
- package/dist/node_modules/node-fetch/src/index.cjs +292 -0
- package/dist/node_modules/node-fetch/src/index.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/index.js +292 -0
- package/dist/node_modules/node-fetch/src/index.js.map +1 -0
- package/dist/node_modules/node-fetch/src/request.cjs +193 -0
- package/dist/node_modules/node-fetch/src/request.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/request.js +193 -0
- package/dist/node_modules/node-fetch/src/request.js.map +1 -0
- package/dist/node_modules/node-fetch/src/response.cjs +110 -0
- package/dist/node_modules/node-fetch/src/response.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/response.js +110 -0
- package/dist/node_modules/node-fetch/src/response.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs +12 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.js +12 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs +8 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.js +8 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is.cjs +28 -0
- package/dist/node_modules/node-fetch/src/utils/is.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is.js +28 -0
- package/dist/node_modules/node-fetch/src/utils/is.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs +350 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js +350 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.cjs +149 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.js +149 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.js.map +1 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +3599 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +3599 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -0
- package/dist/package.json.cjs +5 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/{package.js → package.json.js} +1 -1
- package/dist/package.json.js.map +1 -0
- package/dist/plugin.cjs +2 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/package.json +32 -17
- package/src/constants.ts +5 -0
- package/src/hooks/slice-create.ts +3 -3
- package/src/hooks/sliceSimulator-setup-read.ts +38 -80
- package/src/hooks/snippet-read.ts +42 -22
- package/src/index.ts +0 -6
- package/src/lib/upsertGlobalContentTypes.ts +3 -0
- package/src/lib/upsertSliceLibraryIndexFile.ts +11 -6
- package/dist/package.cjs +0 -5
- package/dist/package.cjs.map +0 -1
- package/dist/package.js.map +0 -1
|
@@ -1,60 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
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
|
|
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/
|
|
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
|
-
|
|
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
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
155
|
-
|
|
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.
|
|
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.
|
|
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
|
|
188
|
-
|
|
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.
|
|
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,QAAA,QACzB;AACD,8BAAoB,KAAK,UAAU;AAAA,QACnC;AAAA,MACD;AAEG,UAAA,oBAAoB,UAAU,sBAAsB,QAAQ;AACxD,eAAA;AAAA,UACN,MAAMG,UAA6C,6CAAA;AAAA,UACnD,OAAO;AAAA,UACP,SAASD,WAAAA;AAAAA;AAAAA;AAAAA,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,MAAMC,UAA6C,6CAAA;AAAA,UACnD,OAAO;AAAA,UACP,SAASD,WAAAA;AAAAA,gDACkC;AAAA;AAAA,QAAA;AA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AASD,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,MAAMC,UAA6C,6CAAA;AAAA,UACnD,OAAO;AAAA,UACP,SAASD,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAGD,YAAM,KAAK,MAAM,IAAI,QAAiB,CAAC,YAAW;AAC7C,YAAA,QAAQ,OAAO,wBAAwB;AAC1CG,0BAAK,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,MAAMF,UAA6C,6CAAA;AAAA,UACnD,OAAO;AAAA,UACP,SAASD,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
|
+
{"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,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,SAASE,WAAAA;AAAAA;AAAAA;AAAAA,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,SAASA,WAAAA;AAAAA,gDACkC;AAAA;AAAA,QAAA;AAAA,MAG5C;AAAA,IACF;AAAA,EAAA;AA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AAA;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 {
|
|
2
|
-
import { stripIndent } from "common-tags";
|
|
1
|
+
import { source } from "common-tags";
|
|
3
2
|
import { createRequire } from "node:module";
|
|
4
|
-
import
|
|
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/
|
|
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
|
-
|
|
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
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
134
|
-
|
|
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:
|
|
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:
|
|
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
|
|
167
|
-
|
|
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:
|
|
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":";;;;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A,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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a;AAAA,IACb,MAAM;AAAA;AAAA;AAAA;AAAA,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,SAAS;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,OAAO;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAGD,YAAM,MAAM,MAAM,MAAM,QAAQ,OAAO,sBAAsB;AAEzD,UAAA,CAAC,IAAI,IAAI;AACL,eAAA;AAAA,UACN,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,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const prismicT = require("@prismicio/types");
|
|
4
4
|
const commonTags = require("common-tags");
|
|
5
|
-
function
|
|
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__ */
|
|
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
|
|
51
|
+
code: await format(commonTags.stripIndent`
|
|
37
52
|
<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
|
|
38
|
-
`,
|
|
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
|
|
61
|
+
code: await format(commonTags.stripIndent`
|
|
47
62
|
<PrismicNextImage field={${dotPath(fieldPath)}} />
|
|
48
|
-
`,
|
|
63
|
+
`, helpers)
|
|
49
64
|
},
|
|
50
65
|
{
|
|
51
66
|
label,
|
|
52
67
|
language: "tsx",
|
|
53
|
-
code: await
|
|
68
|
+
code: await format(commonTags.stripIndent`
|
|
54
69
|
<PrismicImage field={${dotPath(fieldPath)}} />
|
|
55
|
-
`,
|
|
70
|
+
`, helpers)
|
|
56
71
|
}
|
|
57
72
|
];
|
|
58
73
|
}
|
|
59
74
|
case prismicT__namespace.CustomTypeModelFieldType.Group: {
|
|
60
|
-
const code = await
|
|
75
|
+
const code = await format(commonTags.stripIndent`
|
|
61
76
|
<>{${dotPath(fieldPath)}.map(item => (
|
|
62
77
|
<>{/* Render content for item */}</>
|
|
63
78
|
))}</>
|
|
64
|
-
`,
|
|
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
|
|
87
|
+
const code = await format(commonTags.stripIndent`
|
|
73
88
|
<SliceZone
|
|
74
89
|
slices={${dotPath(fieldPath)}}
|
|
75
90
|
components={components}
|
|
76
91
|
/>
|
|
77
|
-
`,
|
|
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
|
|
103
|
+
code: await format(commonTags.stripIndent`
|
|
89
104
|
<>{${dotPath(fieldPath)}}</>
|
|
90
|
-
`,
|
|
105
|
+
`, helpers)
|
|
91
106
|
};
|
|
92
107
|
}
|
|
93
108
|
}
|