Skip to main content
Glama
using-repomix-as-a-library.md2.61 kB
# Repomix를 라이브러리로 사용하기 Repomix를 CLI 도구로 사용하는 것 외에도 Node.js 애플리케이션에 직접 기능을 통합할 수 있습니다. ## 설치 프로젝트에 Repomix를 의존성으로 설치하세요: ```bash npm install repomix ``` ## 기본 사용법 Repomix를 사용하는 가장 간단한 방법은 명령줄 인터페이스와 동일한 기능을 제공하는 `runCli` 함수를 통해 사용하는 것입니다: ```javascript import { runCli, type CliOptions } from 'repomix'; // 사용자 정의 옵션으로 현재 디렉토리 처리 async function packProject() { const options = { output: 'output.xml', style: 'xml', compress: true, quiet: true } as CliOptions; const result = await runCli(['.'], process.cwd(), options); return result.packResult; } ``` `result.packResult`에는 처리된 파일에 대한 다음 정보가 포함됩니다: - `totalFiles`: 처리된 파일 수 - `totalCharacters`: 총 문자 수 - `totalTokens`: 총 토큰 수(LLM 컨텍스트 제한에 유용) - `fileCharCounts`: 파일별 문자 수 - `fileTokenCounts`: 파일별 토큰 수 ## 원격 저장소 처리 원격 저장소를 클론하고 처리할 수 있습니다: ```javascript import { runCli, type CliOptions } from 'repomix'; // GitHub 저장소 클론 및 처리 async function processRemoteRepo(repoUrl) { const options = { remote: repoUrl, output: 'output.xml', compress: true } as CliOptions; return await runCli(['.'], process.cwd(), options); } ``` ## 핵심 컴포넌트 사용 더 많은 제어를 위해 Repomix의 저수준 API를 직접 사용할 수 있습니다: ```javascript import { searchFiles, collectFiles, processFiles, TokenCounter } from 'repomix'; async function analyzeFiles(directory) { // 파일 찾기 및 수집 const { filePaths } = await searchFiles(directory, { /* 설정 */ }); const rawFiles = await collectFiles(filePaths, directory); const processedFiles = await processFiles(rawFiles, { /* 설정 */ }); // 토큰 계산 const tokenCounter = new TokenCounter('o200k_base'); // 분석 결과 반환 return processedFiles.map(file => ({ path: file.path, tokens: tokenCounter.countTokens(file.content) })); } ``` ## 실제 사례 Repomix 웹사이트([repomix.com](https://repomix.com))는 원격 저장소를 처리하기 위해 라이브러리로 Repomix를 사용합니다. [website/server/src/remoteRepo.ts](https://github.com/yamadashy/repomix/blob/main/website/server/src/remoteRepo.ts)에서 구현을 확인할 수 있습니다.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yamadashy/repomix'

If you have feedback or need assistance with the MCP directory API, please join our Discord server