diff --git a/.circleci/config.yml b/.circleci/config.yml index 8d19b6d..c3daae5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,9 +38,6 @@ jobs: - run: name: Lint command: pnpm run lint - - run: - name: Test - command: pnpm run coverage - sonarcloud/scan - slack/notify: channel: circleci diff --git a/.gitignore b/.gitignore index f6273c8..4f6bde1 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,24 @@ playground/.vercel/ wordpress/files/ playground/schema.graphql +playground/queries/Menu.gql +playground/queries/Page.gql +playground/queries/Pages.gql +playground/queries/Post.gql +playground/queries/PostByUri.gql +playground/queries/Posts.gql +playground/queries/Revisions.gql +playground/queries/Settings.gql +playground/queries/Viewer.gql +playground/queries/fragments/ContentNode.fragment.gql +playground/queries/fragments/CoreGallery.fragment.gql +playground/queries/fragments/CoreImage.fragment.gql +playground/queries/fragments/CoreParagraph.fragment.gql +playground/queries/fragments/CoreQuote.fragment.gql +playground/queries/fragments/EditorBlock.fragment.gql +playground/queries/fragments/MediaItem.fragment.gql +playground/queries/fragments/NodeWithExcerpt.fragment.gql +playground/queries/fragments/NodeWithFeaturedImage.fragment.gql +playground/queries/fragments/NodeWithFeaturedImageToMediaItemConnectionEdge.fragment.gql +playground/queries/fragments/Page.fragment.gql +playground/queries/fragments/Post.fragment.gql diff --git a/CHANGELOG.md b/CHANGELOG.md index b8026da..ba6abd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog +## v0.1.30 + +[compare changes](https://github.com/vernaillen/wpnuxt-module/compare/v0.1.29...v0.1.30) + ## v0.1.29 [compare changes](https://github.com/vernaillen/wpnuxt-module/compare/v0.1.28...v0.1.29) diff --git a/examples/custom-posttypes/.gitignore b/examples/custom-posttypes/.gitignore new file mode 100644 index 0000000..4a7f73a --- /dev/null +++ b/examples/custom-posttypes/.gitignore @@ -0,0 +1,24 @@ +# Nuxt dev/build outputs +.output +.data +.nuxt +.nitro +.cache +dist + +# Node dependencies +node_modules + +# Logs +logs +*.log + +# Misc +.DS_Store +.fleet +.idea + +# Local env files +.env +.env.* +!.env.example diff --git a/examples/custom-posttypes/README.md b/examples/custom-posttypes/README.md new file mode 100644 index 0000000..f5db2a2 --- /dev/null +++ b/examples/custom-posttypes/README.md @@ -0,0 +1,75 @@ +# Nuxt 3 Minimal Starter + +Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more. + +## Setup + +Make sure to install the dependencies: + +```bash +# npm +npm install + +# pnpm +pnpm install + +# yarn +yarn install + +# bun +bun install +``` + +## Development Server + +Start the development server on `http://localhost:3000`: + +```bash +# npm +npm run dev + +# pnpm +pnpm run dev + +# yarn +yarn dev + +# bun +bun run dev +``` + +## Production + +Build the application for production: + +```bash +# npm +npm run build + +# pnpm +pnpm run build + +# yarn +yarn build + +# bun +bun run build +``` + +Locally preview production build: + +```bash +# npm +npm run preview + +# pnpm +pnpm run preview + +# yarn +yarn preview + +# bun +bun run preview +``` + +Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information. diff --git a/examples/custom-posttypes/app.vue b/examples/custom-posttypes/app.vue new file mode 100644 index 0000000..a495b75 --- /dev/null +++ b/examples/custom-posttypes/app.vue @@ -0,0 +1,5 @@ + diff --git a/examples/custom-posttypes/nuxt.config.ts b/examples/custom-posttypes/nuxt.config.ts new file mode 100644 index 0000000..8851e77 --- /dev/null +++ b/examples/custom-posttypes/nuxt.config.ts @@ -0,0 +1,4 @@ +// https://nuxt.com/docs/api/configuration/nuxt-config +export default defineNuxtConfig({ + devtools: { enabled: true } +}) diff --git a/examples/custom-posttypes/package.json b/examples/custom-posttypes/package.json new file mode 100644 index 0000000..7d743a1 --- /dev/null +++ b/examples/custom-posttypes/package.json @@ -0,0 +1,17 @@ +{ + "name": "nuxt-app", + "private": true, + "type": "module", + "scripts": { + "build": "nuxt build", + "dev": "nuxt dev", + "generate": "nuxt generate", + "preview": "nuxt preview", + "postinstall": "nuxt prepare" + }, + "dependencies": { + "nuxt": "^3.10.3", + "vue": "^3.4.19", + "vue-router": "^4.3.0" + } +} diff --git a/examples/custom-posttypes/public/favicon.ico b/examples/custom-posttypes/public/favicon.ico new file mode 100644 index 0000000..18993ad Binary files /dev/null and b/examples/custom-posttypes/public/favicon.ico differ diff --git a/examples/custom-posttypes/server/tsconfig.json b/examples/custom-posttypes/server/tsconfig.json new file mode 100644 index 0000000..b9ed69c --- /dev/null +++ b/examples/custom-posttypes/server/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../.nuxt/tsconfig.server.json" +} diff --git a/examples/custom-posttypes/tsconfig.json b/examples/custom-posttypes/tsconfig.json new file mode 100644 index 0000000..a746f2a --- /dev/null +++ b/examples/custom-posttypes/tsconfig.json @@ -0,0 +1,4 @@ +{ + // https://nuxt.com/docs/guide/concepts/typescript + "extends": "./.nuxt/tsconfig.json" +} diff --git a/examples/yoastseo/.gitignore b/examples/yoastseo/.gitignore new file mode 100644 index 0000000..4a7f73a --- /dev/null +++ b/examples/yoastseo/.gitignore @@ -0,0 +1,24 @@ +# Nuxt dev/build outputs +.output +.data +.nuxt +.nitro +.cache +dist + +# Node dependencies +node_modules + +# Logs +logs +*.log + +# Misc +.DS_Store +.fleet +.idea + +# Local env files +.env +.env.* +!.env.example diff --git a/examples/yoastseo/README.md b/examples/yoastseo/README.md new file mode 100644 index 0000000..f5db2a2 --- /dev/null +++ b/examples/yoastseo/README.md @@ -0,0 +1,75 @@ +# Nuxt 3 Minimal Starter + +Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more. + +## Setup + +Make sure to install the dependencies: + +```bash +# npm +npm install + +# pnpm +pnpm install + +# yarn +yarn install + +# bun +bun install +``` + +## Development Server + +Start the development server on `http://localhost:3000`: + +```bash +# npm +npm run dev + +# pnpm +pnpm run dev + +# yarn +yarn dev + +# bun +bun run dev +``` + +## Production + +Build the application for production: + +```bash +# npm +npm run build + +# pnpm +pnpm run build + +# yarn +yarn build + +# bun +bun run build +``` + +Locally preview production build: + +```bash +# npm +npm run preview + +# pnpm +pnpm run preview + +# yarn +yarn preview + +# bun +bun run preview +``` + +Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information. diff --git a/examples/yoastseo/app.vue b/examples/yoastseo/app.vue new file mode 100644 index 0000000..a495b75 --- /dev/null +++ b/examples/yoastseo/app.vue @@ -0,0 +1,5 @@ + diff --git a/examples/yoastseo/extend/queries/fragments/Page.fragment.gql b/examples/yoastseo/extend/queries/fragments/Page.fragment.gql new file mode 100644 index 0000000..dc505ed --- /dev/null +++ b/examples/yoastseo/extend/queries/fragments/Page.fragment.gql @@ -0,0 +1,31 @@ +#import '~/queries/fragments/ContentNode.fragment.gql'; +#import '~/queries/fragments/CoreGallery.fragment.gql'; +#import '~/queries/fragments/CoreImage.fragment.gql'; +#import '~/queries/fragments/CoreParagraph.fragment.gql'; +#import '~/queries/fragments/CoreQuote.fragment.gql'; +#import '~/queries/fragments/EditorBlock.fragment.gql'; + +fragment Page on Page { + ...ContentNode + content + isFrontPage + isPostsPage + isPreview + isPrivacyPage + isRestricted + isRevision + title + editorBlocks { + name + ...CoreGallery + ...CoreImage + ...CoreParagraph + ...CoreQuote + ...EditorBlock + } + seo { + metaDesc + title + fullHead + } +} diff --git a/examples/yoastseo/extend/queries/fragments/Post.fragment.gql b/examples/yoastseo/extend/queries/fragments/Post.fragment.gql new file mode 100644 index 0000000..6a22f59 --- /dev/null +++ b/examples/yoastseo/extend/queries/fragments/Post.fragment.gql @@ -0,0 +1,28 @@ + +#import '~/queries/fragments/ContentNode.fragment.gql'; +#import '~/queries/fragments/NodeWithFeaturedImage.fragment.gql'; +#import '~/queries/fragments/CoreGallery.fragment.gql'; +#import '~/queries/fragments/CoreImage.fragment.gql'; +#import '~/queries/fragments/CoreParagraph.fragment.gql'; +#import '~/queries/fragments/CoreQuote.fragment.gql'; +#import '~/queries/fragments/EditorBlock.fragment.gql'; + +fragment Post on Post { + ...ContentNode + ...NodeWithFeaturedImage + content + title + editorBlocks { + name + ...CoreGallery + ...CoreImage + ...CoreParagraph + ...CoreQuote + ...EditorBlock + } + seo { + metaDesc + title + fullHead + } +} diff --git a/examples/yoastseo/extend/wpinstall/script.sh b/examples/yoastseo/extend/wpinstall/script.sh new file mode 100644 index 0000000..53c502d --- /dev/null +++ b/examples/yoastseo/extend/wpinstall/script.sh @@ -0,0 +1,3 @@ + + +# install Yoast SEO plugin & Add WPGraphQL SEO diff --git a/examples/yoastseo/nuxt.config.ts b/examples/yoastseo/nuxt.config.ts new file mode 100644 index 0000000..8851e77 --- /dev/null +++ b/examples/yoastseo/nuxt.config.ts @@ -0,0 +1,4 @@ +// https://nuxt.com/docs/api/configuration/nuxt-config +export default defineNuxtConfig({ + devtools: { enabled: true } +}) diff --git a/examples/yoastseo/package.json b/examples/yoastseo/package.json new file mode 100644 index 0000000..7d743a1 --- /dev/null +++ b/examples/yoastseo/package.json @@ -0,0 +1,17 @@ +{ + "name": "nuxt-app", + "private": true, + "type": "module", + "scripts": { + "build": "nuxt build", + "dev": "nuxt dev", + "generate": "nuxt generate", + "preview": "nuxt preview", + "postinstall": "nuxt prepare" + }, + "dependencies": { + "nuxt": "^3.10.3", + "vue": "^3.4.19", + "vue-router": "^4.3.0" + } +} diff --git a/examples/yoastseo/public/favicon.ico b/examples/yoastseo/public/favicon.ico new file mode 100644 index 0000000..18993ad Binary files /dev/null and b/examples/yoastseo/public/favicon.ico differ diff --git a/examples/yoastseo/server/tsconfig.json b/examples/yoastseo/server/tsconfig.json new file mode 100644 index 0000000..b9ed69c --- /dev/null +++ b/examples/yoastseo/server/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../.nuxt/tsconfig.server.json" +} diff --git a/examples/yoastseo/tsconfig.json b/examples/yoastseo/tsconfig.json new file mode 100644 index 0000000..a746f2a --- /dev/null +++ b/examples/yoastseo/tsconfig.json @@ -0,0 +1,4 @@ +{ + // https://nuxt.com/docs/guide/concepts/typescript + "extends": "./.nuxt/tsconfig.json" +} diff --git a/package.json b/package.json index 82d9201..af3be39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vernaillen/wpnuxt", - "version": "0.1.29", + "version": "0.1.30", "description": "WPNuxt", "repository": "vernaillen/wpnuxt-module", "license": "MIT", diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 485b9c8..5ed6cd4 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -17,7 +17,7 @@ export default defineNuxtConfig({ faustSecretKey: '', showBlockInfo: false, debug: false, - replaceSchema: true + replaceSchema: false }, graphqlMiddleware: { downloadSchema: true, diff --git a/playground/pages/[...slug].vue b/playground/pages/[...slug].vue index d158541..582dfca 100644 --- a/playground/pages/[...slug].vue +++ b/playground/pages/[...slug].vue @@ -47,7 +47,10 @@ if (post?.data?.title) { published:
{{ post.data.date.split('T')[0] }} -
+
meta:
{{ post.data.seo.metaDesc }}
diff --git a/playground/queries/testyoastseo.gql b/playground/queries/testyoastseo.gql deleted file mode 100644 index 9d1565e..0000000 --- a/playground/queries/testyoastseo.gql +++ /dev/null @@ -1,316 +0,0 @@ -fragment ContentNode on ContentNode { - # contentType - contentTypeName - databaseId - date - dateGmt - desiredSlug - # editingLockedBy - enclosure - # enqueuedScripts - # enqueuedStylesheets - guid - id - isContentNode - isPreview - isRestricted - isTermNode - # lastEditedBy - link - modified - modifiedGmt - previewRevisionDatabaseId - previewRevisionId - slug - status - # template - uri -} -fragment CoreGallery on CoreGallery { - ...EditorBlock - innerBlocks { - ...CoreImage - } -} -fragment CoreImage on CoreImage { - ...EditorBlock - attributes { - align - alt - anchor - aspectRatio - borderColor - caption - className - cssClassName - height - href - id - linkClass - linkDestination - linkTarget - lock - rel - scale - sizeSlug - src - style - title - url - width - } -} -fragment CoreParagraph on CoreParagraph { - ...EditorBlock - attributes { - content - } -} -fragment CoreQuote on CoreQuote { - ...EditorBlock -} -fragment EditorBlock on EditorBlock { - apiVersion - blockEditorCategoryName - clientId - cssClassNames - isDynamic - name - parentClientId - renderedHtml -} -fragment MediaItem on MediaItem { - altText - # ancestors - # author - authorDatabaseId - authorId - caption - # children - commentCount - commentStatus - # comments - # contentType - contentTypeName - databaseId - date - dateGmt - description - desiredSlug - # editingLockedBy - enclosure - # enqueuedScripts - # enqueuedStylesheets - fileSize - guid - id - isContentNode - isPreview - isRestricted - isTermNode - # lastEditedBy - link - # mediaDetails - mediaItemId - mediaItemUrl - mediaType - mimeType - modified - modifiedGmt - # parent - parentDatabaseId - parentId - previewRevisionDatabaseId - previewRevisionId - sizes - slug - sourceUrl - srcSet - status - # template - title - uri -} -fragment NodeWithExcerpt on NodeWithExcerpt { - excerpt - id -} -fragment NodeWithFeaturedImage on NodeWithFeaturedImage { - featuredImage { - ...NodeWithFeaturedImageToMediaItemConnectionEdge - } - featuredImageDatabaseId - featuredImageId - id -} -fragment NodeWithFeaturedImageToMediaItemConnectionEdge on NodeWithFeaturedImageToMediaItemConnectionEdge { - cursor - node { - ...MediaItem - } -} -fragment Page on Page { - ...ContentNode - content - isFrontPage - isPostsPage - isPreview - isPrivacyPage - isRestricted - isRevision - title - editorBlocks { - name - ...CoreGallery - ...CoreImage - ...CoreParagraph - ...CoreQuote - ...EditorBlock - } -} -fragment Post on Post { - ...ContentNode - ...NodeWithFeaturedImage - content - title - editorBlocks { - name - ...CoreGallery - ...CoreImage - ...CoreParagraph - ...CoreQuote - ...EditorBlock - } -} - -query Pages($limit: Int = 10) { - pages(first: $limit) { - nodes { - ...Page - } - } -} -query Posts($limit: Int = 10) { - posts(first: $limit) { - nodes { - ...Post - ...NodeWithExcerpt - } - } -} -query LatestPost { - posts(first: 1) { - nodes { - ...Post - ...NodeWithExcerpt - } - } -} -query PostByUri($uri: String!) { - nodeByUri(uri: $uri) { - ...Page - ...Post - } -} -query PostById($id: ID!, $asPreview: Boolean = false) { - post(id: $id, idType: DATABASE_ID, asPreview: $asPreview) { - ...Post - } -} -query PageById($id: ID!) { - page(id: $id, idType: DATABASE_ID, asPreview: true) { - ...Page - } -} -query Settings { - generalSettings { - title - description - url - email - dateFormat - language - startOfWeek - timezone - timeFormat - } -} -query Menu($name: ID! = "main", $idType: MenuNodeIdTypeEnum! = NAME) { - menu(id: $name, idType: $idType) { - id - name - menuItems { - nodes { - label - uri - } - } - } -} -query Viewer { - viewer { - username - userId - id - email - description - firstName - lastName - locale - url - uri - } -} -query Revisions { - revisions { - nodes { - date - uri - isPreview - } - } -} - -fragment Page on Page { - ...ContentNode - content - isFrontPage - isPostsPage - isPreview - isPrivacyPage - isRestricted - isRevision - title - editorBlocks { - name - ...CoreGallery - ...CoreImage - ...CoreParagraph - ...CoreQuote - ...EditorBlock - } - seo { - metaDesc - title - fullHead - } -} -fragment Post on Post { - ...ContentNode - ...NodeWithFeaturedImage - content - title - editorBlocks { - name - ...CoreGallery - ...CoreImage - ...CoreParagraph - ...CoreQuote - ...EditorBlock - } - seo { - metaDesc - title - fullHead - } -} diff --git a/sonar-project.properties b/sonar-project.properties index 582b0e8..d6c34dc 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,10 +1,9 @@ sonar.projectKey=wpnuxt-module sonar.projectName=WPNuxt-module sonar.organization=vernaillen - -sonar.tests=tests -sonar.test.inclusions=tests/** -sonar.coverage.exclusions=tests/** + +#sonar.tests=tests +#sonar.test.inclusions=tests/** +#sonar.coverage.exclusions=tests/** sonar.javascript.lcov.reportPaths=./coverage/coverage-final.json - \ No newline at end of file diff --git a/src/module.ts b/src/module.ts index e956fd9..61547a4 100644 --- a/src/module.ts +++ b/src/module.ts @@ -135,19 +135,19 @@ export default defineNuxtModule({ } })*/ - const userQueryPath = '~/queries/' + const queryOutputPath = resolver.resolve(nuxt.options.rootDir + '/queries/') + + const userQueryPath = '~/extend/queries/' .replace(/^(~~|@@)/, nuxt.options.rootDir) .replace(/^(~|@)/, nuxt.options.srcDir) const userQueryPathExists = existsSync(userQueryPath) - let queryPaths - if (userQueryPathExists && options.replaceSchema) { - queryPaths = [ resolver.resolve(userQueryPath + '**/*.gql')] - } else if (userQueryPathExists && !options.replaceSchema) { - queryPaths = [ resolver.resolve(userQueryPath + '**/*.gql'), resolver.resolve('./runtime/queries/**/*.gql')] - } else { - queryPaths = [ resolver.resolve('./runtime/queries/**/*.gql')] + + fs.cpSync(resolver.resolve('./runtime/queries/'), queryOutputPath, {recursive: true}) + if (userQueryPathExists) { + logger.debug('Extending queries:', userQueryPath) + fs.cpSync(resolver.resolve(userQueryPath), queryOutputPath, {recursive: true}) } - logger.debug('Loading query paths:', queryPaths) + logger.debug('Copied merged queries in folder:', queryOutputPath) await installModule('nuxt-graphql-middleware', { debug: nuxt.options.runtimeConfig.public.wpNuxt.debug, @@ -162,11 +162,13 @@ export default defineNuxtModule({ disableOnBuild: false, schema: { } as any, - documents: [resolver.resolve('!./graphql/**/*')], + documents: [ + resolver.resolve('!./graphql/**/*') + ], generates: { './graphql/': { preset: 'client', - plugins: [], + plugins: ['typescript-operations'], }, }, }, @@ -178,7 +180,7 @@ export default defineNuxtModule({ }, }, outputDocuments: true, - autoImportPatterns: queryPaths + autoImportPatterns: queryOutputPath }) /*const resolvedMCPath = resolver.resolve('./runtime/app/multiCache.serverOptions') const templateMC = addTemplate({ diff --git a/src/runtime/components/StagingBanner.vue b/src/runtime/components/StagingBanner.vue index f8ebe7d..0878c91 100644 --- a/src/runtime/components/StagingBanner.vue +++ b/src/runtime/components/StagingBanner.vue @@ -28,7 +28,8 @@ useHead({