refactor: restructure

monorepo with apps/ and services/
  directories
This commit is contained in:
Wuesteon 2025-11-26 03:03:24 +01:00
parent 25824ed0ac
commit ff80aeec1f
4062 changed files with 2592 additions and 1278 deletions

View file

@ -0,0 +1,73 @@
import fs from 'fs-extra';
import path from 'path';
import { ComponentInfo } from '../types';
import { getComponentsPath, ensureDir } from './paths';
/**
* Copy a component's files to the destination
*/
export async function copyComponent(
component: ComponentInfo,
category: string,
destinationBase: string
): Promise<string[]> {
const sourcePath = path.join(getComponentsPath(), category, component.name);
const destPath = path.join(destinationBase, category, component.name);
// Ensure destination directory exists
await ensureDir(destPath);
const copiedFiles: string[] = [];
// Copy each file
for (const file of component.files) {
const sourceFile = path.join(sourcePath, file);
const destFile = path.join(destPath, file);
if (!await fs.pathExists(sourceFile)) {
throw new Error(`Source file not found: ${sourceFile}`);
}
await fs.copy(sourceFile, destFile, { overwrite: true });
copiedFiles.push(destFile);
}
// Also copy index.ts if it exists
const indexFile = path.join(sourcePath, 'index.ts');
if (await fs.pathExists(indexFile)) {
const destIndex = path.join(destPath, 'index.ts');
await fs.copy(indexFile, destIndex, { overwrite: true });
copiedFiles.push(destIndex);
}
return copiedFiles;
}
/**
* Check if a component already exists at the destination
*/
export async function componentExists(
component: ComponentInfo,
category: string,
destinationBase: string
): Promise<boolean> {
const destPath = path.join(destinationBase, category, component.name);
return await fs.pathExists(destPath);
}
/**
* Get the list of files that would be copied
*/
export function getComponentFiles(
component: ComponentInfo,
category: string,
destinationBase: string
): string[] {
const destPath = path.join(destinationBase, category, component.name);
const files = component.files.map(file => path.join(destPath, file));
// Add index.ts
files.push(path.join(destPath, 'index.ts'));
return files;
}

View file

@ -0,0 +1,53 @@
import path from 'path';
import fs from 'fs-extra';
/**
* Get the root directory of the memoro-ui package
*/
export function getPackageRoot(): string {
// CLI is in packages/memoro-ui/cli/
// Package root is packages/memoro-ui/
return path.resolve(__dirname, '../../../');
}
/**
* Get the path to the registry.json file
*/
export function getRegistryPath(): string {
return path.join(getPackageRoot(), 'registry.json');
}
/**
* Get the path to the components directory
*/
export function getComponentsPath(): string {
return path.join(getPackageRoot(), 'components');
}
/**
* Get the destination path for components in the target app
*/
export function getDestinationPath(cwd: string = process.cwd()): string {
// Check if we're in an app directory with a components folder
const possiblePaths = [
path.join(cwd, 'components'),
path.join(cwd, 'app', 'components'),
path.join(cwd, 'src', 'components'),
];
for (const p of possiblePaths) {
if (fs.existsSync(p)) {
return p;
}
}
// Default to components/ in current directory
return path.join(cwd, 'components');
}
/**
* Ensure a directory exists, create if not
*/
export async function ensureDir(dirPath: string): Promise<void> {
await fs.ensureDir(dirPath);
}

View file

@ -0,0 +1,85 @@
import fs from 'fs-extra';
import { ComponentRegistry, ComponentInfo } from '../types';
import { getRegistryPath } from './paths';
/**
* Load the component registry
*/
export async function loadRegistry(): Promise<ComponentRegistry> {
const registryPath = getRegistryPath();
if (!await fs.pathExists(registryPath)) {
throw new Error(`Registry not found at ${registryPath}`);
}
const content = await fs.readFile(registryPath, 'utf-8');
return JSON.parse(content);
}
/**
* Get a specific component from the registry
*/
export async function getComponent(
componentKey: string
): Promise<{ key: string; component: ComponentInfo; category: string } | null> {
const registry = await loadRegistry();
for (const [category, components] of Object.entries(registry.components)) {
if (componentKey in components) {
return {
key: componentKey,
component: components[componentKey],
category,
};
}
}
return null;
}
/**
* Get all components from the registry
*/
export async function getAllComponents(): Promise<
Array<{ key: string; component: ComponentInfo; category: string }>
> {
const registry = await loadRegistry();
const components: Array<{ key: string; component: ComponentInfo; category: string }> = [];
for (const [category, categoryComponents] of Object.entries(registry.components)) {
for (const [key, component] of Object.entries(categoryComponents)) {
components.push({ key, component, category });
}
}
return components;
}
/**
* Resolve dependencies for a component recursively
*/
export async function resolveDependencies(
componentKey: string,
visited = new Set<string>()
): Promise<string[]> {
if (visited.has(componentKey)) {
return [];
}
visited.add(componentKey);
const item = await getComponent(componentKey);
if (!item) {
return [];
}
const deps = item.component.dependencies || [];
const allDeps = [...deps];
for (const dep of deps) {
const subDeps = await resolveDependencies(dep, visited);
allDeps.push(...subDeps);
}
return [...new Set(allDeps)];
}