MCPcopy
hub / github.com/callumalpass/tasknotes / ensureStarterNote

Function ensureStarterNote

src/bootstrap/starterNote.ts:142–187  ·  view source on GitHub ↗
(host: StarterNoteHost)

Source from the content-addressed store, hash-verified

140};
141
142export async function ensureStarterNote(host: StarterNoteHost): Promise<StarterNoteResult> {
143 if (host.settings.starterNoteCreated) {
144 return "already-created";
145 }
146
147 if (!host.shouldCreateStarterNote) {
148 return "not-first-install";
149 }
150
151 const normalizedPath = normalizePath(STARTER_NOTE_PATH);
152
153 try {
154 const vault = host.app.vault;
155 const existing = await vault.adapter.exists(normalizedPath);
156 let file: TFile;
157 let result: StarterNoteResult = "created";
158
159 if (existing) {
160 const existingFile = vault.getAbstractFileByPath(normalizedPath);
161 if (!(existingFile instanceof TFile)) {
162 host.warn?.(
163 `[TaskNotes][StarterNote] Starter note path exists but is not a file: ${normalizedPath}`
164 );
165 return "path-not-file";
166 }
167 file = existingFile;
168 result = "opened-existing";
169 } else {
170 const lastSlashIndex = normalizedPath.lastIndexOf("/");
171 const directory =
172 lastSlashIndex >= 0 ? normalizedPath.substring(0, lastSlashIndex) : "";
173 if (directory) {
174 await ensureFolderHierarchy(vault, directory);
175 }
176 file = await vault.create(normalizedPath, STARTER_NOTE_CONTENT);
177 }
178
179 host.settings.starterNoteCreated = true;
180 await host.saveSettings();
181 await host.app.workspace.getLeaf("tab").openFile(file);
182 return result;
183 } catch (error) {
184 host.warn?.("[TaskNotes][StarterNote] Failed to create starter note:", error);
185 return "failed";
186 }
187}

Callers 1

Calls 8

normalizePathFunction · 0.90
ensureFolderHierarchyFunction · 0.90
existsMethod · 0.80
getAbstractFileByPathMethod · 0.80
warnMethod · 0.80
getLeafMethod · 0.80
createMethod · 0.65
saveSettingsMethod · 0.45

Tested by

no test coverage detected