mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 21:01:08 +02:00
feat: add monorepo configuration and shared packages structure
Root-level setup: - package.json with Turborepo scripts - pnpm-workspace.yaml for workspace management - turbo.json for build pipeline - Common config files (.nvmrc, .prettierrc, .editorconfig) Shared packages (packages/): - @manacore/shared-types - Common TypeScript types - @manacore/shared-supabase - Unified Supabase client - @manacore/shared-utils - Date, string, async utilities - @manacore/shared-ui - React Native UI components (placeholder) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e7f5f942f3
commit
2c58d03f63
23 changed files with 738 additions and 0 deletions
21
packages/shared-utils/package.json
Normal file
21
packages/shared-utils/package.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "@manacore/shared-utils",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Shared utility functions for Manacore monorepo",
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"type-check": "tsc --noEmit",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"date-fns": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.9.2"
|
||||
}
|
||||
}
|
||||
71
packages/shared-utils/src/async.ts
Normal file
71
packages/shared-utils/src/async.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/**
|
||||
* Async utility functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sleep for a specified number of milliseconds
|
||||
*/
|
||||
export function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry a function with exponential backoff
|
||||
*/
|
||||
export async function retry<T>(
|
||||
fn: () => Promise<T>,
|
||||
options: {
|
||||
maxAttempts?: number;
|
||||
initialDelay?: number;
|
||||
maxDelay?: number;
|
||||
backoffMultiplier?: number;
|
||||
} = {}
|
||||
): Promise<T> {
|
||||
const {
|
||||
maxAttempts = 3,
|
||||
initialDelay = 1000,
|
||||
maxDelay = 10000,
|
||||
backoffMultiplier = 2,
|
||||
} = options;
|
||||
|
||||
let lastError: Error | undefined;
|
||||
let delay = initialDelay;
|
||||
|
||||
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||
try {
|
||||
return await fn();
|
||||
} catch (error) {
|
||||
lastError = error as Error;
|
||||
|
||||
if (attempt === maxAttempts) {
|
||||
break;
|
||||
}
|
||||
|
||||
await sleep(delay);
|
||||
delay = Math.min(delay * backoffMultiplier, maxDelay);
|
||||
}
|
||||
}
|
||||
|
||||
throw lastError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Debounce a function
|
||||
*/
|
||||
export function debounce<T extends (...args: any[]) => any>(
|
||||
fn: T,
|
||||
delay: number
|
||||
): (...args: Parameters<T>) => void {
|
||||
let timeoutId: NodeJS.Timeout | null = null;
|
||||
|
||||
return (...args: Parameters<T>) => {
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
|
||||
timeoutId = setTimeout(() => {
|
||||
fn(...args);
|
||||
timeoutId = null;
|
||||
}, delay);
|
||||
};
|
||||
}
|
||||
43
packages/shared-utils/src/date.ts
Normal file
43
packages/shared-utils/src/date.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* Date utility functions
|
||||
*/
|
||||
|
||||
import { format, formatDistanceToNow, parseISO } from 'date-fns';
|
||||
import { de, enUS } from 'date-fns/locale';
|
||||
|
||||
const locales = {
|
||||
de,
|
||||
en: enUS,
|
||||
};
|
||||
|
||||
type LocaleKey = keyof typeof locales;
|
||||
|
||||
/**
|
||||
* Format a date string to a readable format
|
||||
*/
|
||||
export function formatDate(
|
||||
date: string | Date,
|
||||
formatStr: string = 'PPP',
|
||||
locale: LocaleKey = 'de'
|
||||
): string {
|
||||
const dateObj = typeof date === 'string' ? parseISO(date) : date;
|
||||
return format(dateObj, formatStr, { locale: locales[locale] });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get relative time from now (e.g., "2 hours ago")
|
||||
*/
|
||||
export function formatRelativeTime(date: string | Date, locale: LocaleKey = 'de'): string {
|
||||
const dateObj = typeof date === 'string' ? parseISO(date) : date;
|
||||
return formatDistanceToNow(dateObj, {
|
||||
addSuffix: true,
|
||||
locale: locales[locale],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a date for API requests (ISO string)
|
||||
*/
|
||||
export function toISOString(date: Date): string {
|
||||
return date.toISOString();
|
||||
}
|
||||
12
packages/shared-utils/src/index.ts
Normal file
12
packages/shared-utils/src/index.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* Shared utility functions for Manacore monorepo
|
||||
*/
|
||||
|
||||
// Date utilities
|
||||
export * from './date';
|
||||
|
||||
// String utilities
|
||||
export * from './string';
|
||||
|
||||
// Async utilities
|
||||
export * from './async';
|
||||
43
packages/shared-utils/src/string.ts
Normal file
43
packages/shared-utils/src/string.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* String utility functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Truncate a string to a maximum length with ellipsis
|
||||
*/
|
||||
export function truncate(str: string, maxLength: number): string {
|
||||
if (str.length <= maxLength) return str;
|
||||
return str.slice(0, maxLength - 3) + '...';
|
||||
}
|
||||
|
||||
/**
|
||||
* Capitalize the first letter of a string
|
||||
*/
|
||||
export function capitalize(str: string): string {
|
||||
if (!str) return str;
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random string ID
|
||||
*/
|
||||
export function generateId(length: number = 8): string {
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let result = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Slugify a string for URLs
|
||||
*/
|
||||
export function slugify(str: string): string {
|
||||
return str
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^\w\s-]/g, '')
|
||||
.replace(/[\s_-]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '');
|
||||
}
|
||||
17
packages/shared-utils/tsconfig.json
Normal file
17
packages/shared-utils/tsconfig.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"lib": ["ES2020"],
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue