@wpnuxt/core 1.0.0-edge.5 → 1.0.0-edge.6

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 CHANGED
@@ -14,37 +14,20 @@ 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
- <!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) -->
18
- <!-- - [📖 &nbsp;Documentation](https://example.com) -->
17
+ - [🏀 Online playground](https://stackblitz.com/github/wpnuxt/wpnuxt-core?file=playground%2Fapp%2Fpages%2Findex.vue)
18
+ - [📖 &nbsp;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), using WPEngine's wp-graphql-content-blocks https://faustjs.org/tutorial/get-started-with-wp-graphql-content-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
- 1. Add `@vernaillen/wpnuxt` dependency to your project
27
+ Install the module to your Nuxt application with one command:
28
28
 
29
29
  ```bash
30
- # Using pnpm
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
38
- ```
39
-
40
- 2. Add '@vernaillen/wpnuxt' to the `modules` section of `nuxt.config.ts`
41
-
42
- ```js
43
- export default defineNuxtConfig({
44
- modules: [
45
- '@vernaillen/wpnuxt'
46
- ]
47
- })
30
+ npx nuxi module add @wpnuxt/core
48
31
  ```
49
32
 
50
33
  That's it! You can now use the WPNuxt module in your Nuxt app ✨
@@ -53,26 +36,26 @@ That's it! You can now use the WPNuxt module in your Nuxt app ✨
53
36
 
54
37
  ```bash
55
38
  # Install dependencies
56
- npm install
39
+ pnpm install
57
40
 
58
41
  # Generate type stubs
59
- npm run dev:prepare
42
+ pnpm run dev:prepare
60
43
 
61
44
  # Develop with the playground
62
- npm run dev
45
+ pnpm run dev
63
46
 
64
47
  # Build the playground
65
- npm run dev:build
48
+ pnpm run dev:build
66
49
 
67
50
  # Run ESLint
68
- npm run lint
51
+ pnpm run lint
69
52
 
70
53
  # Run Vitest
71
- npm run test
72
- npm run test:watch
54
+ pnpm run test
55
+ pnpm run test:watch
73
56
 
74
57
  # Release new version
75
- npm run release
58
+ pnpm run release
76
59
  ```
77
60
 
78
61
  <!-- Badges -->
package/dist/module.d.mts CHANGED
@@ -21,24 +21,14 @@ interface WPNuxtConfig {
21
21
  faustSecretKey?: string
22
22
  defaultMenuName?: string
23
23
 
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
24
  enableCache?: boolean
34
25
 
35
26
  staging?: boolean
27
+
36
28
  /**
37
- * Generate composables based on the GraphQL queries, provided by both the WPNuxt module as the queries added by the user.
38
- *
39
- * @default { enabled: true, prefix: 'useWP' }
29
+ * @default 'useWP'
40
30
  */
41
- generateComposables?: WPNuxtConfigComposables
31
+ composablesPrefix: string
42
32
 
43
33
  queries?: WPNuxtConfigQueries
44
34
 
@@ -53,18 +43,6 @@ interface WPNuxtConfig {
53
43
  downloadSchema?: boolean
54
44
  }
55
45
 
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
46
  interface WPNuxtConfigQueries {
69
47
  /**
70
48
  * @default true
package/dist/module.d.ts CHANGED
@@ -21,24 +21,14 @@ interface WPNuxtConfig {
21
21
  faustSecretKey?: string
22
22
  defaultMenuName?: string
23
23
 
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
24
  enableCache?: boolean
34
25
 
35
26
  staging?: boolean
27
+
36
28
  /**
37
- * Generate composables based on the GraphQL queries, provided by both the WPNuxt module as the queries added by the user.
38
- *
39
- * @default { enabled: true, prefix: 'useWP' }
29
+ * @default 'useWP'
40
30
  */
41
- generateComposables?: WPNuxtConfigComposables
31
+ composablesPrefix: string
42
32
 
43
33
  queries?: WPNuxtConfigQueries
44
34
 
@@ -53,18 +43,6 @@ interface WPNuxtConfig {
53
43
  downloadSchema?: boolean
54
44
  }
55
45
 
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
46
  interface WPNuxtConfigQueries {
69
47
  /**
70
48
  * @default true
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "1.0.0-edge.5",
3
+ "version": "1.0.0-edge.6",
4
4
  "configKey": "wpNuxt",
5
5
  "nuxt": ">=3.1.0",
6
6
  "builder": {
package/dist/module.mjs CHANGED
@@ -1,5 +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';
2
+ import { resolveFiles, defineNuxtModule, createResolver, addPlugin, addImports, addComponent, addServerHandler, installModule, hasNuxtModule, addTemplate, addTypeTemplate } from '@nuxt/kit';
3
3
  import defu from 'defu';
4
4
  import { join } from 'pathe';
5
5
  import consola, { createConsola } from 'consola';
@@ -8,7 +8,7 @@ import { upperFirst } from 'scule';
8
8
  import { parse } from 'graphql';
9
9
 
10
10
  const name = "@wpnuxt/core";
11
- const version = "1.0.0-edge.5";
11
+ const version = "1.0.0-edge.6";
12
12
 
13
13
  const loggerRef = ref();
14
14
  const initLogger = (logLevel) => {
@@ -78,18 +78,14 @@ async function prepareContext(ctx) {
78
78
  if (ctx.docs) {
79
79
  await prepareFunctions(ctx);
80
80
  }
81
- const fnName = (fn) => ctx.composables.prefix + upperFirst(fn);
81
+ const fnName = (fn) => ctx.composablesPrefix + upperFirst(fn);
82
82
  const fnExp = (q, typed = false) => {
83
83
  const functionName = fnName(q.name);
84
84
  if (!typed) {
85
- const nodesArray = q.nodes?.map((n) => `'${n}'`);
86
- return `export const ${functionName} = (params) => useWPContent('${q.name}', [${nodesArray?.join(",")}], false, params)`;
85
+ return `export const ${functionName} = (params) => useWPContent('${q.name}', [${q.nodes?.map((n) => `'${n}'`).join(",")}], false, params)`;
87
86
  }
88
- let fragmentSuffix = "";
89
- if (q.fragments && q.fragments.length > 0 && q.nodes && q.nodes.length > 0 && q.nodes.includes("nodes")) {
90
- fragmentSuffix = "[]";
91
- }
92
- const fragments = q.fragments && q.fragments.length > 0 ? q.fragments.map((f) => `${f}Fragment${fragmentSuffix}`).join(" | ") : "any";
87
+ const fragmentSuffix = q.fragments?.length && q.nodes?.includes("nodes") ? "[]" : "";
88
+ const fragments = q.fragments?.length ? q.fragments.map((f) => `${f}Fragment${fragmentSuffix}`).join(" | ") : "any";
93
89
  return ` export const ${functionName}: (params?: ${q.name}QueryVariables) => AsyncData<${fragments}, FetchError | null | undefined>`;
94
90
  };
95
91
  ctx.generateImports = () => [
@@ -145,21 +141,15 @@ async function generateWPNuxtComposables(ctx, queryOutputPath, resolver) {
145
141
  await prepareContext(ctx);
146
142
  }
147
143
 
148
- const defaultComposablesConfig = {
149
- enabled: true,
150
- prefix: "useWP"
151
- };
152
144
  const defaultConfigs = {
153
145
  wordpressUrl: "",
154
146
  frontendUrl: "",
155
147
  faustSecretKey: "",
156
148
  defaultMenuName: "main",
157
- blocks: true,
158
- replaceSchema: false,
159
149
  enableCache: true,
160
150
  staging: false,
161
151
  logLevel: 3,
162
- generateComposables: defaultComposablesConfig
152
+ composablesPrefix: "useWP"
163
153
  };
164
154
  const module = defineNuxtModule({
165
155
  meta: {
@@ -177,14 +167,11 @@ const module = defineNuxtModule({
177
167
  wordpressUrl: process.env.WPNUXT_WORDPRESS_URL || options.wordpressUrl,
178
168
  frontendUrl: process.env.WPNUXT_FRONTEND_URL || options.frontendUrl,
179
169
  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
170
  enableCache: process.env.WPNUXT_ENABLE_CACHE ? process.env.WPNUXT_ENABLE_CACHE === "true" : options.enableCache,
183
171
  staging: process.env.WPNUXT_STAGING === "true" || options.staging,
184
172
  downloadSchema: process.env.WPNUXT_DOWNLOAD_SCHEMA === "true" || options.downloadSchema,
185
- // TODO also allow below options as env vars?
186
173
  logLevel: process.env.WPNUXT_LOG_LEVEL ? Number.parseInt(process.env.WPNUXT_LOG_LEVEL) : options.logLevel,
187
- generateComposables: options.generateComposables
174
+ composablesPrefix: process.env.WPNUXT_COMPOSABLES_PREFIX || options.composablesPrefix
188
175
  };
189
176
  nuxt.options.runtimeConfig.wpNuxt = defu(nuxt.options.runtimeConfig.wpNuxt, {
190
177
  faustSecretKey: process.env.WPNUXT_FAUST_SECRET_KEY ? process.env.WPNUXT_FAUST_SECRET_KEY : options.faustSecretKey
@@ -199,8 +186,6 @@ const module = defineNuxtModule({
199
186
  logger.debug("Debug mode enabled, log level:", publicWPNuxtConfig.logLevel);
200
187
  if (publicWPNuxtConfig.staging)
201
188
  logger.info("Staging enabled");
202
- if (publicWPNuxtConfig.blocks)
203
- logger.info("Blocks enabled");
204
189
  const { resolve } = createResolver(import.meta.url);
205
190
  const resolveRuntimeModule = (path) => resolve("./runtime", path);
206
191
  const srcResolver = createResolver(nuxt.options.srcDir);
@@ -245,6 +230,7 @@ const module = defineNuxtModule({
245
230
  const userQueryPathExists = existsSync(userQueryPath);
246
231
  cpSync(resolveRuntimeModule("./queries/"), queryOutputPath, { recursive: true });
247
232
  if (hasNuxtModule("@wpnuxt/blocks")) {
233
+ logger.debug("Loading @wpnuxt/blocks");
248
234
  for (const m of nuxt.options._installedModules) {
249
235
  if (m.meta.name === "@wpnuxt/blocks" && m.entryPath) {
250
236
  let blocksQueriesPath;
@@ -257,7 +243,7 @@ const module = defineNuxtModule({
257
243
  }
258
244
  }
259
245
  } else {
260
- logger.debug("!!! If you want to render Gutenberg blocks with separate vue components, please install the @wpnuxt/blocks module");
246
+ logger.debug("Tip: Install the @wpnuxt/blocks module if you want to render Gutenberg blocks with separate vue components");
261
247
  }
262
248
  if (userQueryPathExists) {
263
249
  logger.debug("Extending queries:", userQueryPath);
@@ -276,6 +262,7 @@ const module = defineNuxtModule({
276
262
  dedupeFragments: true,
277
263
  onlyOperationTypes: true,
278
264
  avoidOptionals: false,
265
+ maybeValue: "T | undefined",
279
266
  disableOnBuild: false,
280
267
  gqlImport: "graphql-request#wpnuxt",
281
268
  namingConvention: {
@@ -319,29 +306,26 @@ const module = defineNuxtModule({
319
306
  });
320
307
  nuxt.options.nitro.externals.inline.push(template.dst);
321
308
  nuxt.options.alias["#graphql-middleware-server-options-build"] = template.dst;
322
- if (publicWPNuxtConfig.generateComposables && publicWPNuxtConfig.generateComposables.enabled) {
323
- logger.trace("Generating composables");
324
- const composablesConfig = typeof publicWPNuxtConfig.generateComposables === "object" ? publicWPNuxtConfig.generateComposables : defaultComposablesConfig;
325
- const ctx = await {
326
- fns: [],
327
- fnImports: [],
328
- composables: composablesConfig
329
- };
330
- await generateWPNuxtComposables(ctx, queryOutputPath, srcResolver);
331
- addTemplate({
332
- write: true,
333
- filename: "wpnuxt.mjs",
334
- getContents: () => ctx.generateImports?.() || ""
335
- });
336
- addTemplate({
337
- write: true,
338
- filename: "wpnuxt/index.d.ts",
339
- getContents: () => ctx.generateDeclarations?.() || ""
340
- });
341
- nuxt.hook("imports:extend", (autoimports) => {
342
- autoimports.push(...ctx.fnImports || []);
343
- });
344
- }
309
+ logger.trace("Start generating composables");
310
+ const ctx = await {
311
+ fns: [],
312
+ fnImports: [],
313
+ composablesPrefix: publicWPNuxtConfig.composablesPrefix
314
+ };
315
+ await generateWPNuxtComposables(ctx, queryOutputPath, srcResolver);
316
+ addTemplate({
317
+ write: true,
318
+ filename: "wpnuxt/index.mjs",
319
+ getContents: () => ctx.generateImports?.() || ""
320
+ });
321
+ addTypeTemplate({
322
+ write: true,
323
+ filename: "wpnuxt/index.d.ts",
324
+ getContents: () => ctx.generateDeclarations?.() || ""
325
+ });
326
+ nuxt.hook("imports:extend", (autoimports) => {
327
+ autoimports.push(...ctx.fnImports || []);
328
+ });
345
329
  nuxt.hook("nitro:init", async (nitro) => {
346
330
  const keys = await nitro.storage.getKeys("cache:content");
347
331
  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.5",
3
+ "version": "1.0.0-edge.6",
4
4
  "description": "WPNuxt",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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
  }