- Obsidian vault importer with wikilink → edge conversion - Markdown folder importer with frontmatter parsing - Markdown exporter with wikilinks and frontmatter - JSON-LD linked data exporter - Database backup/restore functionality - CLI: import, backup, restore-backup, list-backups - MCP tools: memory_import, memory_backup, memory_export_markdown, memory_export_jsonld
67 lines
2.5 KiB
TypeScript
67 lines
2.5 KiB
TypeScript
import { Command } from 'commander';
|
|
import chalk from 'chalk';
|
|
import { importObsidian } from '../../core/import/obsidian';
|
|
import { importMarkdown } from '../../core/import/markdown';
|
|
|
|
export const importCommand = new Command('import')
|
|
.description('Import data from external sources')
|
|
.argument('<source>', 'Source type: obsidian, markdown')
|
|
.argument('<path>', 'Path to import from')
|
|
.option('-t, --tags <tags>', 'Additional tags (comma-separated)')
|
|
.option('-k, --kind <kind>', 'Node kind (default: memory)')
|
|
.option('--hierarchy', 'Create folder hierarchy (obsidian only)')
|
|
.option('--dry-run', 'Preview import without making changes')
|
|
.action(async (source: string, inputPath: string, opts) => {
|
|
try {
|
|
const tags = opts.tags?.split(',').map((t: string) => t.trim());
|
|
|
|
switch (source.toLowerCase()) {
|
|
case 'obsidian': {
|
|
console.log(chalk.cyan(`Importing Obsidian vault from ${inputPath}...`));
|
|
const result = await importObsidian(inputPath, {
|
|
kind: opts.kind,
|
|
hierarchy: opts.hierarchy,
|
|
dryRun: opts.dryRun,
|
|
});
|
|
|
|
if (opts.dryRun) {
|
|
console.log(chalk.yellow(`Dry run: would import ${result.imported} notes`));
|
|
console.log(chalk.dim(` Would create ${result.edges} edges from wikilinks`));
|
|
} else {
|
|
console.log(chalk.green(`✓ Imported ${result.imported} notes`));
|
|
if (result.edges > 0) {
|
|
console.log(chalk.dim(` Created ${result.edges} edges from wikilinks`));
|
|
}
|
|
if (result.skipped > 0) {
|
|
console.log(chalk.yellow(` Skipped ${result.skipped} files (already exist)`));
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case 'markdown':
|
|
case 'md': {
|
|
console.log(chalk.cyan(`Importing markdown files from ${inputPath}...`));
|
|
const result = await importMarkdown(inputPath, {
|
|
kind: opts.kind as any,
|
|
tags,
|
|
dryRun: opts.dryRun,
|
|
});
|
|
|
|
if (opts.dryRun) {
|
|
console.log(chalk.yellow(`Dry run: would import ${result.imported} files`));
|
|
} else {
|
|
console.log(chalk.green(`✓ Imported ${result.imported} files`));
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
console.error(chalk.red(`Unknown source type: ${source}`));
|
|
console.log(chalk.dim('Supported: obsidian, markdown'));
|
|
process.exit(1);
|
|
}
|
|
} catch (err: any) {
|
|
console.error(chalk.red(`Error: ${err.message}`));
|
|
process.exit(1);
|
|
}
|
|
});
|