mirror of
https://github.com/jung-geun/NFD2NFC.git
synced 2026-08-07 01:04:04 +09:00
tsconfig.json: module ESNext로 변경, renderer 제외. .eslintrc.cjs: varsIgnorePattern '^_' 추가. store.ts: notificationIntervalSecs 기본값(30) 추가. src/lib/index.ts: FilterOptions/ScanEntry를 올바른 소스 파일에서 import. scanner.ts: 미사용 fs import 제거. ipc.ts: 미사용 nanoid import 제거. cli/index.ts: 미사용 argv 변수 void 처리, showHelp() → 메시지 출력으로 대체. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { Dirent } from 'fs';
|
|
import fsPromises from 'fs/promises';
|
|
import path from 'path';
|
|
import { shouldNormalize } from './filter';
|
|
import type { FilterOptions } from './filter';
|
|
|
|
export interface ScanEntry {
|
|
path: string;
|
|
type: 'file' | 'directory';
|
|
}
|
|
|
|
/**
|
|
* 디렉토리를 재귀적으로 스캔해 NFD→NFC 변환이 필요한 항목을 반환한다.
|
|
* 깊이 역순으로 정렬해 자식부터 rename할 수 있게 한다 (부모 경로 무효화 방지).
|
|
*/
|
|
export async function scan(
|
|
dirPath: string,
|
|
recursive: boolean,
|
|
opts?: FilterOptions
|
|
): Promise<ScanEntry[]> {
|
|
const entries: ScanEntry[] = [];
|
|
await walk(dirPath, recursive, entries, opts);
|
|
// 경로 깊이 역순: 하위 항목이 먼저 오도록
|
|
entries.sort((a, b) => b.path.split(path.sep).length - a.path.split(path.sep).length);
|
|
return entries;
|
|
}
|
|
|
|
async function walk(
|
|
dir: string,
|
|
recursive: boolean,
|
|
entries: ScanEntry[],
|
|
opts?: FilterOptions
|
|
): Promise<void> {
|
|
let dirents: Dirent[];
|
|
try {
|
|
dirents = await fsPromises.readdir(dir, { withFileTypes: true });
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
for (const dirent of dirents) {
|
|
const fullPath = path.join(dir, dirent.name);
|
|
if (shouldNormalize(dirent.name, opts)) {
|
|
entries.push({ path: fullPath, type: dirent.isDirectory() ? 'directory' : 'file' });
|
|
}
|
|
if (recursive && dirent.isDirectory()) {
|
|
await walk(fullPath, recursive, entries, opts);
|
|
}
|
|
}
|
|
}
|