MCPcopy Create free account
hub / github.com/callumalpass/tasknotes / ensureDefaultBasesViewFiles

Function ensureDefaultBasesViewFiles

src/bootstrap/defaultBasesFiles.ts:56–122  ·  view source on GitHub ↗
(
	host: DefaultBasesFileHost,
	options: DefaultBasesFileOptions = {}
)

Source from the content-addressed store, hash-verified

54}
55
56export async function ensureDefaultBasesViewFiles(
57 host: DefaultBasesFileHost,
58 options: DefaultBasesFileOptions = {}
59): Promise<DefaultBasesFileResult> {
60 const created: string[] = [];
61 const updated: string[] = [];
62 const skipped: string[] = [];
63 const overwriteExisting = options.overwriteExisting === true;
64
65 try {
66 const vault = host.app.vault;
67 const adapter = vault.adapter;
68 const commandFileMapping = {
69 ...DEFAULT_SETTINGS.commandFileMapping,
70 ...(host.settings.commandFileMapping ?? {}),
71 };
72 host.settings.commandFileMapping = commandFileMapping;
73
74 for (const [commandId, rawPath] of Object.entries(commandFileMapping)) {
75 if (!rawPath) {
76 continue;
77 }
78
79 const normalizedPath = normalizePath(rawPath);
80 const template = host.generateTemplate(commandId);
81 if (!template) {
82 skipped.push(rawPath);
83 continue;
84 }
85
86 if (await adapter.exists(normalizedPath)) {
87 if (!overwriteExisting) {
88 skipped.push(rawPath);
89 continue;
90 }
91
92 const existing = vault.getAbstractFileByPath(normalizedPath);
93 if (!(existing instanceof TFile)) {
94 host.warn?.(
95 `[TaskNotes][Bases] Cannot update default Bases file because path is not a file: ${normalizedPath}`
96 );
97 skipped.push(rawPath);
98 continue;
99 }
100
101 await vault.modify(existing, template);
102 updated.push(rawPath);
103 continue;
104 }
105
106 const lastSlashIndex = normalizedPath.lastIndexOf("/");
107 const directory =
108 lastSlashIndex >= 0 ? normalizedPath.substring(0, lastSlashIndex) : "";
109
110 if (directory) {
111 await ensureFolderHierarchy(vault, directory);
112 }
113

Callers 2

ensureBasesViewFilesMethod · 0.90

Calls 7

normalizePathFunction · 0.90
ensureFolderHierarchyFunction · 0.85
existsMethod · 0.80
getAbstractFileByPathMethod · 0.80
warnMethod · 0.80
createMethod · 0.65
modifyMethod · 0.45

Tested by

no test coverage detected