Skip to content

Commit

Permalink
fix: build
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Sep 16, 2024
1 parent 7aeaee0 commit 066f065
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 166 deletions.
2 changes: 1 addition & 1 deletion packages/cli-app/src/api/configuration/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod"

import { fullPluginSchema } from "@/lib/plugins/store"
import { fullPluginSchema } from "@/lib/plugins/types"
import { storeNameRegex, storeVersionRegex } from "@next-boilerplate/scripts/utils/template-config/index.js"

export const configurationSchema = () =>
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-app/src/api/plugins/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod"

import { fullPluginSchema, singlePluginSchema } from "@/lib/plugins/store"
import { fullPluginSchema, singlePluginSchema } from "@/lib/plugins/types"

export const getPluginsSchema = () =>
z.object({
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-app/src/api/templates/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod"

import { fullTemplateSchema, singleTemplateSchema } from "@/lib/templates/store"
import { fullTemplateSchema, singleTemplateSchema } from "@/lib/templates/types"

export const getTemplatesSchema = () =>
z.object({
Expand Down
19 changes: 1 addition & 18 deletions packages/cli-app/src/lib/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import { TRPCError } from "@trpc/server"
import { env } from "../env"
import { getStores } from "../stores"

import {
getPluginsFromStore,
getSinglePluginFromStore,
setPluginsToStore,
setSinglePluginToStore,
TPluginStore,
} from "./store"
import { TPluginStore } from "./types"

// Get the current package directory
const cwd = process.cwd()
Expand Down Expand Up @@ -64,18 +58,11 @@ const loadPlugins = async () => {

pluginsFilled.sort((a, b) => a.name.localeCompare(b.name))

setPluginsToStore(pluginsFilled)
return pluginsFilled
}

export const getPlugins = async (opts?: { search?: string }) => {
const plugins = await new Promise<TPluginStore[]>(async (resolve) => {
const pluginsFromStore = await getPluginsFromStore()
if (pluginsFromStore) {
resolve(pluginsFromStore)
return
}

const plugins = await loadPlugins()
resolve(plugins)
return
Expand All @@ -87,9 +74,6 @@ export const getPlugins = async (opts?: { search?: string }) => {
}

export const getPlugin = async (id: string) => {
const pluginFromStore = await getSinglePluginFromStore(id)
if (pluginFromStore) return pluginFromStore

const plugins = await getPlugins()
const plugin = plugins.find((p) => p.id === id)
if (!plugin) {
Expand All @@ -99,6 +83,5 @@ export const getPlugin = async (id: string) => {
})
}

setSinglePluginToStore(id, plugin)
return plugin
}
40 changes: 0 additions & 40 deletions packages/cli-app/src/lib/plugins/store.ts

This file was deleted.

11 changes: 11 additions & 0 deletions packages/cli-app/src/lib/plugins/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from "zod"

import { pluginConfigSchema } from "@next-boilerplate/scripts/utils/template-config/index.js"

export const fullPluginSchema = pluginConfigSchema.extend({
sourcePath: z.string(),
id: z.string(),
})
export const singlePluginSchema = fullPluginSchema
export type TPlugin = z.infer<typeof singlePluginSchema>
export type TPluginStore = z.infer<typeof fullPluginSchema>
24 changes: 6 additions & 18 deletions packages/cli-app/src/lib/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import { storeConfigSchema } from "@next-boilerplate/scripts/utils/template-conf
import { logger } from "@rharkor/logger"
import { TRPCError } from "@trpc/server"

export const fullStoreSchema = storeConfigSchema.extend({
fullPath: z.string(),
})

export type TStoreStore = z.infer<typeof fullStoreSchema>

type TConfig = z.infer<typeof storeConfigSchema>

import { z } from "zod"

import { optionalConfigSchema } from "../configuration"
import { env } from "../env"
import { resetPluginsStore, resetSinglePluginStore } from "../plugins/store"
import { resetSingleTemplateStore, resetTemplatesStore } from "../templates/store"

import { getStoresFromStore, resetStoresStore, setStoresToStore, TStoreStore } from "./store"

// Get the current package directory
const cwd = process.cwd()
Expand Down Expand Up @@ -63,18 +65,11 @@ const loadStores = async () => {

storesFilled.sort((a, b) => `${a.name}@${a.version}`.localeCompare(`${b.name}@${b.version}`))

setStoresToStore(storesFilled)
return storesFilled
}

export const getStores = async (opts?: { search?: string }) => {
const stores = await new Promise<TStoreStore[]>(async (resolve) => {
const storesFromStore = await getStoresFromStore()
if (storesFromStore) {
resolve(storesFromStore)
return
}

const stores = await loadStores()
resolve(stores)
return
Expand Down Expand Up @@ -158,11 +153,4 @@ export const handleDownloadStores = async (config: z.infer<typeof optionalConfig
})
})
}

// Refresh the cache
await resetStoresStore()
await resetPluginsStore()
await resetSinglePluginStore()
await resetTemplatesStore()
await resetSingleTemplateStore()
}
22 changes: 0 additions & 22 deletions packages/cli-app/src/lib/stores/store.ts

This file was deleted.

19 changes: 1 addition & 18 deletions packages/cli-app/src/lib/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ import { z } from "zod"

import { getStores } from "../stores"

import {
getSingleTemplateFromStore,
getTemplatesFromStore,
setSingleTemplateToStore,
setTemplatesToStore,
TTemplateStore,
} from "./store"
import { TTemplateStore } from "./types"

const configFileName = "config.json"

Expand Down Expand Up @@ -64,18 +58,11 @@ const loadTemplates = async () => {

templatesFilled.sort((a, b) => a.name.localeCompare(b.name))

setTemplatesToStore(templatesFilled)
return templatesFilled
}

export const getTemplates = async (opts?: { search?: string }) => {
const templates = await new Promise<TTemplateStore[]>(async (resolve) => {
const templatesFromStore = await getTemplatesFromStore()
if (templatesFromStore) {
resolve(templatesFromStore)
return
}

const templates = await loadTemplates()
resolve(templates)
return
Expand All @@ -87,9 +74,6 @@ export const getTemplates = async (opts?: { search?: string }) => {
}

export const getTemplate = async (id: string) => {
const templateFromStore = await getSingleTemplateFromStore(id)
if (templateFromStore) return templateFromStore

const templates = await getTemplates()
const template = templates.find((p) => p.id === id)
if (!template) {
Expand All @@ -116,6 +100,5 @@ export const getTemplate = async (id: string) => {
plugins: foundPlugins,
}

setSingleTemplateToStore(id, filledTemplate)
return filledTemplate
}
43 changes: 0 additions & 43 deletions packages/cli-app/src/lib/templates/store.ts

This file was deleted.

16 changes: 16 additions & 0 deletions packages/cli-app/src/lib/templates/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { z } from "zod"

import { templateSchema } from "@next-boilerplate/scripts/utils/template-config/index.js"

import { fullPluginSchema } from "../plugins/types"

export const fullTemplateSchema = templateSchema.extend({
sourcePath: z.string(),
id: z.string(),
})
export type TTemplateStore = z.infer<typeof fullTemplateSchema>

export const singleTemplateSchema = fullTemplateSchema.extend({
plugins: z.array(fullPluginSchema),
})
export type TTemplate = z.infer<typeof singleTemplateSchema>
4 changes: 1 addition & 3 deletions packages/cli-app/src/lib/utils/client-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRouter } from "next/navigation"
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime"

import { toast } from "react-toastify"

Expand All @@ -14,8 +14,6 @@ type TOptions = {
showNotification?: boolean // default true
}

type AppRouterInstance = ReturnType<typeof useRouter>

export const handleQueryError = <T extends TRPCClientErrorLike<AppRouter>>(
error: T,
dictionary: TDictionary<{
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-app/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

0 comments on commit 066f065

Please sign in to comment.