mirror of
https://github.com/yamadashy/repomix.git
synced 2026-02-03 11:33:39 +01:00
- Add oxlint as dev dependency and integrate into npm run lint - Create oxlint configuration with warning levels for gradual adoption - Add oxlint CI job to GitHub Actions - Fix regex patterns flagged by oxlint: - Remove unnecessary escape characters in file regex patterns - Fix regex patterns in website validation and PHP test files - Update lint script order: biome -> oxlint -> ts -> secretlint oxlint provides 50-100x faster linting with 500+ rules from ESLint ecosystem. Current warnings are configured as non-blocking to allow gradual improvement.
118 lines
3.3 KiB
TypeScript
118 lines
3.3 KiB
TypeScript
import type { Ace } from 'ace-builds';
|
|
import type { PackResult } from '../api/client';
|
|
import { analyticsUtils } from './analytics';
|
|
|
|
/**
|
|
* Format timestamp to locale string
|
|
*/
|
|
export function formatTimestamp(timestamp: string): string {
|
|
return new Date(timestamp).toLocaleString();
|
|
}
|
|
|
|
/**
|
|
* Handle clipboard copy with analytics tracking
|
|
*/
|
|
export async function copyToClipboard(content: string, format: string): Promise<boolean> {
|
|
try {
|
|
await navigator.clipboard.writeText(content);
|
|
analyticsUtils.trackCopyOutput(format);
|
|
return true;
|
|
} catch (err) {
|
|
console.error('Failed to copy:', err);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Convert repository name to format suitable for filename
|
|
*/
|
|
function formatRepositoryName(repository: string): string {
|
|
// Extract owner and repo from GitHub URL format or use as is
|
|
const match = repository.match(/(?:https:\/\/github\.com\/)?([^/]+)\/([^/]+)(?:\.git)?$/);
|
|
if (match) {
|
|
const [, owner, repo] = match;
|
|
return `${owner}-${repo}`;
|
|
}
|
|
// For non-GitHub repositories or local files, clean up the name
|
|
return repository.replace(/[/\\]/g, '-').replace(/\.git$/, '');
|
|
}
|
|
|
|
/**
|
|
* Handle file download with analytics tracking
|
|
*/
|
|
export function downloadResult(content: string, format: string, result: PackResult): void {
|
|
const blob = new Blob([content], { type: 'text/plain' });
|
|
const url = window.URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
const extension = format === 'markdown' ? 'md' : format === 'xml' ? 'xml' : 'txt';
|
|
|
|
const repoName = formatRepositoryName(result.metadata.repository);
|
|
a.href = url;
|
|
a.download = `repomix-output-${repoName}.${extension}`;
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
|
|
analyticsUtils.trackDownloadOutput(format);
|
|
window.URL.revokeObjectURL(url);
|
|
document.body.removeChild(a);
|
|
}
|
|
|
|
/**
|
|
* Handle sharing with Web Share API as file
|
|
*/
|
|
export async function shareResult(content: string, format: string, result: PackResult): Promise<boolean> {
|
|
try {
|
|
const repoName = formatRepositoryName(result.metadata.repository);
|
|
const extension = format === 'markdown' ? 'md' : format === 'xml' ? 'xml' : 'txt';
|
|
const filename = `repomix-output-${repoName}.${extension}`;
|
|
|
|
const mimeType = format === 'markdown' ? 'text/markdown' : format === 'xml' ? 'application/xml' : 'text/plain';
|
|
const blob = new Blob([content], { type: mimeType });
|
|
const file = new File([blob], filename, { type: mimeType });
|
|
|
|
const shareData = {
|
|
files: [file],
|
|
};
|
|
|
|
if (navigator.canShare?.(shareData)) {
|
|
await navigator.share(shareData);
|
|
analyticsUtils.trackShareOutput(format);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
} catch (err) {
|
|
console.error('Failed to share:', err);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if Web Share API is supported for file sharing
|
|
*/
|
|
export function canShareFiles(): boolean {
|
|
if (navigator.canShare && typeof navigator.canShare === 'function') {
|
|
try {
|
|
const dummyFile = new File([''], 'dummy.txt', { type: 'text/plain' });
|
|
return navigator.canShare({ files: [dummyFile] });
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get Ace editor options
|
|
*/
|
|
export function getEditorOptions(): Partial<Ace.EditorOptions> {
|
|
return {
|
|
readOnly: true,
|
|
wrap: false,
|
|
showPrintMargin: false,
|
|
fontSize: '13px',
|
|
useWorker: false,
|
|
highlightActiveLine: false,
|
|
};
|
|
}
|