@slicemachine/adapter-nuxt 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.
Files changed (104) hide show
  1. package/dist/plugin.cjs +1 -3
  2. package/dist/plugin.cjs.map +1 -1
  3. package/dist/plugin.js +1 -3
  4. package/dist/plugin.js.map +1 -1
  5. package/package.json +2 -3
  6. package/src/plugin.ts +0 -7
  7. package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs +0 -41
  8. package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs.map +0 -1
  9. package/dist/_node_modules/data-uri-to-buffer/dist/index.js +0 -41
  10. package/dist/_node_modules/data-uri-to-buffer/dist/index.js.map +0 -1
  11. package/dist/_node_modules/fetch-blob/file.cjs +0 -61
  12. package/dist/_node_modules/fetch-blob/file.cjs.map +0 -1
  13. package/dist/_node_modules/fetch-blob/file.js +0 -61
  14. package/dist/_node_modules/fetch-blob/file.js.map +0 -1
  15. package/dist/_node_modules/fetch-blob/index.cjs +0 -223
  16. package/dist/_node_modules/fetch-blob/index.cjs.map +0 -1
  17. package/dist/_node_modules/fetch-blob/index.js +0 -223
  18. package/dist/_node_modules/fetch-blob/index.js.map +0 -1
  19. package/dist/_node_modules/fetch-blob/streams.cjs +0 -43
  20. package/dist/_node_modules/fetch-blob/streams.cjs.map +0 -1
  21. package/dist/_node_modules/fetch-blob/streams.js +0 -42
  22. package/dist/_node_modules/fetch-blob/streams.js.map +0 -1
  23. package/dist/_node_modules/formdata-polyfill/esm.min.cjs +0 -116
  24. package/dist/_node_modules/formdata-polyfill/esm.min.cjs.map +0 -1
  25. package/dist/_node_modules/formdata-polyfill/esm.min.js +0 -116
  26. package/dist/_node_modules/formdata-polyfill/esm.min.js.map +0 -1
  27. package/dist/_node_modules/node-domexception/index.cjs +0 -11
  28. package/dist/_node_modules/node-domexception/index.cjs.map +0 -1
  29. package/dist/_node_modules/node-domexception/index.js +0 -10
  30. package/dist/_node_modules/node-domexception/index.js.map +0 -1
  31. package/dist/_node_modules/node-fetch/src/body.cjs +0 -262
  32. package/dist/_node_modules/node-fetch/src/body.cjs.map +0 -1
  33. package/dist/_node_modules/node-fetch/src/body.js +0 -262
  34. package/dist/_node_modules/node-fetch/src/body.js.map +0 -1
  35. package/dist/_node_modules/node-fetch/src/errors/abort-error.cjs +0 -10
  36. package/dist/_node_modules/node-fetch/src/errors/abort-error.cjs.map +0 -1
  37. package/dist/_node_modules/node-fetch/src/errors/abort-error.js +0 -10
  38. package/dist/_node_modules/node-fetch/src/errors/abort-error.js.map +0 -1
  39. package/dist/_node_modules/node-fetch/src/errors/base.cjs +0 -17
  40. package/dist/_node_modules/node-fetch/src/errors/base.cjs.map +0 -1
  41. package/dist/_node_modules/node-fetch/src/errors/base.js +0 -17
  42. package/dist/_node_modules/node-fetch/src/errors/base.js.map +0 -1
  43. package/dist/_node_modules/node-fetch/src/errors/fetch-error.cjs +0 -19
  44. package/dist/_node_modules/node-fetch/src/errors/fetch-error.cjs.map +0 -1
  45. package/dist/_node_modules/node-fetch/src/errors/fetch-error.js +0 -19
  46. package/dist/_node_modules/node-fetch/src/errors/fetch-error.js.map +0 -1
  47. package/dist/_node_modules/node-fetch/src/headers.cjs +0 -190
  48. package/dist/_node_modules/node-fetch/src/headers.cjs.map +0 -1
  49. package/dist/_node_modules/node-fetch/src/headers.js +0 -190
  50. package/dist/_node_modules/node-fetch/src/headers.js.map +0 -1
  51. package/dist/_node_modules/node-fetch/src/index.cjs +0 -292
  52. package/dist/_node_modules/node-fetch/src/index.cjs.map +0 -1
  53. package/dist/_node_modules/node-fetch/src/index.js +0 -292
  54. package/dist/_node_modules/node-fetch/src/index.js.map +0 -1
  55. package/dist/_node_modules/node-fetch/src/request.cjs +0 -206
  56. package/dist/_node_modules/node-fetch/src/request.cjs.map +0 -1
  57. package/dist/_node_modules/node-fetch/src/request.js +0 -206
  58. package/dist/_node_modules/node-fetch/src/request.js.map +0 -1
  59. package/dist/_node_modules/node-fetch/src/response.cjs +0 -122
  60. package/dist/_node_modules/node-fetch/src/response.cjs.map +0 -1
  61. package/dist/_node_modules/node-fetch/src/response.js +0 -123
  62. package/dist/_node_modules/node-fetch/src/response.js.map +0 -1
  63. package/dist/_node_modules/node-fetch/src/utils/get-search.cjs +0 -12
  64. package/dist/_node_modules/node-fetch/src/utils/get-search.cjs.map +0 -1
  65. package/dist/_node_modules/node-fetch/src/utils/get-search.js +0 -12
  66. package/dist/_node_modules/node-fetch/src/utils/get-search.js.map +0 -1
  67. package/dist/_node_modules/node-fetch/src/utils/is-redirect.cjs +0 -8
  68. package/dist/_node_modules/node-fetch/src/utils/is-redirect.cjs.map +0 -1
  69. package/dist/_node_modules/node-fetch/src/utils/is-redirect.js +0 -8
  70. package/dist/_node_modules/node-fetch/src/utils/is-redirect.js.map +0 -1
  71. package/dist/_node_modules/node-fetch/src/utils/is.cjs +0 -28
  72. package/dist/_node_modules/node-fetch/src/utils/is.cjs.map +0 -1
  73. package/dist/_node_modules/node-fetch/src/utils/is.js +0 -28
  74. package/dist/_node_modules/node-fetch/src/utils/is.js.map +0 -1
  75. package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs +0 -356
  76. package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs.map +0 -1
  77. package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js +0 -356
  78. package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js.map +0 -1
  79. package/dist/_node_modules/node-fetch/src/utils/referrer.cjs +0 -149
  80. package/dist/_node_modules/node-fetch/src/utils/referrer.cjs.map +0 -1
  81. package/dist/_node_modules/node-fetch/src/utils/referrer.js +0 -149
  82. package/dist/_node_modules/node-fetch/src/utils/referrer.js.map +0 -1
  83. package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +0 -3822
  84. package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +0 -1
  85. package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +0 -3822
  86. package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +0 -1
  87. package/dist/_virtual/_commonjsHelpers.cjs +0 -5
  88. package/dist/_virtual/_commonjsHelpers.cjs.map +0 -1
  89. package/dist/_virtual/_commonjsHelpers.js +0 -5
  90. package/dist/_virtual/_commonjsHelpers.js.map +0 -1
  91. package/dist/_virtual/ponyfill.es2018.cjs +0 -5
  92. package/dist/_virtual/ponyfill.es2018.cjs.map +0 -1
  93. package/dist/_virtual/ponyfill.es2018.js +0 -5
  94. package/dist/_virtual/ponyfill.es2018.js.map +0 -1
  95. package/dist/hooks/sliceSimulator-setup-read.cjs +0 -150
  96. package/dist/hooks/sliceSimulator-setup-read.cjs.map +0 -1
  97. package/dist/hooks/sliceSimulator-setup-read.d.ts +0 -3
  98. package/dist/hooks/sliceSimulator-setup-read.js +0 -150
  99. package/dist/hooks/sliceSimulator-setup-read.js.map +0 -1
  100. package/src/hooks/sliceSimulator-setup-read.ts +0 -209
  101. /package/dist/{packages/adapter-nuxt/package.json.cjs → package.json.cjs} +0 -0
  102. /package/dist/{packages/adapter-nuxt/package.json.cjs.map → package.json.cjs.map} +0 -0
  103. /package/dist/{packages/adapter-nuxt/package.json.js → package.json.js} +0 -0
  104. /package/dist/{packages/adapter-nuxt/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,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- var ponyfill_es2018 = { exports: {} };
4
- exports.__module = ponyfill_es2018;
5
- //# sourceMappingURL=ponyfill.es2018.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ponyfill.es2018.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,5 +0,0 @@
1
- var ponyfill_es2018 = { exports: {} };
2
- export {
3
- ponyfill_es2018 as __module
4
- };
5
- //# sourceMappingURL=ponyfill.es2018.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ponyfill.es2018.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,150 +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 checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
7
- var __freeze = Object.freeze;
8
- var __defProp = Object.defineProperty;
9
- var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
10
- var _a;
11
- const REQUIRED_DEPENDENCIES = ["@nuxtjs/prismic"];
12
- const createStep1 = async ({ project, helpers }) => {
13
- const require2 = node_module.createRequire(project.root);
14
- return {
15
- title: "Install packages",
16
- description: "The simulator requires some dependencies.",
17
- // TODO: Create a plugin runner helper to provide the correct
18
- // package manager
19
- body: commonTags.source`
20
- The simulator requires extra dependencies. Run the following command to install them.
21
-
22
- ~~~sh
23
- npm install --save ${REQUIRED_DEPENDENCIES.join(" ")}
24
- ~~~
25
- `,
26
- validate: async () => {
27
- const missingDependencies = [];
28
- for (const dependency of REQUIRED_DEPENDENCIES) {
29
- try {
30
- require2.resolve(dependency, {
31
- paths: [helpers.joinPathFromRoot("node_modules")]
32
- });
33
- } catch {
34
- missingDependencies.push(dependency);
35
- }
36
- }
37
- if (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {
38
- return {
39
- title: "Missing all dependencies",
40
- message: commonTags.source`
41
- Install the required dependencies to continue.
42
- `
43
- };
44
- }
45
- if (missingDependencies.length > 0) {
46
- const formattedMissingDependencies = missingDependencies.map((missingDependency) => `\`${missingDependency}\``).join(", ");
47
- return {
48
- title: "Missing some dependencies",
49
- message: commonTags.source`
50
- The following dependencies are missing: ${formattedMissingDependencies}
51
- `
52
- };
53
- }
54
- }
55
- };
56
- };
57
- const createStep2 = async ({ helpers, options }) => {
58
- const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
59
- helpers,
60
- options
61
- });
62
- const fileName = "slice-simulator.vue";
63
- const filePath = helpers.joinPathFromRoot("pages", fileName);
64
- const scriptAttributes = ["setup"];
65
- if (isTypeScriptProject) {
66
- scriptAttributes.push('lang="ts"');
67
- }
68
- const fileContents = await helpers.format(commonTags.source(_a || (_a = __template(["\n <script ", '>\n import { SliceSimulator } from "@slicemachine/adapter-nuxt/simulator";\n import { components } from "~/slices";\n <\/script>\n\n <template>\n <SliceSimulator #default="{ slices }">\n <SliceZone :slices="slices" :components="components" />\n </SliceSimulator>\n </template>\n '])), scriptAttributes.join(" ")), filePath, {
69
- includeNewlineAtEnd: false
70
- });
71
- return {
72
- title: "Create a page for the simulator",
73
- description: `In your \`pages\` directory, create a file called \`${fileName}\` containing this code.`,
74
- body: commonTags.source`
75
- 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.
76
-
77
- ~~~vue
78
- ${fileContents}
79
- ~~~
80
- `
81
- };
82
- };
83
- const createStep3 = async ({ helpers }) => {
84
- const filePath = helpers.joinPathFromRoot("slicemachine.config.json");
85
- const fileContents = await helpers.format(commonTags.source`
86
- {
87
- "localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
88
- }
89
- `, filePath, {
90
- includeNewlineAtEnd: false
91
- });
92
- return {
93
- title: "Update `slicemachine.config.json`",
94
- description: `Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.`,
95
- body: commonTags.source`
96
- Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.
97
-
98
- ~~~json
99
- ${fileContents}
100
- ~~~
101
- `,
102
- validate: async () => {
103
- const project = await helpers.getProject();
104
- if (!("localSliceSimulatorURL" in project.config)) {
105
- return {
106
- title: "Missing `localSliceSimulatorURL` property",
107
- message: commonTags.source`
108
- A \`localSliceSimulatorURL\` property was not found in your \`slicemachine.config.json\` file.
109
- `
110
- };
111
- }
112
- try {
113
- if (project.config.localSliceSimulatorURL) {
114
- new URL(project.config.localSliceSimulatorURL);
115
- } else {
116
- throw new Error("Undefined Slice Simulator URL");
117
- }
118
- } catch {
119
- return {
120
- title: "An invalid URL was provided",
121
- message: commonTags.source`
122
- The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
123
- `
124
- };
125
- }
126
- let res = void 0;
127
- try {
128
- res = await index.default(project.config.localSliceSimulatorURL);
129
- } catch (error) {
130
- }
131
- if (!res || !res.ok) {
132
- return {
133
- title: "Unable to connect to simulator page",
134
- message: commonTags.source`
135
- Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/nuxt-setup) for more details.
136
- `
137
- };
138
- }
139
- }
140
- };
141
- };
142
- const sliceSimulatorSetupRead = async (_data, context) => {
143
- return Promise.all([
144
- createStep1(context),
145
- createStep2(context),
146
- createStep3(context)
147
- ]);
148
- };
149
- exports.sliceSimulatorSetupRead = sliceSimulatorSetupRead;
150
- //# 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 { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\"@nuxtjs/prismic\"];\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 isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst fileName = \"slice-simulator.vue\";\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tconst scriptAttributes = [\"setup\"];\n\tif (isTypeScriptProject) {\n\t\tscriptAttributes.push('lang=\"ts\"');\n\t}\n\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t<script ${scriptAttributes.join(\" \")}>\n\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-nuxt/simulator\";\n\t\t\timport { components } from \"~/slices\";\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<SliceSimulator #default=\"{ slices }\">\n\t\t\t\t\t<SliceZone :slices=\"slices\" :components=\"components\" />\n\t\t\t\t</SliceSimulator>\n\t\t\t</template>\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~~~vue\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/nuxt-setup) 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","checkIsTypeScriptProject","fetch"],"mappings":";;;;;;;;;AAKA,IAAA;AAQA,MAAM,wBAAwB,CAAC,iBAAiB;AAIhD,MAAM,cAAc,OAAO,EAC1B,SACA,cAC4C;AACtCA,QAAAA,WAAUC,YAAAA,cAAc,QAAQ,IAAI;AAEnC,SAAA;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA;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;AAKHF,mBAAQ,QAAQ,YAAY;AAAA,YAC3B,OAAO,CAAC,QAAQ,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AAA;AAAAA,KAKA,UACA;AAAA,IACC,qBAAqB;AAAA,EAAA,CACrB;AAGK,SAAA;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAMA,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA,KAIH;AAAA;AAAA;AAAA,IAGH,UAAU,YAAW;AACd,YAAA,UAAU,MAAM,QAAQ;AAE1B,UAAA,EAAE,4BAA4B,QAAQ,SAAS;AAC3C,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASA,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAGG,UAAA;AACC,YAAA,QAAQ,OAAO,wBAAwB;AACtC,cAAA,IAAI,QAAQ,OAAO,sBAAsB;AAAA,QAAA,OACvC;AACA,gBAAA,IAAI,MAAM,+BAA+B;AAAA,QAC/C;AAAA,MAAA,QACA;AACM,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASA,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAGD,UAAI,MAA4B;AAC5B,UAAA;AACH,cAAM,MAAME,MAAA,QAAM,QAAQ,OAAO,sBAAsB;AAAA,eAC/C;MAER;AAED,UAAI,CAAC,OAAO,CAAC,IAAI,IAAI;AACb,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,3 +0,0 @@
1
- import type { SliceSimulatorSetupReadHook } from "@slicemachine/plugin-kit";
2
- import type { PluginOptions } from "../types";
3
- export declare const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<PluginOptions>;
@@ -1,150 +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 { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
5
- var __freeze = Object.freeze;
6
- var __defProp = Object.defineProperty;
7
- var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
8
- var _a;
9
- const REQUIRED_DEPENDENCIES = ["@nuxtjs/prismic"];
10
- const createStep1 = async ({ project, helpers }) => {
11
- const require2 = createRequire(project.root);
12
- return {
13
- title: "Install packages",
14
- description: "The simulator requires some dependencies.",
15
- // TODO: Create a plugin runner helper to provide the correct
16
- // package manager
17
- body: source`
18
- The simulator requires extra dependencies. Run the following command to install them.
19
-
20
- ~~~sh
21
- npm install --save ${REQUIRED_DEPENDENCIES.join(" ")}
22
- ~~~
23
- `,
24
- validate: async () => {
25
- const missingDependencies = [];
26
- for (const dependency of REQUIRED_DEPENDENCIES) {
27
- try {
28
- require2.resolve(dependency, {
29
- paths: [helpers.joinPathFromRoot("node_modules")]
30
- });
31
- } catch {
32
- missingDependencies.push(dependency);
33
- }
34
- }
35
- if (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {
36
- return {
37
- title: "Missing all dependencies",
38
- message: source`
39
- Install the required dependencies to continue.
40
- `
41
- };
42
- }
43
- if (missingDependencies.length > 0) {
44
- const formattedMissingDependencies = missingDependencies.map((missingDependency) => `\`${missingDependency}\``).join(", ");
45
- return {
46
- title: "Missing some dependencies",
47
- message: source`
48
- The following dependencies are missing: ${formattedMissingDependencies}
49
- `
50
- };
51
- }
52
- }
53
- };
54
- };
55
- const createStep2 = async ({ helpers, options }) => {
56
- const isTypeScriptProject = await checkIsTypeScriptProject({
57
- helpers,
58
- options
59
- });
60
- const fileName = "slice-simulator.vue";
61
- const filePath = helpers.joinPathFromRoot("pages", fileName);
62
- const scriptAttributes = ["setup"];
63
- if (isTypeScriptProject) {
64
- scriptAttributes.push('lang="ts"');
65
- }
66
- const fileContents = await helpers.format(source(_a || (_a = __template(["\n <script ", '>\n import { SliceSimulator } from "@slicemachine/adapter-nuxt/simulator";\n import { components } from "~/slices";\n <\/script>\n\n <template>\n <SliceSimulator #default="{ slices }">\n <SliceZone :slices="slices" :components="components" />\n </SliceSimulator>\n </template>\n '])), scriptAttributes.join(" ")), filePath, {
67
- includeNewlineAtEnd: false
68
- });
69
- return {
70
- title: "Create a page for the simulator",
71
- description: `In your \`pages\` directory, create a file called \`${fileName}\` containing this code.`,
72
- body: source`
73
- 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.
74
-
75
- ~~~vue
76
- ${fileContents}
77
- ~~~
78
- `
79
- };
80
- };
81
- const createStep3 = async ({ helpers }) => {
82
- const filePath = helpers.joinPathFromRoot("slicemachine.config.json");
83
- const fileContents = await helpers.format(source`
84
- {
85
- "localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
86
- }
87
- `, filePath, {
88
- includeNewlineAtEnd: false
89
- });
90
- return {
91
- title: "Update `slicemachine.config.json`",
92
- description: `Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.`,
93
- body: source`
94
- Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.
95
-
96
- ~~~json
97
- ${fileContents}
98
- ~~~
99
- `,
100
- validate: async () => {
101
- const project = await helpers.getProject();
102
- if (!("localSliceSimulatorURL" in project.config)) {
103
- return {
104
- title: "Missing `localSliceSimulatorURL` property",
105
- message: source`
106
- A \`localSliceSimulatorURL\` property was not found in your \`slicemachine.config.json\` file.
107
- `
108
- };
109
- }
110
- try {
111
- if (project.config.localSliceSimulatorURL) {
112
- new URL(project.config.localSliceSimulatorURL);
113
- } else {
114
- throw new Error("Undefined Slice Simulator URL");
115
- }
116
- } catch {
117
- return {
118
- title: "An invalid URL was provided",
119
- message: source`
120
- The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
121
- `
122
- };
123
- }
124
- let res = void 0;
125
- try {
126
- res = await fetch(project.config.localSliceSimulatorURL);
127
- } catch (error) {
128
- }
129
- if (!res || !res.ok) {
130
- return {
131
- title: "Unable to connect to simulator page",
132
- message: source`
133
- Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/nuxt-setup) for more details.
134
- `
135
- };
136
- }
137
- }
138
- };
139
- };
140
- const sliceSimulatorSetupRead = async (_data, context) => {
141
- return Promise.all([
142
- createStep1(context),
143
- createStep2(context),
144
- createStep3(context)
145
- ]);
146
- };
147
- export {
148
- sliceSimulatorSetupRead
149
- };
150
- //# 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 { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\"@nuxtjs/prismic\"];\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 isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst fileName = \"slice-simulator.vue\";\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tconst scriptAttributes = [\"setup\"];\n\tif (isTypeScriptProject) {\n\t\tscriptAttributes.push('lang=\"ts\"');\n\t}\n\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t<script ${scriptAttributes.join(\" \")}>\n\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-nuxt/simulator\";\n\t\t\timport { components } from \"~/slices\";\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<SliceSimulator #default=\"{ slices }\">\n\t\t\t\t\t<SliceZone :slices=\"slices\" :components=\"components\" />\n\t\t\t\t</SliceSimulator>\n\t\t\t</template>\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~~~vue\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/nuxt-setup) 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":";;;;;;;AAKA,IAAA;AAQA,MAAM,wBAAwB,CAAC,iBAAiB;AAIhD,MAAM,cAAc,OAAO,EAC1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YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,EAAA,CACnB;AACF;"}
@@ -1,209 +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 { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
11
-
12
- import type { PluginOptions } from "../types";
13
-
14
- const REQUIRED_DEPENDENCIES = ["@nuxtjs/prismic"];
15
-
16
- type Args = SliceMachineContext<PluginOptions>;
17
-
18
- const createStep1 = async ({
19
- project,
20
- helpers,
21
- }: Args): Promise<SliceSimulatorSetupStep> => {
22
- const require = createRequire(project.root);
23
-
24
- return {
25
- title: "Install packages",
26
- description: "The simulator requires some dependencies.",
27
- // TODO: Create a plugin runner helper to provide the correct
28
- // package manager
29
- body: source`
30
- The simulator requires extra dependencies. Run the following command to install them.
31
-
32
- ~~~sh
33
- npm install --save ${REQUIRED_DEPENDENCIES.join(" ")}
34
- ~~~
35
- `,
36
- validate: async () => {
37
- const missingDependencies: string[] = [];
38
-
39
- for (const dependency of REQUIRED_DEPENDENCIES) {
40
- try {
41
- // `require.resolve()` is preferred
42
- // over `import()` because we don't
43
- // want to load the module. Loading a
44
- // module could introduce side-effects.
45
- require.resolve(dependency, {
46
- paths: [helpers.joinPathFromRoot("node_modules")],
47
- });
48
- } catch {
49
- missingDependencies.push(dependency);
50
- }
51
- }
52
-
53
- if (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {
54
- return {
55
- title: "Missing all dependencies",
56
- message: source`
57
- Install the required dependencies to continue.
58
- `,
59
- };
60
- }
61
-
62
- if (missingDependencies.length > 0) {
63
- const formattedMissingDependencies = missingDependencies
64
- .map((missingDependency) => `\`${missingDependency}\``)
65
- .join(", ");
66
-
67
- return {
68
- title: "Missing some dependencies",
69
- message: source`
70
- The following dependencies are missing: ${formattedMissingDependencies}
71
- `,
72
- };
73
- }
74
- },
75
- };
76
- };
77
-
78
- const createStep2 = async ({
79
- helpers,
80
- options,
81
- }: Args): Promise<SliceSimulatorSetupStep> => {
82
- const isTypeScriptProject = await checkIsTypeScriptProject({
83
- helpers,
84
- options,
85
- });
86
-
87
- const fileName = "slice-simulator.vue";
88
- const filePath = helpers.joinPathFromRoot("pages", fileName);
89
-
90
- const scriptAttributes = ["setup"];
91
- if (isTypeScriptProject) {
92
- scriptAttributes.push('lang="ts"');
93
- }
94
-
95
- const fileContents = await helpers.format(
96
- source`
97
- <script ${scriptAttributes.join(" ")}>
98
- import { SliceSimulator } from "@slicemachine/adapter-nuxt/simulator";
99
- import { components } from "~/slices";
100
- </script>
101
-
102
- <template>
103
- <SliceSimulator #default="{ slices }">
104
- <SliceZone :slices="slices" :components="components" />
105
- </SliceSimulator>
106
- </template>
107
- `,
108
- filePath,
109
- {
110
- includeNewlineAtEnd: false,
111
- },
112
- );
113
-
114
- return {
115
- title: "Create a page for the simulator",
116
- description: `In your \`pages\` directory, create a file called \`${fileName}\` containing this code.`,
117
- body: source`
118
- 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.
119
-
120
- ~~~vue
121
- ${fileContents}
122
- ~~~
123
- `,
124
- };
125
- };
126
-
127
- const createStep3 = async ({
128
- helpers,
129
- }: Args): Promise<SliceSimulatorSetupStep> => {
130
- const filePath = helpers.joinPathFromRoot("slicemachine.config.json");
131
- const fileContents = await helpers.format(
132
- source`
133
- {
134
- "localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
135
- }
136
- `,
137
- filePath,
138
- {
139
- includeNewlineAtEnd: false,
140
- },
141
- );
142
-
143
- return {
144
- title: "Update `slicemachine.config.json`",
145
- description: `Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.`,
146
- body: source`
147
- Update your \`slicemachine.config.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`/slice-simulator\` page.
148
-
149
- ~~~json
150
- ${fileContents}
151
- ~~~
152
- `,
153
- validate: async () => {
154
- const project = await helpers.getProject();
155
-
156
- if (!("localSliceSimulatorURL" in project.config)) {
157
- return {
158
- title: "Missing `localSliceSimulatorURL` property",
159
- message: source`
160
- A \`localSliceSimulatorURL\` property was not found in your \`slicemachine.config.json\` file.
161
- `,
162
- };
163
- }
164
-
165
- // Test if the URL is valid.
166
- try {
167
- if (project.config.localSliceSimulatorURL) {
168
- new URL(project.config.localSliceSimulatorURL);
169
- } else {
170
- throw new Error("Undefined Slice Simulator URL");
171
- }
172
- } catch {
173
- return {
174
- title: "An invalid URL was provided",
175
- message: source`
176
- The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
177
- `,
178
- };
179
- }
180
-
181
- // Check if the URL is accessible.
182
- let res: Response | undefined = undefined;
183
- try {
184
- res = await fetch(project.config.localSliceSimulatorURL);
185
- } catch (error) {
186
- // Noop, we return if `res` is not defined
187
- }
188
-
189
- if (!res || !res.ok) {
190
- return {
191
- title: "Unable to connect to simulator page",
192
- message: source`
193
- Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/nuxt-setup) for more details.
194
- `,
195
- };
196
- }
197
- },
198
- };
199
- };
200
-
201
- export const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<
202
- PluginOptions
203
- > = async (_data, context) => {
204
- return Promise.all([
205
- createStep1(context),
206
- createStep2(context),
207
- createStep3(context),
208
- ]);
209
- };