@wpnuxt/core 1.0.0-edge.10

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 (59) hide show
  1. package/README.md +80 -0
  2. package/dist/module.cjs +5 -0
  3. package/dist/module.d.mts +89 -0
  4. package/dist/module.d.ts +89 -0
  5. package/dist/module.json +10 -0
  6. package/dist/module.mjs +345 -0
  7. package/dist/runtime/app/graphqlMiddleware.serverOptions.d.ts +2 -0
  8. package/dist/runtime/app/graphqlMiddleware.serverOptions.js +11 -0
  9. package/dist/runtime/components/ContentRenderer.vue +13 -0
  10. package/dist/runtime/components/StagingBanner.vue +107 -0
  11. package/dist/runtime/components/WPContent.vue +26 -0
  12. package/dist/runtime/components/WPNuxtLogo.vue +17 -0
  13. package/dist/runtime/components/WordPressLogo.vue +15 -0
  14. package/dist/runtime/composables/index.d.ts +3 -0
  15. package/dist/runtime/composables/index.js +3 -0
  16. package/dist/runtime/composables/isStaging.d.ts +1 -0
  17. package/dist/runtime/composables/isStaging.js +6 -0
  18. package/dist/runtime/composables/useFeaturedImage.d.ts +2 -0
  19. package/dist/runtime/composables/useFeaturedImage.js +7 -0
  20. package/dist/runtime/composables/usePrevNextPost.d.ts +4 -0
  21. package/dist/runtime/composables/usePrevNextPost.js +25 -0
  22. package/dist/runtime/composables/useWPContent.d.ts +5 -0
  23. package/dist/runtime/composables/useWPContent.js +30 -0
  24. package/dist/runtime/composables/useWPUri.d.ts +8 -0
  25. package/dist/runtime/composables/useWPUri.js +23 -0
  26. package/dist/runtime/plugins/vue-sanitize-directive.d.ts +2 -0
  27. package/dist/runtime/plugins/vue-sanitize-directive.js +5 -0
  28. package/dist/runtime/queries/GeneralSettings.gql +7 -0
  29. package/dist/runtime/queries/Menu.gql +11 -0
  30. package/dist/runtime/queries/Node.gql +9 -0
  31. package/dist/runtime/queries/Pages.gql +19 -0
  32. package/dist/runtime/queries/Posts.gql +19 -0
  33. package/dist/runtime/queries/Revisions.gql +9 -0
  34. package/dist/runtime/queries/Viewer.gql +14 -0
  35. package/dist/runtime/queries/fragments/ContentNode.fragment.gql +28 -0
  36. package/dist/runtime/queries/fragments/GeneralSettings.fragment.gql +11 -0
  37. package/dist/runtime/queries/fragments/MediaItem.fragment.gql +52 -0
  38. package/dist/runtime/queries/fragments/MenuItem.fragment.gql +4 -0
  39. package/dist/runtime/queries/fragments/NodeWithContentEditor.fragment.gql +3 -0
  40. package/dist/runtime/queries/fragments/NodeWithExcerpt.fragment.gql +3 -0
  41. package/dist/runtime/queries/fragments/NodeWithFeaturedImage.fragment.gql +10 -0
  42. package/dist/runtime/queries/fragments/NodeWithFeaturedImageToMediaItemConnectionEdge.fragment.gql +8 -0
  43. package/dist/runtime/queries/fragments/Page.fragment.gql +16 -0
  44. package/dist/runtime/queries/fragments/Post.fragment.gql +12 -0
  45. package/dist/runtime/server/api/purgeCache.get.d.ts +5 -0
  46. package/dist/runtime/server/api/purgeCache.get.js +9 -0
  47. package/dist/runtime/server/api/wpContent.post.d.ts +9 -0
  48. package/dist/runtime/server/api/wpContent.post.js +50 -0
  49. package/dist/runtime/server/index.d.ts +1 -0
  50. package/dist/runtime/server/index.js +8 -0
  51. package/dist/runtime/server/storage.d.ts +3 -0
  52. package/dist/runtime/server/storage.js +11 -0
  53. package/dist/runtime/util/images.d.ts +2 -0
  54. package/dist/runtime/util/images.js +8 -0
  55. package/dist/runtime/util/logger.d.ts +3 -0
  56. package/dist/runtime/util/logger.js +25 -0
  57. package/dist/types.d.mts +7 -0
  58. package/dist/types.d.ts +7 -0
  59. package/package.json +104 -0
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+
2
+ This module is still being developed and not ready for production usage yet.
3
+ There will be many smaller alpha releases the coming weeks, often with breaking changes.
4
+
5
+ I am working towards a stable release. And will inform about it here
6
+
7
+ # WPNuxt
8
+
9
+ [![npm version][npm-version-src]][npm-version-href]
10
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
11
+ [![License][license-src]][license-href]
12
+ [![Nuxt][nuxt-src]][nuxt-href]
13
+
14
+ Nuxt module for using WordPress as a headless CMS with a Nuxt 3 frontend
15
+
16
+ - [✨  Release Notes](/CHANGELOG.md)
17
+ - [🏀 Online playground](https://stackblitz.com/github/wpnuxt/wpnuxt-core?file=playground%2Fapp%2Fpages%2Findex.vue)
18
+ - [📖  Documentation](https://wpnuxt.com)
19
+
20
+ ## Features
21
+
22
+ - Content is fetched from WordPress using server-side GraphQL api calls
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
+
25
+ ## Quick Setup
26
+
27
+ Install the module to your Nuxt application with one command:
28
+
29
+ ```bash
30
+ npx nuxi module add @wpnuxt/core
31
+ ```
32
+
33
+ And connect WPNuxt to your wordpress installation in your nuxt.config.ts:
34
+
35
+ ```json
36
+ wpNuxt: {
37
+ wordpressUrl: 'https://yourwordpress.domain.com'
38
+ },
39
+ ```
40
+
41
+ That's it! You can now use the WPNuxt module in your Nuxt app ✨
42
+
43
+ ## Development
44
+
45
+ ```bash
46
+ # Install dependencies
47
+ pnpm install
48
+
49
+ # Generate type stubs
50
+ pnpm run dev:prepare
51
+
52
+ # Develop with the playground
53
+ pnpm run dev
54
+
55
+ # Build the playground
56
+ pnpm run dev:build
57
+
58
+ # Run ESLint
59
+ pnpm run lint
60
+
61
+ # Run Vitest
62
+ pnpm run test
63
+ pnpm run test:watch
64
+
65
+ # Release new version
66
+ pnpm run release
67
+ ```
68
+
69
+ <!-- Badges -->
70
+ [npm-version-src]: https://img.shields.io/npm/v/@vernaillen/wpnuxt/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
71
+ [npm-version-href]: https://www.npmjs.com/package/@vernaillen/wpnuxt
72
+
73
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@vernaillen/wpnuxt.svg?style=flat&colorA=18181B&colorB=28CF8D
74
+ [npm-downloads-href]: https://www.npmjs.com/package/@vernaillen/wpnuxt
75
+
76
+ [license-src]: https://img.shields.io/npm/l/@vernaillen/wpnuxt?style=flat&colorA=18181B&colorB=28CF8D
77
+ [license-href]: https://www.npmjs.com/package/@vernaillen/wpnuxt
78
+
79
+ [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
80
+ [nuxt-href]: https://nuxt.com
@@ -0,0 +1,5 @@
1
+ module.exports = function(...args) {
2
+ return import('./module.mjs').then(m => m.default.call(this, ...args))
3
+ }
4
+ const _meta = module.exports.meta = require('./module.json')
5
+ module.exports.getMeta = () => Promise.resolve(_meta)
@@ -0,0 +1,89 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ interface WPNuxtConfig {
4
+
5
+ /**
6
+ * Log level for the WPNuxt module
7
+ * @default 3
8
+ * @example 0 = silent, 1 = error, 2 = warn, 3 = info, 4 = debug, 5 = trace
9
+ */
10
+ logLevel?: number
11
+ /**
12
+ * URL of the WordPress site
13
+ *
14
+ * There is no default value for this option, so it's required.
15
+ *
16
+ * @example 'https://wordpress.wpnuxt.com'
17
+ */
18
+ wordpressUrl: string
19
+ frontendUrl: string
20
+
21
+ defaultMenuName?: string
22
+
23
+ enableCache?: boolean
24
+
25
+ staging?: boolean
26
+
27
+ /**
28
+ * @default 'useWP'
29
+ */
30
+ composablesPrefix: string
31
+
32
+ queries?: WPNuxtConfigQueries
33
+
34
+ /**
35
+ * Download the GraphQL schema and store it on disk.
36
+ *
37
+ * When setting this to false, the module will expect a graphql.schema file to be available.
38
+ * You could first enable this, commit the schema file and then set downloadSchema to false to avoid have to query the graphql introspection on each start of the application
39
+ *
40
+ * @default true
41
+ */
42
+ downloadSchema?: boolean
43
+ }
44
+
45
+ interface WPNuxtConfigQueries {
46
+
47
+ /**
48
+ * Folder for user defined queries
49
+ *
50
+ * relative to the src dir of your nuxt app
51
+ *
52
+ * @default extend/queries
53
+ */
54
+ extendDir?: string
55
+
56
+ /**
57
+ * The predefined queries & the user defined queries will be merged and placed in the queries output folder
58
+ *
59
+ * relative to the src dir of your nuxt app
60
+ *
61
+ * @default queries
62
+ */
63
+ outputDir?: string
64
+ }
65
+
66
+ declare const _default: _nuxt_schema.NuxtModule<WPNuxtConfig>;
67
+
68
+ declare module '@nuxt/schema' {
69
+ interface RuntimeConfig {
70
+ wpNuxt: {
71
+ faustSecretKey: string;
72
+ };
73
+ }
74
+ interface PublicRuntimeConfig {
75
+ wpNuxt: WPNuxtConfig;
76
+ }
77
+ interface ConfigSchema {
78
+ wpNuxt: {
79
+ faustSecretKey: string;
80
+ };
81
+ runtimeConfig: {
82
+ public?: {
83
+ wpNuxt: WPNuxtConfig;
84
+ };
85
+ };
86
+ }
87
+ }
88
+
89
+ export { _default as default };
@@ -0,0 +1,89 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ interface WPNuxtConfig {
4
+
5
+ /**
6
+ * Log level for the WPNuxt module
7
+ * @default 3
8
+ * @example 0 = silent, 1 = error, 2 = warn, 3 = info, 4 = debug, 5 = trace
9
+ */
10
+ logLevel?: number
11
+ /**
12
+ * URL of the WordPress site
13
+ *
14
+ * There is no default value for this option, so it's required.
15
+ *
16
+ * @example 'https://wordpress.wpnuxt.com'
17
+ */
18
+ wordpressUrl: string
19
+ frontendUrl: string
20
+
21
+ defaultMenuName?: string
22
+
23
+ enableCache?: boolean
24
+
25
+ staging?: boolean
26
+
27
+ /**
28
+ * @default 'useWP'
29
+ */
30
+ composablesPrefix: string
31
+
32
+ queries?: WPNuxtConfigQueries
33
+
34
+ /**
35
+ * Download the GraphQL schema and store it on disk.
36
+ *
37
+ * When setting this to false, the module will expect a graphql.schema file to be available.
38
+ * You could first enable this, commit the schema file and then set downloadSchema to false to avoid have to query the graphql introspection on each start of the application
39
+ *
40
+ * @default true
41
+ */
42
+ downloadSchema?: boolean
43
+ }
44
+
45
+ interface WPNuxtConfigQueries {
46
+
47
+ /**
48
+ * Folder for user defined queries
49
+ *
50
+ * relative to the src dir of your nuxt app
51
+ *
52
+ * @default extend/queries
53
+ */
54
+ extendDir?: string
55
+
56
+ /**
57
+ * The predefined queries & the user defined queries will be merged and placed in the queries output folder
58
+ *
59
+ * relative to the src dir of your nuxt app
60
+ *
61
+ * @default queries
62
+ */
63
+ outputDir?: string
64
+ }
65
+
66
+ declare const _default: _nuxt_schema.NuxtModule<WPNuxtConfig>;
67
+
68
+ declare module '@nuxt/schema' {
69
+ interface RuntimeConfig {
70
+ wpNuxt: {
71
+ faustSecretKey: string;
72
+ };
73
+ }
74
+ interface PublicRuntimeConfig {
75
+ wpNuxt: WPNuxtConfig;
76
+ }
77
+ interface ConfigSchema {
78
+ wpNuxt: {
79
+ faustSecretKey: string;
80
+ };
81
+ runtimeConfig: {
82
+ public?: {
83
+ wpNuxt: WPNuxtConfig;
84
+ };
85
+ };
86
+ }
87
+ }
88
+
89
+ export { _default as default };
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@wpnuxt/core",
3
+ "version": "1.0.0-edge.10",
4
+ "configKey": "wpNuxt",
5
+ "nuxt": ">=3.1.0",
6
+ "builder": {
7
+ "@nuxt/module-builder": "0.8.3",
8
+ "unbuild": "2.0.0"
9
+ }
10
+ }
@@ -0,0 +1,345 @@
1
+ import { promises, statSync, existsSync, cpSync } from 'node:fs';
2
+ import { resolveFiles, defineNuxtModule, createResolver, addPlugin, addImports, addComponentsDir, addServerHandler, installModule, hasNuxtModule, addTemplate, addTypeTemplate } from '@nuxt/kit';
3
+ import { join } from 'pathe';
4
+ import consola, { createConsola } from 'consola';
5
+ import { ref } from 'vue';
6
+ import { upperFirst } from 'scule';
7
+ import { parse } from 'graphql';
8
+
9
+ const name = "@wpnuxt/core";
10
+ const version = "1.0.0-edge.10";
11
+
12
+ const loggerRef = ref();
13
+ const initLogger = (logLevel) => {
14
+ loggerRef.value = createConsola({
15
+ level: logLevel ? logLevel : 3,
16
+ formatOptions: {
17
+ colors: true,
18
+ compact: true,
19
+ date: true,
20
+ fancy: true
21
+ }
22
+ }).withTag("wpnuxt");
23
+ return loggerRef.value;
24
+ };
25
+ const getLogger = () => {
26
+ if (loggerRef.value) {
27
+ return loggerRef.value;
28
+ }
29
+ };
30
+ function validateConfig(options) {
31
+ if (!options.wordpressUrl || options.wordpressUrl.length === 0) {
32
+ throw new Error("WPNuxt error: WordPress url is missing");
33
+ } else if (options.wordpressUrl.substring(options.wordpressUrl.length - 1) === "/") {
34
+ throw new Error("WPNuxt error: WordPress url should not have a trailing slash: " + options.wordpressUrl);
35
+ }
36
+ if (options.frontendUrl && options.frontendUrl.substring(options.frontendUrl.length - 1) === "/") {
37
+ throw new Error("WPNuxt error: frontend url should not have a trailing slash: " + options.frontendUrl);
38
+ }
39
+ }
40
+
41
+ const _parseDoc = async (doc) => {
42
+ const { definitions } = parse(doc);
43
+ const operations = definitions.filter(({ kind }) => kind === "OperationDefinition").map((definition) => {
44
+ const operationDefinition = definition;
45
+ if (!operationDefinition.name?.value) {
46
+ throw new Error(`Operation name missing in: ${doc}`);
47
+ }
48
+ const query = {
49
+ name: operationDefinition.name.value.trim(),
50
+ nodes: [],
51
+ fragments: [],
52
+ params: {}
53
+ };
54
+ processSelections(operationDefinition.selectionSet.selections, 0, query);
55
+ return query;
56
+ });
57
+ return operations;
58
+ };
59
+ function processSelections(selections, level, query) {
60
+ if (!selections || selections.length === 0)
61
+ return;
62
+ if (selections.length === 1 && selections[0].kind === "Field") {
63
+ query.nodes.push(selections[0].name.value.trim());
64
+ }
65
+ selections.forEach((s) => {
66
+ if (s.kind === "FragmentSpread") {
67
+ query.fragments.push(s.name.value.trim());
68
+ } else if (s.selectionSet?.selections) {
69
+ processSelections(s.selectionSet.selections, level + 1, query);
70
+ }
71
+ });
72
+ }
73
+ const parseDoc = _parseDoc;
74
+
75
+ async function prepareContext(ctx) {
76
+ const logger = getLogger();
77
+ if (ctx.docs) {
78
+ await prepareFunctions(ctx);
79
+ }
80
+ const fnName = (fn) => ctx.composablesPrefix + upperFirst(fn);
81
+ const fnExp = (q, typed = false) => {
82
+ const functionName = fnName(q.name);
83
+ if (!typed) {
84
+ return `export const ${functionName} = (params) => useWPContent('${q.name}', [${q.nodes?.map((n) => `'${n}'`).join(",")}], false, params)`;
85
+ }
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";
88
+ return ` export const ${functionName}: (params?: ${q.name}QueryVariables) => AsyncData<${fragments}, FetchError | null | undefined>`;
89
+ };
90
+ ctx.generateImports = () => [
91
+ ...ctx.fns.map((f) => fnExp(f))
92
+ ].join("\n");
93
+ const types = [];
94
+ ctx.fns.forEach((o) => types.push(...getQueryTypeTemplate(o)));
95
+ ctx.generateDeclarations = () => [
96
+ `import type { ${[...new Set(types)].join(", ")} } from '#build/graphql-operations'`,
97
+ "import { AsyncData } from 'nuxt/app'",
98
+ "import { FetchError } from 'ofetch'",
99
+ "declare module '#wpnuxt' {",
100
+ ...[
101
+ ...ctx.fns.map((f) => fnExp(f, true))
102
+ ],
103
+ "}"
104
+ ].join("\n");
105
+ ctx.fnImports = ctx.fns.map((fn) => ({ from: "#wpnuxt", name: fnName(fn.name) }));
106
+ logger.debug("generated WPNuxt composables: ");
107
+ ctx.fns.forEach((f) => logger.debug(` ${fnName(f.name)}()`));
108
+ }
109
+ function getQueryTypeTemplate(q) {
110
+ const types = [];
111
+ types.push(`${q.name}QueryVariables`);
112
+ if (q.fragments && q.fragments.length > 0) {
113
+ q.fragments.forEach((f) => types.push(`${f}Fragment`));
114
+ }
115
+ return types;
116
+ }
117
+ async function prepareFunctions(ctx) {
118
+ if (!ctx.docs) {
119
+ getLogger().error("no GraphQL query documents were found!");
120
+ return;
121
+ }
122
+ for await (const doc of ctx.docs) {
123
+ const operations = await parseDoc(await promises.readFile(doc, "utf8"));
124
+ operations.forEach((query) => {
125
+ ctx.fns.push(query);
126
+ });
127
+ }
128
+ }
129
+
130
+ const allowDocument = (f, resolver) => {
131
+ const isSchema = f.match(/([^/]+)\.(gql|graphql)$/)?.[0]?.toLowerCase().includes("schema");
132
+ return !isSchema && !!statSync(resolver.resolve(f)).size;
133
+ };
134
+ async function generateWPNuxtComposables(ctx, queryOutputPath, resolver) {
135
+ const gqlMatch = "**/*.{gql,graphql}";
136
+ const documents = [];
137
+ const files = (await resolveFiles(queryOutputPath, [gqlMatch, "!**/schemas"], { followSymbolicLinks: false })).filter((doc) => allowDocument(doc, resolver));
138
+ documents.push(...files);
139
+ ctx.docs = documents;
140
+ await prepareContext(ctx);
141
+ }
142
+
143
+ const defaultConfigs = {
144
+ wordpressUrl: "",
145
+ frontendUrl: "",
146
+ defaultMenuName: "main",
147
+ enableCache: true,
148
+ staging: false,
149
+ logLevel: 3,
150
+ composablesPrefix: "useWP"
151
+ };
152
+ const module = defineNuxtModule({
153
+ meta: {
154
+ name,
155
+ version,
156
+ configKey: "wpNuxt",
157
+ nuxt: ">=3.1.0"
158
+ },
159
+ // Default configuration options of the Nuxt module
160
+ defaults: defaultConfigs,
161
+ async setup(options, nuxt) {
162
+ const startTime = (/* @__PURE__ */ new Date()).getTime();
163
+ consola.log("::: Starting WPNuxt setup ::: ");
164
+ const publicWPNuxtConfig = {
165
+ wordpressUrl: process.env.WPNUXT_WORDPRESS_URL || options.wordpressUrl,
166
+ frontendUrl: process.env.WPNUXT_FRONTEND_URL || options.frontendUrl,
167
+ defaultMenuName: process.env.WPNUXT_DEFAULT_MENU_NAME || options.defaultMenuName,
168
+ enableCache: process.env.WPNUXT_ENABLE_CACHE ? process.env.WPNUXT_ENABLE_CACHE === "true" : options.enableCache,
169
+ staging: process.env.WPNUXT_STAGING === "true" || options.staging,
170
+ downloadSchema: process.env.WPNUXT_DOWNLOAD_SCHEMA === "true" || options.downloadSchema,
171
+ logLevel: process.env.WPNUXT_LOG_LEVEL ? Number.parseInt(process.env.WPNUXT_LOG_LEVEL) : options.logLevel,
172
+ composablesPrefix: process.env.WPNUXT_COMPOSABLES_PREFIX || options.composablesPrefix
173
+ };
174
+ nuxt.options.runtimeConfig.public.wpNuxt = publicWPNuxtConfig;
175
+ validateConfig(publicWPNuxtConfig);
176
+ const logger = initLogger(publicWPNuxtConfig.logLevel);
177
+ logger.info("Connecting GraphQL to", publicWPNuxtConfig.wordpressUrl);
178
+ logger.info("frontendUrl:", publicWPNuxtConfig.frontendUrl);
179
+ if (publicWPNuxtConfig.enableCache)
180
+ logger.info("Cache enabled");
181
+ logger.debug("Debug mode enabled, log level:", publicWPNuxtConfig.logLevel);
182
+ if (publicWPNuxtConfig.staging)
183
+ logger.info("Staging enabled");
184
+ const { resolve } = createResolver(import.meta.url);
185
+ const resolveRuntimeModule = (path) => resolve("./runtime", path);
186
+ const srcResolver = createResolver(nuxt.options.srcDir);
187
+ nuxt.options.alias["#wpnuxt"] = resolve(nuxt.options.buildDir, "wpnuxt");
188
+ nuxt.options.alias["#wpnuxt/*"] = resolve(nuxt.options.buildDir, "wpnuxt", "*");
189
+ nuxt.options.alias["#wpnuxt/types"] = resolve("./types");
190
+ nuxt.options.nitro.alias = nuxt.options.nitro.alias || {};
191
+ nuxt.options.nitro.alias["#wpnuxt/types"] = resolve("./types");
192
+ nuxt.options.nitro.externals = nuxt.options.nitro.externals || {};
193
+ nuxt.options.nitro.externals.inline = nuxt.options.nitro.externals.inline || [];
194
+ addPlugin({
195
+ src: resolveRuntimeModule("plugins/vue-sanitize-directive")
196
+ });
197
+ addImports([
198
+ { name: "isStaging", as: "isStaging", from: resolveRuntimeModule("./composables/isStaging") },
199
+ { name: "useWPContent", as: "useWPContent", from: resolveRuntimeModule("./composables/useWPContent") },
200
+ { name: "parseDoc", as: "parseDoc", from: resolveRuntimeModule("./composables/useParser") },
201
+ { name: "usePrevNextPost", as: "usePrevNextPost", from: resolveRuntimeModule("./composables/usePrevNextPost") },
202
+ { name: "loginUser", as: "loginUser", from: resolveRuntimeModule("./composables/user") },
203
+ { name: "logoutUser", as: "logoutUser", from: resolveRuntimeModule("./composables/user") },
204
+ { name: "getCurrentUserId", as: "getCurrentUserId", from: resolveRuntimeModule("./composables/user") },
205
+ { name: "getCurrentUserName", as: "getCurrentUserName", from: resolveRuntimeModule("./composables/user") },
206
+ { name: "useTokens", as: "useTokens", from: resolveRuntimeModule("./composables/useTokens") },
207
+ { name: "useWPUri", as: "useWPUri", from: resolveRuntimeModule("./composables/useWPUri") },
208
+ { name: "useFeaturedImage", as: "useFeaturedImage", from: resolveRuntimeModule("./composables/useFeaturedImage") }
209
+ ]);
210
+ addComponentsDir({
211
+ path: resolveRuntimeModule("./components"),
212
+ pathPrefix: false,
213
+ prefix: "",
214
+ global: true
215
+ });
216
+ addServerHandler({
217
+ route: "/api/wpContent",
218
+ handler: resolveRuntimeModule("./server/api/wpContent.post")
219
+ });
220
+ addServerHandler({
221
+ route: "/api/purgeCache",
222
+ handler: resolveRuntimeModule("./server/api/purgeCache.get")
223
+ });
224
+ await installModule("@vueuse/nuxt", {});
225
+ const queryOutputPath = resolve((nuxt.options.srcDir || nuxt.options.rootDir) + "/.queries/");
226
+ await promises.rm(queryOutputPath, { recursive: true, force: true });
227
+ const userQueryPath = "~/extend/queries/".replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir);
228
+ const userQueryPathExists = existsSync(userQueryPath);
229
+ cpSync(resolveRuntimeModule("./queries/"), queryOutputPath, { recursive: true });
230
+ if (hasNuxtModule("@wpnuxt/blocks")) {
231
+ for (const m of nuxt.options._installedModules) {
232
+ if (m.meta.name === "@wpnuxt/blocks" && m.entryPath) {
233
+ logger.debug("Loading queries from @wpnuxt/blocks");
234
+ let blocksQueriesPath;
235
+ if (m.entryPath.startsWith("../")) {
236
+ blocksQueriesPath = join(nuxt.options.rootDir, "../", m.entryPath, "./runtime/queries/");
237
+ } else {
238
+ blocksQueriesPath = join("./node_modules", m.entryPath, "dist/runtime/queries/");
239
+ }
240
+ cpSync(blocksQueriesPath, queryOutputPath, { recursive: true });
241
+ }
242
+ }
243
+ } else {
244
+ logger.debug("Tip: Install the @wpnuxt/blocks module if you want to render Gutenberg blocks with separate vue components");
245
+ addTemplate({
246
+ write: true,
247
+ filename: "wpnuxt/blocks.mjs",
248
+ getContents: () => `export { }`
249
+ });
250
+ nuxt.options.alias["#wpnuxt/blocks"] = resolve(nuxt.options.buildDir, "wpnuxt/blocks");
251
+ }
252
+ if (userQueryPathExists) {
253
+ logger.debug("Extending queries:", userQueryPath);
254
+ cpSync(resolve(userQueryPath), queryOutputPath, { recursive: true });
255
+ }
256
+ logger.debug("Copied merged queries in folder:", queryOutputPath);
257
+ await installModule("nuxt-graphql-middleware", {
258
+ debug: publicWPNuxtConfig.logLevel ? publicWPNuxtConfig.logLevel > 3 : false,
259
+ graphqlEndpoint: `${publicWPNuxtConfig.wordpressUrl}/graphql`,
260
+ downloadSchema: publicWPNuxtConfig.downloadSchema,
261
+ codegenConfig: {
262
+ silent: false,
263
+ skipTypename: true,
264
+ useTypeImports: true,
265
+ // inlineFragmentTypes: 'combine',
266
+ dedupeFragments: true,
267
+ onlyOperationTypes: true,
268
+ avoidOptionals: false,
269
+ maybeValue: "T | undefined",
270
+ disableOnBuild: false,
271
+ gqlImport: "graphql-request#wpnuxt",
272
+ namingConvention: {
273
+ enumValues: "change-case-all#upperCaseFirst"
274
+ },
275
+ documents: [
276
+ resolve("!./graphql/**/*")
277
+ ]
278
+ },
279
+ codegenSchemaConfig: {
280
+ urlSchemaOptions: {
281
+ headers: {
282
+ Authorization: "server-token"
283
+ }
284
+ }
285
+ },
286
+ outputDocuments: true,
287
+ autoImportPatterns: queryOutputPath,
288
+ includeComposables: true,
289
+ devtools: true
290
+ });
291
+ const resolvedPath = resolveRuntimeModule("./app/graphqlMiddleware.serverOptions");
292
+ const template = addTemplate({
293
+ filename: "graphqlMiddleware.serverOptions.ts",
294
+ write: true,
295
+ getContents: () => `
296
+ import type { GraphqlMiddlewareServerOptions } from '#graphql-middleware/types'
297
+ import serverOptions from '${resolvedPath}'
298
+ import type { GraphqlServerResponse } from '#graphql-middleware/types'
299
+ import type { GraphqlMiddlewareResponseUnion } from '#build/nuxt-graphql-middleware'
300
+
301
+ type GraphqlResponseAdditions =
302
+ typeof serverOptions extends GraphqlMiddlewareServerOptions<infer R> ? R : {}
303
+
304
+ export type GraphqlResponse<T> = GraphqlServerResponse<T> & GraphqlResponseAdditions
305
+
306
+ export type GraphqlResponseTyped = GraphqlResponse<GraphqlMiddlewareResponseUnion>
307
+
308
+ export { serverOptions }
309
+ `
310
+ });
311
+ nuxt.options.nitro.externals.inline.push(template.dst);
312
+ nuxt.options.alias["#graphql-middleware-server-options-build"] = template.dst;
313
+ logger.trace("Start generating composables");
314
+ const ctx = await {
315
+ fns: [],
316
+ fnImports: [],
317
+ composablesPrefix: publicWPNuxtConfig.composablesPrefix
318
+ };
319
+ await generateWPNuxtComposables(ctx, queryOutputPath, srcResolver);
320
+ addTemplate({
321
+ write: true,
322
+ filename: "wpnuxt/index.mjs",
323
+ getContents: () => ctx.generateImports?.() || ""
324
+ });
325
+ addTypeTemplate({
326
+ write: true,
327
+ filename: "wpnuxt/index.d.ts",
328
+ getContents: () => ctx.generateDeclarations?.() || ""
329
+ });
330
+ nuxt.hook("imports:extend", (autoimports) => {
331
+ autoimports.push(...ctx.fnImports || []);
332
+ });
333
+ nuxt.hook("nitro:init", async (nitro) => {
334
+ const keys = await nitro.storage.getKeys("cache:content");
335
+ keys.forEach(async (key) => {
336
+ if (key.startsWith("cache:content"))
337
+ await nitro.storage.removeItem(key);
338
+ });
339
+ });
340
+ const endTime = (/* @__PURE__ */ new Date()).getTime();
341
+ logger.success("::: Finished WPNuxt setup in " + (endTime - startTime) + "ms ::: ");
342
+ }
343
+ });
344
+
345
+ export { module as default };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt-graphql-middleware").GraphqlMiddlewareServerOptions<object>;
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { defineGraphqlServerOptions } from "nuxt-graphql-middleware/dist/runtime/serverOptions";
2
+ import { getHeader } from "h3";
3
+ export default defineGraphqlServerOptions({
4
+ serverFetchOptions(event) {
5
+ return {
6
+ headers: {
7
+ Authorization: getHeader(event, "Authorization")
8
+ }
9
+ };
10
+ }
11
+ });
@@ -0,0 +1,13 @@
1
+ <script setup lang="ts">
2
+ import type { NodeWithContentEditorFragment } from '#build/graphql-operations'
3
+
4
+ defineProps<{
5
+ post: NodeWithContentEditorFragment
6
+ }>()
7
+ </script>
8
+
9
+ <template>
10
+ <div
11
+ v-sanitize="post.content"
12
+ />
13
+ </template>