mirror of
https://github.com/jung-geun/NFD2NFC.git
synced 2025-12-19 20:14:39 +09:00
preload.js 및 normalize_ko.js 파일 삭제, normalize.js 기능 개선 및 README 문서 업데이트
This commit is contained in:
89
README.md
89
README.md
@@ -1,29 +1,94 @@
|
|||||||
# 파일 이름 변환기
|
# NFD to NFC Normalizer
|
||||||
|
|
||||||
백그라운드에서 파일을 감지하고 변환하여 파일 이름을 NFD에서 NFC 인코딩으로 자동 변환하는 macOS 패키지입니다.
|
이 애플리케이션은 백그라운드에서 선택한 디렉토리를 감시하고, NFD로 인코딩된 파일 이름을 자동으로 NFC 인코딩으로 변환합니다.
|
||||||
|
|
||||||
npm 패키지는 명령어를 통해 사용할 수 있는 CLI 도구를 제공합니다.
|
Nomalize는 macOS 용 애플리케이션과 Node.js 패키지로 제공됩니다. macOS 앱은 `MACOS-APP`에서 빌드 가능하며, Node.js 패키지는 `nfd2nfc`에서 빌드 가능하고 다음 명령어로 설치할 수 있습니다:
|
||||||
Application 패키지는 macOS에서 백그라운드 프로세스로 실행되며, 파일 변환을 자동으로 처리합니다.
|
|
||||||
|
|
||||||
## 특징
|
```bash
|
||||||
|
npm install @pieroot/nfd2nfc
|
||||||
- 자동 파일 감지
|
```
|
||||||
- 백그라운드 변환 프로세스
|
|
||||||
- NFD에서 NFC 변환 지원
|
|
||||||
|
|
||||||
## 설치
|
## 설치
|
||||||
|
|
||||||
|
### macOS 애플리케이션
|
||||||
|
|
||||||
|
`MACOS-APP` 디렉토리에서 빌드하여 설치하거나 [릴리즈 페이지]()에서 다운로드합니다.
|
||||||
|
|
||||||
|
### Node.js 패키지
|
||||||
|
|
||||||
|
npm을 통해 패키지를 설치합니다:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 설치 지침을 여기에 작성하세요
|
# 지역적으로 설치
|
||||||
|
npm install @pieroot/nfd2nfc
|
||||||
|
|
||||||
|
# 글로벌로 설치
|
||||||
npm install -g @pieroot/nfd2nfc
|
npm install -g @pieroot/nfd2nfc
|
||||||
```
|
```
|
||||||
|
|
||||||
## 사용법
|
## 사용법
|
||||||
|
|
||||||
```bash
|
### macOS 애플리케이션
|
||||||
|
|
||||||
|
애플리케이션을 실행하여 원하는 기능을 사용합니다.
|
||||||
|
|
||||||
|

|
||||||
|
디렉토리 선택 버튼을 클릭하여 디렉토리를 선택합니다.
|
||||||
|
|
||||||
|

|
||||||
|
감시할 디렉토리를 선택합니다.
|
||||||
|
|
||||||
|
### CLI
|
||||||
|
|
||||||
|
CLI를 사용하여 변환할 문자열을 입력합니다:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nfd2nfc [options] <path>
|
||||||
|
|
||||||
|
# 옵션
|
||||||
|
nfd2nfc -h # 도움말
|
||||||
|
nfd2nfc -v # verbose 모드
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Node.js 패키지
|
||||||
|
|
||||||
|
패키지를 불러와서 사용합니다:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const nfd2nfc = require("@pieroot/nfd2nfc");
|
||||||
|
|
||||||
|
let str_nfc = nfd2nfc.normalizeToNFC("NFD로 인코딩된 문자열");
|
||||||
|
let str_nfd = nfd2nfc.normalizeToNFD("NFC로 인코딩된 문자열");
|
||||||
|
```
|
||||||
|
|
||||||
|
## 빌드 방법
|
||||||
|
|
||||||
|
- macOS 애플리케이션은 `MACOS-APP`에서 빌드할 수 있습니다.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd MACOS-APP
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
- Node.js 패키지는 `nfd2nfc`에서 빌드 가능하며, 다음 명령어로 설치할 수 있습니다:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd nfd2nfc
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
## 기여
|
||||||
|
|
||||||
|
이 프로젝트에 기여하려면 다음 단계를 따르세요:
|
||||||
|
|
||||||
|
1. 이 저장소를 포크합니다.
|
||||||
|
2. 새로운 브랜치를 만듭니다: `git checkout -b feat/new-feature`
|
||||||
|
3. 변경 사항을 커밋합니다: `git commit -am 'Add new feature'`
|
||||||
|
4. 브랜치에 푸시합니다: `git push origin feat/new-feature`
|
||||||
|
5. PR을 만듭니다.
|
||||||
|
|
||||||
## 라이선스
|
## 라이선스
|
||||||
|
|
||||||
MIT 라이선스
|
이 프로젝트는 MIT 라이선스를 사용합니다.
|
||||||
|
|||||||
BIN
assets/select-directory.png
Normal file
BIN
assets/select-directory.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
BIN
assets/start-app.png
Normal file
BIN
assets/start-app.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 107 KiB |
166
index.html
166
index.html
@@ -1,166 +0,0 @@
|
|||||||
<!-- index.html -->
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ko">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Directory Watcher App</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: Arial, sans-serif;
|
|
||||||
text-align: center;
|
|
||||||
padding: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#selected-directories {
|
|
||||||
margin-top: 20px;
|
|
||||||
max-width: 700px;
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
table {
|
|
||||||
width: 100%;
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
|
|
||||||
th,
|
|
||||||
td {
|
|
||||||
padding: 12px;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
}
|
|
||||||
|
|
||||||
th {
|
|
||||||
background-color: #f2f2f2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.remove-button {
|
|
||||||
background-color: #ff4d4d;
|
|
||||||
border: none;
|
|
||||||
color: white;
|
|
||||||
padding: 5px 10px;
|
|
||||||
border-radius: 3px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
#log {
|
|
||||||
margin-top: 20px;
|
|
||||||
text-align: left;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
background-color: #f0f0f0;
|
|
||||||
padding: 10px;
|
|
||||||
border-radius: 5px;
|
|
||||||
height: 150px;
|
|
||||||
overflow-y: scroll;
|
|
||||||
max-width: 700px;
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
padding: 10px 20px;
|
|
||||||
font-size: 16px;
|
|
||||||
cursor: pointer;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>디렉토리 감시 애플리케이션</h1>
|
|
||||||
<button id="select-directory">디렉토리 선택</button>
|
|
||||||
|
|
||||||
<div id="selected-directories">
|
|
||||||
<h2>감시 중인 디렉토리</h2>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>디렉토리 경로</th>
|
|
||||||
<th>제거</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="directories-list">
|
|
||||||
<!-- 선택된 디렉토리 목록이 여기에 표시됩니다 -->
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="log">
|
|
||||||
로그가 여기에 표시됩니다.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
const selectDirButton = document.getElementById('select-directory');
|
|
||||||
const directoriesList = document.getElementById('directories-list');
|
|
||||||
const logDiv = document.getElementById('log');
|
|
||||||
|
|
||||||
selectDirButton.addEventListener('click', async () => {
|
|
||||||
const result = await window.electronAPI.selectDirectories();
|
|
||||||
if (!result.canceled) {
|
|
||||||
refreshDirectories(); // 즉시 갱신
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function addDirectoryToList(dirPath) {
|
|
||||||
if (document.querySelector(`[data-path="${ dirPath }"]`)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const directoryRow = document.createElement('tr');
|
|
||||||
directoryRow.setAttribute('data-path', dirPath);
|
|
||||||
|
|
||||||
const pathCell = document.createElement('td');
|
|
||||||
pathCell.textContent = dirPath;
|
|
||||||
|
|
||||||
const removeCell = document.createElement('td');
|
|
||||||
const removeBtn = document.createElement('button');
|
|
||||||
removeBtn.className = 'remove-button';
|
|
||||||
removeBtn.textContent = '제거';
|
|
||||||
removeBtn.addEventListener('click', async () => {
|
|
||||||
const response = await window.electronAPI.removeDirectory(dirPath);
|
|
||||||
if (response.success) {
|
|
||||||
directoriesList.removeChild(directoryRow);
|
|
||||||
appendLog(`디렉토리 감시 중지: "${ dirPath }"`);
|
|
||||||
} else {
|
|
||||||
appendLog(`디렉토리 제거 실패: "${ response.message }"`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
removeCell.appendChild(removeBtn);
|
|
||||||
|
|
||||||
directoryRow.appendChild(pathCell);
|
|
||||||
directoryRow.appendChild(removeCell);
|
|
||||||
directoriesList.appendChild(directoryRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
function refreshDirectories() {
|
|
||||||
window.electronAPI.getDirectories().then((directories) => {
|
|
||||||
directoriesList.innerHTML = '';
|
|
||||||
for (const dirPath of Object.keys(directories)) {
|
|
||||||
addDirectoryToList(dirPath);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
|
||||||
// Initially load directories
|
|
||||||
refreshDirectories();
|
|
||||||
// Then refresh every 10 seconds
|
|
||||||
setInterval(refreshDirectories, 10000);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Listen for refresh-directories event
|
|
||||||
window.electronAPI.on('refresh-directories', refreshDirectories);
|
|
||||||
|
|
||||||
function appendLog(message) {
|
|
||||||
logDiv.textContent += `${ message }\n`;
|
|
||||||
logDiv.scrollTop = logDiv.scrollHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.electronAPI.onLog((message) => {
|
|
||||||
appendLog(message);
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
431
main.js
431
main.js
@@ -1,431 +0,0 @@
|
|||||||
// main.js
|
|
||||||
const {
|
|
||||||
app,
|
|
||||||
BrowserWindow,
|
|
||||||
dialog,
|
|
||||||
ipcMain,
|
|
||||||
Notification,
|
|
||||||
Tray,
|
|
||||||
Menu,
|
|
||||||
} = require("electron");
|
|
||||||
const path = require("path");
|
|
||||||
const chokidar = require("chokidar");
|
|
||||||
const fs = require("fs").promises;
|
|
||||||
const fsSync = require("fs"); // For synchronous path checks
|
|
||||||
|
|
||||||
let tray = null;
|
|
||||||
let mainWindow = null;
|
|
||||||
let watchers = {}; // To keep track of file watchers
|
|
||||||
|
|
||||||
// 로그 파일 경로 지정
|
|
||||||
const logFilePath = path.join(app.getPath("userData"), "watcher.log");
|
|
||||||
|
|
||||||
// JSON 파일 경로 지정
|
|
||||||
const watchedDirectoriesPath = path.join(
|
|
||||||
app.getPath("userData"),
|
|
||||||
"watchedDirectories.json"
|
|
||||||
);
|
|
||||||
|
|
||||||
// 현재 감시 중인 디렉토리 목록 및 마지막 갱신 시간
|
|
||||||
let watchedDirectories = {}; // { "path/to/dir": "2024-12-16T23:30:25.615Z", ... }
|
|
||||||
|
|
||||||
// Load the directories from JSON
|
|
||||||
async function loadWatchedDirectories() {
|
|
||||||
try {
|
|
||||||
const data = await fs.readFile(watchedDirectoriesPath, "utf-8");
|
|
||||||
watchedDirectories = JSON.parse(data);
|
|
||||||
for (const dirPath of Object.keys(watchedDirectories)) {
|
|
||||||
watchDirectory(dirPath);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (error.code !== "ENOENT") {
|
|
||||||
console.error(`Error loading directories: ${error}`);
|
|
||||||
new Notification({
|
|
||||||
title: "Error",
|
|
||||||
body: `Error loading directories: ${error.message}`,
|
|
||||||
}).show();
|
|
||||||
} else {
|
|
||||||
console.log("No watched directories found. Starting fresh.");
|
|
||||||
watchedDirectories = {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save directories to JSON
|
|
||||||
async function saveWatchedDirectories() {
|
|
||||||
try {
|
|
||||||
await fs.writeFile(
|
|
||||||
watchedDirectoriesPath,
|
|
||||||
JSON.stringify(watchedDirectories, null, 2),
|
|
||||||
"utf-8"
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error saving directories: ${error}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 로그 기록 함수
|
|
||||||
async function log(message) {
|
|
||||||
const timestamp = new Date().toISOString();
|
|
||||||
const logMessage = `[${timestamp}] ${message}\n`;
|
|
||||||
try {
|
|
||||||
await fs.appendFile(logFilePath, logMessage);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("로그 파일 작성 실패:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 무시할 파일/디렉토리를 결정하는 함수
|
|
||||||
function shouldIgnore(itemName) {
|
|
||||||
const ignoredItems = [".git", "node_modules", ".env"];
|
|
||||||
return ignoredItems.includes(itemName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 파일 이름을 정규화하는 함수
|
|
||||||
async function normalizeFileName(filePath) {
|
|
||||||
const dir = path.dirname(filePath);
|
|
||||||
const oldName = path.basename(filePath);
|
|
||||||
const newName = oldName.normalize("NFC");
|
|
||||||
|
|
||||||
if (oldName !== newName && !shouldIgnore(oldName)) {
|
|
||||||
const newPath = path.join(dir, newName);
|
|
||||||
try {
|
|
||||||
await fs.rename(filePath, newPath);
|
|
||||||
// watchedDirectories[newPath] = new Date().toISOString();
|
|
||||||
// delete watchedDirectories[filePath];
|
|
||||||
await saveWatchedDirectories();
|
|
||||||
await log(`이름 변경: "${oldName}" -> "${newName}"`);
|
|
||||||
|
|
||||||
// 알림 생성
|
|
||||||
new Notification({
|
|
||||||
title: "이름 변경 완료",
|
|
||||||
body: `"${oldName}"이 "${newName}"으로 변경되었습니다.`,
|
|
||||||
}).show();
|
|
||||||
|
|
||||||
// 렌더러 프로세스로 알림 전송
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send(
|
|
||||||
"log-message",
|
|
||||||
`이름 변경: "${oldName}" -> "${newName}"`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newPath;
|
|
||||||
} catch (error) {
|
|
||||||
await log(`이름 변경 실패 ("${oldName}"): ${error}`);
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send(
|
|
||||||
"log-message",
|
|
||||||
`이름 변경 실패 ("${oldName}"): ${error}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 변경 시 마지막 갱신 시간 업데이트
|
|
||||||
// watchedDirectories[filePath] = new Date().toISOString();
|
|
||||||
// await saveWatchedDirectories();
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 디렉토리를 재귀적으로 처리하는 함수
|
|
||||||
async function processDirectory(dirPath) {
|
|
||||||
try {
|
|
||||||
await log(`디렉토리 처리 시작: "${dirPath}"`);
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send(
|
|
||||||
"log-message",
|
|
||||||
`디렉토리 처리 시작: "${dirPath}"`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
||||||
|
|
||||||
for (const entry of entries) {
|
|
||||||
const fullPath = path.join(dirPath, entry.name);
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
if (!shouldIgnore(entry.name)) {
|
|
||||||
await processDirectory(fullPath);
|
|
||||||
await normalizeFileName(fullPath);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await normalizeFileName(fullPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await normalizeFileName(dirPath);
|
|
||||||
// console.log(`디렉토리 처리 완료: "${dirPath}"`);
|
|
||||||
// watchedDirectories[dirPath] = new Date().toISOString();
|
|
||||||
// await saveWatchedDirectories();
|
|
||||||
await log(`디렉토리 처리 완료: "${dirPath}"`);
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send(
|
|
||||||
"log-message",
|
|
||||||
`디렉토리 처리 완료: "${dirPath}"`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
await log(`디렉토리 처리 중 오류 발생 ("${dirPath}"): ${error}`);
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send(
|
|
||||||
"log-message",
|
|
||||||
`디렉토리 처리 중 오류 발생 ("${dirPath}"): ${error}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 디렉토리를 감시하는 함수
|
|
||||||
function watchDirectory(directory) {
|
|
||||||
const watcher = chokidar.watch(directory, {
|
|
||||||
ignored: (pathStr) => {
|
|
||||||
const baseName = path.basename(pathStr);
|
|
||||||
return shouldIgnore(baseName);
|
|
||||||
},
|
|
||||||
persistent: true,
|
|
||||||
ignoreInitial: false,
|
|
||||||
awaitWriteFinish: {
|
|
||||||
stabilityThreshold: 200,
|
|
||||||
pollInterval: 100,
|
|
||||||
},
|
|
||||||
depth: Infinity,
|
|
||||||
});
|
|
||||||
|
|
||||||
watchers[directory] = watcher;
|
|
||||||
|
|
||||||
watcher
|
|
||||||
.on("add", async (filePath) => {
|
|
||||||
// await log(`파일 추가됨: "${filePath}"`);
|
|
||||||
// if (mainWindow) {
|
|
||||||
// mainWindow.webContents.send(
|
|
||||||
// "log-message",
|
|
||||||
// `파일 추가됨: "${filePath}"`
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
await normalizeFileName(filePath);
|
|
||||||
})
|
|
||||||
.on("change", async (filePath) => {
|
|
||||||
// await log(`파일 변경됨: "${filePath}"`);
|
|
||||||
// if (mainWindow) {
|
|
||||||
// mainWindow.webContents.send(
|
|
||||||
// "log-message",
|
|
||||||
// `파일 변경됨: "${filePath}"`
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
await normalizeFileName(filePath);
|
|
||||||
})
|
|
||||||
.on("unlink", async (filePath) => {
|
|
||||||
// await log(`파일 삭제됨: "${filePath}"`);
|
|
||||||
// if (mainWindow) {
|
|
||||||
// mainWindow.webContents.send(
|
|
||||||
// "log-message",
|
|
||||||
// `파일 삭제됨: "${filePath}"`
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
})
|
|
||||||
.on("addDir", async (dirPath) => {
|
|
||||||
// await log(`디렉토리 추가됨: "${dirPath}"`);
|
|
||||||
// if (mainWindow) {
|
|
||||||
// mainWindow.webContents.send(
|
|
||||||
// "log-message",
|
|
||||||
// `디렉토리 추가됨: "${dirPath}"`
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
await processDirectory(dirPath);
|
|
||||||
})
|
|
||||||
.on("unlinkDir", async (dirPath) => {
|
|
||||||
// await log(`디렉토리 삭제됨: "${dirPath}"`);
|
|
||||||
// if (mainWindow) {
|
|
||||||
// mainWindow.webContents.send(
|
|
||||||
// "log-message",
|
|
||||||
// `디렉토리 삭제됨: "${dirPath}"`
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
})
|
|
||||||
.on("error", async (error) => {
|
|
||||||
await log(`Watcher error: ${error}`);
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send("log-message", `Watcher error: ${error}`);
|
|
||||||
}
|
|
||||||
new Notification({
|
|
||||||
title: "Watcher Error",
|
|
||||||
body: `Error watching directory: ${error.message}`,
|
|
||||||
}).show();
|
|
||||||
})
|
|
||||||
.on("ready", () => {
|
|
||||||
log(
|
|
||||||
`초기 스캔 완료. "${directory}"에서 변경 사항을 감시 중입니다.`
|
|
||||||
).catch(console.error);
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send(
|
|
||||||
"log-message",
|
|
||||||
`초기 스캔 완료. "${directory}"에서 변경 사항을 감시 중입니다.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function setTray() {
|
|
||||||
const iconPath = path.join(__dirname, "build/Macicon.iconset/icon_32x32.png"); // Define iconPath here
|
|
||||||
|
|
||||||
if (!fsSync.existsSync(iconPath)) {
|
|
||||||
console.error("Tray icon not found at:", iconPath);
|
|
||||||
new Notification({
|
|
||||||
title: "Error",
|
|
||||||
body: `Tray icon not found at ${iconPath}`,
|
|
||||||
}).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tray = new Tray(iconPath);
|
|
||||||
|
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
|
||||||
{
|
|
||||||
label: "열기",
|
|
||||||
click: () => {
|
|
||||||
if (mainWindow === null) {
|
|
||||||
createWindow();
|
|
||||||
} else {
|
|
||||||
mainWindow.show();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "종료",
|
|
||||||
click: () => {
|
|
||||||
app.quit();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
tray.setToolTip("Directory Watcher App");
|
|
||||||
tray.setContextMenu(contextMenu);
|
|
||||||
|
|
||||||
// 더블 클릭 시 창 열기
|
|
||||||
tray.on("double-click", () => {
|
|
||||||
if (mainWindow === null) {
|
|
||||||
createWindow();
|
|
||||||
} else {
|
|
||||||
mainWindow.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 애플리케이션 준비 시 창 및 트레이 설정 후 디렉토리 목록 로드
|
|
||||||
app.whenReady().then(async () => {
|
|
||||||
createWindow();
|
|
||||||
setTray();
|
|
||||||
await loadWatchedDirectories();
|
|
||||||
|
|
||||||
app.on("activate", function () {
|
|
||||||
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 모든 창이 닫히면 애플리케이션 종료 (macOS 특성)
|
|
||||||
app.on("window-all-closed", function () {
|
|
||||||
if (process.platform !== "darwin") app.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
// 디렉토리 감시 로직 처리
|
|
||||||
ipcMain.handle("select-directories", async () => {
|
|
||||||
const result = await dialog.showOpenDialog({
|
|
||||||
properties: ["openDirectory", "multiSelections"],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result.canceled) {
|
|
||||||
return { canceled: true };
|
|
||||||
} else {
|
|
||||||
const selectedPaths = result.filePaths;
|
|
||||||
await log(`선택된 디렉토리: "${selectedPaths.join('", "')}"`);
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send(
|
|
||||||
"log-message",
|
|
||||||
`선택된 디렉토리: "${selectedPaths.join('", "')}"`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const selectedPath of selectedPaths) {
|
|
||||||
if (!watchedDirectories.hasOwnProperty(selectedPath)) {
|
|
||||||
watchedDirectories[selectedPath] = new Date().toISOString();
|
|
||||||
watchDirectory(selectedPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await saveWatchedDirectories();
|
|
||||||
|
|
||||||
// 렌더러 프로세스로 선택된 디렉토리 목록 업데이트 요청
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send("update-directories", watchedDirectories);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { canceled: false, paths: selectedPaths };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 디렉토리 제거 핸들러
|
|
||||||
ipcMain.handle("remove-directory", async (event, dirPath) => {
|
|
||||||
if (watchedDirectories.hasOwnProperty(dirPath)) {
|
|
||||||
watchedDirectories = Object.keys(watchedDirectories)
|
|
||||||
.filter((key) => key !== dirPath)
|
|
||||||
.reduce((obj, key) => {
|
|
||||||
obj[key] = watchedDirectories[key];
|
|
||||||
return obj;
|
|
||||||
}, {});
|
|
||||||
if (watchers[dirPath]) {
|
|
||||||
await watchers[dirPath].close();
|
|
||||||
delete watchers[dirPath];
|
|
||||||
await log(`디렉토리 감시 중지: "${dirPath}"`);
|
|
||||||
if (mainWindow) {
|
|
||||||
mainWindow.webContents.send(
|
|
||||||
"log-message",
|
|
||||||
`디렉토리 감시 중지: "${dirPath}"`
|
|
||||||
);
|
|
||||||
mainWindow.webContents.send("update-directories", watchedDirectories);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await saveWatchedDirectories();
|
|
||||||
|
|
||||||
return { success: true };
|
|
||||||
} else {
|
|
||||||
return { success: false, message: "디렉토리가 감시 목록에 없습니다." };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.handle("get-directories", async () => {
|
|
||||||
return watchedDirectories;
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on("unhandledRejection", (reason, promise) => {
|
|
||||||
new Notification({
|
|
||||||
title: "Unhandled Promise Rejection",
|
|
||||||
body: reason.message || "Unknown error",
|
|
||||||
}).show();
|
|
||||||
});
|
|
||||||
|
|
||||||
// 창을 생성하는 함수
|
|
||||||
function createWindow() {
|
|
||||||
mainWindow = new BrowserWindow({
|
|
||||||
width: 550, // 너비 조정
|
|
||||||
height: 550, // 높이 조정
|
|
||||||
webPreferences: {
|
|
||||||
preload: path.join(__dirname, "preload.js"), // 보안상 추천
|
|
||||||
nodeIntegration: false,
|
|
||||||
contextIsolation: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
mainWindow.loadFile("index.html");
|
|
||||||
|
|
||||||
// 개발자 도구 열기 (배포 시 제거 권장)
|
|
||||||
// mainWindow.webContents.openDevTools();
|
|
||||||
mainWindow.on("show", () => {
|
|
||||||
mainWindow.webContents.send("get-directories");
|
|
||||||
});
|
|
||||||
|
|
||||||
mainWindow.on("closed", function () {
|
|
||||||
mainWindow = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -50,11 +50,19 @@ function shouldIgnore(itemName) {
|
|||||||
return ignoredItems.includes(itemName);
|
return ignoredItems.includes(itemName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeToNFC(str) {
|
||||||
|
return str.normalize("NFC");
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeToNFD(str) {
|
||||||
|
return str.normalize("NFD");
|
||||||
|
}
|
||||||
|
|
||||||
// Function to normalize file names
|
// Function to normalize file names
|
||||||
async function normalizeFileName(filePath) {
|
async function normalizeFileName(filePath) {
|
||||||
const dir = path.dirname(filePath);
|
const dir = path.dirname(filePath);
|
||||||
const oldName = path.basename(filePath);
|
const oldName = path.basename(filePath);
|
||||||
const newName = oldName.normalize("NFC");
|
const newName = convertToNFC(oldName);
|
||||||
|
|
||||||
if (oldName !== newName && !shouldIgnore(oldName)) {
|
if (oldName !== newName && !shouldIgnore(oldName)) {
|
||||||
const newPath = path.join(dir, newName);
|
const newPath = path.join(dir, newName);
|
||||||
@@ -118,6 +126,14 @@ const progressBar = new cliProgress.SingleBar(
|
|||||||
cliProgress.Presets.shades_classic
|
cliProgress.Presets.shades_classic
|
||||||
);
|
);
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
processPath,
|
||||||
|
shouldIgnore,
|
||||||
|
normalizeToNFC,
|
||||||
|
normalizeToNFD,
|
||||||
|
normalizeFileName,
|
||||||
|
};
|
||||||
|
|
||||||
// Handle input: if no flags, assume first non-flag argument is a path
|
// Handle input: if no flags, assume first non-flag argument is a path
|
||||||
const nonFlagArgs = args._;
|
const nonFlagArgs = args._;
|
||||||
if (nonFlagArgs.length > 0) {
|
if (nonFlagArgs.length > 0) {
|
||||||
|
|||||||
105
normalize.js
105
normalize.js
@@ -1,105 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
const fs = require("fs").promises;
|
|
||||||
const path = require("path");
|
|
||||||
const minimist = require("minimist");
|
|
||||||
|
|
||||||
// Parse command-line arguments
|
|
||||||
const args = minimist(process.argv.slice(2), {
|
|
||||||
alias: { d: 'directory', f: 'file', v: 'verbose', h: 'help' }
|
|
||||||
});
|
|
||||||
|
|
||||||
// Function to display help message
|
|
||||||
function displayHelp() {
|
|
||||||
console.log(`
|
|
||||||
Usage: node index.js [options]
|
|
||||||
Options:
|
|
||||||
-d, --directory Specify a directory to process
|
|
||||||
-f, --file Specify a file to process
|
|
||||||
-v, --verbose Enable verbose logging
|
|
||||||
-h, --help Display this help message
|
|
||||||
`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for help flag or no arguments
|
|
||||||
if (args.help || (!args.directory && !args.file)) {
|
|
||||||
displayHelp();
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main processing logic
|
|
||||||
async function processPath(targetPath) {
|
|
||||||
if (!targetPath) {
|
|
||||||
console.error("Please provide a path using -d or -f");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const stats = await fs.lstat(targetPath);
|
|
||||||
if (stats.isDirectory()) {
|
|
||||||
await processDirectory(targetPath);
|
|
||||||
} else if (stats.isFile()) {
|
|
||||||
await normalizeFileName(targetPath);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error processing path "${targetPath}":`, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to determine if a file/directory should be ignored
|
|
||||||
function shouldIgnore(itemName) {
|
|
||||||
const ignoredItems = [".git", "node_modules", ".env"];
|
|
||||||
return ignoredItems.includes(itemName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to normalize file names
|
|
||||||
async function normalizeFileName(filePath) {
|
|
||||||
const dir = path.dirname(filePath);
|
|
||||||
const oldName = path.basename(filePath);
|
|
||||||
const newName = oldName.normalize("NFC");
|
|
||||||
|
|
||||||
if (oldName !== newName && !shouldIgnore(oldName)) {
|
|
||||||
const newPath = path.join(dir, newName);
|
|
||||||
try {
|
|
||||||
await fs.rename(filePath, newPath);
|
|
||||||
if (args.verbose) {
|
|
||||||
console.log(`Renamed: "${oldName}" -> "${newName}"`);
|
|
||||||
}
|
|
||||||
return newPath;
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Failed to rename "${oldName}":`, error);
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to process directories recursively
|
|
||||||
async function processDirectory(dirPath) {
|
|
||||||
if (args.verbose) {
|
|
||||||
console.log(`Processing directory: "${dirPath}"`);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
||||||
for (const entry of entries) {
|
|
||||||
const fullPath = path.join(dirPath, entry.name);
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
if (!shouldIgnore(entry.name)) {
|
|
||||||
await processDirectory(fullPath);
|
|
||||||
await normalizeFileName(fullPath);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await normalizeFileName(fullPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await normalizeFileName(dirPath);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error processing directory "${dirPath}":`, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process the given path based on arguments
|
|
||||||
if (args.directory) {
|
|
||||||
processPath(args.directory);
|
|
||||||
} else if (args.file) {
|
|
||||||
processPath(args.file);
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
const fs = require("fs").promises;
|
|
||||||
const path = require("path");
|
|
||||||
function containsKorean(text) {
|
|
||||||
// 한글 유니코드 범위: 가-힣, ㄱ-ㅎ, ㅏ-ㅣ
|
|
||||||
return /[가-힣ㄱ-ㅎㅏ-ㅣ]/.test(text);
|
|
||||||
}
|
|
||||||
// 특정 파일/디렉토리를 무시하는 기능 추가
|
|
||||||
function shouldIgnore(itemName) {
|
|
||||||
const ignoredItems = [".git", "node_modules", ".env"];
|
|
||||||
return ignoredItems.includes(itemName);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function normalizeFileName(filePath) {
|
|
||||||
const dir = path.dirname(filePath);
|
|
||||||
const oldName = path.basename(filePath);
|
|
||||||
|
|
||||||
if (!containsKorean(oldName)) {
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
const newName = oldName.normalize("NFC");
|
|
||||||
|
|
||||||
if (oldName !== newName && !shouldIgnore(oldName)) {
|
|
||||||
const newPath = path.join(dir, newName);
|
|
||||||
try {
|
|
||||||
// 경로에 공백이 있을 경우를 대비해 이스케이프 처리
|
|
||||||
const escapedOldPath = filePath.replace(/ /g, "\\ ");
|
|
||||||
const escapedNewPath = newPath.replace(/ /g, "\\ ");
|
|
||||||
await fs.rename(escapedOldPath, escapedNewPath);
|
|
||||||
console.log(`이름 변경: "${oldName}" -> "${newName}"`);
|
|
||||||
return newPath;
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`이름 변경 실패 ("${oldName}"):`, error);
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function processDirectory(dirPath) {
|
|
||||||
try {
|
|
||||||
// 경로에 공백이 있을 경우를 대비해 이스케이프 처리
|
|
||||||
const escapedDirPath = dirPath.replace(/ /g, "\\ ");
|
|
||||||
const entries = await fs.readdir(escapedDirPath, { withFileTypes: true });
|
|
||||||
|
|
||||||
const items = entries.map((entry) => ({
|
|
||||||
name: entry.name,
|
|
||||||
fullPath: path.join(dirPath, entry.name),
|
|
||||||
isDirectory: entry.isDirectory(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
for (const item of items) {
|
|
||||||
if (item.isDirectory) {
|
|
||||||
await processDirectory(item.fullPath);
|
|
||||||
await normalizeFileName(item.fullPath);
|
|
||||||
} else {
|
|
||||||
await normalizeFileName(item.fullPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`디렉토리 처리 중 오류 발생 ("${dirPath}"):`, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function processRoot(rootPath) {
|
|
||||||
try {
|
|
||||||
// 경로에 공백이 있을 경우를 대비해 이스케이프 처리
|
|
||||||
const escapedRootPath = path.resolve(rootPath);
|
|
||||||
const stats = await fs.stat(escapedRootPath);
|
|
||||||
|
|
||||||
if (stats.isDirectory()) {
|
|
||||||
const normalizedRootPath = await normalizeFileName(rootPath);
|
|
||||||
await processDirectory(normalizedRootPath);
|
|
||||||
} else {
|
|
||||||
await normalizeFileName(rootPath);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`처리 중 오류 발생 ("${rootPath}"):`, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 명령줄 인자로 경로를 받거나 기본값 사용
|
|
||||||
// 경로에 공백이 있을 경우를 대비해 따옴표로 감싸진 경로도 처리
|
|
||||||
const targetPath = process.argv[2] || "./convert";
|
|
||||||
|
|
||||||
// 프로그램 실행
|
|
||||||
processRoot(targetPath)
|
|
||||||
.then(() => console.log("모든 처리가 완료되었습니다."))
|
|
||||||
.catch((error) => console.error("프로그램 실행 중 오류 발생:", error));
|
|
||||||
2110
package-lock.json
generated
2110
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
47
package.json
47
package.json
@@ -1,47 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@pieroot/nfd2nfc",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"main": "main.js",
|
|
||||||
"description": "Convert NFD to NFC",
|
|
||||||
"dependencies": {
|
|
||||||
"chokidar": "^4.0.1",
|
|
||||||
"electron": "^33.2.1",
|
|
||||||
"readdirp": "^4.0.2"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "electron .",
|
|
||||||
"package": "electron-packager . NFD2NFC --platform=darwin --arch=arm64,x64 --icon=build/icons/MacIcon.icns --overwrite --prune=true --out=dist",
|
|
||||||
"package dev": "electron-packager . NFD2NFC --platform=darwin --arch=arm64,x64 --icon=build/icons/MacIcon-dev.icns --overwrite --prune=true --out=dist --asar --app-bundle-id=com.pieroot.nfd2nfc",
|
|
||||||
"pkg": "pkg normalize.js --target node16-macos-x64,node16-linux-x64,node16-win-x64 --output ./dist/NFD2NFC",
|
|
||||||
"prepare-release": "npm run pkg && npm run package"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"nfd2nfc": "normalize.js"
|
|
||||||
},
|
|
||||||
"directories": {
|
|
||||||
"output": "dist",
|
|
||||||
"buildResources": "build"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"NFD",
|
|
||||||
"NFC",
|
|
||||||
"Unicode",
|
|
||||||
"Normalization",
|
|
||||||
"macOS",
|
|
||||||
"Linux",
|
|
||||||
"korean"
|
|
||||||
],
|
|
||||||
"author": "jung-geun <pieroot.02@gmail.com>",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/jung-geun/NFD2NFC.git"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"devDependencies": {
|
|
||||||
"electron-packager": "^17.1.2"
|
|
||||||
},
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/jung-geun/NFD2NFC/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/jung-geun/NFD2NFC#readme"
|
|
||||||
}
|
|
||||||
14
preload.js
14
preload.js
@@ -1,14 +0,0 @@
|
|||||||
// preload.js
|
|
||||||
const { contextBridge, ipcRenderer } = require("electron");
|
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld("electronAPI", {
|
|
||||||
selectDirectories: () => ipcRenderer.invoke("select-directories"),
|
|
||||||
removeDirectory: (dirPath) => ipcRenderer.invoke("remove-directory", dirPath),
|
|
||||||
getDirectories: () => ipcRenderer.invoke("get-directories"),
|
|
||||||
onLog: (callback) =>
|
|
||||||
ipcRenderer.on("log-message", (event, message) => callback(message)),
|
|
||||||
onUpdateDirectories: (callback) =>
|
|
||||||
ipcRenderer.on("update-directories", (event, directories) =>
|
|
||||||
callback(directories)
|
|
||||||
),
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user