From ef865d8cb5c3a2f3a654acfa4dfaf488b4939247 Mon Sep 17 00:00:00 2001 From: rharkor Date: Mon, 16 Sep 2024 11:21:03 +0200 Subject: [PATCH] refactor: plugins path --- packages/cli-app/src/api/plugins/queries.ts | 4 +- packages/cli-app/src/api/plugins/schemas.ts | 4 +- packages/cli-app/src/api/templates/queries.ts | 4 +- packages/cli-app/src/api/templates/schemas.ts | 4 +- .../app/components/current-configuration.tsx | 12 ++++-- .../cli-app/src/app/plugins/[id]/content.tsx | 43 +++++++++++++------ .../cli-app/src/app/plugins/[id]/page.tsx | 31 ++++++++++++- packages/cli-app/src/app/plugins/content.tsx | 18 +++++++- packages/cli-app/src/app/plugins/plugin.tsx | 24 ++++++++--- .../src/app/templates/[id]/content.tsx | 28 +++++++----- .../cli-app/src/app/templates/[id]/page.tsx | 25 ++++++++++- .../cli-app/src/app/templates/content.tsx | 6 +-- .../cli-app/src/lib/configuration/index.ts | 10 +++-- packages/cli-app/src/lib/plugins/index.ts | 17 +++++--- packages/cli-app/src/lib/plugins/types.ts | 4 +- packages/cli-app/src/lib/templates/index.ts | 29 +++++++++---- packages/cli-app/src/lib/templates/types.ts | 4 +- packages/cli-app/tsconfig.tsbuildinfo | 2 +- packages/cli/schemas/template.d.json | 3 ++ .../src/utils/template-config/index.ts | 36 ++++++++-------- 20 files changed, 219 insertions(+), 89 deletions(-) diff --git a/packages/cli-app/src/api/plugins/queries.ts b/packages/cli-app/src/api/plugins/queries.ts index 8d5ba8df..a07a2cd1 100644 --- a/packages/cli-app/src/api/plugins/queries.ts +++ b/packages/cli-app/src/api/plugins/queries.ts @@ -17,9 +17,9 @@ export const getPluginsQuery = async ({ input }: apiInputFromSchema) => { +export const getPluginQuery = async ({ input: { name, store } }: apiInputFromSchema) => { try { - const plugin = await getPlugin(id) + const plugin = await getPlugin(name, store) if (!plugin) { throw new Error("Plugin not found") diff --git a/packages/cli-app/src/api/plugins/schemas.ts b/packages/cli-app/src/api/plugins/schemas.ts index 058fcb61..02621a52 100644 --- a/packages/cli-app/src/api/plugins/schemas.ts +++ b/packages/cli-app/src/api/plugins/schemas.ts @@ -1,6 +1,7 @@ import { z } from "zod" import { fullPluginSchema, singlePluginSchema } from "@/lib/plugins/types" +import { storeConfigSchema } from "@next-boilerplate/scripts/utils/template-config/index.js" export const getPluginsSchema = () => z.object({ @@ -14,7 +15,8 @@ export const getPluginsResponseSchema = () => export const getPluginSchema = () => z.object({ - id: z.string(), + name: z.string(), + store: storeConfigSchema, }) export const getPluginResponseSchema = () => diff --git a/packages/cli-app/src/api/templates/queries.ts b/packages/cli-app/src/api/templates/queries.ts index c0f29b71..9398848a 100644 --- a/packages/cli-app/src/api/templates/queries.ts +++ b/packages/cli-app/src/api/templates/queries.ts @@ -17,9 +17,9 @@ export const getTemplatesQuery = async ({ input }: apiInputFromSchema) => { +export const getTemplateQuery = async ({ input: { name, store } }: apiInputFromSchema) => { try { - const template = await getTemplate(id) + const template = await getTemplate(name, store) if (!template) { throw new Error("Template not found") diff --git a/packages/cli-app/src/api/templates/schemas.ts b/packages/cli-app/src/api/templates/schemas.ts index 257cd080..662882ce 100644 --- a/packages/cli-app/src/api/templates/schemas.ts +++ b/packages/cli-app/src/api/templates/schemas.ts @@ -1,6 +1,7 @@ import { z } from "zod" import { fullTemplateSchema, singleTemplateSchema } from "@/lib/templates/types" +import { storeConfigSchema } from "@next-boilerplate/scripts/utils/template-config/index.js" export const getTemplatesSchema = () => z.object({ @@ -14,7 +15,8 @@ export const getTemplatesResponseSchema = () => export const getTemplateSchema = () => z.object({ - id: z.string(), + name: z.string(), + store: storeConfigSchema, }) export const getTemplateResponseSchema = () => diff --git a/packages/cli-app/src/app/components/current-configuration.tsx b/packages/cli-app/src/app/components/current-configuration.tsx index 5c583113..dc0de08c 100644 --- a/packages/cli-app/src/app/components/current-configuration.tsx +++ b/packages/cli-app/src/app/components/current-configuration.tsx @@ -167,7 +167,11 @@ export default function CurrentConfiguration({ await updateConfiguration({ configuration: { plugins: configuration.data.configuration.plugins?.map((p) => { - if (p.id === plugin.id) { + if ( + p.name === plugin.name && + p.store.name === plugin.store.name && + p.store.version === plugin.store.version + ) { return plugin } return p @@ -203,7 +207,7 @@ export default function CurrentConfiguration({ {plugins.map((plugin) => (