From d041d9965a753518fa58e809c40436002efd14b6 Mon Sep 17 00:00:00 2001 From: Wouter Vernaillen Date: Sat, 18 May 2024 13:22:43 +0200 Subject: [PATCH] 105 generate fully typed composables based on queries (#108) * Generate fully typed composables based on queries #105 * lint:fix * run github ci on PR's * added peerDependencies, because Build is done with some warnings: - Inlined implicit external consola - Inlined implicit external scule - Inlined implicit external graphql * moved parser, so it can be called from module.ts * workaround for The inferred type of 'default' cannot be named without a reference * moved parser, so it can be called from module.ts * fix consola LogLevel issue --- .github/workflows/ci.yml | 9 + package.json | 5 + playground/components/HeaderComponent.vue | 4 + playground/nuxt.config.ts | 12 +- playground/pages/composables.vue | 43 + playground/pages/index.vue | 2 - playground/pages/test.vue | 13 +- pnpm-lock.yaml | 928 ++++++++-------------- src/context.ts | 71 ++ src/generate.ts | 17 + src/module.ts | 177 +++-- src/runtime/composables/useWPContent.ts | 26 + src/runtime/composables/wpNuxtLogger.ts | 28 - src/runtime/middleware/auth.ts | 5 +- src/runtime/server/api/wpContent.post.ts | 28 +- src/runtime/server/storage.ts | 4 +- src/runtime/types/index.ts | 31 - src/runtime/util/logger.ts | 12 + src/types.d.ts | 89 +++ src/useParser.ts | 42 + src/utils.ts | 34 + 21 files changed, 833 insertions(+), 747 deletions(-) create mode 100644 playground/pages/composables.vue create mode 100644 src/context.ts create mode 100644 src/generate.ts delete mode 100644 src/runtime/composables/wpNuxtLogger.ts delete mode 100644 src/runtime/types/index.ts create mode 100644 src/runtime/util/logger.ts create mode 100644 src/types.d.ts create mode 100644 src/useParser.ts create mode 100644 src/utils.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17cb412..87135a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,15 @@ name: ci-main on: push: + paths-ignore: + - "docs/**" + - "*.md" + branches: + - main + pull_request: + paths-ignore: + - "docs/**" + - "*.md" branches: - main diff --git a/package.json b/package.json index a6d5561..52599ef 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,11 @@ "vue-docgen-web-types": "^0.1.8", "vue-tsc": "^2.0.19" }, + "peerDependencies": { + "consola": "^3.2.3", + "graphql": "^16.8.1", + "scule": "^1.3.0" + }, "release-it": { "git": { "commitMessage": "chore(release): release v${version}" diff --git a/playground/components/HeaderComponent.vue b/playground/components/HeaderComponent.vue index 76ceb44..4825466 100644 --- a/playground/components/HeaderComponent.vue +++ b/playground/components/HeaderComponent.vue @@ -16,6 +16,10 @@ const links = [ label: 'Test', to: '/test' }, + { + label: 'Generated Composables', + to: '/composables' + }, { label: 'Auth', to: '/auth' diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index ac40d31..9f50b49 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -29,13 +29,15 @@ export default defineNuxtConfig({ frontendUrl: 'https://demo.wpnuxt.com', faustSecretKey: '', showBlockInfo: false, - debug: false, replaceSchema: false, enableCache: true, - staging: false - }, - graphqlMiddleware: { - downloadSchema: true + staging: false, + logLevel: 4, + downloadSchema: true, + generateComposables: { + enabled: true, + prefix: 'wp' + } }, ui: { icons: ['heroicons', 'uil', 'mdi'] diff --git a/playground/pages/composables.vue b/playground/pages/composables.vue new file mode 100644 index 0000000..7a6a90a --- /dev/null +++ b/playground/pages/composables.vue @@ -0,0 +1,43 @@ + + + diff --git a/playground/pages/index.vue b/playground/pages/index.vue index 5a7645d..14feb6c 100644 --- a/playground/pages/index.vue +++ b/playground/pages/index.vue @@ -1,6 +1,4 @@