Skip to content

Commit

Permalink
chore: add script for dumping test metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-lednev committed Nov 24, 2024
1 parent 833f999 commit 9d1a6d9
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/dump-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { App } from "obsidian";
import { getAPI } from "obsidian-dataview";

const fixtureVaultPath = "fixture-vault";
const metadataDumpPath =
".obsidian/plugins/obsidian-day-planner/fixtures/metadata-dump";

export function createDumpMetadataCommand(app: App) {
return async () => {
const pathToHeadings = Object.fromEntries(
app.vault
.getMarkdownFiles()
.map((tFile) => [
tFile.path,
app.metadataCache.getFileCache(tFile)?.headings,
]),
);

const exists = await app.vault.adapter.exists(metadataDumpPath);

if (exists) {
await app.vault.adapter.rmdir(metadataDumpPath, true);
}

await app.vault.adapter.mkdir(metadataDumpPath);

await app.vault.create(
`${metadataDumpPath}/headings-metadata.json`,
JSON.stringify(pathToHeadings, null, 2),
);

const tasks = getAPI(app)
?.pages(`"${fixtureVaultPath}"`)
.file.tasks.array();

await app.vault.create(
`${metadataDumpPath}/tasks.json`,
JSON.stringify(tasks, null, 2),
);
};
}

0 comments on commit 9d1a6d9

Please sign in to comment.