@wpnuxt/core 1.0.0-edge.5 → 1.0.0-edge.7
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 +18 -27
- package/dist/module.d.mts +3 -30
- package/dist/module.d.ts +3 -30
- package/dist/module.json +2 -2
- package/dist/module.mjs +31 -52
- package/package.json +11 -8
package/README.md
CHANGED
|
@@ -14,37 +14,28 @@ I am working towards a stable release. And will inform about it here
|
|
|
14
14
|
Nuxt module for using WordPress as a headless CMS with a Nuxt 3 frontend
|
|
15
15
|
|
|
16
16
|
- [✨ Release Notes](/CHANGELOG.md)
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
- [🏀 Online playground](https://stackblitz.com/github/wpnuxt/wpnuxt-core?file=playground%2Fapp%2Fpages%2Findex.vue)
|
|
18
|
+
- [📖 Documentation](https://wpnuxt.com)
|
|
19
19
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
22
22
|
- Content is fetched from WordPress using server-side GraphQL api calls
|
|
23
|
-
- Support for (Gutenberg Blocks),
|
|
23
|
+
- Support for (Gutenberg Blocks) by adding the separate [@wpnuxt/blocks](https://github.com/wpnuxt/wpnuxt-blocks), which uses WPEngine's [wp-graphql-content-blocks](https://faustjs.org/tutorial/get-started-with-wp-graphql-content-blocks) and a set of custom vue components
|
|
24
24
|
|
|
25
25
|
## Quick Setup
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
Install the module to your Nuxt application with one command:
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
|
|
31
|
-
pnpm add -D @vernaillen/wpnuxt
|
|
32
|
-
|
|
33
|
-
# Using yarn
|
|
34
|
-
yarn add --dev @vernaillen/wpnuxt
|
|
35
|
-
|
|
36
|
-
# Using npm
|
|
37
|
-
npm install --save-dev @vernaillen/wpnuxt
|
|
30
|
+
npx nuxi module add @wpnuxt/core
|
|
38
31
|
```
|
|
39
32
|
|
|
40
|
-
|
|
33
|
+
And connect WPNuxt to your wordpress installation in your nuxt.config.ts:
|
|
41
34
|
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
]
|
|
47
|
-
})
|
|
35
|
+
```json
|
|
36
|
+
wpNuxt: {
|
|
37
|
+
wordpressUrl: 'https://yourwordpress.domain.com'
|
|
38
|
+
},
|
|
48
39
|
```
|
|
49
40
|
|
|
50
41
|
That's it! You can now use the WPNuxt module in your Nuxt app ✨
|
|
@@ -53,26 +44,26 @@ That's it! You can now use the WPNuxt module in your Nuxt app ✨
|
|
|
53
44
|
|
|
54
45
|
```bash
|
|
55
46
|
# Install dependencies
|
|
56
|
-
|
|
47
|
+
pnpm install
|
|
57
48
|
|
|
58
49
|
# Generate type stubs
|
|
59
|
-
|
|
50
|
+
pnpm run dev:prepare
|
|
60
51
|
|
|
61
52
|
# Develop with the playground
|
|
62
|
-
|
|
53
|
+
pnpm run dev
|
|
63
54
|
|
|
64
55
|
# Build the playground
|
|
65
|
-
|
|
56
|
+
pnpm run dev:build
|
|
66
57
|
|
|
67
58
|
# Run ESLint
|
|
68
|
-
|
|
59
|
+
pnpm run lint
|
|
69
60
|
|
|
70
61
|
# Run Vitest
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
pnpm run test
|
|
63
|
+
pnpm run test:watch
|
|
73
64
|
|
|
74
65
|
# Release new version
|
|
75
|
-
|
|
66
|
+
pnpm run release
|
|
76
67
|
```
|
|
77
68
|
|
|
78
69
|
<!-- Badges -->
|
package/dist/module.d.mts
CHANGED
|
@@ -18,27 +18,16 @@ interface WPNuxtConfig {
|
|
|
18
18
|
wordpressUrl: string
|
|
19
19
|
frontendUrl: string
|
|
20
20
|
|
|
21
|
-
faustSecretKey?: string
|
|
22
21
|
defaultMenuName?: string
|
|
23
22
|
|
|
24
|
-
/**
|
|
25
|
-
* Enable custom components for Gutenberg blocks
|
|
26
|
-
* When disabled the module will use the renderedHtml of each block returned by WordPress
|
|
27
|
-
*
|
|
28
|
-
* @default true
|
|
29
|
-
*/
|
|
30
|
-
blocks?: boolean
|
|
31
|
-
|
|
32
|
-
replaceSchema?: boolean
|
|
33
23
|
enableCache?: boolean
|
|
34
24
|
|
|
35
25
|
staging?: boolean
|
|
26
|
+
|
|
36
27
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @default { enabled: true, prefix: 'useWP' }
|
|
28
|
+
* @default 'useWP'
|
|
40
29
|
*/
|
|
41
|
-
|
|
30
|
+
composablesPrefix: string
|
|
42
31
|
|
|
43
32
|
queries?: WPNuxtConfigQueries
|
|
44
33
|
|
|
@@ -53,23 +42,7 @@ interface WPNuxtConfig {
|
|
|
53
42
|
downloadSchema?: boolean
|
|
54
43
|
}
|
|
55
44
|
|
|
56
|
-
interface WPNuxtConfigComposables {
|
|
57
|
-
enabled?: boolean
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Prefix to use for generated composables
|
|
61
|
-
*
|
|
62
|
-
* @example 'useWP' => 'useWPPages', 'useWPPosts', 'useWPMenu'
|
|
63
|
-
* @default 'useWP'
|
|
64
|
-
*/
|
|
65
|
-
prefix?: string
|
|
66
|
-
}
|
|
67
|
-
|
|
68
45
|
interface WPNuxtConfigQueries {
|
|
69
|
-
/**
|
|
70
|
-
* @default true
|
|
71
|
-
*/
|
|
72
|
-
usePredefinedQueries?: boolean
|
|
73
46
|
|
|
74
47
|
/**
|
|
75
48
|
* Folder for user defined queries
|
package/dist/module.d.ts
CHANGED
|
@@ -18,27 +18,16 @@ interface WPNuxtConfig {
|
|
|
18
18
|
wordpressUrl: string
|
|
19
19
|
frontendUrl: string
|
|
20
20
|
|
|
21
|
-
faustSecretKey?: string
|
|
22
21
|
defaultMenuName?: string
|
|
23
22
|
|
|
24
|
-
/**
|
|
25
|
-
* Enable custom components for Gutenberg blocks
|
|
26
|
-
* When disabled the module will use the renderedHtml of each block returned by WordPress
|
|
27
|
-
*
|
|
28
|
-
* @default true
|
|
29
|
-
*/
|
|
30
|
-
blocks?: boolean
|
|
31
|
-
|
|
32
|
-
replaceSchema?: boolean
|
|
33
23
|
enableCache?: boolean
|
|
34
24
|
|
|
35
25
|
staging?: boolean
|
|
26
|
+
|
|
36
27
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @default { enabled: true, prefix: 'useWP' }
|
|
28
|
+
* @default 'useWP'
|
|
40
29
|
*/
|
|
41
|
-
|
|
30
|
+
composablesPrefix: string
|
|
42
31
|
|
|
43
32
|
queries?: WPNuxtConfigQueries
|
|
44
33
|
|
|
@@ -53,23 +42,7 @@ interface WPNuxtConfig {
|
|
|
53
42
|
downloadSchema?: boolean
|
|
54
43
|
}
|
|
55
44
|
|
|
56
|
-
interface WPNuxtConfigComposables {
|
|
57
|
-
enabled?: boolean
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Prefix to use for generated composables
|
|
61
|
-
*
|
|
62
|
-
* @example 'useWP' => 'useWPPages', 'useWPPosts', 'useWPMenu'
|
|
63
|
-
* @default 'useWP'
|
|
64
|
-
*/
|
|
65
|
-
prefix?: string
|
|
66
|
-
}
|
|
67
|
-
|
|
68
45
|
interface WPNuxtConfigQueries {
|
|
69
|
-
/**
|
|
70
|
-
* @default true
|
|
71
|
-
*/
|
|
72
|
-
usePredefinedQueries?: boolean
|
|
73
46
|
|
|
74
47
|
/**
|
|
75
48
|
* Folder for user defined queries
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { promises, statSync, existsSync, cpSync } from 'node:fs';
|
|
2
|
-
import { resolveFiles, defineNuxtModule, createResolver, addPlugin, addImports, addComponent, addServerHandler, installModule, hasNuxtModule, addTemplate } from '@nuxt/kit';
|
|
3
|
-
import defu from 'defu';
|
|
2
|
+
import { resolveFiles, defineNuxtModule, createResolver, addPlugin, addImports, addComponent, addServerHandler, installModule, hasNuxtModule, addTemplate, addTypeTemplate } from '@nuxt/kit';
|
|
4
3
|
import { join } from 'pathe';
|
|
5
4
|
import consola, { createConsola } from 'consola';
|
|
6
5
|
import { ref } from 'vue';
|
|
@@ -8,7 +7,7 @@ import { upperFirst } from 'scule';
|
|
|
8
7
|
import { parse } from 'graphql';
|
|
9
8
|
|
|
10
9
|
const name = "@wpnuxt/core";
|
|
11
|
-
const version = "1.0.0-edge.
|
|
10
|
+
const version = "1.0.0-edge.7";
|
|
12
11
|
|
|
13
12
|
const loggerRef = ref();
|
|
14
13
|
const initLogger = (logLevel) => {
|
|
@@ -78,18 +77,14 @@ async function prepareContext(ctx) {
|
|
|
78
77
|
if (ctx.docs) {
|
|
79
78
|
await prepareFunctions(ctx);
|
|
80
79
|
}
|
|
81
|
-
const fnName = (fn) => ctx.
|
|
80
|
+
const fnName = (fn) => ctx.composablesPrefix + upperFirst(fn);
|
|
82
81
|
const fnExp = (q, typed = false) => {
|
|
83
82
|
const functionName = fnName(q.name);
|
|
84
83
|
if (!typed) {
|
|
85
|
-
const
|
|
86
|
-
return `export const ${functionName} = (params) => useWPContent('${q.name}', [${nodesArray?.join(",")}], false, params)`;
|
|
84
|
+
return `export const ${functionName} = (params) => useWPContent('${q.name}', [${q.nodes?.map((n) => `'${n}'`).join(",")}], false, params)`;
|
|
87
85
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
fragmentSuffix = "[]";
|
|
91
|
-
}
|
|
92
|
-
const fragments = q.fragments && q.fragments.length > 0 ? q.fragments.map((f) => `${f}Fragment${fragmentSuffix}`).join(" | ") : "any";
|
|
86
|
+
const fragmentSuffix = q.fragments?.length && q.nodes?.includes("nodes") ? "[]" : "";
|
|
87
|
+
const fragments = q.fragments?.length ? q.fragments.map((f) => `${f}Fragment${fragmentSuffix}`).join(" | ") : "any";
|
|
93
88
|
return ` export const ${functionName}: (params?: ${q.name}QueryVariables) => AsyncData<${fragments}, FetchError | null | undefined>`;
|
|
94
89
|
};
|
|
95
90
|
ctx.generateImports = () => [
|
|
@@ -145,21 +140,14 @@ async function generateWPNuxtComposables(ctx, queryOutputPath, resolver) {
|
|
|
145
140
|
await prepareContext(ctx);
|
|
146
141
|
}
|
|
147
142
|
|
|
148
|
-
const defaultComposablesConfig = {
|
|
149
|
-
enabled: true,
|
|
150
|
-
prefix: "useWP"
|
|
151
|
-
};
|
|
152
143
|
const defaultConfigs = {
|
|
153
144
|
wordpressUrl: "",
|
|
154
145
|
frontendUrl: "",
|
|
155
|
-
faustSecretKey: "",
|
|
156
146
|
defaultMenuName: "main",
|
|
157
|
-
blocks: true,
|
|
158
|
-
replaceSchema: false,
|
|
159
147
|
enableCache: true,
|
|
160
148
|
staging: false,
|
|
161
149
|
logLevel: 3,
|
|
162
|
-
|
|
150
|
+
composablesPrefix: "useWP"
|
|
163
151
|
};
|
|
164
152
|
const module = defineNuxtModule({
|
|
165
153
|
meta: {
|
|
@@ -177,18 +165,12 @@ const module = defineNuxtModule({
|
|
|
177
165
|
wordpressUrl: process.env.WPNUXT_WORDPRESS_URL || options.wordpressUrl,
|
|
178
166
|
frontendUrl: process.env.WPNUXT_FRONTEND_URL || options.frontendUrl,
|
|
179
167
|
defaultMenuName: process.env.WPNUXT_DEFAULT_MENU_NAME || options.defaultMenuName,
|
|
180
|
-
blocks: process.env.WPNUXT_BLOCKS ? process.env.WPNUXT_BLOCKS === "true" : options.blocks,
|
|
181
|
-
replaceSchema: process.env.WPNUXT_REPLACE_SCHEMA === "true" || options.replaceSchema,
|
|
182
168
|
enableCache: process.env.WPNUXT_ENABLE_CACHE ? process.env.WPNUXT_ENABLE_CACHE === "true" : options.enableCache,
|
|
183
169
|
staging: process.env.WPNUXT_STAGING === "true" || options.staging,
|
|
184
170
|
downloadSchema: process.env.WPNUXT_DOWNLOAD_SCHEMA === "true" || options.downloadSchema,
|
|
185
|
-
// TODO also allow below options as env vars?
|
|
186
171
|
logLevel: process.env.WPNUXT_LOG_LEVEL ? Number.parseInt(process.env.WPNUXT_LOG_LEVEL) : options.logLevel,
|
|
187
|
-
|
|
172
|
+
composablesPrefix: process.env.WPNUXT_COMPOSABLES_PREFIX || options.composablesPrefix
|
|
188
173
|
};
|
|
189
|
-
nuxt.options.runtimeConfig.wpNuxt = defu(nuxt.options.runtimeConfig.wpNuxt, {
|
|
190
|
-
faustSecretKey: process.env.WPNUXT_FAUST_SECRET_KEY ? process.env.WPNUXT_FAUST_SECRET_KEY : options.faustSecretKey
|
|
191
|
-
});
|
|
192
174
|
nuxt.options.runtimeConfig.public.wpNuxt = publicWPNuxtConfig;
|
|
193
175
|
validateConfig(publicWPNuxtConfig);
|
|
194
176
|
const logger = initLogger(publicWPNuxtConfig.logLevel);
|
|
@@ -199,8 +181,6 @@ const module = defineNuxtModule({
|
|
|
199
181
|
logger.debug("Debug mode enabled, log level:", publicWPNuxtConfig.logLevel);
|
|
200
182
|
if (publicWPNuxtConfig.staging)
|
|
201
183
|
logger.info("Staging enabled");
|
|
202
|
-
if (publicWPNuxtConfig.blocks)
|
|
203
|
-
logger.info("Blocks enabled");
|
|
204
184
|
const { resolve } = createResolver(import.meta.url);
|
|
205
185
|
const resolveRuntimeModule = (path) => resolve("./runtime", path);
|
|
206
186
|
const srcResolver = createResolver(nuxt.options.srcDir);
|
|
@@ -245,6 +225,7 @@ const module = defineNuxtModule({
|
|
|
245
225
|
const userQueryPathExists = existsSync(userQueryPath);
|
|
246
226
|
cpSync(resolveRuntimeModule("./queries/"), queryOutputPath, { recursive: true });
|
|
247
227
|
if (hasNuxtModule("@wpnuxt/blocks")) {
|
|
228
|
+
logger.debug("Loading @wpnuxt/blocks");
|
|
248
229
|
for (const m of nuxt.options._installedModules) {
|
|
249
230
|
if (m.meta.name === "@wpnuxt/blocks" && m.entryPath) {
|
|
250
231
|
let blocksQueriesPath;
|
|
@@ -257,7 +238,7 @@ const module = defineNuxtModule({
|
|
|
257
238
|
}
|
|
258
239
|
}
|
|
259
240
|
} else {
|
|
260
|
-
logger.debug("
|
|
241
|
+
logger.debug("Tip: Install the @wpnuxt/blocks module if you want to render Gutenberg blocks with separate vue components");
|
|
261
242
|
}
|
|
262
243
|
if (userQueryPathExists) {
|
|
263
244
|
logger.debug("Extending queries:", userQueryPath);
|
|
@@ -276,6 +257,7 @@ const module = defineNuxtModule({
|
|
|
276
257
|
dedupeFragments: true,
|
|
277
258
|
onlyOperationTypes: true,
|
|
278
259
|
avoidOptionals: false,
|
|
260
|
+
maybeValue: "T | undefined",
|
|
279
261
|
disableOnBuild: false,
|
|
280
262
|
gqlImport: "graphql-request#wpnuxt",
|
|
281
263
|
namingConvention: {
|
|
@@ -319,29 +301,26 @@ const module = defineNuxtModule({
|
|
|
319
301
|
});
|
|
320
302
|
nuxt.options.nitro.externals.inline.push(template.dst);
|
|
321
303
|
nuxt.options.alias["#graphql-middleware-server-options-build"] = template.dst;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
autoimports.push(...ctx.fnImports || []);
|
|
343
|
-
});
|
|
344
|
-
}
|
|
304
|
+
logger.trace("Start generating composables");
|
|
305
|
+
const ctx = await {
|
|
306
|
+
fns: [],
|
|
307
|
+
fnImports: [],
|
|
308
|
+
composablesPrefix: publicWPNuxtConfig.composablesPrefix
|
|
309
|
+
};
|
|
310
|
+
await generateWPNuxtComposables(ctx, queryOutputPath, srcResolver);
|
|
311
|
+
addTemplate({
|
|
312
|
+
write: true,
|
|
313
|
+
filename: "wpnuxt/index.mjs",
|
|
314
|
+
getContents: () => ctx.generateImports?.() || ""
|
|
315
|
+
});
|
|
316
|
+
addTypeTemplate({
|
|
317
|
+
write: true,
|
|
318
|
+
filename: "wpnuxt/index.d.ts",
|
|
319
|
+
getContents: () => ctx.generateDeclarations?.() || ""
|
|
320
|
+
});
|
|
321
|
+
nuxt.hook("imports:extend", (autoimports) => {
|
|
322
|
+
autoimports.push(...ctx.fnImports || []);
|
|
323
|
+
});
|
|
345
324
|
nuxt.hook("nitro:init", async (nitro) => {
|
|
346
325
|
const keys = await nitro.storage.getKeys("cache:content");
|
|
347
326
|
keys.forEach(async (key) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wpnuxt/core",
|
|
3
|
-
"version": "1.0.0-edge.
|
|
3
|
+
"version": "1.0.0-edge.7",
|
|
4
4
|
"description": "WPNuxt",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@nuxt/kit": "3.12.4",
|
|
56
|
-
"@vueuse/nuxt": "^
|
|
56
|
+
"@vueuse/nuxt": "^11.0.0",
|
|
57
57
|
"defu": "^6.1.4",
|
|
58
58
|
"graphql": "^16.9.0",
|
|
59
59
|
"nuxt-graphql-middleware": "4.1.1",
|
|
@@ -67,12 +67,12 @@
|
|
|
67
67
|
"@graphql-codegen/typescript-operations": "^4.2.3",
|
|
68
68
|
"@nuxt/devtools": "^1.3.9",
|
|
69
69
|
"@nuxt/eslint-config": "^0.5.0",
|
|
70
|
-
"@nuxt/module-builder": "^0.8.
|
|
70
|
+
"@nuxt/module-builder": "^0.8.3",
|
|
71
71
|
"@nuxt/schema": "3.12.4",
|
|
72
|
-
"@nuxt/test-utils": "^3.14.
|
|
72
|
+
"@nuxt/test-utils": "^3.14.1",
|
|
73
73
|
"@rollup/rollup-linux-arm64-gnu": "^4.20.0",
|
|
74
74
|
"@rollup/rollup-linux-arm64-musl": "^4.20.0",
|
|
75
|
-
"@types/node": "22.
|
|
75
|
+
"@types/node": "22.3.0",
|
|
76
76
|
"@vitest/coverage-v8": "^2.0.5",
|
|
77
77
|
"@vue/test-utils": "^2.4.6",
|
|
78
78
|
"@wordpress/env": "^10.5.0",
|
|
@@ -81,11 +81,11 @@
|
|
|
81
81
|
"nuxt": "^3.12.4",
|
|
82
82
|
"nuxt-content-twoslash": "^0.1.1",
|
|
83
83
|
"release-it": "^17.6.0",
|
|
84
|
-
"shiki": "^1.
|
|
84
|
+
"shiki": "^1.13.0",
|
|
85
85
|
"twoslash": "^0.2.9",
|
|
86
86
|
"typescript": "^5.5.4",
|
|
87
87
|
"untyped": "1.4.2",
|
|
88
|
-
"vite": "^5.4.
|
|
88
|
+
"vite": "^5.4.1",
|
|
89
89
|
"vitest": "^2.0.5",
|
|
90
90
|
"vue-docgen-web-types": "^0.1.8",
|
|
91
91
|
"vue-tsc": "2.0.29"
|
|
@@ -97,5 +97,8 @@
|
|
|
97
97
|
"pathe": "^1.1.2",
|
|
98
98
|
"scule": "^1.3.0"
|
|
99
99
|
},
|
|
100
|
-
"packageManager": "pnpm@9.7.0"
|
|
100
|
+
"packageManager": "pnpm@9.7.0",
|
|
101
|
+
"engines": {
|
|
102
|
+
"node": ">=18"
|
|
103
|
+
}
|
|
101
104
|
}
|