realtimecursor
Version:
Real-time collaboration system with cursor tracking and approval workflow
124 lines (103 loc) • 3.27 kB
JavaScript
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Ensure dist directory exists
if (!fs.existsSync('./dist')) {
fs.mkdirSync('./dist');
}
// Copy CSS file to dist
fs.copyFileSync('./src/cursor.css', './dist/cursor.css');
// Create a simple bundle using babel
try {
console.log('Building CommonJS version...');
execSync('npx babel src/index.js --out-file dist/index.js --plugins @babel/plugin-transform-modules-commonjs', { stdio: 'inherit' });
console.log('Building ESM version...');
execSync('npx babel src/index.js --out-file dist/index.esm.js', { stdio: 'inherit' });
// Create a simple TypeScript declaration file
const dtsContent = `import { ReactNode } from 'react';
export interface RealtimeCursorOptions {
apiUrl: string;
projectId: string;
user: {
id: string;
name: string;
color?: string;
};
}
export interface CursorPosition {
x?: number;
y?: number;
relativeX?: number;
relativeY?: number;
textPosition?: number;
}
export interface Cursor {
id: string;
position: CursorPosition;
user: {
id: string;
name: string;
color?: string;
};
timestamp: number;
}
export interface Collaborator {
id: string;
name: string;
color?: string;
socketId?: string;
}
export class RealtimeCursor {
constructor(options: RealtimeCursorOptions);
connect(): void;
disconnect(): void;
updateCursor(position: CursorPosition): void;
updateContent(content: string, version?: number): void;
onConnect?: () => void;
onDisconnect?: () => void;
onCursorsChange?: (cursors: Record<string, Cursor>) => void;
onCollaboratorsChange?: (collaborators: Collaborator[]) => void;
onContentUpdate?: (data: any) => void;
onUserJoined?: (user: Collaborator) => void;
onUserLeft?: (user: Collaborator) => void;
onError?: (error: any) => void;
}
export interface UseRealtimeCursorResult {
cursors: Record<string, Cursor>;
collaborators: Collaborator[];
connected: boolean;
connect: () => void;
disconnect: () => void;
updateCursor: (position: CursorPosition) => void;
updateContent: (content: string, version?: number) => void;
}
export function useRealtimeCursor(options: RealtimeCursorOptions): UseRealtimeCursorResult;
export interface CursorOverlayProps {
cursors: Record<string, Cursor>;
containerRef?: React.RefObject<HTMLElement>;
}
export const CursorOverlay: React.FC<CursorOverlayProps>;
export interface CollaboratorsListProps {
collaborators: Collaborator[];
}
export const CollaboratorsList: React.FC<CollaboratorsListProps>;
declare const _default: {
RealtimeCursor: typeof RealtimeCursor;
useRealtimeCursor: typeof useRealtimeCursor;
CursorOverlay: typeof CursorOverlay;
CollaboratorsList: typeof CollaboratorsList;
};
export default _default;
`;
fs.writeFileSync('./dist/index.d.ts', dtsContent);
console.log('✅ Build completed successfully!');
console.log('📦 Files in dist:');
fs.readdirSync('./dist').forEach(file => {
const stats = fs.statSync(path.join('./dist', file));
console.log(` - ${file} (${(stats.size / 1024).toFixed(2)} KB)`);
});
} catch (error) {
console.error('❌ Build failed:', error);
process.exit(1);
}