retrex-extensibles-core 2.1.3 → 2.1.4
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/hooks/useUtils.ts","../../../src/core/hooks/useSettings.ts","../../../src/core/hooks/useExtensibles.ts"],"sourcesContent":["/* @vite-ignore */\n// packages/retrex-extensibles-core/hooks/useUtils.ts\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport { useSettings } from './useSettings';\n\nfunction toFileUrl(filePath: string): string {\n const normalized = filePath.replace(/\\\\/g, '/');\n if (normalized.startsWith('file://')) return normalized;\n const prefix = normalized.startsWith('/') ? 'file://' : 'file:///';\n return `${prefix}${encodeURI(normalized)}`;\n}\n\nexport const useUtils = {\n logPrefix,\n async loadThemeComponent(\n componentName: string,\n options: {\n theme: {\n name: string;\n type: 'admin' | 'client' | 'portal' | 'email';\n };\n search?: {\n themes?: boolean;\n modules?: boolean;\n services?: boolean;\n };\n }\n ): Promise<React.ComponentType<any> | null> {\n const { search = {}, theme } = options;\n const searchThemes = search.themes ?? true;\n const searchModules = search.modules ?? true;\n const searchServices = search.services ?? true;\n\n const possiblePaths: string[] = [];\n\n console.log(`Searching for component \"${componentName}\" in theme \"${theme.name}\" of type \"${theme.type}\"...`);\n\n try {\n if (searchThemes) {\n const templatesRoot = path.resolve(useSettings.getPaths().templates);\n possiblePaths.push(\n path.resolve(\n templatesRoot,\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n \n if (searchModules) {\n const modulesRoot = path.resolve(useSettings.getPaths().modules);\n if (fs.existsSync(modulesRoot)) {\n const moduleDirs = await fs.readdirSync(modulesRoot);\n for (const mod of moduleDirs) {\n possiblePaths.push(\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n }\n }\n \n if (searchServices) {\n const servicesRoot = path.resolve(useSettings.getPaths().services);\n if (fs.existsSync(servicesRoot)) {\n const serviceDirs = await fs.readdirSync(servicesRoot);\n for (const svc of serviceDirs) {\n possiblePaths.push(\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n }\n }\n \n for (const filePath of possiblePaths) {\n if (await fs.existsSync(filePath)) {\n try {\n const mod = await import(toFileUrl(filePath));\n if (mod.default) return mod.default;\n } catch (err) {\n console.error(`Error loading component at ${filePath}:`, err);\n }\n }\n }\n \n console.warn(`Component \"${componentName}\" not found in theme \"${theme.name}\" of type \"${theme.type}\".`);\n return null;\n } catch (err) {\n console.error(`Error searching for component \"${componentName}\":`, err);\n console.warn(`Component \"${componentName}\" not found in theme \"${theme.name}\" of type \"${theme.type}\".`);\n console.warn(`Searched paths:`, possiblePaths);\n console.warn(`Ensure the component exists in the specified theme and type.`);\n console.warn(`If the component is in a module or service, ensure the theme structure is correct.`);\n console.warn(`If you are using a custom theme, module, or service, ensure it is properly configured and registered in the settings.`);\n return null;\n }\n }\n}\n\n/**\n * Log prefix helper (safe in Node and browser).\n * Mirrors server.js behavior with optional chalk styling when available.\n */\nexport function logPrefix(\n et?: 'Providers' | 'Routes' | 'Templates' | 'Modules' | 'Services' | 'Events' | 'Server' | string,\n type?: 'error' | 'success' | 'info' | 'warning' | string,\n color?: 'green' | 'cyan' | 'magenta' | 'blue' | 'yellow' | 'red' | 'gray' | 'black' | 'white' | string\n): string {\n const label = `${et || 'Extensibles'} Manager${type ? ' | ' + type?.charAt(0).toUpperCase() + type?.slice(1) : ''}`;\n\n const getChalk = (): any => {\n if (typeof window !== 'undefined') return null;\n try {\n // eslint-disable-next-line no-eval\n const req = eval('require');\n const mod = req('chalk');\n return mod?.default ?? mod;\n } catch {\n return null;\n }\n };\n\n const chalk = getChalk();\n const wrap = (fn: ((v: string) => string) | null, value: string) => (fn ? fn(value) : value);\n\n let colored = label;\n if (chalk) {\n if (type === 'error') colored = wrap(chalk.redBright, label);\n else if (type === 'warning') colored = wrap(chalk.yellow, label);\n else if (type === 'success') colored = wrap(chalk.green, label);\n else if (type === 'info') colored = wrap(chalk.blue, label);\n else if (color === 'green') colored = wrap(chalk.green, label);\n else if (color === 'cyan') colored = wrap(chalk.cyan, label);\n else if (color === 'magenta') colored = wrap(chalk.magenta, label);\n else if (color === 'blue') colored = wrap(chalk.blue, label);\n else if (color === 'yellow') colored = wrap(chalk.yellow, label);\n else if (color === 'red') colored = wrap(chalk.red, label);\n else if (color === 'gray') colored = wrap(chalk.gray, label);\n else if (color === 'black') colored = wrap(chalk.black, label);\n else if (color === 'white') colored = wrap(chalk.white, label);\n }\n\n if (chalk?.white) {\n return chalk.white('[') + colored + chalk.white('] ');\n }\n return `[${colored}] `;\n}\n","// src/hooks/useSettings.ts\n\nimport path from 'node:path';\nimport fs from 'node:fs';\n\nimport { loadJSON, saveJSON } from './useExtensibles';\nimport type { ExtensiblePaths } from '../types'; // Adjust the import path as necessary\n\nconst defaultPaths: ExtensiblePaths = {\n modules: './app/modules',\n templates: './app/resources/themes',\n services: './app/services',\n events: './app/events',\n langs: './public/langs',\n providers: './app/providers',\n};\n\nlet extensiblePaths: ExtensiblePaths = { ...defaultPaths };\nconst isServer = typeof window === 'undefined';\n\n\nexport const useSettings = {\n getPaths(): ExtensiblePaths {\n if (isServer) {\n const json = loadJSON('./app/extensiblePaths.json');\n if (json) extensiblePaths = json;\n }\n\n if (isServer) {\n for (const key of Object.keys(defaultPaths) as Array<keyof ExtensiblePaths>) {\n const candidate = extensiblePaths[key];\n if (!candidate || !fs.existsSync(candidate)) {\n extensiblePaths[key] = defaultPaths[key];\n }\n }\n }\n\n extensiblePaths = {\n ...extensiblePaths,\n langs: './langs',\n };\n // extensiblePaths = loadJSON(\"./app/extensiblePaths.json\");\n return extensiblePaths;\n },\n\n setPaths(paths: Partial<ExtensiblePaths>): void {\n if (isServer) {\n saveJSON('./app/extensiblePaths.json', {\n ...extensiblePaths,\n ...paths,\n });\n }\n\n extensiblePaths = {\n ...extensiblePaths,\n ...paths,\n };\n },\n \n getKeyValue(key: string): string {\n return 'Coming Soon'\n },\n setKeyValue(key: string, value: string): void {\n return;\n },\n};\n","// src/hooks/useExtensibles.ts\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { useSettings } from './useSettings';\nimport type { TemplateType, ExtensibleMeta, ExtensiblePaths } from '../types';\n\nlet paths: ExtensiblePaths;\n\nfunction toFileUrl(filePath: string): string {\n const normalized = filePath.replace(/\\\\/g, '/');\n if (normalized.startsWith('file://')) return normalized;\n const prefix = normalized.startsWith('/') ? 'file://' : 'file:///';\n return `${prefix}${encodeURI(normalized)}`;\n}\n\nexport function registerExtensibles(extensiblePaths: ExtensiblePaths) {\n paths = extensiblePaths;\n}\n\nexport function loadJSON(filePath: string): any {\n if (!fs.existsSync(filePath)) return null;\n return JSON.parse(fs.readFileSync(filePath, 'utf-8'));\n}\n\nexport function saveJSON(filePath: string, data: any) {\n fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');\n}\n\n// --- MODULES ---\n\nexport function getModules(): ExtensibleMeta[] {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n\n const dirs = fs\n .readdirSync(useSettings.getPaths().modules)\n .filter((d: any) => fs.statSync(path.join(useSettings.getPaths().modules, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(useSettings.getPaths().modules, dir, 'module.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: meta.lowerName || dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isModuleEnabled(name: string) {\n const modules = getModules();\n return modules.find((m) => m.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\nexport function toggleModule(name: string, enabled: boolean) {\n const modules = getModules();\n const mod = modules.find((m) => m.lowerName === name.toLowerCase());\n if (!mod) throw new Error(`Module ${name} not found`);\n\n const metaPath = path.join(useSettings.getPaths().modules, mod.lowerName, 'module.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = enabled;\n saveJSON(metaPath, meta);\n\n if (enabled) onModuleEnabled(mod.name);\n else onModuleDisabled(mod.name);\n}\n\n// --- SERVICES ---\n\nexport function getServices(): ExtensibleMeta[] {\n if (!useSettings.getPaths().services) throw new Error('Services path not registered.');\n\n const dirs = fs\n .readdirSync(useSettings.getPaths().services)\n .filter((d: any) => fs.statSync(path.join(useSettings.getPaths().services, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(useSettings.getPaths().services, dir, 'service.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: meta.lowerName || dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isServiceEnabled(name: string) {\n const services = getServices();\n return services.find((s) => s.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\nexport function toggleService(name: string, enabled: boolean) {\n const services = getServices();\n const svc = services.find((s) => s.lowerName === name.toLowerCase());\n if (!svc) throw new Error(`Service ${name} not found`);\n\n const metaPath = path.join(useSettings.getPaths().services, svc.lowerName, 'service.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = enabled;\n saveJSON(metaPath, meta);\n\n if (enabled) onServiceEnabled(svc.name);\n else onServiceDisabled(svc.name);\n}\n\n// --- TEMPLATES ---\n\n// Helper to get base path for a template type\nfunction getTemplateBasePath(type: TemplateType): string {\n if (!useSettings.getPaths().templates) throw new Error('Templates path not registered.');\n switch (type) {\n case 'admin-theme':\n case 'client-theme':\n return path.join(useSettings.getPaths().templates, 'themes');\n case 'portal':\n return path.join(useSettings.getPaths().templates, 'portals');\n case 'email':\n return path.join(useSettings.getPaths().templates, 'emails');\n default:\n throw new Error(`Unknown template type: ${type}`);\n }\n}\n\nexport function getTemplates(type: TemplateType): ExtensibleMeta[] {\n const basePath = getTemplateBasePath(type);\n if (!fs.existsSync(basePath)) return [];\n\n const dirs = fs\n .readdirSync(basePath)\n .filter((d: any) => fs.statSync(path.join(basePath, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(basePath, dir, 'template.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isTemplateActive(type: TemplateType, name: string) {\n const templates = getTemplates(type);\n return templates.find((t) => t.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\n// Toggle templates: only 1 active per type allowed\nexport function toggleTemplate(type: TemplateType, name: string) {\n const templates = getTemplates(type);\n\n templates.forEach((tpl) => {\n const metaPath = path.join(getTemplateBasePath(type), tpl.lowerName, 'template.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = tpl.lowerName === name.toLowerCase();\n saveJSON(metaPath, meta);\n });\n\n onTemplateSelect(type, name);\n}\n\n// --- EVENTS (replace with your event system integration) ---\n\nexport function onModuleEnabled(name: string) {\n console.log(`Module enabled: ${name}`);\n // emit event or custom logic here\n}\n\nexport function onModuleDisabled(name: string) {\n console.log(`Module disabled: ${name}`);\n}\n\nexport function onServiceEnabled(name: string) {\n console.log(`Service enabled: ${name}`);\n}\n\nexport function onServiceDisabled(name: string) {\n console.log(`Service disabled: ${name}`);\n}\n\nexport function onTemplateSelect(type: TemplateType, name: string) {\n console.log(`Template selected: type=${type}, name=${name}`);\n}\n\n// --- REGISTER HOOKS FOR MODULES ---\n\nexport async function registerEvents() {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n const modules = getModules().filter((m) => m.enabled);\n for (const mod of modules) {\n const eventsFile = path.join(useSettings.getPaths().modules, mod.lowerName, 'events.server.js');\n if (fs.existsSync(eventsFile)) {\n const modEvents = await import(eventsFile);\n if (modEvents?.registerEvents) await modEvents.registerEvents();\n }\n }\n}\n\nexport async function registerMiddleware() {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n const modules = getModules().filter((m) => m.enabled);\n for (const mod of modules) {\n const middlewareFile = path.join(useSettings.getPaths().modules, mod.lowerName, 'middleware.server.js');\n if (fs.existsSync(middlewareFile)) {\n const modMiddleware = await import(middlewareFile);\n if (modMiddleware?.registerMiddleware) await modMiddleware.registerMiddleware();\n }\n }\n}\n\n/**\n * Registers routes given a path to routes folder (for pages and API routes)\n * @param routesFolderPath string - path to module/service routes folder\n */\nexport async function registerRoutes(routesFolderPath: string) {\n if (!fs.existsSync(routesFolderPath)) return;\n\n const routeFiles = fs.readdirSync(routesFolderPath).filter((f: any) => /\\.(js|ts|jsx|tsx)$/.test(f));\n for (const file of routeFiles) {\n const routeModule = await import(path.join(routesFolderPath, file));\n if (routeModule?.registerRoute) {\n await routeModule.registerRoute();\n }\n }\n}\n\nexport async function loadProviders() {\n const paths = useSettings.getPaths();\n\n const all = [\n { type: 'module', list: getModules(), basePath: paths.modules },\n { type: 'service', list: getServices(), basePath: paths.services },\n ];\n\n for (const { type, list, basePath } of all) {\n for (const item of list) {\n if (!item.enabled) continue;\n\n const metaPath = path.join(path.resolve(basePath), item.lowerName, `${type}.json`);\n const meta = loadJSON(metaPath);\n if (!meta?.providers || !Array.isArray(meta.providers)) continue;\n\n for (const providerRelPath of meta.providers) {\n try {\n let providerAbsPath = path.join(path.resolve(basePath), item.lowerName, providerRelPath);\n\n // Try .js fallback if file is .ts or .tsx\n const ext = path.extname(providerAbsPath);\n if (ext === '.ts' || ext === '.tsx') {\n const jsPath = providerAbsPath.replace(/\\.(ts|tsx)$/, '.js');\n try {\n await fs.accessSync(jsPath); // Check if compiled JS file exists\n providerAbsPath = jsPath;\n } catch {\n throw new Error(`Compiled JS version not found for provider: ${providerRelPath}`);\n }\n }\n\n const providerUrl = toFileUrl(providerAbsPath);\n const providerModule = await import(providerUrl);\n\n if (typeof providerModule.default === 'function') {\n // Expose context so nav registration can auto-tag module/service\n (globalThis as any).__retrex_provider_context__ = {\n type,\n name: item.lowerName,\n };\n await providerModule.default();\n (globalThis as any).__retrex_provider_context__ = undefined;\n console.log(`[${type}] ✅ Provider loaded: ${providerRelPath}`);\n } else {\n console.warn(`[${type}] ⚠️ Provider ${providerRelPath} has no default export.`);\n }\n } catch (err) {\n console.error(`[${type}] ❌ Failed to load provider ${providerRelPath}:`, err);\n }\n }\n }\n }\n}\n\n\n// export async function loadProviders() {\n// paths = {\n// modules: useSettings.getPaths().modules,\n// templates: useSettings.getPaths().templates,\n// services: useSettings.getPaths().services,\n// events: useSettings.getPaths().events,\n// }\n// const all = [\n// { type: 'module', list: getModules(), basePath: useSettings.getPaths().modules },\n// { type: 'service', list: getServices(), basePath: useSettings.getPaths().services },\n// ];\n\n// for (const { type, list, basePath } of all) {\n// for (const item of list) {\n// if (!item.enabled) continue;\n\n// const metaPath = path.join(basePath, item.lowerName, `${type}.json`);\n// const meta = loadJSON(metaPath);\n// if (!meta?.providers || !Array.isArray(meta.providers)) continue;\n\n// for (const providerRelPath of meta.providers) {\n// try {\n// const providerPath = path.join(basePath, item.lowerName, providerRelPath);\n// const providerModule = await import(providerPath);\n// if (typeof providerModule.default === 'function') {\n// await providerModule.default(); // Call provider\n// console.log(`[${type}] Provider loaded: ${providerRelPath}`);\n// } else {\n// console.warn(`[${type}] Provider ${providerRelPath} has no default export.`);\n// }\n// } catch (err) {\n// console.error(`[${type}] Failed to load provider ${providerRelPath}:`, err);\n// }\n// }\n// }\n// }\n// }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAAA,oBAAiB;AACjB,IAAAC,kBAAe;;;ACAf,IAAAC,kBAAe;;;ACDf,qBAAe;AACf,uBAAiB;AAiBV,SAAS,SAAS,UAAuB;AAC9C,MAAI,CAAC,eAAAC,QAAG,WAAW,QAAQ,EAAG,QAAO;AACrC,SAAO,KAAK,MAAM,eAAAA,QAAG,aAAa,UAAU,OAAO,CAAC;AACtD;AAEO,SAAS,SAAS,UAAkB,MAAW;AACpD,iBAAAA,QAAG,cAAc,UAAU,KAAK,UAAU,MAAM,MAAM,CAAC,GAAG,OAAO;AACnE;;;ADnBA,IAAM,eAAgC;AAAA,EACpC,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,WAAW;AACb;AAEA,IAAI,kBAAmC,EAAE,GAAG,aAAa;AACzD,IAAM,WAAW,OAAO,WAAW;AAG5B,IAAM,cAAc;AAAA,EACzB,WAA4B;AAC1B,QAAI,UAAU;AACZ,YAAM,OAAO,SAAS,4BAA4B;AAClD,UAAI,KAAM,mBAAkB;AAAA,IAC9B;AAEA,QAAI,UAAU;AACZ,iBAAW,O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AU,OAAQ,WAAU,KAAK,MAAM,MAAM,KAAK;AAAA,aAClD,UAAU,UAAW,WAAU,KAAK,MAAM,SAAS,KAAK;AAAA,aACxD,UAAU,OAAQ,WAAU,KAAK,MAAM,MAAM,KAAK;AAAA,aAClD,UAAU,SAAU,WAAU,KAAK,MAAM,QAAQ,KAAK;AAAA,aACtD,UAAU,MAAO,WAAU,KAAK,MAAM,KAAK,KAAK;AAAA,aAChD,UAAU,OAAQ,WAAU,KAAK,MAAM,MAAM,KAAK;AAAA,aAClD,UAAU,QAAS,WAAU,KAAK,MAAM,OAAO,KAAK;AAAA,aACpD,UAAU,QAAS,WAAU,KAAK,MAAM,OAAO,KAAK;AAAA,EAC/D;AAEA,MAAI,OAAO,OAAO;AAChB,WAAO,MAAM,MAAM,GAAG,IAAI,UAAU,MAAM,MAAM,IAAI;AAAA,EACtD;AACA,SAAO,IAAI,OAAO;AACpB;","names":["import_node_path","import_node_fs","import_node_fs","fs","fs","path","fs","mod"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/core/hooks/useUtils.ts","../../../src/core/hooks/useSettings.ts","../../../src/core/hooks/useExtensibles.ts"],"sourcesContent":["/* @vite-ignore */\n// packages/retrex-extensibles-core/hooks/useUtils.ts\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport { useSettings } from './useSettings';\n\nfunction toFileUrl(filePath: string): string {\n const normalized = filePath.replace(/\\\\/g, '/');\n if (normalized.startsWith('file://')) return normalized;\n const prefix = normalized.startsWith('/') ? 'file://' : 'file:///';\n return `${prefix}${encodeURI(normalized)}`;\n}\n\nexport const useUtils = {\n logPrefix,\n async loadThemeComponent(\n componentName: string,\n options: {\n theme: {\n name: string;\n type: 'admin' | 'client' | 'portal' | 'email';\n };\n search?: {\n themes?: boolean;\n modules?: boolean;\n services?: boolean;\n };\n }\n ): Promise<React.ComponentType<any> | null> {\n const { search = {}, theme } = options;\n const searchThemes = search.themes ?? true;\n const searchModules = search.modules ?? true;\n const searchServices = search.services ?? true;\n\n const possiblePaths: string[] = [];\n\n console.log(`Searching for component \"${componentName}\" in theme \"${theme.name}\" of type \"${theme.type}\"...`);\n\n try {\n if (searchThemes) {\n const templatesRoot = path.resolve(useSettings.getPaths().templates);\n possiblePaths.push(\n path.resolve(\n templatesRoot,\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n \n if (searchModules) {\n const modulesRoot = path.resolve(useSettings.getPaths().modules);\n if (fs.existsSync(modulesRoot)) {\n const moduleDirs = await fs.readdirSync(modulesRoot);\n for (const mod of moduleDirs) {\n possiblePaths.push(\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n }\n }\n \n if (searchServices) {\n const servicesRoot = path.resolve(useSettings.getPaths().services);\n if (fs.existsSync(servicesRoot)) {\n const serviceDirs = await fs.readdirSync(servicesRoot);\n for (const svc of serviceDirs) {\n possiblePaths.push(\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n }\n }\n \n for (const filePath of possiblePaths) {\n if (await fs.existsSync(filePath)) {\n try {\n const mod = await import(toFileUrl(filePath));\n if (mod.default) return mod.default;\n } catch (err) {\n console.error(`Error loading component at ${filePath}:`, err);\n }\n }\n }\n \n console.warn(`Component \"${componentName}\" not found in theme \"${theme.name}\" of type \"${theme.type}\".`);\n return null;\n } catch (err) {\n console.error(`Error searching for component \"${componentName}\":`, err);\n console.warn(`Component \"${componentName}\" not found in theme \"${theme.name}\" of type \"${theme.type}\".`);\n console.warn(`Searched paths:`, possiblePaths);\n console.warn(`Ensure the component exists in the specified theme and type.`);\n console.warn(`If the component is in a module or service, ensure the theme structure is correct.`);\n console.warn(`If you are using a custom theme, module, or service, ensure it is properly configured and registered in the settings.`);\n return null;\n }\n }\n}\n\n/**\n * \n * @param { 'Providers' | 'Routes' | 'Templates' | 'Modules' | 'Services' | 'Events' | 'Server' | undefined } [et=undefined]\n * @param { 'error' | 'success' | 'info' | 'warning' | undefined } [type=undefined]\n * @param { 'green' | 'cyan' | 'magenta' | 'blue' | 'yellow' | 'red' | 'gray' | 'black' | 'white' | undefined } [color=undefined]\n * @returns\n * Log prefix helper (safe in Node and browser).\n * Mirrors server.js behavior with optional chalk styling when available.\n */\nexport function logPrefix(\n et?: 'Providers' | 'Routes' | 'Templates' | 'Modules' | 'Services' | 'Events' | 'Server' | string,\n type?: 'error' | 'success' | 'info' | 'warning' | string,\n color?: 'green' | 'cyan' | 'magenta' | 'blue' | 'yellow' | 'red' | 'gray' | 'black' | 'white' | string\n): string {\n const label = `${et || 'Extensibles'} Manager${type ? ' | ' + type?.charAt(0).toUpperCase() + type?.slice(1) : ''}`;\n\n const getChalk = (): any => {\n if (typeof window !== 'undefined') return null;\n try {\n // eslint-disable-next-line no-eval\n const req = eval('require');\n const mod = req('chalk');\n return mod?.default ?? mod;\n } catch {\n return null;\n }\n };\n\n const chalk = getChalk();\n const wrap = (fn: ((v: string) => string) | null, value: string) => (fn ? fn(value) : value);\n\n let colored = label;\n if (chalk) {\n if (type === 'error') colored = wrap(chalk.redBright, label);\n else if (type === 'warning') colored = wrap(chalk.yellow, label);\n else if (type === 'success') colored = wrap(chalk.green, label);\n else if (type === 'info') colored = wrap(chalk.blue, label);\n else if (color === 'green') colored = wrap(chalk.green, label);\n else if (color === 'cyan') colored = wrap(chalk.cyan, label);\n else if (color === 'magenta') colored = wrap(chalk.magenta, label);\n else if (color === 'blue') colored = wrap(chalk.blue, label);\n else if (color === 'yellow') colored = wrap(chalk.yellow, label);\n else if (color === 'red') colored = wrap(chalk.red, label);\n else if (color === 'gray') colored = wrap(chalk.gray, label);\n else if (color === 'black') colored = wrap(chalk.black, label);\n else if (color === 'white') colored = wrap(chalk.white, label);\n }\n\n if (chalk?.white) {\n return chalk.white('[') + colored + chalk.white('] ');\n }\n return `[${colored}] `;\n}\n","// src/hooks/useSettings.ts\n\nimport path from 'node:path';\nimport fs from 'node:fs';\n\nimport { loadJSON, saveJSON } from './useExtensibles';\nimport type { ExtensiblePaths } from '../types'; // Adjust the import path as necessary\n\nconst defaultPaths: ExtensiblePaths = {\n modules: './app/modules',\n templates: './app/resources/themes',\n services: './app/services',\n events: './app/events',\n langs: './public/langs',\n providers: './app/providers',\n};\n\nlet extensiblePaths: ExtensiblePaths = { ...defaultPaths };\nconst isServer = typeof window === 'undefined';\n\n\nexport const useSettings = {\n getPaths(): ExtensiblePaths {\n if (isServer) {\n const json = loadJSON('./app/extensiblePaths.json');\n if (json) extensiblePaths = json;\n }\n\n if (isServer) {\n for (const key of Object.keys(defaultPaths) as Array<keyof ExtensiblePaths>) {\n const candidate = extensiblePaths[key];\n if (!candidate || !fs.existsSync(candidate)) {\n extensiblePaths[key] = defaultPaths[key];\n }\n }\n }\n\n extensiblePaths = {\n ...extensiblePaths,\n langs: './langs',\n };\n // extensiblePaths = loadJSON(\"./app/extensiblePaths.json\");\n return extensiblePaths;\n },\n\n setPaths(paths: Partial<ExtensiblePaths>): void {\n if (isServer) {\n saveJSON('./app/extensiblePaths.json', {\n ...extensiblePaths,\n ...paths,\n });\n }\n\n extensiblePaths = {\n ...extensiblePaths,\n ...paths,\n };\n },\n \n getKeyValue(key: string): string {\n return 'Coming Soon'\n },\n setKeyValue(key: string, value: string): void {\n return;\n },\n};\n","// src/hooks/useExtensibles.ts\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { useSettings } from './useSettings';\nimport type { TemplateType, ExtensibleMeta, ExtensiblePaths } from '../types';\n\nlet paths: ExtensiblePaths;\n\nfunction toFileUrl(filePath: string): string {\n const normalized = filePath.replace(/\\\\/g, '/');\n if (normalized.startsWith('file://')) return normalized;\n const prefix = normalized.startsWith('/') ? 'file://' : 'file:///';\n return `${prefix}${encodeURI(normalized)}`;\n}\n\nexport function registerExtensibles(extensiblePaths: ExtensiblePaths) {\n paths = extensiblePaths;\n}\n\nexport function loadJSON(filePath: string): any {\n if (!fs.existsSync(filePath)) return null;\n return JSON.parse(fs.readFileSync(filePath, 'utf-8'));\n}\n\nexport function saveJSON(filePath: string, data: any) {\n fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');\n}\n\n// --- MODULES ---\n\nexport function getModules(): ExtensibleMeta[] {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n\n const dirs = fs\n .readdirSync(useSettings.getPaths().modules)\n .filter((d: any) => fs.statSync(path.join(useSettings.getPaths().modules, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(useSettings.getPaths().modules, dir, 'module.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: meta.lowerName || dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isModuleEnabled(name: string) {\n const modules = getModules();\n return modules.find((m) => m.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\nexport function toggleModule(name: string, enabled: boolean) {\n const modules = getModules();\n const mod = modules.find((m) => m.lowerName === name.toLowerCase());\n if (!mod) throw new Error(`Module ${name} not found`);\n\n const metaPath = path.join(useSettings.getPaths().modules, mod.lowerName, 'module.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = enabled;\n saveJSON(metaPath, meta);\n\n if (enabled) onModuleEnabled(mod.name);\n else onModuleDisabled(mod.name);\n}\n\n// --- SERVICES ---\n\nexport function getServices(): ExtensibleMeta[] {\n if (!useSettings.getPaths().services) throw new Error('Services path not registered.');\n\n const dirs = fs\n .readdirSync(useSettings.getPaths().services)\n .filter((d: any) => fs.statSync(path.join(useSettings.getPaths().services, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(useSettings.getPaths().services, dir, 'service.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: meta.lowerName || dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isServiceEnabled(name: string) {\n const services = getServices();\n return services.find((s) => s.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\nexport function toggleService(name: string, enabled: boolean) {\n const services = getServices();\n const svc = services.find((s) => s.lowerName === name.toLowerCase());\n if (!svc) throw new Error(`Service ${name} not found`);\n\n const metaPath = path.join(useSettings.getPaths().services, svc.lowerName, 'service.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = enabled;\n saveJSON(metaPath, meta);\n\n if (enabled) onServiceEnabled(svc.name);\n else onServiceDisabled(svc.name);\n}\n\n// --- TEMPLATES ---\n\n// Helper to get base path for a template type\nfunction getTemplateBasePath(type: TemplateType): string {\n if (!useSettings.getPaths().templates) throw new Error('Templates path not registered.');\n switch (type) {\n case 'admin-theme':\n case 'client-theme':\n return path.join(useSettings.getPaths().templates, 'themes');\n case 'portal':\n return path.join(useSettings.getPaths().templates, 'portals');\n case 'email':\n return path.join(useSettings.getPaths().templates, 'emails');\n default:\n throw new Error(`Unknown template type: ${type}`);\n }\n}\n\nexport function getTemplates(type: TemplateType): ExtensibleMeta[] {\n const basePath = getTemplateBasePath(type);\n if (!fs.existsSync(basePath)) return [];\n\n const dirs = fs\n .readdirSync(basePath)\n .filter((d: any) => fs.statSync(path.join(basePath, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(basePath, dir, 'template.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isTemplateActive(type: TemplateType, name: string) {\n const templates = getTemplates(type);\n return templates.find((t) => t.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\n// Toggle templates: only 1 active per type allowed\nexport function toggleTemplate(type: TemplateType, name: string) {\n const templates = getTemplates(type);\n\n templates.forEach((tpl) => {\n const metaPath = path.join(getTemplateBasePath(type), tpl.lowerName, 'template.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = tpl.lowerName === name.toLowerCase();\n saveJSON(metaPath, meta);\n });\n\n onTemplateSelect(type, name);\n}\n\n// --- EVENTS (replace with your event system integration) ---\n\nexport function onModuleEnabled(name: string) {\n console.log(`Module enabled: ${name}`);\n // emit event or custom logic here\n}\n\nexport function onModuleDisabled(name: string) {\n console.log(`Module disabled: ${name}`);\n}\n\nexport function onServiceEnabled(name: string) {\n console.log(`Service enabled: ${name}`);\n}\n\nexport function onServiceDisabled(name: string) {\n console.log(`Service disabled: ${name}`);\n}\n\nexport function onTemplateSelect(type: TemplateType, name: string) {\n console.log(`Template selected: type=${type}, name=${name}`);\n}\n\n// --- REGISTER HOOKS FOR MODULES ---\n\nexport async function registerEvents() {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n const modules = getModules().filter((m) => m.enabled);\n for (const mod of modules) {\n const eventsFile = path.join(useSettings.getPaths().modules, mod.lowerName, 'events.server.js');\n if (fs.existsSync(eventsFile)) {\n const modEvents = await import(eventsFile);\n if (modEvents?.registerEvents) await modEvents.registerEvents();\n }\n }\n}\n\nexport async function registerMiddleware() {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n const modules = getModules().filter((m) => m.enabled);\n for (const mod of modules) {\n const middlewareFile = path.join(useSettings.getPaths().modules, mod.lowerName, 'middleware.server.js');\n if (fs.existsSync(middlewareFile)) {\n const modMiddleware = await import(middlewareFile);\n if (modMiddleware?.registerMiddleware) await modMiddleware.registerMiddleware();\n }\n }\n}\n\n/**\n * Registers routes given a path to routes folder (for pages and API routes)\n * @param routesFolderPath string - path to module/service routes folder\n */\nexport async function registerRoutes(routesFolderPath: string) {\n if (!fs.existsSync(routesFolderPath)) return;\n\n const routeFiles = fs.readdirSync(routesFolderPath).filter((f: any) => /\\.(js|ts|jsx|tsx)$/.test(f));\n for (const file of routeFiles) {\n const routeModule = await import(path.join(routesFolderPath, file));\n if (routeModule?.registerRoute) {\n await routeModule.registerRoute();\n }\n }\n}\n\nexport async function loadProviders() {\n const paths = useSettings.getPaths();\n\n const all = [\n { type: 'module', list: getModules(), basePath: paths.modules },\n { type: 'service', list: getServices(), basePath: paths.services },\n ];\n\n for (const { type, list, basePath } of all) {\n for (const item of list) {\n if (!item.enabled) continue;\n\n const metaPath = path.join(path.resolve(basePath), item.lowerName, `${type}.json`);\n const meta = loadJSON(metaPath);\n if (!meta?.providers || !Array.isArray(meta.providers)) continue;\n\n for (const providerRelPath of meta.providers) {\n try {\n let providerAbsPath = path.join(path.resolve(basePath), item.lowerName, providerRelPath);\n\n // Try .js fallback if file is .ts or .tsx\n const ext = path.extname(providerAbsPath);\n if (ext === '.ts' || ext === '.tsx') {\n const jsPath = providerAbsPath.replace(/\\.(ts|tsx)$/, '.js');\n try {\n await fs.accessSync(jsPath); // Check if compiled JS file exists\n providerAbsPath = jsPath;\n } catch {\n throw new Error(`Compiled JS version not found for provider: ${providerRelPath}`);\n }\n }\n\n const providerUrl = toFileUrl(providerAbsPath);\n const providerModule = await import(providerUrl);\n\n if (typeof providerModule.default === 'function') {\n // Expose context so nav registration can auto-tag module/service\n (globalThis as any).__retrex_provider_context__ = {\n type,\n name: item.lowerName,\n };\n await providerModule.default();\n (globalThis as any).__retrex_provider_context__ = undefined;\n console.log(`[${type}] ✅ Provider loaded: ${providerRelPath}`);\n } else {\n console.warn(`[${type}] ⚠️ Provider ${providerRelPath} has no default export.`);\n }\n } catch (err) {\n console.error(`[${type}] ❌ Failed to load provider ${providerRelPath}:`, err);\n }\n }\n }\n }\n}\n\n\n// export async function loadProviders() {\n// paths = {\n// modules: useSettings.getPaths().modules,\n// templates: useSettings.getPaths().templates,\n// services: useSettings.getPaths().services,\n// events: useSettings.getPaths().events,\n// }\n// const all = [\n// { type: 'module', list: getModules(), basePath: useSettings.getPaths().modules },\n// { type: 'service', list: getServices(), basePath: useSettings.getPaths().services },\n// ];\n\n// for (const { type, list, basePath } of all) {\n// for (const item of list) {\n// if (!item.enabled) continue;\n\n// const metaPath = path.join(basePath, item.lowerName, `${type}.json`);\n// const meta = loadJSON(metaPath);\n// if (!meta?.providers || !Array.isArray(meta.providers)) continue;\n\n// for (const providerRelPath of meta.providers) {\n// try {\n// const providerPath = path.join(basePath, item.lowerName, providerRelPath);\n// const providerModule = await import(providerPath);\n// if (typeof providerModule.default === 'function') {\n// await providerModule.default(); // Call provider\n// console.log(`[${type}] Provider loaded: ${providerRelPath}`);\n// } else {\n// console.warn(`[${type}] Provider ${providerRelPath} has no default export.`);\n// }\n// } catch (err) {\n// console.error(`[${type}] Failed to load provider ${providerRelPath}:`, err);\n// }\n// }\n// }\n// }\n// }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAAA,oBAAiB;AAC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,SAAO,IAAI,OAAO;AACpB;","names":["import_node_path","import_node_fs","import_node_fs","fs","fs","path","fs","mod"]}
|
|
@@ -13,6 +13,11 @@ declare const useUtils: {
|
|
|
13
13
|
}): Promise<React.ComponentType<any> | null>;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
+
*
|
|
17
|
+
* @param { 'Providers' | 'Routes' | 'Templates' | 'Modules' | 'Services' | 'Events' | 'Server' | undefined } [et=undefined]
|
|
18
|
+
* @param { 'error' | 'success' | 'info' | 'warning' | undefined } [type=undefined]
|
|
19
|
+
* @param { 'green' | 'cyan' | 'magenta' | 'blue' | 'yellow' | 'red' | 'gray' | 'black' | 'white' | undefined } [color=undefined]
|
|
20
|
+
* @returns
|
|
16
21
|
* Log prefix helper (safe in Node and browser).
|
|
17
22
|
* Mirrors server.js behavior with optional chalk styling when available.
|
|
18
23
|
*/
|
|
@@ -13,6 +13,11 @@ declare const useUtils: {
|
|
|
13
13
|
}): Promise<React.ComponentType<any> | null>;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
+
*
|
|
17
|
+
* @param { 'Providers' | 'Routes' | 'Templates' | 'Modules' | 'Services' | 'Events' | 'Server' | undefined } [et=undefined]
|
|
18
|
+
* @param { 'error' | 'success' | 'info' | 'warning' | undefined } [type=undefined]
|
|
19
|
+
* @param { 'green' | 'cyan' | 'magenta' | 'blue' | 'yellow' | 'red' | 'gray' | 'black' | 'white' | undefined } [color=undefined]
|
|
20
|
+
* @returns
|
|
16
21
|
* Log prefix helper (safe in Node and browser).
|
|
17
22
|
* Mirrors server.js behavior with optional chalk styling when available.
|
|
18
23
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/hooks/useUtils.ts","../../../src/core/hooks/useSettings.ts","../../../src/core/hooks/useExtensibles.ts"],"sourcesContent":["/* @vite-ignore */\n// packages/retrex-extensibles-core/hooks/useUtils.ts\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport { useSettings } from './useSettings';\n\nfunction toFileUrl(filePath: string): string {\n const normalized = filePath.replace(/\\\\/g, '/');\n if (normalized.startsWith('file://')) return normalized;\n const prefix = normalized.startsWith('/') ? 'file://' : 'file:///';\n return `${prefix}${encodeURI(normalized)}`;\n}\n\nexport const useUtils = {\n logPrefix,\n async loadThemeComponent(\n componentName: string,\n options: {\n theme: {\n name: string;\n type: 'admin' | 'client' | 'portal' | 'email';\n };\n search?: {\n themes?: boolean;\n modules?: boolean;\n services?: boolean;\n };\n }\n ): Promise<React.ComponentType<any> | null> {\n const { search = {}, theme } = options;\n const searchThemes = search.themes ?? true;\n const searchModules = search.modules ?? true;\n const searchServices = search.services ?? true;\n\n const possiblePaths: string[] = [];\n\n console.log(`Searching for component \"${componentName}\" in theme \"${theme.name}\" of type \"${theme.type}\"...`);\n\n try {\n if (searchThemes) {\n const templatesRoot = path.resolve(useSettings.getPaths().templates);\n possiblePaths.push(\n path.resolve(\n templatesRoot,\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n \n if (searchModules) {\n const modulesRoot = path.resolve(useSettings.getPaths().modules);\n if (fs.existsSync(modulesRoot)) {\n const moduleDirs = await fs.readdirSync(modulesRoot);\n for (const mod of moduleDirs) {\n possiblePaths.push(\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n }\n }\n \n if (searchServices) {\n const servicesRoot = path.resolve(useSettings.getPaths().services);\n if (fs.existsSync(servicesRoot)) {\n const serviceDirs = await fs.readdirSync(servicesRoot);\n for (const svc of serviceDirs) {\n possiblePaths.push(\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n }\n }\n \n for (const filePath of possiblePaths) {\n if (await fs.existsSync(filePath)) {\n try {\n const mod = await import(toFileUrl(filePath));\n if (mod.default) return mod.default;\n } catch (err) {\n console.error(`Error loading component at ${filePath}:`, err);\n }\n }\n }\n \n console.warn(`Component \"${componentName}\" not found in theme \"${theme.name}\" of type \"${theme.type}\".`);\n return null;\n } catch (err) {\n console.error(`Error searching for component \"${componentName}\":`, err);\n console.warn(`Component \"${componentName}\" not found in theme \"${theme.name}\" of type \"${theme.type}\".`);\n console.warn(`Searched paths:`, possiblePaths);\n console.warn(`Ensure the component exists in the specified theme and type.`);\n console.warn(`If the component is in a module or service, ensure the theme structure is correct.`);\n console.warn(`If you are using a custom theme, module, or service, ensure it is properly configured and registered in the settings.`);\n return null;\n }\n }\n}\n\n/**\n * Log prefix helper (safe in Node and browser).\n * Mirrors server.js behavior with optional chalk styling when available.\n */\nexport function logPrefix(\n et?: 'Providers' | 'Routes' | 'Templates' | 'Modules' | 'Services' | 'Events' | 'Server' | string,\n type?: 'error' | 'success' | 'info' | 'warning' | string,\n color?: 'green' | 'cyan' | 'magenta' | 'blue' | 'yellow' | 'red' | 'gray' | 'black' | 'white' | string\n): string {\n const label = `${et || 'Extensibles'} Manager${type ? ' | ' + type?.charAt(0).toUpperCase() + type?.slice(1) : ''}`;\n\n const getChalk = (): any => {\n if (typeof window !== 'undefined') return null;\n try {\n // eslint-disable-next-line no-eval\n const req = eval('require');\n const mod = req('chalk');\n return mod?.default ?? mod;\n } catch {\n return null;\n }\n };\n\n const chalk = getChalk();\n const wrap = (fn: ((v: string) => string) | null, value: string) => (fn ? fn(value) : value);\n\n let colored = label;\n if (chalk) {\n if (type === 'error') colored = wrap(chalk.redBright, label);\n else if (type === 'warning') colored = wrap(chalk.yellow, label);\n else if (type === 'success') colored = wrap(chalk.green, label);\n else if (type === 'info') colored = wrap(chalk.blue, label);\n else if (color === 'green') colored = wrap(chalk.green, label);\n else if (color === 'cyan') colored = wrap(chalk.cyan, label);\n else if (color === 'magenta') colored = wrap(chalk.magenta, label);\n else if (color === 'blue') colored = wrap(chalk.blue, label);\n else if (color === 'yellow') colored = wrap(chalk.yellow, label);\n else if (color === 'red') colored = wrap(chalk.red, label);\n else if (color === 'gray') colored = wrap(chalk.gray, label);\n else if (color === 'black') colored = wrap(chalk.black, label);\n else if (color === 'white') colored = wrap(chalk.white, label);\n }\n\n if (chalk?.white) {\n return chalk.white('[') + colored + chalk.white('] ');\n }\n return `[${colored}] `;\n}\n","// src/hooks/useSettings.ts\n\nimport path from 'node:path';\nimport fs from 'node:fs';\n\nimport { loadJSON, saveJSON } from './useExtensibles';\nimport type { ExtensiblePaths } from '../types'; // Adjust the import path as necessary\n\nconst defaultPaths: ExtensiblePaths = {\n modules: './app/modules',\n templates: './app/resources/themes',\n services: './app/services',\n events: './app/events',\n langs: './public/langs',\n providers: './app/providers',\n};\n\nlet extensiblePaths: ExtensiblePaths = { ...defaultPaths };\nconst isServer = typeof window === 'undefined';\n\n\nexport const useSettings = {\n getPaths(): ExtensiblePaths {\n if (isServer) {\n const json = loadJSON('./app/extensiblePaths.json');\n if (json) extensiblePaths = json;\n }\n\n if (isServer) {\n for (const key of Object.keys(defaultPaths) as Array<keyof ExtensiblePaths>) {\n const candidate = extensiblePaths[key];\n if (!candidate || !fs.existsSync(candidate)) {\n extensiblePaths[key] = defaultPaths[key];\n }\n }\n }\n\n extensiblePaths = {\n ...extensiblePaths,\n langs: './langs',\n };\n // extensiblePaths = loadJSON(\"./app/extensiblePaths.json\");\n return extensiblePaths;\n },\n\n setPaths(paths: Partial<ExtensiblePaths>): void {\n if (isServer) {\n saveJSON('./app/extensiblePaths.json', {\n ...extensiblePaths,\n ...paths,\n });\n }\n\n extensiblePaths = {\n ...extensiblePaths,\n ...paths,\n };\n },\n \n getKeyValue(key: string): string {\n return 'Coming Soon'\n },\n setKeyValue(key: string, value: string): void {\n return;\n },\n};\n","// src/hooks/useExtensibles.ts\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { useSettings } from './useSettings';\nimport type { TemplateType, ExtensibleMeta, ExtensiblePaths } from '../types';\n\nlet paths: ExtensiblePaths;\n\nfunction toFileUrl(filePath: string): string {\n const normalized = filePath.replace(/\\\\/g, '/');\n if (normalized.startsWith('file://')) return normalized;\n const prefix = normalized.startsWith('/') ? 'file://' : 'file:///';\n return `${prefix}${encodeURI(normalized)}`;\n}\n\nexport function registerExtensibles(extensiblePaths: ExtensiblePaths) {\n paths = extensiblePaths;\n}\n\nexport function loadJSON(filePath: string): any {\n if (!fs.existsSync(filePath)) return null;\n return JSON.parse(fs.readFileSync(filePath, 'utf-8'));\n}\n\nexport function saveJSON(filePath: string, data: any) {\n fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');\n}\n\n// --- MODULES ---\n\nexport function getModules(): ExtensibleMeta[] {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n\n const dirs = fs\n .readdirSync(useSettings.getPaths().modules)\n .filter((d: any) => fs.statSync(path.join(useSettings.getPaths().modules, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(useSettings.getPaths().modules, dir, 'module.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: meta.lowerName || dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isModuleEnabled(name: string) {\n const modules = getModules();\n return modules.find((m) => m.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\nexport function toggleModule(name: string, enabled: boolean) {\n const modules = getModules();\n const mod = modules.find((m) => m.lowerName === name.toLowerCase());\n if (!mod) throw new Error(`Module ${name} not found`);\n\n const metaPath = path.join(useSettings.getPaths().modules, mod.lowerName, 'module.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = enabled;\n saveJSON(metaPath, meta);\n\n if (enabled) onModuleEnabled(mod.name);\n else onModuleDisabled(mod.name);\n}\n\n// --- SERVICES ---\n\nexport function getServices(): ExtensibleMeta[] {\n if (!useSettings.getPaths().services) throw new Error('Services path not registered.');\n\n const dirs = fs\n .readdirSync(useSettings.getPaths().services)\n .filter((d: any) => fs.statSync(path.join(useSettings.getPaths().services, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(useSettings.getPaths().services, dir, 'service.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: meta.lowerName || dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isServiceEnabled(name: string) {\n const services = getServices();\n return services.find((s) => s.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\nexport function toggleService(name: string, enabled: boolean) {\n const services = getServices();\n const svc = services.find((s) => s.lowerName === name.toLowerCase());\n if (!svc) throw new Error(`Service ${name} not found`);\n\n const metaPath = path.join(useSettings.getPaths().services, svc.lowerName, 'service.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = enabled;\n saveJSON(metaPath, meta);\n\n if (enabled) onServiceEnabled(svc.name);\n else onServiceDisabled(svc.name);\n}\n\n// --- TEMPLATES ---\n\n// Helper to get base path for a template type\nfunction getTemplateBasePath(type: TemplateType): string {\n if (!useSettings.getPaths().templates) throw new Error('Templates path not registered.');\n switch (type) {\n case 'admin-theme':\n case 'client-theme':\n return path.join(useSettings.getPaths().templates, 'themes');\n case 'portal':\n return path.join(useSettings.getPaths().templates, 'portals');\n case 'email':\n return path.join(useSettings.getPaths().templates, 'emails');\n default:\n throw new Error(`Unknown template type: ${type}`);\n }\n}\n\nexport function getTemplates(type: TemplateType): ExtensibleMeta[] {\n const basePath = getTemplateBasePath(type);\n if (!fs.existsSync(basePath)) return [];\n\n const dirs = fs\n .readdirSync(basePath)\n .filter((d: any) => fs.statSync(path.join(basePath, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(basePath, dir, 'template.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isTemplateActive(type: TemplateType, name: string) {\n const templates = getTemplates(type);\n return templates.find((t) => t.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\n// Toggle templates: only 1 active per type allowed\nexport function toggleTemplate(type: TemplateType, name: string) {\n const templates = getTemplates(type);\n\n templates.forEach((tpl) => {\n const metaPath = path.join(getTemplateBasePath(type), tpl.lowerName, 'template.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = tpl.lowerName === name.toLowerCase();\n saveJSON(metaPath, meta);\n });\n\n onTemplateSelect(type, name);\n}\n\n// --- EVENTS (replace with your event system integration) ---\n\nexport function onModuleEnabled(name: string) {\n console.log(`Module enabled: ${name}`);\n // emit event or custom logic here\n}\n\nexport function onModuleDisabled(name: string) {\n console.log(`Module disabled: ${name}`);\n}\n\nexport function onServiceEnabled(name: string) {\n console.log(`Service enabled: ${name}`);\n}\n\nexport function onServiceDisabled(name: string) {\n console.log(`Service disabled: ${name}`);\n}\n\nexport function onTemplateSelect(type: TemplateType, name: string) {\n console.log(`Template selected: type=${type}, name=${name}`);\n}\n\n// --- REGISTER HOOKS FOR MODULES ---\n\nexport async function registerEvents() {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n const modules = getModules().filter((m) => m.enabled);\n for (const mod of modules) {\n const eventsFile = path.join(useSettings.getPaths().modules, mod.lowerName, 'events.server.js');\n if (fs.existsSync(eventsFile)) {\n const modEvents = await import(eventsFile);\n if (modEvents?.registerEvents) await modEvents.registerEvents();\n }\n }\n}\n\nexport async function registerMiddleware() {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n const modules = getModules().filter((m) => m.enabled);\n for (const mod of modules) {\n const middlewareFile = path.join(useSettings.getPaths().modules, mod.lowerName, 'middleware.server.js');\n if (fs.existsSync(middlewareFile)) {\n const modMiddleware = await import(middlewareFile);\n if (modMiddleware?.registerMiddleware) await modMiddleware.registerMiddleware();\n }\n }\n}\n\n/**\n * Registers routes given a path to routes folder (for pages and API routes)\n * @param routesFolderPath string - path to module/service routes folder\n */\nexport async function registerRoutes(routesFolderPath: string) {\n if (!fs.existsSync(routesFolderPath)) return;\n\n const routeFiles = fs.readdirSync(routesFolderPath).filter((f: any) => /\\.(js|ts|jsx|tsx)$/.test(f));\n for (const file of routeFiles) {\n const routeModule = await import(path.join(routesFolderPath, file));\n if (routeModule?.registerRoute) {\n await routeModule.registerRoute();\n }\n }\n}\n\nexport async function loadProviders() {\n const paths = useSettings.getPaths();\n\n const all = [\n { type: 'module', list: getModules(), basePath: paths.modules },\n { type: 'service', list: getServices(), basePath: paths.services },\n ];\n\n for (const { type, list, basePath } of all) {\n for (const item of list) {\n if (!item.enabled) continue;\n\n const metaPath = path.join(path.resolve(basePath), item.lowerName, `${type}.json`);\n const meta = loadJSON(metaPath);\n if (!meta?.providers || !Array.isArray(meta.providers)) continue;\n\n for (const providerRelPath of meta.providers) {\n try {\n let providerAbsPath = path.join(path.resolve(basePath), item.lowerName, providerRelPath);\n\n // Try .js fallback if file is .ts or .tsx\n const ext = path.extname(providerAbsPath);\n if (ext === '.ts' || ext === '.tsx') {\n const jsPath = providerAbsPath.replace(/\\.(ts|tsx)$/, '.js');\n try {\n await fs.accessSync(jsPath); // Check if compiled JS file exists\n providerAbsPath = jsPath;\n } catch {\n throw new Error(`Compiled JS version not found for provider: ${providerRelPath}`);\n }\n }\n\n const providerUrl = toFileUrl(providerAbsPath);\n const providerModule = await import(providerUrl);\n\n if (typeof providerModule.default === 'function') {\n // Expose context so nav registration can auto-tag module/service\n (globalThis as any).__retrex_provider_context__ = {\n type,\n name: item.lowerName,\n };\n await providerModule.default();\n (globalThis as any).__retrex_provider_context__ = undefined;\n console.log(`[${type}] ✅ Provider loaded: ${providerRelPath}`);\n } else {\n console.warn(`[${type}] ⚠️ Provider ${providerRelPath} has no default export.`);\n }\n } catch (err) {\n console.error(`[${type}] ❌ Failed to load provider ${providerRelPath}:`, err);\n }\n }\n }\n }\n}\n\n\n// export async function loadProviders() {\n// paths = {\n// modules: useSettings.getPaths().modules,\n// templates: useSettings.getPaths().templates,\n// services: useSettings.getPaths().services,\n// events: useSettings.getPaths().events,\n// }\n// const all = [\n// { type: 'module', list: getModules(), basePath: useSettings.getPaths().modules },\n// { type: 'service', list: getServices(), basePath: useSettings.getPaths().services },\n// ];\n\n// for (const { type, list, basePath } of all) {\n// for (const item of list) {\n// if (!item.enabled) continue;\n\n// const metaPath = path.join(basePath, item.lowerName, `${type}.json`);\n// const meta = loadJSON(metaPath);\n// if (!meta?.providers || !Array.isArray(meta.providers)) continue;\n\n// for (const providerRelPath of meta.providers) {\n// try {\n// const providerPath = path.join(basePath, item.lowerName, providerRelPath);\n// const providerModule = await import(providerPath);\n// if (typeof providerModule.default === 'function') {\n// await providerModule.default(); // Call provider\n// console.log(`[${type}] Provider loaded: ${providerRelPath}`);\n// } else {\n// console.warn(`[${type}] Provider ${providerRelPath} has no default export.`);\n// }\n// } catch (err) {\n// console.error(`[${type}] Failed to load provider ${providerRelPath}:`, err);\n// }\n// }\n// }\n// }\n// }\n"],"mappings":";AAEA,OAAOA,WAAU;AACjB,OAAOC,SAAQ;;;ACAf,OAAOC,SAAQ;;;ACDf,OAAO,QAAQ;AACf,OAAO,UAAU;AAiBV,SAAS,SAAS,UAAuB;AAC9C,MAAI,CAAC,GAAG,WAAW,QAAQ,EAAG,QAAO;AACrC,SAAO,KAAK,MAAM,GAAG,aAAa,UAAU,OAAO,CAAC;AACtD;AAEO,SAAS,SAAS,UAAkB,MAAW;AACpD,KAAG,cAAc,UAAU,KAAK,UAAU,MAAM,MAAM,CAAC,GAAG,OAAO;AACnE;;;ADnBA,IAAM,eAAgC;AAAA,EACpC,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,WAAW;AACb;AAEA,IAAI,kBAAmC,EAAE,GAAG,aAAa;AACzD,IAAM,WAAW,OAAO,WAAW;AAG5B,IAAM,cAAc;AAAA,EACzB,WAA4B;AAC1B,QAAI,UAAU;AACZ,YAAM,OAAO,SAAS,4BAA4B;AAClD,UAAI,KAAM,mBAAkB;AAAA,IAC9B;AAEA,QAAI,UAAU;AACZ,iBAAW,OAAO,OAAO,KAAK,YAAY,GAAmC;AAC3E,cAAM,YAAY,gBAAgB,GAAG;AACrC,YAAI,CAAC,aAAa,CAACC,IAAG,WAAW,SAAS,GAAG;AAC3C,0BAAgB,GAAG,IAAI,aAAa,GAAG;AAAA,QACzC;AAAA,MACF;AAAA,IACF;AAEA,sBAAkB;AAAA,MAChB,GAAG;AAAA,MACH,OAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,OAAuC;AAC9C,QAAI,UAAU;AACZ,eAAS,8BAA8B;AAAA,QACrC,GAAG;AAAA,QACH,GAAG;AAAA,MACL,CAAC;AAAA,IACH;AAEA,sBAAkB;AA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","fs","path","fs","mod"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/core/hooks/useUtils.ts","../../../src/core/hooks/useSettings.ts","../../../src/core/hooks/useExtensibles.ts"],"sourcesContent":["/* @vite-ignore */\n// packages/retrex-extensibles-core/hooks/useUtils.ts\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport { useSettings } from './useSettings';\n\nfunction toFileUrl(filePath: string): string {\n const normalized = filePath.replace(/\\\\/g, '/');\n if (normalized.startsWith('file://')) return normalized;\n const prefix = normalized.startsWith('/') ? 'file://' : 'file:///';\n return `${prefix}${encodeURI(normalized)}`;\n}\n\nexport const useUtils = {\n logPrefix,\n async loadThemeComponent(\n componentName: string,\n options: {\n theme: {\n name: string;\n type: 'admin' | 'client' | 'portal' | 'email';\n };\n search?: {\n themes?: boolean;\n modules?: boolean;\n services?: boolean;\n };\n }\n ): Promise<React.ComponentType<any> | null> {\n const { search = {}, theme } = options;\n const searchThemes = search.themes ?? true;\n const searchModules = search.modules ?? true;\n const searchServices = search.services ?? true;\n\n const possiblePaths: string[] = [];\n\n console.log(`Searching for component \"${componentName}\" in theme \"${theme.name}\" of type \"${theme.type}\"...`);\n\n try {\n if (searchThemes) {\n const templatesRoot = path.resolve(useSettings.getPaths().templates);\n possiblePaths.push(\n path.resolve(\n templatesRoot,\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n templatesRoot,\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n \n if (searchModules) {\n const modulesRoot = path.resolve(useSettings.getPaths().modules);\n if (fs.existsSync(modulesRoot)) {\n const moduleDirs = await fs.readdirSync(modulesRoot);\n for (const mod of moduleDirs) {\n possiblePaths.push(\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n modulesRoot,\n mod,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n }\n }\n \n if (searchServices) {\n const servicesRoot = path.resolve(useSettings.getPaths().services);\n if (fs.existsSync(servicesRoot)) {\n const serviceDirs = await fs.readdirSync(servicesRoot);\n for (const svc of serviceDirs) {\n possiblePaths.push(\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n theme.name,\n 'components',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'routes',\n `${componentName}.tsx`\n ),\n path.resolve(\n servicesRoot,\n svc,\n 'resources',\n 'themes',\n theme.type,\n 'default',\n 'components',\n `${componentName}.tsx`\n )\n );\n }\n }\n }\n \n for (const filePath of possiblePaths) {\n if (await fs.existsSync(filePath)) {\n try {\n const mod = await import(toFileUrl(filePath));\n if (mod.default) return mod.default;\n } catch (err) {\n console.error(`Error loading component at ${filePath}:`, err);\n }\n }\n }\n \n console.warn(`Component \"${componentName}\" not found in theme \"${theme.name}\" of type \"${theme.type}\".`);\n return null;\n } catch (err) {\n console.error(`Error searching for component \"${componentName}\":`, err);\n console.warn(`Component \"${componentName}\" not found in theme \"${theme.name}\" of type \"${theme.type}\".`);\n console.warn(`Searched paths:`, possiblePaths);\n console.warn(`Ensure the component exists in the specified theme and type.`);\n console.warn(`If the component is in a module or service, ensure the theme structure is correct.`);\n console.warn(`If you are using a custom theme, module, or service, ensure it is properly configured and registered in the settings.`);\n return null;\n }\n }\n}\n\n/**\n * \n * @param { 'Providers' | 'Routes' | 'Templates' | 'Modules' | 'Services' | 'Events' | 'Server' | undefined } [et=undefined]\n * @param { 'error' | 'success' | 'info' | 'warning' | undefined } [type=undefined]\n * @param { 'green' | 'cyan' | 'magenta' | 'blue' | 'yellow' | 'red' | 'gray' | 'black' | 'white' | undefined } [color=undefined]\n * @returns\n * Log prefix helper (safe in Node and browser).\n * Mirrors server.js behavior with optional chalk styling when available.\n */\nexport function logPrefix(\n et?: 'Providers' | 'Routes' | 'Templates' | 'Modules' | 'Services' | 'Events' | 'Server' | string,\n type?: 'error' | 'success' | 'info' | 'warning' | string,\n color?: 'green' | 'cyan' | 'magenta' | 'blue' | 'yellow' | 'red' | 'gray' | 'black' | 'white' | string\n): string {\n const label = `${et || 'Extensibles'} Manager${type ? ' | ' + type?.charAt(0).toUpperCase() + type?.slice(1) : ''}`;\n\n const getChalk = (): any => {\n if (typeof window !== 'undefined') return null;\n try {\n // eslint-disable-next-line no-eval\n const req = eval('require');\n const mod = req('chalk');\n return mod?.default ?? mod;\n } catch {\n return null;\n }\n };\n\n const chalk = getChalk();\n const wrap = (fn: ((v: string) => string) | null, value: string) => (fn ? fn(value) : value);\n\n let colored = label;\n if (chalk) {\n if (type === 'error') colored = wrap(chalk.redBright, label);\n else if (type === 'warning') colored = wrap(chalk.yellow, label);\n else if (type === 'success') colored = wrap(chalk.green, label);\n else if (type === 'info') colored = wrap(chalk.blue, label);\n else if (color === 'green') colored = wrap(chalk.green, label);\n else if (color === 'cyan') colored = wrap(chalk.cyan, label);\n else if (color === 'magenta') colored = wrap(chalk.magenta, label);\n else if (color === 'blue') colored = wrap(chalk.blue, label);\n else if (color === 'yellow') colored = wrap(chalk.yellow, label);\n else if (color === 'red') colored = wrap(chalk.red, label);\n else if (color === 'gray') colored = wrap(chalk.gray, label);\n else if (color === 'black') colored = wrap(chalk.black, label);\n else if (color === 'white') colored = wrap(chalk.white, label);\n }\n\n if (chalk?.white) {\n return chalk.white('[') + colored + chalk.white('] ');\n }\n return `[${colored}] `;\n}\n","// src/hooks/useSettings.ts\n\nimport path from 'node:path';\nimport fs from 'node:fs';\n\nimport { loadJSON, saveJSON } from './useExtensibles';\nimport type { ExtensiblePaths } from '../types'; // Adjust the import path as necessary\n\nconst defaultPaths: ExtensiblePaths = {\n modules: './app/modules',\n templates: './app/resources/themes',\n services: './app/services',\n events: './app/events',\n langs: './public/langs',\n providers: './app/providers',\n};\n\nlet extensiblePaths: ExtensiblePaths = { ...defaultPaths };\nconst isServer = typeof window === 'undefined';\n\n\nexport const useSettings = {\n getPaths(): ExtensiblePaths {\n if (isServer) {\n const json = loadJSON('./app/extensiblePaths.json');\n if (json) extensiblePaths = json;\n }\n\n if (isServer) {\n for (const key of Object.keys(defaultPaths) as Array<keyof ExtensiblePaths>) {\n const candidate = extensiblePaths[key];\n if (!candidate || !fs.existsSync(candidate)) {\n extensiblePaths[key] = defaultPaths[key];\n }\n }\n }\n\n extensiblePaths = {\n ...extensiblePaths,\n langs: './langs',\n };\n // extensiblePaths = loadJSON(\"./app/extensiblePaths.json\");\n return extensiblePaths;\n },\n\n setPaths(paths: Partial<ExtensiblePaths>): void {\n if (isServer) {\n saveJSON('./app/extensiblePaths.json', {\n ...extensiblePaths,\n ...paths,\n });\n }\n\n extensiblePaths = {\n ...extensiblePaths,\n ...paths,\n };\n },\n \n getKeyValue(key: string): string {\n return 'Coming Soon'\n },\n setKeyValue(key: string, value: string): void {\n return;\n },\n};\n","// src/hooks/useExtensibles.ts\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { useSettings } from './useSettings';\nimport type { TemplateType, ExtensibleMeta, ExtensiblePaths } from '../types';\n\nlet paths: ExtensiblePaths;\n\nfunction toFileUrl(filePath: string): string {\n const normalized = filePath.replace(/\\\\/g, '/');\n if (normalized.startsWith('file://')) return normalized;\n const prefix = normalized.startsWith('/') ? 'file://' : 'file:///';\n return `${prefix}${encodeURI(normalized)}`;\n}\n\nexport function registerExtensibles(extensiblePaths: ExtensiblePaths) {\n paths = extensiblePaths;\n}\n\nexport function loadJSON(filePath: string): any {\n if (!fs.existsSync(filePath)) return null;\n return JSON.parse(fs.readFileSync(filePath, 'utf-8'));\n}\n\nexport function saveJSON(filePath: string, data: any) {\n fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');\n}\n\n// --- MODULES ---\n\nexport function getModules(): ExtensibleMeta[] {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n\n const dirs = fs\n .readdirSync(useSettings.getPaths().modules)\n .filter((d: any) => fs.statSync(path.join(useSettings.getPaths().modules, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(useSettings.getPaths().modules, dir, 'module.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: meta.lowerName || dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isModuleEnabled(name: string) {\n const modules = getModules();\n return modules.find((m) => m.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\nexport function toggleModule(name: string, enabled: boolean) {\n const modules = getModules();\n const mod = modules.find((m) => m.lowerName === name.toLowerCase());\n if (!mod) throw new Error(`Module ${name} not found`);\n\n const metaPath = path.join(useSettings.getPaths().modules, mod.lowerName, 'module.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = enabled;\n saveJSON(metaPath, meta);\n\n if (enabled) onModuleEnabled(mod.name);\n else onModuleDisabled(mod.name);\n}\n\n// --- SERVICES ---\n\nexport function getServices(): ExtensibleMeta[] {\n if (!useSettings.getPaths().services) throw new Error('Services path not registered.');\n\n const dirs = fs\n .readdirSync(useSettings.getPaths().services)\n .filter((d: any) => fs.statSync(path.join(useSettings.getPaths().services, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(useSettings.getPaths().services, dir, 'service.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: meta.lowerName || dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isServiceEnabled(name: string) {\n const services = getServices();\n return services.find((s) => s.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\nexport function toggleService(name: string, enabled: boolean) {\n const services = getServices();\n const svc = services.find((s) => s.lowerName === name.toLowerCase());\n if (!svc) throw new Error(`Service ${name} not found`);\n\n const metaPath = path.join(useSettings.getPaths().services, svc.lowerName, 'service.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = enabled;\n saveJSON(metaPath, meta);\n\n if (enabled) onServiceEnabled(svc.name);\n else onServiceDisabled(svc.name);\n}\n\n// --- TEMPLATES ---\n\n// Helper to get base path for a template type\nfunction getTemplateBasePath(type: TemplateType): string {\n if (!useSettings.getPaths().templates) throw new Error('Templates path not registered.');\n switch (type) {\n case 'admin-theme':\n case 'client-theme':\n return path.join(useSettings.getPaths().templates, 'themes');\n case 'portal':\n return path.join(useSettings.getPaths().templates, 'portals');\n case 'email':\n return path.join(useSettings.getPaths().templates, 'emails');\n default:\n throw new Error(`Unknown template type: ${type}`);\n }\n}\n\nexport function getTemplates(type: TemplateType): ExtensibleMeta[] {\n const basePath = getTemplateBasePath(type);\n if (!fs.existsSync(basePath)) return [];\n\n const dirs = fs\n .readdirSync(basePath)\n .filter((d: any) => fs.statSync(path.join(basePath, d)).isDirectory());\n\n return dirs.map((dir: any) => {\n const meta = loadJSON(path.join(basePath, dir, 'template.json')) || {};\n return {\n name: meta.name || dir,\n lowerName: dir.toLowerCase(),\n version: meta.version,\n description: meta.description,\n author: meta.author,\n icon: meta.icon,\n enabled: meta.enabled ?? false,\n };\n });\n}\n\nexport function isTemplateActive(type: TemplateType, name: string) {\n const templates = getTemplates(type);\n return templates.find((t) => t.lowerName === name.toLowerCase())?.enabled ?? false;\n}\n\n// Toggle templates: only 1 active per type allowed\nexport function toggleTemplate(type: TemplateType, name: string) {\n const templates = getTemplates(type);\n\n templates.forEach((tpl) => {\n const metaPath = path.join(getTemplateBasePath(type), tpl.lowerName, 'template.json');\n const meta = loadJSON(metaPath) || {};\n meta.enabled = tpl.lowerName === name.toLowerCase();\n saveJSON(metaPath, meta);\n });\n\n onTemplateSelect(type, name);\n}\n\n// --- EVENTS (replace with your event system integration) ---\n\nexport function onModuleEnabled(name: string) {\n console.log(`Module enabled: ${name}`);\n // emit event or custom logic here\n}\n\nexport function onModuleDisabled(name: string) {\n console.log(`Module disabled: ${name}`);\n}\n\nexport function onServiceEnabled(name: string) {\n console.log(`Service enabled: ${name}`);\n}\n\nexport function onServiceDisabled(name: string) {\n console.log(`Service disabled: ${name}`);\n}\n\nexport function onTemplateSelect(type: TemplateType, name: string) {\n console.log(`Template selected: type=${type}, name=${name}`);\n}\n\n// --- REGISTER HOOKS FOR MODULES ---\n\nexport async function registerEvents() {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n const modules = getModules().filter((m) => m.enabled);\n for (const mod of modules) {\n const eventsFile = path.join(useSettings.getPaths().modules, mod.lowerName, 'events.server.js');\n if (fs.existsSync(eventsFile)) {\n const modEvents = await import(eventsFile);\n if (modEvents?.registerEvents) await modEvents.registerEvents();\n }\n }\n}\n\nexport async function registerMiddleware() {\n if (!useSettings.getPaths().modules) throw new Error('Modules path not registered.');\n const modules = getModules().filter((m) => m.enabled);\n for (const mod of modules) {\n const middlewareFile = path.join(useSettings.getPaths().modules, mod.lowerName, 'middleware.server.js');\n if (fs.existsSync(middlewareFile)) {\n const modMiddleware = await import(middlewareFile);\n if (modMiddleware?.registerMiddleware) await modMiddleware.registerMiddleware();\n }\n }\n}\n\n/**\n * Registers routes given a path to routes folder (for pages and API routes)\n * @param routesFolderPath string - path to module/service routes folder\n */\nexport async function registerRoutes(routesFolderPath: string) {\n if (!fs.existsSync(routesFolderPath)) return;\n\n const routeFiles = fs.readdirSync(routesFolderPath).filter((f: any) => /\\.(js|ts|jsx|tsx)$/.test(f));\n for (const file of routeFiles) {\n const routeModule = await import(path.join(routesFolderPath, file));\n if (routeModule?.registerRoute) {\n await routeModule.registerRoute();\n }\n }\n}\n\nexport async function loadProviders() {\n const paths = useSettings.getPaths();\n\n const all = [\n { type: 'module', list: getModules(), basePath: paths.modules },\n { type: 'service', list: getServices(), basePath: paths.services },\n ];\n\n for (const { type, list, basePath } of all) {\n for (const item of list) {\n if (!item.enabled) continue;\n\n const metaPath = path.join(path.resolve(basePath), item.lowerName, `${type}.json`);\n const meta = loadJSON(metaPath);\n if (!meta?.providers || !Array.isArray(meta.providers)) continue;\n\n for (const providerRelPath of meta.providers) {\n try {\n let providerAbsPath = path.join(path.resolve(basePath), item.lowerName, providerRelPath);\n\n // Try .js fallback if file is .ts or .tsx\n const ext = path.extname(providerAbsPath);\n if (ext === '.ts' || ext === '.tsx') {\n const jsPath = providerAbsPath.replace(/\\.(ts|tsx)$/, '.js');\n try {\n await fs.accessSync(jsPath); // Check if compiled JS file exists\n providerAbsPath = jsPath;\n } catch {\n throw new Error(`Compiled JS version not found for provider: ${providerRelPath}`);\n }\n }\n\n const providerUrl = toFileUrl(providerAbsPath);\n const providerModule = await import(providerUrl);\n\n if (typeof providerModule.default === 'function') {\n // Expose context so nav registration can auto-tag module/service\n (globalThis as any).__retrex_provider_context__ = {\n type,\n name: item.lowerName,\n };\n await providerModule.default();\n (globalThis as any).__retrex_provider_context__ = undefined;\n console.log(`[${type}] ✅ Provider loaded: ${providerRelPath}`);\n } else {\n console.warn(`[${type}] ⚠️ Provider ${providerRelPath} has no default export.`);\n }\n } catch (err) {\n console.error(`[${type}] ❌ Failed to load provider ${providerRelPath}:`, err);\n }\n }\n }\n }\n}\n\n\n// export async function loadProviders() {\n// paths = {\n// modules: useSettings.getPaths().modules,\n// templates: useSettings.getPaths().templates,\n// services: useSettings.getPaths().services,\n// events: useSettings.getPaths().events,\n// }\n// const all = [\n// { type: 'module', list: getModules(), basePath: useSettings.getPaths().modules },\n// { type: 'service', list: getServices(), basePath: useSettings.getPaths().services },\n// ];\n\n// for (const { type, list, basePath } of all) {\n// for (const item of list) {\n// if (!item.enabled) continue;\n\n// const metaPath = path.join(basePath, item.lowerName, `${type}.json`);\n// const meta = loadJSON(metaPath);\n// if (!meta?.providers || !Array.isArray(meta.providers)) continue;\n\n// for (const providerRelPath of meta.providers) {\n// try {\n// const providerPath = path.join(basePath, item.lowerName, providerRelPath);\n// const providerModule = await import(providerPath);\n// if (typeof providerModule.default === 'function') {\n// await providerModule.default(); // Call provider\n// console.log(`[${type}] Provider loaded: ${providerRelPath}`);\n// } else {\n// console.warn(`[${type}] Provider ${providerRelPath} has no default export.`);\n// }\n// } catch (err) {\n// console.error(`[${type}] Failed to load provider ${providerRelPath}:`, err);\n// }\n// }\n// }\n// }\n// }\n"],"mappings":";AAEA,OAAOA,WAAU;AACjB,OAAOC,SAAQ;;;ACAf,OAAOC,SAAQ;;;ACDf,OAAO,QAAQ;AACf,OAAO,UAAU;AAiBV,SAAS,SAAS,UAAuB;AAC9C,MAAI,CAAC,GAAG,WAAW,QAAQ,EAAG,QAAO;AACrC,SAAO,KAAK,MAAM,GAAG,aAAa,UAAU,OAAO,CAAC;AACtD;AAEO,SAAS,SAAS,UAAkB,MAAW;AACpD,KAAG,cAAc,UAAU,KAAK,UAAU,MAAM,MAAM,CAAC,GAAG,OAAO;AACnE;;;ADnBA,IAAM,eAAgC;AAAA,EACpC,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,WAAW;AACb;AAEA,IAAI,kBAAmC,EAAE,GAAG,aAAa;AACzD,IAAM,WAAW,OAAO,WAAW;AAG5B,IAAM,cAAc;AAAA,EACzB,WAA4B;AAC1B,QAAI,UAAU;AACZ,YAAM,OAAO,SAAS,4BAA4B;AAClD,UAAI,KAAM,mBAAkB;AAAA,IAC9B;AAEA,QAAI,UAAU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