@nuxtjs/prismic 5.2.0 → 5.2.1-canary.776ac17
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/README.md +1 -12
- package/dist/module.d.mts +3 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +49 -2
- package/package.json +17 -17
- package/src/module.ts +71 -7
package/README.md
CHANGED
|
@@ -27,18 +27,7 @@ Install the module to your Nuxt application with one command:
|
|
|
27
27
|
npx nuxi@latest module add prismic
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```javascript
|
|
33
|
-
import { defineNuxtConfig } from "nuxt"
|
|
34
|
-
|
|
35
|
-
export default defineNuxtConfig({
|
|
36
|
-
modules: ["@nuxtjs/prismic"],
|
|
37
|
-
prismic: {
|
|
38
|
-
endpoint: "my-repository",
|
|
39
|
-
},
|
|
40
|
-
})
|
|
41
|
-
```
|
|
30
|
+
The module automatically loads your repository name and `routes` from `prismic.config.json`, so for most projects all you need to do is register the module (done by the `module add` command). If needed, you can still override those values and configure the Nuxt module further in `nuxt.config.ts` or Nuxt's `runtimeConfig`.
|
|
42
31
|
|
|
43
32
|
That's it! You can now use Prismic in your Nuxt app ✨
|
|
44
33
|
|
package/dist/module.d.mts
CHANGED
|
@@ -82,9 +82,9 @@ type PrismicModuleOptions = {
|
|
|
82
82
|
* Controls which auto-imports are added by the module.
|
|
83
83
|
*
|
|
84
84
|
* - `"all"` will add all imports.
|
|
85
|
-
* - `
|
|
86
|
-
* - `
|
|
87
|
-
* - `
|
|
85
|
+
* - `"vue"` will add `@nuxtjs/prismic` and `@prismicio/vue` imports.
|
|
86
|
+
* - `"javascript"` will add `@prismicio/client` imports.
|
|
87
|
+
* - `"content"` will add the `Content` type import.
|
|
88
88
|
* - `false` will not add any import.
|
|
89
89
|
*
|
|
90
90
|
* @defaultValue `["vue"]`
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { useLogger, defineNuxtModule, createResolver, addPlugin, addComponent, addImports, extendPages, getNuxtVersion, addTemplate } from '@nuxt/kit';
|
|
@@ -7,9 +7,10 @@ import { addDependency } from 'nypm';
|
|
|
7
7
|
import { readPackage } from 'pkg-types';
|
|
8
8
|
|
|
9
9
|
const name = "@nuxtjs/prismic";
|
|
10
|
-
const version = "5.2.
|
|
10
|
+
const version = "5.2.1-canary.776ac17";
|
|
11
11
|
|
|
12
12
|
const logger = useLogger("nuxt:prismic");
|
|
13
|
+
const PRISMIC_CONFIG_FILENAME = "prismic.config.json";
|
|
13
14
|
async function addPrismicClient() {
|
|
14
15
|
try {
|
|
15
16
|
const pkg = await readPackage();
|
|
@@ -73,6 +74,7 @@ const module$1 = defineNuxtModule({
|
|
|
73
74
|
nuxt.options.runtimeConfig.public?.prismic,
|
|
74
75
|
options
|
|
75
76
|
);
|
|
77
|
+
loadPrismicConfig();
|
|
76
78
|
exposeRuntimeConfig();
|
|
77
79
|
transpileDependencies();
|
|
78
80
|
const ok = proxyUserFiles();
|
|
@@ -81,6 +83,29 @@ const module$1 = defineNuxtModule({
|
|
|
81
83
|
addAutoImports();
|
|
82
84
|
addPreviewRoute();
|
|
83
85
|
extendESLintConfig();
|
|
86
|
+
function loadPrismicConfig() {
|
|
87
|
+
const prismicConfigPath = join(nuxt.options.rootDir, PRISMIC_CONFIG_FILENAME);
|
|
88
|
+
const prismicConfig = readPrismicConfig(prismicConfigPath);
|
|
89
|
+
const configKeys = [];
|
|
90
|
+
if (!moduleOptions.endpoint && prismicConfig.repositoryName) {
|
|
91
|
+
moduleOptions.endpoint = prismicConfig.repositoryName;
|
|
92
|
+
configKeys.push("repository name");
|
|
93
|
+
}
|
|
94
|
+
if (!moduleOptions.clientConfig?.routes && prismicConfig.routes) {
|
|
95
|
+
moduleOptions.clientConfig.routes = prismicConfig.routes;
|
|
96
|
+
configKeys.push("routes");
|
|
97
|
+
}
|
|
98
|
+
if (configKeys.length > 0) {
|
|
99
|
+
nuxt.options.watch.push(prismicConfigPath);
|
|
100
|
+
nuxt.hook("builder:watch", async (_, path) => {
|
|
101
|
+
if (path.replace(/\\/g, "/") === prismicConfigPath.replace(/\\/g, "/")) {
|
|
102
|
+
logger.info(`${PRISMIC_CONFIG_FILENAME} updated`);
|
|
103
|
+
await nuxt.callHook("restart");
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
logger.info(`Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
84
109
|
function exposeRuntimeConfig() {
|
|
85
110
|
nuxt.options.runtimeConfig.public ||= {};
|
|
86
111
|
nuxt.options.runtimeConfig.public.prismic = moduleOptions;
|
|
@@ -298,5 +323,27 @@ function fileExists(path, extensions = ["js", "ts"]) {
|
|
|
298
323
|
);
|
|
299
324
|
return extension ? `${path}.${extension}` : null;
|
|
300
325
|
}
|
|
326
|
+
function readPrismicConfig(configPath) {
|
|
327
|
+
if (!existsSync(configPath)) {
|
|
328
|
+
return {};
|
|
329
|
+
}
|
|
330
|
+
try {
|
|
331
|
+
const contents = readFileSync(configPath, "utf-8");
|
|
332
|
+
const rawConfig = JSON.parse(contents);
|
|
333
|
+
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
334
|
+
return {};
|
|
335
|
+
}
|
|
336
|
+
const config = {};
|
|
337
|
+
if ("repositoryName" in rawConfig && typeof rawConfig.repositoryName === "string") {
|
|
338
|
+
config.repositoryName = rawConfig.repositoryName;
|
|
339
|
+
}
|
|
340
|
+
if ("routes" in rawConfig && Array.isArray(rawConfig.routes)) {
|
|
341
|
+
config.routes = rawConfig.routes;
|
|
342
|
+
}
|
|
343
|
+
return config;
|
|
344
|
+
} catch {
|
|
345
|
+
return {};
|
|
346
|
+
}
|
|
347
|
+
}
|
|
301
348
|
|
|
302
349
|
export { module$1 as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/prismic",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.1-canary.776ac17",
|
|
4
4
|
"description": "Easily connect your Nuxt application to your content hosted on Prismic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -52,30 +52,30 @@
|
|
|
52
52
|
"test": "npm run lint && npm run types && npm run unit && npm run build"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@nuxt/kit": "^4.
|
|
56
|
-
"@prismicio/vue": "^6.1.
|
|
57
|
-
"defu": "^6.1.
|
|
58
|
-
"nypm": "^0.6.
|
|
59
|
-
"pkg-types": "^2.3.
|
|
55
|
+
"@nuxt/kit": "^4.4.4",
|
|
56
|
+
"@prismicio/vue": "^6.1.3",
|
|
57
|
+
"defu": "^6.1.7",
|
|
58
|
+
"nypm": "^0.6.6",
|
|
59
|
+
"pkg-types": "^2.3.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@nuxt/module-builder": "^1.0.2",
|
|
63
|
-
"@nuxt/schema": "^4.
|
|
63
|
+
"@nuxt/schema": "^4.4.4",
|
|
64
64
|
"@nuxt/test-utils": "^3.23.0",
|
|
65
|
-
"@prismicio/client": "^7.21.
|
|
65
|
+
"@prismicio/client": "^7.21.8",
|
|
66
66
|
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
67
|
-
"@types/node": "^25.0
|
|
68
|
-
"@vitest/coverage-v8": "^4.
|
|
69
|
-
"nuxt": "^4.
|
|
70
|
-
"oxlint": "^1.
|
|
71
|
-
"prettier": "^3.8.
|
|
67
|
+
"@types/node": "^25.6.0",
|
|
68
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
69
|
+
"nuxt": "^4.4.4",
|
|
70
|
+
"oxlint": "^1.62.0",
|
|
71
|
+
"prettier": "^3.8.3",
|
|
72
72
|
"prettier-plugin-jsdoc": "^1.8.0",
|
|
73
|
-
"typescript": "^
|
|
74
|
-
"vitest": "^4.
|
|
75
|
-
"vue-tsc": "^3.2.
|
|
73
|
+
"typescript": "^6.0.3",
|
|
74
|
+
"vitest": "^4.1.5",
|
|
75
|
+
"vue-tsc": "^3.2.7"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@prismicio/client": "^7"
|
|
78
|
+
"@prismicio/client": "^7.21.8"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=20.0.0"
|
package/src/module.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync } from "node:fs"
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
2
2
|
import { readFile } from "node:fs/promises"
|
|
3
3
|
import { join } from "node:path"
|
|
4
4
|
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
getNuxtVersion,
|
|
14
14
|
useLogger,
|
|
15
15
|
} from "@nuxt/kit"
|
|
16
|
-
import type { ClientConfig } from "@prismicio/client"
|
|
16
|
+
import type { ClientConfig, Route } from "@prismicio/client"
|
|
17
17
|
import { defu } from "defu"
|
|
18
18
|
import { addDependency } from "nypm"
|
|
19
19
|
import { readPackage } from "pkg-types"
|
|
@@ -108,9 +108,9 @@ export type PrismicModuleOptions = {
|
|
|
108
108
|
* Controls which auto-imports are added by the module.
|
|
109
109
|
*
|
|
110
110
|
* - `"all"` will add all imports.
|
|
111
|
-
* - `
|
|
112
|
-
* - `
|
|
113
|
-
* - `
|
|
111
|
+
* - `"vue"` will add `@nuxtjs/prismic` and `@prismicio/vue` imports.
|
|
112
|
+
* - `"javascript"` will add `@prismicio/client` imports.
|
|
113
|
+
* - `"content"` will add the `Content` type import.
|
|
114
114
|
* - `false` will not add any import.
|
|
115
115
|
*
|
|
116
116
|
* @defaultValue `["vue"]`
|
|
@@ -148,6 +148,7 @@ declare module "@nuxt/schema" {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
const logger = useLogger("nuxt:prismic")
|
|
151
|
+
const PRISMIC_CONFIG_FILENAME = "prismic.config.json"
|
|
151
152
|
|
|
152
153
|
async function addPrismicClient() {
|
|
153
154
|
try {
|
|
@@ -220,10 +221,11 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
220
221
|
const resolver = createResolver(import.meta.url)
|
|
221
222
|
|
|
222
223
|
const moduleOptions: PrismicModuleOptions = defu(
|
|
223
|
-
nuxt.options.runtimeConfig.public?.prismic,
|
|
224
|
+
nuxt.options.runtimeConfig.public?.prismic as PrismicModuleOptions,
|
|
224
225
|
options,
|
|
225
226
|
)
|
|
226
227
|
|
|
228
|
+
loadPrismicConfig()
|
|
227
229
|
exposeRuntimeConfig()
|
|
228
230
|
transpileDependencies()
|
|
229
231
|
const ok = proxyUserFiles()
|
|
@@ -233,10 +235,37 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
233
235
|
addPreviewRoute()
|
|
234
236
|
extendESLintConfig()
|
|
235
237
|
|
|
238
|
+
function loadPrismicConfig() {
|
|
239
|
+
const prismicConfigPath = join(nuxt.options.rootDir, PRISMIC_CONFIG_FILENAME)
|
|
240
|
+
const prismicConfig = readPrismicConfig(prismicConfigPath)
|
|
241
|
+
|
|
242
|
+
const configKeys: string[] = []
|
|
243
|
+
if (!moduleOptions.endpoint && prismicConfig.repositoryName) {
|
|
244
|
+
moduleOptions.endpoint = prismicConfig.repositoryName
|
|
245
|
+
configKeys.push("repository name")
|
|
246
|
+
}
|
|
247
|
+
if (!moduleOptions.clientConfig?.routes && prismicConfig.routes) {
|
|
248
|
+
moduleOptions.clientConfig!.routes = prismicConfig.routes
|
|
249
|
+
configKeys.push("routes")
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (configKeys.length > 0) {
|
|
253
|
+
nuxt.options.watch.push(prismicConfigPath)
|
|
254
|
+
nuxt.hook("builder:watch", async (_, path) => {
|
|
255
|
+
if (path.replace(/\\/g, "/") === prismicConfigPath.replace(/\\/g, "/")) {
|
|
256
|
+
logger.info(`${PRISMIC_CONFIG_FILENAME} updated`)
|
|
257
|
+
await nuxt.callHook("restart")
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
logger.info(`Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
236
265
|
function exposeRuntimeConfig() {
|
|
237
266
|
nuxt.options.runtimeConfig.public ||=
|
|
238
267
|
{} as typeof nuxt.options.runtimeConfig.public
|
|
239
|
-
nuxt.options.runtimeConfig.public.prismic = moduleOptions
|
|
268
|
+
(nuxt.options.runtimeConfig.public.prismic as PrismicModuleOptions) = moduleOptions
|
|
240
269
|
}
|
|
241
270
|
|
|
242
271
|
function transpileDependencies() {
|
|
@@ -510,3 +539,38 @@ function fileExists(path?: string, extensions = ["js", "ts"]): string | null {
|
|
|
510
539
|
|
|
511
540
|
return extension ? `${path}.${extension}` : null
|
|
512
541
|
}
|
|
542
|
+
|
|
543
|
+
type PrismicConfig = {
|
|
544
|
+
repositoryName?: string
|
|
545
|
+
routes?: Route[]
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function readPrismicConfig(
|
|
549
|
+
configPath: string,
|
|
550
|
+
): PrismicConfig {
|
|
551
|
+
if (!existsSync(configPath)) {
|
|
552
|
+
return {}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
try {
|
|
556
|
+
const contents = readFileSync(configPath, "utf-8")
|
|
557
|
+
const rawConfig = JSON.parse(contents) as unknown
|
|
558
|
+
|
|
559
|
+
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
560
|
+
return {}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const config: PrismicConfig = {}
|
|
564
|
+
if ("repositoryName" in rawConfig && typeof rawConfig.repositoryName === "string") {
|
|
565
|
+
config.repositoryName = rawConfig.repositoryName
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if ("routes" in rawConfig && Array.isArray(rawConfig.routes)) {
|
|
569
|
+
config.routes = rawConfig.routes
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
return config
|
|
573
|
+
} catch {
|
|
574
|
+
return {}
|
|
575
|
+
}
|
|
576
|
+
}
|