@nuxtjs/prismic 5.2.1-canary.d380eb6 → 5.2.1
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 +12 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +2 -41
- package/package.json +1 -1
- package/src/module.ts +2 -58
package/README.md
CHANGED
|
@@ -27,7 +27,18 @@ Install the module to your Nuxt application with one command:
|
|
|
27
27
|
npx nuxi@latest module add prismic
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
Then, configure your Prismic API endpoint:
|
|
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
|
+
```
|
|
31
42
|
|
|
32
43
|
That's it! You can now use Prismic in your Nuxt app ✨
|
|
33
44
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } 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,10 +7,9 @@ import { addDependency } from 'nypm';
|
|
|
7
7
|
import { readPackage } from 'pkg-types';
|
|
8
8
|
|
|
9
9
|
const name = "@nuxtjs/prismic";
|
|
10
|
-
const version = "5.2.1
|
|
10
|
+
const version = "5.2.1";
|
|
11
11
|
|
|
12
12
|
const logger = useLogger("nuxt:prismic");
|
|
13
|
-
const PRISMIC_CONFIG_FILENAME = "prismic.config.json";
|
|
14
13
|
async function addPrismicClient() {
|
|
15
14
|
try {
|
|
16
15
|
const pkg = await readPackage();
|
|
@@ -74,21 +73,6 @@ const module$1 = defineNuxtModule({
|
|
|
74
73
|
nuxt.options.runtimeConfig.public?.prismic,
|
|
75
74
|
options
|
|
76
75
|
);
|
|
77
|
-
const prismicConfig = readPrismicConfig(
|
|
78
|
-
nuxt.options.rootDir
|
|
79
|
-
);
|
|
80
|
-
const configKeys = [];
|
|
81
|
-
if (!moduleOptions.endpoint && prismicConfig.repositoryName) {
|
|
82
|
-
moduleOptions.endpoint = prismicConfig.repositoryName;
|
|
83
|
-
configKeys.push("repository name");
|
|
84
|
-
}
|
|
85
|
-
if (!moduleOptions.clientConfig?.routes && prismicConfig.routes) {
|
|
86
|
-
moduleOptions.clientConfig.routes = prismicConfig.routes;
|
|
87
|
-
configKeys.push("routes");
|
|
88
|
-
}
|
|
89
|
-
if (configKeys.length > 0) {
|
|
90
|
-
logger.info(`Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``);
|
|
91
|
-
}
|
|
92
76
|
exposeRuntimeConfig();
|
|
93
77
|
transpileDependencies();
|
|
94
78
|
const ok = proxyUserFiles();
|
|
@@ -314,28 +298,5 @@ function fileExists(path, extensions = ["js", "ts"]) {
|
|
|
314
298
|
);
|
|
315
299
|
return extension ? `${path}.${extension}` : null;
|
|
316
300
|
}
|
|
317
|
-
function readPrismicConfig(rootDir) {
|
|
318
|
-
const configPath = join(rootDir, PRISMIC_CONFIG_FILENAME);
|
|
319
|
-
if (!existsSync(configPath)) {
|
|
320
|
-
return {};
|
|
321
|
-
}
|
|
322
|
-
try {
|
|
323
|
-
const contents = readFileSync(configPath, "utf-8");
|
|
324
|
-
const rawConfig = JSON.parse(contents);
|
|
325
|
-
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
326
|
-
return {};
|
|
327
|
-
}
|
|
328
|
-
const config = {};
|
|
329
|
-
if ("repositoryName" in rawConfig && typeof rawConfig.repositoryName === "string") {
|
|
330
|
-
config.repositoryName = rawConfig.repositoryName;
|
|
331
|
-
}
|
|
332
|
-
if ("routes" in rawConfig && Array.isArray(rawConfig.routes)) {
|
|
333
|
-
config.routes = rawConfig.routes;
|
|
334
|
-
}
|
|
335
|
-
return config;
|
|
336
|
-
} catch {
|
|
337
|
-
return {};
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
301
|
|
|
341
302
|
export { module$1 as default };
|
package/package.json
CHANGED
package/src/module.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } 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
|
|
16
|
+
import type { ClientConfig } from "@prismicio/client"
|
|
17
17
|
import { defu } from "defu"
|
|
18
18
|
import { addDependency } from "nypm"
|
|
19
19
|
import { readPackage } from "pkg-types"
|
|
@@ -148,7 +148,6 @@ declare module "@nuxt/schema" {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
const logger = useLogger("nuxt:prismic")
|
|
151
|
-
const PRISMIC_CONFIG_FILENAME = "prismic.config.json"
|
|
152
151
|
|
|
153
152
|
async function addPrismicClient() {
|
|
154
153
|
try {
|
|
@@ -225,24 +224,6 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
225
224
|
options,
|
|
226
225
|
)
|
|
227
226
|
|
|
228
|
-
const prismicConfig = readPrismicConfig(
|
|
229
|
-
nuxt.options.rootDir,
|
|
230
|
-
)
|
|
231
|
-
|
|
232
|
-
const configKeys: string[] = []
|
|
233
|
-
if (!moduleOptions.endpoint && prismicConfig.repositoryName) {
|
|
234
|
-
moduleOptions.endpoint = prismicConfig.repositoryName
|
|
235
|
-
configKeys.push("repository name")
|
|
236
|
-
}
|
|
237
|
-
if (!moduleOptions.clientConfig?.routes && prismicConfig.routes) {
|
|
238
|
-
moduleOptions.clientConfig!.routes = prismicConfig.routes
|
|
239
|
-
configKeys.push("routes")
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (configKeys.length > 0) {
|
|
243
|
-
logger.info(`Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
227
|
exposeRuntimeConfig()
|
|
247
228
|
transpileDependencies()
|
|
248
229
|
const ok = proxyUserFiles()
|
|
@@ -529,40 +510,3 @@ function fileExists(path?: string, extensions = ["js", "ts"]): string | null {
|
|
|
529
510
|
|
|
530
511
|
return extension ? `${path}.${extension}` : null
|
|
531
512
|
}
|
|
532
|
-
|
|
533
|
-
type PrismicConfig = {
|
|
534
|
-
repositoryName?: string
|
|
535
|
-
routes?: Route[]
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
function readPrismicConfig(
|
|
539
|
-
rootDir: string,
|
|
540
|
-
): PrismicConfig {
|
|
541
|
-
const configPath = join(rootDir, PRISMIC_CONFIG_FILENAME)
|
|
542
|
-
|
|
543
|
-
if (!existsSync(configPath)) {
|
|
544
|
-
return {}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
try {
|
|
548
|
-
const contents = readFileSync(configPath, "utf-8")
|
|
549
|
-
const rawConfig = JSON.parse(contents) as unknown
|
|
550
|
-
|
|
551
|
-
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
552
|
-
return {}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const config: PrismicConfig = {}
|
|
556
|
-
if ("repositoryName" in rawConfig && typeof rawConfig.repositoryName === "string") {
|
|
557
|
-
config.repositoryName = rawConfig.repositoryName
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
if ("routes" in rawConfig && Array.isArray(rawConfig.routes)) {
|
|
561
|
-
config.routes = rawConfig.routes
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
return config
|
|
565
|
-
} catch {
|
|
566
|
-
return {}
|
|
567
|
-
}
|
|
568
|
-
}
|