@nuxtjs/prismic 4.0.0 → 4.1.0-canary.a1dda93
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/LICENSE +1 -1
- package/README.md +18 -32
- package/dist/module.d.mts +48 -75
- package/dist/module.json +3 -3
- package/dist/module.mjs +216 -240
- package/dist/runtime/PrismicPreview.d.vue.ts +3 -0
- package/dist/runtime/PrismicPreview.vue +10 -23
- package/dist/runtime/PrismicPreview.vue.d.ts +3 -0
- package/dist/runtime/plugin.client.js +10 -7
- package/dist/runtime/plugin.js +86 -69
- package/dist/runtime/usePrismicPreview.d.ts +1 -5
- package/dist/runtime/usePrismicPreview.js +2 -2
- package/dist/types.d.mts +3 -1
- package/package.json +42 -44
- package/src/module.ts +383 -185
- package/src/runtime/PrismicPreview.vue +10 -41
- package/src/runtime/plugin.client.ts +13 -13
- package/src/runtime/plugin.ts +114 -103
- package/src/runtime/usePrismicPreview.ts +6 -10
- package/dist/client/200.html +0 -1
- package/dist/client/404.html +0 -1
- package/dist/client/_nuxt/BMD6bpEv.js +0 -1
- package/dist/client/_nuxt/BQB6UGbx.js +0 -25
- package/dist/client/_nuxt/CkG7IjgS.js +0 -1
- package/dist/client/_nuxt/DlAUqK2U.js +0 -1
- package/dist/client/_nuxt/H1okkFcd.js +0 -1
- package/dist/client/_nuxt/RYS3n4u0.js +0 -1
- package/dist/client/_nuxt/V_weDLQm.js +0 -1
- package/dist/client/_nuxt/builds/latest.json +0 -1
- package/dist/client/_nuxt/builds/meta/ef21bbff-0463-480b-852c-adffad3f33b7.json +0 -1
- package/dist/client/_nuxt/entry.BC9BDAld.css +0 -1
- package/dist/client/_nuxt/error-404.smTsHvdw.css +0 -1
- package/dist/client/_nuxt/error-500.Bo-s0s94.css +0 -1
- package/dist/client/_nuxt/index.C4BggqQh.css +0 -1
- package/dist/client/index.html +0 -1
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -136
- package/dist/types.d.ts +0 -1
- package/src/devtools/index.ts +0 -127
- package/src/devtools/types.ts +0 -22
- package/src/lib/fileExists.ts +0 -15
- package/src/lib/index.ts +0 -2
- package/src/lib/logger.ts +0 -3
- package/src/types.ts +0 -137
package/src/module.ts
CHANGED
|
@@ -1,115 +1,259 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readFile } from
|
|
3
|
-
import {
|
|
1
|
+
import { existsSync } from "node:fs"
|
|
2
|
+
import { readFile } from "node:fs/promises"
|
|
3
|
+
import { join } from "node:path"
|
|
4
4
|
|
|
5
|
-
import { defu } from 'defu'
|
|
6
5
|
import {
|
|
7
|
-
defineNuxtModule,
|
|
8
|
-
createResolver,
|
|
9
|
-
addTemplate,
|
|
10
|
-
addPlugin,
|
|
11
|
-
addImports,
|
|
12
6
|
addComponent,
|
|
7
|
+
addImports,
|
|
8
|
+
addPlugin,
|
|
9
|
+
addTemplate,
|
|
10
|
+
createResolver,
|
|
11
|
+
defineNuxtModule,
|
|
13
12
|
extendPages,
|
|
14
13
|
getNuxtVersion,
|
|
15
|
-
|
|
14
|
+
useLogger,
|
|
15
|
+
} from "@nuxt/kit"
|
|
16
|
+
import type { ClientConfig } from "@prismicio/client"
|
|
17
|
+
import { defu } from "defu"
|
|
18
|
+
import { addDependency } from "nypm"
|
|
19
|
+
import { readPackage } from "pkg-types"
|
|
16
20
|
|
|
17
|
-
import
|
|
18
|
-
import { setupDevToolsUI } from './devtools'
|
|
21
|
+
import { name, version } from "../package.json"
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Prismic Nuxt module options.
|
|
25
|
+
*
|
|
26
|
+
* @see {@link https://prismic.io/docs/nuxt}
|
|
27
|
+
* @see {@link https://prismic.io/docs/technical-reference/nuxtjs-prismic}
|
|
28
|
+
*/
|
|
29
|
+
export type PrismicModuleOptions = {
|
|
30
|
+
/**
|
|
31
|
+
* The Prismic repository name or full Content API endpoint to init the
|
|
32
|
+
* module's client instance used to fetch content from a Prismic repository
|
|
33
|
+
* with.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
*
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // With a repository name
|
|
39
|
+
* createClient("my-repo")
|
|
40
|
+
*
|
|
41
|
+
* // With a full Prismic Content API endpoint
|
|
42
|
+
* createClient("https://my-repo.cdn.prismic.io/api/v2")
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
46
|
+
*/
|
|
47
|
+
endpoint?: string
|
|
22
48
|
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
/**
|
|
50
|
+
* The Prismic environment in use by Slice Machine configured through
|
|
51
|
+
* environment variables.
|
|
52
|
+
*
|
|
53
|
+
* @defaultValue `endpoint` value.
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
environment?: string
|
|
25
58
|
|
|
26
|
-
|
|
27
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Configuration options that determines how content will be queries from the
|
|
61
|
+
* Prismic repository.
|
|
62
|
+
*
|
|
63
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
64
|
+
*/
|
|
65
|
+
clientConfig?: ClientConfig
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* An optional path to a file exporting a Prismic client instance used to
|
|
69
|
+
* fetch content from a Prismic repository to configure the module with.
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* When provided, it takes precedence over the `endpoint` and `clientConfig`
|
|
73
|
+
* options.
|
|
74
|
+
*
|
|
75
|
+
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
76
|
+
*/
|
|
77
|
+
client?: string
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The path to a file exporting a default link resolver used to resolve links
|
|
81
|
+
* when route resolvers cannot be used.
|
|
82
|
+
*
|
|
83
|
+
* @see {@link https://prismic.io/docs/routes}
|
|
84
|
+
*/
|
|
85
|
+
linkResolver?: string
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Desired path of the preview page used by Prismic to enter preview session.
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* `false` can be used to disable the preview page.
|
|
92
|
+
*
|
|
93
|
+
* @defaultValue `"/preview"`
|
|
94
|
+
*/
|
|
95
|
+
preview?: string | false
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Whether to inject Prismic toolbar script.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
* The toolbar script is required for previews to work.
|
|
102
|
+
*
|
|
103
|
+
* @defaultValue `true`
|
|
104
|
+
*/
|
|
105
|
+
toolbar?: boolean
|
|
106
|
+
|
|
107
|
+
/** Options used by Prismic Vue components. */
|
|
108
|
+
components?: {
|
|
28
109
|
/**
|
|
29
|
-
*
|
|
110
|
+
* The path to a file exporting default components or shorthand definitions
|
|
111
|
+
* for rich text and table components.
|
|
30
112
|
*
|
|
31
|
-
* @see
|
|
32
|
-
* @see
|
|
113
|
+
* @see {@link https://prismic.io/docs/fields/rich-text}
|
|
114
|
+
* @see {@link https://prismic.io/docs/fields/table}
|
|
33
115
|
*/
|
|
116
|
+
richTextComponents?: string
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Prismic Nuxt module options.
|
|
122
|
+
*
|
|
123
|
+
* @see {@link https://prismic.io/docs/nuxt}
|
|
124
|
+
* @see {@link https://prismic.io/docs/technical-reference/nuxtjs-prismic}
|
|
125
|
+
*/
|
|
126
|
+
export type ModuleOptions = PrismicModuleOptions
|
|
127
|
+
|
|
128
|
+
declare module "@nuxt/schema" {
|
|
129
|
+
interface PublicRuntimeConfig {
|
|
130
|
+
/** The Prismic Nuxt module options. */
|
|
34
131
|
prismic: PrismicModuleOptions
|
|
35
132
|
}
|
|
36
133
|
}
|
|
37
134
|
|
|
38
|
-
|
|
135
|
+
const logger = useLogger("nuxt:prismic")
|
|
136
|
+
|
|
137
|
+
async function addPrismicClient() {
|
|
138
|
+
try {
|
|
139
|
+
const pkg = await readPackage()
|
|
140
|
+
|
|
141
|
+
if (
|
|
142
|
+
!pkg.dependencies?.["@prismicio/client"] &&
|
|
143
|
+
!pkg.devDependencies?.["@prismicio/client"]
|
|
144
|
+
) {
|
|
145
|
+
await addDependency("@prismicio/client")
|
|
146
|
+
logger.info("Added `@prismicio/client` required peer dependency")
|
|
147
|
+
}
|
|
148
|
+
} catch {
|
|
149
|
+
// noop
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
39
153
|
export default defineNuxtModule<PrismicModuleOptions>({
|
|
40
154
|
meta: {
|
|
41
|
-
name
|
|
42
|
-
|
|
43
|
-
|
|
155
|
+
name,
|
|
156
|
+
version,
|
|
157
|
+
configKey: "prismic",
|
|
158
|
+
compatibility: { nuxt: ">=3.7.0" },
|
|
44
159
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let prismicComponentsFiles = {
|
|
53
|
-
linkRel: '~/app/prismic/linkRel',
|
|
54
|
-
richTextComponents: '~/app/prismic/richTextComponents',
|
|
55
|
-
sliceZoneDefaultComponent: '~/app/prismic/sliceZoneDefaultComponent',
|
|
160
|
+
onInstall() {
|
|
161
|
+
return addPrismicClient()
|
|
162
|
+
},
|
|
163
|
+
onUpgrade(_options: unknown, _nuxt: unknown, previousVersion: string) {
|
|
164
|
+
const previousMajor = parseInt(previousVersion.split(".")[0]!)
|
|
165
|
+
if (previousMajor < 4) {
|
|
166
|
+
return addPrismicClient()
|
|
56
167
|
}
|
|
168
|
+
},
|
|
169
|
+
defaults: (nuxt): Required<PrismicModuleOptions> => {
|
|
170
|
+
const nuxt3flavor =
|
|
171
|
+
getNuxtVersion(nuxt).startsWith("3") &&
|
|
172
|
+
!nuxt.options?.future?.compatibilityVersion
|
|
57
173
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
richTextComponents: '~/prismic/richTextComponents',
|
|
71
|
-
sliceZoneDefaultComponent: '~/prismic/sliceZoneDefaultComponent',
|
|
174
|
+
if (nuxt3flavor) {
|
|
175
|
+
return {
|
|
176
|
+
endpoint: "",
|
|
177
|
+
environment: "",
|
|
178
|
+
clientConfig: {},
|
|
179
|
+
client: "~/app/prismic/client",
|
|
180
|
+
linkResolver: "~/app/prismic/linkResolver",
|
|
181
|
+
preview: "/preview",
|
|
182
|
+
toolbar: true,
|
|
183
|
+
components: {
|
|
184
|
+
richTextComponents: "~/app/prismic/richTextComponents ",
|
|
185
|
+
},
|
|
72
186
|
}
|
|
73
187
|
}
|
|
74
188
|
|
|
75
189
|
return {
|
|
76
|
-
endpoint:
|
|
77
|
-
environment:
|
|
190
|
+
endpoint: "",
|
|
191
|
+
environment: "",
|
|
192
|
+
client: "~/prismic/client",
|
|
193
|
+
linkResolver: "~/prismic/linkResolver",
|
|
78
194
|
clientConfig: {},
|
|
79
|
-
|
|
80
|
-
injectComponents: true,
|
|
81
|
-
components: prismicComponentsFiles,
|
|
82
|
-
preview: '/preview',
|
|
195
|
+
preview: "/preview",
|
|
83
196
|
toolbar: true,
|
|
84
|
-
|
|
197
|
+
components: {
|
|
198
|
+
richTextComponents: "~/prismic/richTextComponents",
|
|
199
|
+
},
|
|
85
200
|
}
|
|
86
201
|
},
|
|
87
|
-
hooks: {},
|
|
88
202
|
setup(options, nuxt) {
|
|
89
|
-
// Expose options through public runtime config
|
|
90
|
-
nuxt.options.runtimeConfig.public ||= {} as typeof nuxt.options.runtimeConfig.public
|
|
91
|
-
const moduleOptions: PrismicModuleOptions = defu(nuxt.options.runtimeConfig.public.prismic, options)
|
|
92
|
-
nuxt.options.runtimeConfig.public.prismic = moduleOptions
|
|
93
|
-
|
|
94
|
-
// Runtime dir boilerplate
|
|
95
203
|
const resolver = createResolver(import.meta.url)
|
|
96
|
-
|
|
97
|
-
|
|
204
|
+
|
|
205
|
+
const moduleOptions: PrismicModuleOptions = defu(
|
|
206
|
+
nuxt.options.runtimeConfig.public?.prismic,
|
|
207
|
+
options,
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
exposeRuntimeConfig()
|
|
211
|
+
transpileDependencies()
|
|
212
|
+
const ok = proxyUserFiles()
|
|
213
|
+
if (!ok) return
|
|
214
|
+
addRuntimePlugins()
|
|
215
|
+
addAutoImports()
|
|
216
|
+
addPreviewRoute()
|
|
217
|
+
extendESLintConfig()
|
|
218
|
+
|
|
219
|
+
function exposeRuntimeConfig() {
|
|
220
|
+
nuxt.options.runtimeConfig.public ||=
|
|
221
|
+
{} as typeof nuxt.options.runtimeConfig.public
|
|
222
|
+
nuxt.options.runtimeConfig.public.prismic = moduleOptions
|
|
98
223
|
}
|
|
99
224
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
225
|
+
function transpileDependencies() {
|
|
226
|
+
nuxt.options.build.transpile.push(
|
|
227
|
+
resolver.resolve("runtime"),
|
|
228
|
+
"@nuxtjs/prismic",
|
|
229
|
+
"@prismicio/vue",
|
|
230
|
+
)
|
|
231
|
+
nuxt.options.vite.optimizeDeps ||= {}
|
|
232
|
+
nuxt.options.vite.optimizeDeps.exclude ||= []
|
|
233
|
+
nuxt.options.vite.optimizeDeps.exclude.push("@prismicio/vue")
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function proxyUserFiles() {
|
|
237
|
+
const proxyUserFileWithUndefinedFallback = (
|
|
238
|
+
filename: string,
|
|
239
|
+
path: string,
|
|
240
|
+
): boolean => {
|
|
103
241
|
const resolvedFilename = `prismic/proxy/${filename}.ts`
|
|
104
|
-
const resolvedPath = path
|
|
105
|
-
|
|
242
|
+
const resolvedPath = path
|
|
243
|
+
.replace(/^(~~|@@)/, nuxt.options.rootDir)
|
|
244
|
+
.replace(/^(~|@)/, nuxt.options.srcDir)
|
|
245
|
+
const maybeUserFile = fileExists(resolvedPath, [
|
|
246
|
+
"js",
|
|
247
|
+
"mjs",
|
|
248
|
+
"ts",
|
|
249
|
+
"vue",
|
|
250
|
+
])
|
|
106
251
|
|
|
107
252
|
if (maybeUserFile) {
|
|
108
|
-
|
|
109
|
-
logger.info(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
253
|
+
// If user file exists, proxy it with vfs
|
|
254
|
+
logger.info(
|
|
255
|
+
`Using user-defined \`${filename}\` at \`${maybeUserFile.replace(nuxt.options.srcDir, "~").replace(nuxt.options.rootDir, "~~").replace(/\\/g, "/")}\``,
|
|
256
|
+
)
|
|
113
257
|
|
|
114
258
|
addTemplate({
|
|
115
259
|
filename: resolvedFilename,
|
|
@@ -117,136 +261,190 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
117
261
|
})
|
|
118
262
|
|
|
119
263
|
return true
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Else provide `undefined` fallback
|
|
264
|
+
} else {
|
|
265
|
+
// Else provide `undefined` fallback
|
|
123
266
|
addTemplate({
|
|
124
267
|
filename: resolvedFilename,
|
|
125
|
-
getContents: () =>
|
|
268
|
+
getContents: () => "export default undefined",
|
|
126
269
|
})
|
|
127
270
|
|
|
128
271
|
return false
|
|
129
272
|
}
|
|
130
273
|
}
|
|
131
274
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
275
|
+
const proxiedUserClient = proxyUserFileWithUndefinedFallback(
|
|
276
|
+
"client",
|
|
277
|
+
moduleOptions.client!,
|
|
278
|
+
)
|
|
279
|
+
if (
|
|
280
|
+
!moduleOptions.endpoint &&
|
|
281
|
+
!proxiedUserClient &&
|
|
282
|
+
!process.env.NUXT_PUBLIC_PRISMIC_ENDPOINT
|
|
283
|
+
) {
|
|
284
|
+
logger.warn(
|
|
285
|
+
`\`endpoint\` option is missing and \`${moduleOptions.client}\` was not found. At least one of them is required for the module to run. Disabling module...`,
|
|
286
|
+
)
|
|
287
|
+
return false
|
|
288
|
+
}
|
|
289
|
+
proxyUserFileWithUndefinedFallback(
|
|
290
|
+
"linkResolver",
|
|
291
|
+
moduleOptions.linkResolver!,
|
|
292
|
+
)
|
|
293
|
+
proxyUserFileWithUndefinedFallback(
|
|
294
|
+
"richTextComponents",
|
|
295
|
+
moduleOptions.components!.richTextComponents!,
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
return true
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function addRuntimePlugins() {
|
|
302
|
+
addPlugin(resolver.resolve("runtime/plugin"))
|
|
303
|
+
addPlugin(resolver.resolve("runtime/plugin.client"))
|
|
136
304
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
nuxt.options.vite.optimizeDeps.exclude.push('@prismicio/vue')
|
|
149
|
-
|
|
150
|
-
// Add plugin
|
|
151
|
-
addPlugin(resolver.resolve('runtime/plugin'))
|
|
152
|
-
addPlugin(resolver.resolve('runtime/plugin.client'))
|
|
153
|
-
|
|
154
|
-
// Add components auto import
|
|
155
|
-
if (moduleOptions.injectComponents) {
|
|
156
|
-
[
|
|
157
|
-
'PrismicEmbed',
|
|
158
|
-
'PrismicImage',
|
|
159
|
-
'PrismicLink',
|
|
160
|
-
'PrismicText',
|
|
161
|
-
'PrismicRichText',
|
|
162
|
-
'SliceZone',
|
|
163
|
-
].forEach((component) => {
|
|
305
|
+
|
|
306
|
+
function addAutoImports() {
|
|
307
|
+
// Components
|
|
308
|
+
;[
|
|
309
|
+
"PrismicImage",
|
|
310
|
+
"PrismicLink",
|
|
311
|
+
"PrismicText",
|
|
312
|
+
"PrismicRichText",
|
|
313
|
+
"PrismicTable",
|
|
314
|
+
"SliceZone",
|
|
315
|
+
].forEach((entry) => {
|
|
164
316
|
addComponent({
|
|
165
|
-
name:
|
|
166
|
-
export:
|
|
167
|
-
filePath:
|
|
317
|
+
name: entry,
|
|
318
|
+
export: entry,
|
|
319
|
+
filePath: "@prismicio/vue",
|
|
168
320
|
})
|
|
169
321
|
})
|
|
170
|
-
}
|
|
171
322
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
323
|
+
// Composables and utils
|
|
324
|
+
addImports(
|
|
325
|
+
[
|
|
326
|
+
"usePrismic",
|
|
327
|
+
"getSliceComponentProps",
|
|
328
|
+
"defineSliceZoneComponents",
|
|
329
|
+
"getRichTextComponentProps",
|
|
330
|
+
"getTableComponentProps",
|
|
331
|
+
].map((entry) => ({ name: entry, as: entry, from: "@prismicio/vue" })),
|
|
332
|
+
)
|
|
333
|
+
addImports({
|
|
334
|
+
name: "usePrismicPreview",
|
|
335
|
+
as: "usePrismicPreview",
|
|
336
|
+
from: resolver.resolve("runtime/usePrismicPreview"),
|
|
183
337
|
})
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function addPreviewRoute() {
|
|
341
|
+
if (moduleOptions.preview) {
|
|
342
|
+
const maybeUserPreviewPage = fileExists(
|
|
343
|
+
join(
|
|
344
|
+
nuxt.options.srcDir,
|
|
345
|
+
nuxt.options.dir.pages,
|
|
346
|
+
moduleOptions.preview,
|
|
347
|
+
),
|
|
348
|
+
["js", "ts", "vue"],
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
if (maybeUserPreviewPage) {
|
|
352
|
+
logger.info(
|
|
353
|
+
`Using user-defined preview page at \`${maybeUserPreviewPage
|
|
354
|
+
.replace(join(nuxt.options.srcDir), "~")
|
|
355
|
+
.replace(nuxt.options.rootDir, "~~")
|
|
356
|
+
.replace(
|
|
357
|
+
/\\/g,
|
|
358
|
+
"/",
|
|
359
|
+
)}\`, available at \`${moduleOptions.preview}\``,
|
|
360
|
+
)
|
|
361
|
+
} else {
|
|
362
|
+
logger.info(
|
|
363
|
+
`Using default preview page, available at \`${moduleOptions.preview}\``,
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
extendPages((pages) => {
|
|
367
|
+
pages.unshift({
|
|
368
|
+
name: "prismic-preview",
|
|
369
|
+
path: moduleOptions.preview as string, // Checked before
|
|
370
|
+
file: resolver.resolve("runtime/PrismicPreview.vue"),
|
|
371
|
+
})
|
|
207
372
|
})
|
|
208
|
-
}
|
|
209
|
-
}
|
|
373
|
+
}
|
|
210
374
|
|
|
211
|
-
|
|
212
|
-
|
|
375
|
+
if (!moduleOptions.toolbar) {
|
|
376
|
+
logger.warn(
|
|
377
|
+
"`toolbar` option is disabled but `preview` is enabled. Previews won't work unless you manually load the toolbar.",
|
|
378
|
+
)
|
|
379
|
+
}
|
|
213
380
|
}
|
|
214
381
|
}
|
|
215
382
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
383
|
+
function extendESLintConfig() {
|
|
384
|
+
nuxt.hook(
|
|
385
|
+
// @ts-expect-error 3rd party hook
|
|
386
|
+
"eslint:config:addons",
|
|
387
|
+
(
|
|
388
|
+
addons: {
|
|
389
|
+
name: string
|
|
390
|
+
getConfigs: () => Promise<{ configs: string[] }>
|
|
391
|
+
}[],
|
|
392
|
+
) => {
|
|
393
|
+
addons.push({
|
|
394
|
+
name: "@nuxtjs/prismic",
|
|
395
|
+
async getConfigs() {
|
|
396
|
+
const configPath = resolver.resolve(
|
|
397
|
+
nuxt.options.rootDir,
|
|
398
|
+
"slicemachine.config.json",
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
const configs: string[] = []
|
|
402
|
+
|
|
403
|
+
try {
|
|
404
|
+
if (existsSync(configPath)) {
|
|
405
|
+
const config = JSON.parse(await readFile(configPath, "utf-8"))
|
|
406
|
+
|
|
407
|
+
if (
|
|
408
|
+
config &&
|
|
409
|
+
"libraries" in config &&
|
|
410
|
+
Array.isArray(config.libraries)
|
|
411
|
+
) {
|
|
412
|
+
configs.push(
|
|
413
|
+
JSON.stringify({
|
|
414
|
+
files: config.libraries.map(
|
|
415
|
+
(library: string) =>
|
|
416
|
+
`${library.replace("./", "")}/**/index.vue`,
|
|
417
|
+
),
|
|
418
|
+
rules: {
|
|
419
|
+
"vue/multi-word-component-names": "off",
|
|
420
|
+
},
|
|
421
|
+
}),
|
|
422
|
+
)
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
} catch {
|
|
426
|
+
// noop
|
|
240
427
|
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
catch {
|
|
244
|
-
// noop
|
|
245
|
-
}
|
|
246
428
|
|
|
247
|
-
|
|
429
|
+
return { configs }
|
|
430
|
+
},
|
|
431
|
+
})
|
|
248
432
|
},
|
|
249
|
-
|
|
250
|
-
}
|
|
433
|
+
)
|
|
434
|
+
}
|
|
251
435
|
},
|
|
252
436
|
})
|
|
437
|
+
|
|
438
|
+
function fileExists(path?: string, extensions = ["js", "ts"]): string | null {
|
|
439
|
+
if (!path) {
|
|
440
|
+
return null
|
|
441
|
+
} else if (existsSync(path)) {
|
|
442
|
+
return path
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const extension = extensions.find((extension) =>
|
|
446
|
+
existsSync(`${path}.${extension}`),
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
return extension ? `${path}.${extension}` : null
|
|
450
|
+
}
|