#!/usr/bin/env node
import { MarkdownManager } from './src/MarkdownManager.js';
import { ObsidianManager } from './src/ObsidianManager.js';
import { promises as fs } from 'fs';
import { join } from 'path';
class SimpleTest {
constructor() {
this.markdownManager = new MarkdownManager('.');
this.obsidianManager = new ObsidianManager('.');
this.testDir = 'test-output';
}
async setup() {
console.log('๐ ๊ฐ๋จํ ๋ก์ปฌ ํ
์คํธ ์์...\n');
// ํ
์คํธ ๋๋ ํ ๋ฆฌ ์์ฑ
try {
await fs.mkdir(this.testDir, { recursive: true });
console.log('โ
ํ
์คํธ ๋๋ ํ ๋ฆฌ ์์ฑ๋จ');
} catch (error) {
console.log('โ ๏ธ ํ
์คํธ ๋๋ ํ ๋ฆฌ ์ด๋ฏธ ์กด์ฌํจ');
}
}
async testBasicOperations() {
console.log('\n๐ ๊ธฐ๋ณธ CRUD ์์
ํ
์คํธ...\n');
const testFile = join(this.testDir, 'test-basic.md');
const testContent = `# ๊ธฐ๋ณธ ํ
์คํธ ํ์ผ
์ด๊ฒ์ ๊ธฐ๋ณธ ํ
์คํธ ํ์ผ์
๋๋ค.
## ์น์
1
๋ด์ฉ์ด ์ฌ๊ธฐ์ ์์ต๋๋ค.
## ์น์
2
๋ค๋ฅธ ๋ด์ฉ์
๋๋ค.
#tag1 #tag2 #test`;
// 1. ํ์ผ ์์ฑ
console.log('1. ํ์ผ ์์ฑ ํ
์คํธ');
try {
await this.markdownManager.createFile(testFile, testContent);
console.log('โ
ํ์ผ ์์ฑ ์ฑ๊ณต');
} catch (error) {
console.log('โ ํ์ผ ์์ฑ ์คํจ:', error.message);
}
// 2. ํ์ผ ์ฝ๊ธฐ
console.log('\n2. ํ์ผ ์ฝ๊ธฐ ํ
์คํธ');
try {
const content = await this.markdownManager.readFile(testFile);
console.log('โ
ํ์ผ ์ฝ๊ธฐ ์ฑ๊ณต');
console.log(' ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ:', content.substring(0, 100) + '...');
} catch (error) {
console.log('โ ํ์ผ ์ฝ๊ธฐ ์คํจ:', error.message);
}
// 3. ํ์ผ ๋ชฉ๋ก ์กฐํ
console.log('\n3. ํ์ผ ๋ชฉ๋ก ์กฐํ ํ
์คํธ');
try {
const files = await this.markdownManager.listFiles(this.testDir);
console.log('โ
ํ์ผ ๋ชฉ๋ก ์กฐํ ์ฑ๊ณต:', files);
} catch (error) {
console.log('โ ํ์ผ ๋ชฉ๋ก ์กฐํ ์คํจ:', error.message);
}
// 4. ๊ฒ์ ํ
์คํธ
console.log('\n4. ๊ฒ์ ํ
์คํธ');
try {
const results = await this.markdownManager.searchContent(this.testDir, {
query: 'ํ
์คํธ'
});
console.log('โ
๊ฒ์ ์ฑ๊ณต:', results.length, '๊ฐ ๊ฒฐ๊ณผ');
if (results.length > 0) {
console.log(' ์ฒซ ๋ฒ์งธ ๊ฒฐ๊ณผ:', results[0]);
}
} catch (error) {
console.log('โ ๊ฒ์ ์คํจ:', error.message);
}
// 5. ํ์ผ ์
๋ฐ์ดํธ
console.log('\n5. ํ์ผ ์
๋ฐ์ดํธ ํ
์คํธ');
try {
await this.markdownManager.updateFile(testFile, '\n\n## ์๋ก์ด ์น์
\n\n์
๋ฐ์ดํธ๋ ๋ด์ฉ์
๋๋ค.\n\n#updated', true);
console.log('โ
ํ์ผ ์
๋ฐ์ดํธ ์ฑ๊ณต');
} catch (error) {
console.log('โ ํ์ผ ์
๋ฐ์ดํธ ์คํจ:', error.message);
}
// 6. Frontmatter ๊ด๋ฆฌ
console.log('\n6. Frontmatter ๊ด๋ฆฌ ํ
์คํธ');
try {
await this.markdownManager.manageFrontmatter(testFile, 'set', {
title: 'ํ
์คํธ ํ์ผ',
tags: ['test', 'markdown'],
status: 'draft'
});
console.log('โ
Frontmatter ์ค์ ์ฑ๊ณต');
} catch (error) {
console.log('โ Frontmatter ์ค์ ์คํจ:', error.message);
}
// 7. Frontmatter ์ฝ๊ธฐ
console.log('\n7. Frontmatter ์ฝ๊ธฐ ํ
์คํธ');
try {
const frontmatter = await this.markdownManager.manageFrontmatter(testFile, 'get');
console.log('โ
Frontmatter ์ฝ๊ธฐ ์ฑ๊ณต:', frontmatter.metadata);
} catch (error) {
console.log('โ Frontmatter ์ฝ๊ธฐ ์คํจ:', error.message);
}
}
async testObsidianFeatures() {
console.log('\n๐ง Obsidian ํนํ ๊ธฐ๋ฅ ํ
์คํธ...\n');
const testFile = join(this.testDir, 'test-obsidian.md');
const testContent = `# Obsidian ํ
์คํธ ํ์ผ
์ด๊ฒ์ Obsidian ๊ธฐ๋ฅ์ ํ
์คํธํ๋ ํ์ผ์
๋๋ค.
## ๋งํฌ ํ
์คํธ
- ๋ด๋ถ ๋งํฌ: [[another-file]]
- ์ธ๋ถ ๋งํฌ: [Google](https://google.com)
- ์๋ฒ ๋: ![[image.png]]
## ํ๊ทธ ํ
์คํธ
#project #important #obsidian
## TODO ํ
์คํธ
- [ ] ์ฒซ ๋ฒ์งธ ํ ์ผ
- [x] ์๋ฃ๋ ํ ์ผ
- [ ] ๋ ๋ฒ์งธ ํ ์ผ
## ์น์
1
๋ด์ฉ์ด ์ฌ๊ธฐ์ ์์ต๋๋ค.
## ์น์
2
๋ค๋ฅธ ๋ด์ฉ์
๋๋ค.`;
// 1. ํ
์คํธ ํ์ผ ์์ฑ
console.log('1. Obsidian ํ
์คํธ ํ์ผ ์์ฑ');
try {
await this.markdownManager.createFile(testFile, testContent);
console.log('โ
Obsidian ํ
์คํธ ํ์ผ ์์ฑ ์ฑ๊ณต');
} catch (error) {
console.log('โ Obsidian ํ
์คํธ ํ์ผ ์์ฑ ์คํจ:', error.message);
}
// 2. ๋งํฌ ์ถ์ถ
console.log('\n2. ๋งํฌ ์ถ์ถ ํ
์คํธ');
try {
const links = await this.obsidianManager.extractLinks(testFile);
console.log('โ
๋งํฌ ์ถ์ถ ์ฑ๊ณต:');
console.log(' ๋ด๋ถ ๋งํฌ:', links.internal.length, '๊ฐ');
console.log(' ์ธ๋ถ ๋งํฌ:', links.external.length, '๊ฐ');
console.log(' ์๋ฒ ๋:', links.embeds.length, '๊ฐ');
console.log(' ํ๊ทธ:', links.tags.length, '๊ฐ');
} catch (error) {
console.log('โ ๋งํฌ ์ถ์ถ ์คํจ:', error.message);
}
// 3. ํ๊ทธ๋ก ํ์ผ ๊ฒ์
console.log('\n3. ํ๊ทธ ๊ฒ์ ํ
์คํธ');
try {
const tagResults = await this.obsidianManager.findFilesByTag('project');
console.log('โ
ํ๊ทธ ๊ฒ์ ์ฑ๊ณต:', tagResults.length, '๊ฐ ๊ฒฐ๊ณผ');
} catch (error) {
console.log('โ ํ๊ทธ ๊ฒ์ ์คํจ:', error.message);
}
// 4. ๋ชจ๋ ํ๊ทธ ์กฐํ
console.log('\n4. ๋ชจ๋ ํ๊ทธ ์กฐํ ํ
์คํธ');
try {
const allTags = await this.obsidianManager.getAllTags();
console.log('โ
๋ชจ๋ ํ๊ทธ ์กฐํ ์ฑ๊ณต:', allTags);
} catch (error) {
console.log('โ ๋ชจ๋ ํ๊ทธ ์กฐํ ์คํจ:', error.message);
}
// 5. ๊ทธ๋ํ ๋ฐ์ดํฐ ์์ฑ
console.log('\n5. ๊ทธ๋ํ ๋ฐ์ดํฐ ์์ฑ ํ
์คํธ');
try {
const graphData = await this.obsidianManager.generateGraphData();
console.log('โ
๊ทธ๋ํ ๋ฐ์ดํฐ ์์ฑ ์ฑ๊ณต:');
console.log(' ๋
ธ๋:', graphData.nodes.length, '๊ฐ');
console.log(' ์ฃ์ง:', graphData.edges.length, '๊ฐ');
} catch (error) {
console.log('โ ๊ทธ๋ํ ๋ฐ์ดํฐ ์์ฑ ์คํจ:', error.message);
}
// 6. TODO ์ถ์ถ
console.log('\n6. TODO ์ถ์ถ ํ
์คํธ');
try {
const todos = await this.obsidianManager.extractTodos(testFile);
console.log('โ
TODO ์ถ์ถ ์ฑ๊ณต:', todos.length, '๊ฐ TODO');
todos.forEach(todo => {
console.log(` - ${todo.completed ? '[x]' : '[ ]'} ${todo.task} (${todo.file}:${todo.line})`);
});
} catch (error) {
console.log('โ TODO ์ถ์ถ ์คํจ:', error.message);
}
// 7. Vault ํต๊ณ
console.log('\n7. Vault ํต๊ณ ํ
์คํธ');
try {
const stats = await this.obsidianManager.generateVaultStats();
console.log('โ
Vault ํต๊ณ ์์ฑ ์ฑ๊ณต:');
console.log(' ์ด ํ์ผ:', stats.totalFiles, '๊ฐ');
console.log(' ์ด ๋จ์ด:', stats.totalWords, '๊ฐ');
console.log(' ์ด ๋งํฌ:', stats.totalLinks, '๊ฐ');
console.log(' ์ด ํ๊ทธ:', stats.totalTags, '๊ฐ');
} catch (error) {
console.log('โ Vault ํต๊ณ ์์ฑ ์คํจ:', error.message);
}
// 8. ์์๋ผ์ธ ์ถ์ถ
console.log('\n8. ์์๋ผ์ธ ์ถ์ถ ํ
์คํธ');
try {
const outline = await this.obsidianManager.extractOutline(testFile);
console.log('โ
์์๋ผ์ธ ์ถ์ถ ์ฑ๊ณต:', outline.length, '๊ฐ ์น์
');
outline.forEach(item => {
console.log(` ${' '.repeat(item.level)}${item.title} (๋ผ์ธ ${item.line})`);
});
} catch (error) {
console.log('โ ์์๋ผ์ธ ์ถ์ถ ์คํจ:', error.message);
}
}
async testAdvancedFeatures() {
console.log('\n๐ ๊ณ ๊ธ ๊ธฐ๋ฅ ํ
์คํธ...\n');
// 1. ๋ฐ์ผ๋ฆฌ ๋
ธํธ ์์ฑ
console.log('1. ๋ฐ์ผ๋ฆฌ ๋
ธํธ ์์ฑ ํ
์คํธ');
try {
const dailyResult = await this.obsidianManager.createDailyNote('2024-01-15', '## ์ค๋์ ํ ์ผ\n\n- [ ] \n\n## ๋ฉ๋ชจ\n\n', 'daily');
console.log('โ
๋ฐ์ผ๋ฆฌ ๋
ธํธ ์์ฑ ์ฑ๊ณต:', dailyResult.filePath);
} catch (error) {
console.log('โ ๋ฐ์ผ๋ฆฌ ๋
ธํธ ์์ฑ ์คํจ:', error.message);
}
// 2. ํ
ํ๋ฆฟ ๊ด๋ฆฌ
console.log('\n2. ํ
ํ๋ฆฟ ๊ด๋ฆฌ ํ
์คํธ');
try {
const templateResult = await this.obsidianManager.manageTemplate('create', 'meeting', '# ํ์๋ก\n\n## ์ฐธ์์\n\n## ์๊ฑด\n\n## ๊ฒฐ์ ์ฌํญ\n\n## ๋ค์ ์ก์
์์ดํ
\n\n');
console.log('โ
ํ
ํ๋ฆฟ ์์ฑ ์ฑ๊ณต:', templateResult.templateName);
} catch (error) {
console.log('โ ํ
ํ๋ฆฟ ์์ฑ ์คํจ:', error.message);
}
// 3. Zettel ID ์์ฑ
console.log('\n3. Zettel ID ์์ฑ ํ
์คํธ');
try {
const zettelId = this.obsidianManager.generateZettelId('TEST');
console.log('โ
Zettel ID ์์ฑ ์ฑ๊ณต:', zettelId);
} catch (error) {
console.log('โ Zettel ID ์์ฑ ์คํจ:', error.message);
}
// 4. ๋
ธํธ ์ ์ฌ์ฑ ๊ณ์ฐ
console.log('\n4. ๋
ธํธ ์ ์ฌ์ฑ ๊ณ์ฐ ํ
์คํธ');
try {
const testFile1 = join(this.testDir, 'similarity-test1.md');
const testFile2 = join(this.testDir, 'similarity-test2.md');
await this.markdownManager.createFile(testFile1, '# ํ์ผ 1\n\n์ด๊ฒ์ ์ฒซ ๋ฒ์งธ ํ์ผ์
๋๋ค.\n\n#test #similarity');
await this.markdownManager.createFile(testFile2, '# ํ์ผ 2\n\n์ด๊ฒ์ ๋ ๋ฒ์งธ ํ์ผ์
๋๋ค.\n\n#test #similarity');
const similarity = await this.obsidianManager.calculateSimilarity(testFile1, testFile2);
console.log('โ
๋
ธํธ ์ ์ฌ์ฑ ๊ณ์ฐ ์ฑ๊ณต:', similarity);
} catch (error) {
console.log('โ ๋
ธํธ ์ ์ฌ์ฑ ๊ณ์ฐ ์คํจ:', error.message);
}
}
async cleanup() {
console.log('\n๐งน ์ ๋ฆฌ ์์
...\n');
try {
// ํ
์คํธ ๋๋ ํ ๋ฆฌ ์ญ์
await fs.rm(this.testDir, { recursive: true, force: true });
console.log('โ
ํ
์คํธ ๋๋ ํ ๋ฆฌ ์ ๋ฆฌ ์๋ฃ');
} catch (error) {
console.log('โ ๏ธ ์ ๋ฆฌ ์ค ์ค๋ฅ:', error.message);
}
}
async run() {
try {
await this.setup();
await this.testBasicOperations();
await this.testObsidianFeatures();
await this.testAdvancedFeatures();
console.log('\n๐ ๋ชจ๋ ํ
์คํธ ์๋ฃ!');
} catch (error) {
console.error('โ ํ
์คํธ ์ค ์ค๋ฅ ๋ฐ์:', error);
} finally {
await this.cleanup();
}
}
}
// ํ
์คํธ ์คํ
const simpleTest = new SimpleTest();
simpleTest.run();