A note-taking app inspired by nb
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

migrate: add migration off .index files

bitquabit.com 75648242 a788466a

verified
+13 -10
-3
folders.ts
··· 1 - import { join } from "@std/path"; 2 1 import { moveFile } from "./utils.ts"; 3 2 import { Hsh } from "./hsh.ts"; 4 3 import { NotebookPath } from "./notebook.ts"; 5 4 6 5 export async function addFolder(path: NotebookPath, hsh: Hsh) { 7 6 Deno.mkdirSync(path.getAbsolutePath(), { recursive: true }); 8 - Deno.writeTextFileSync(join(path.getAbsolutePath(), ".index"), ""); 9 7 await hsh.emitNotebookChanged?.( 10 8 path.notebook, 11 9 `[hsh]: Add folder ${path}`, ··· 23 21 throw new Error(`Folder ${path} is not empty`); 24 22 } 25 23 } 26 - Deno.removeSync(path.withEntry(".index").getAbsolutePath()); 27 24 Deno.removeSync(path.getAbsolutePath(), { recursive: force }); 28 25 await hsh.emitNotebookChanged?.( 29 26 path.notebook,
+1 -2
hsh.ts
··· 112 112 async initNotebook(name: string): Promise<Notebook> { 113 113 const root = join(this.config.root, "notebooks", name); 114 114 await initRepo(root); 115 - Deno.writeTextFileSync(join(root, ".index"), ""); 116 - Deno.writeTextFileSync(join(root, ".hsh"), "version: 1\n"); 115 + Deno.writeTextFileSync(join(root, ".hsh"), "version: 2\n"); 117 116 await this.emitNotebookChanged?.( 118 117 new Notebook(name), 119 118 "[hsh]: Create notebook",
+12 -5
migrate.ts
··· 1 - import { existsSync, walkSync } from "@std/fs"; 1 + import { walk, walkSync } from "@std/fs"; 2 2 import { decodeTime, ulid } from "@std/ulid"; 3 3 4 4 import { moveFile } from "./utils.ts"; ··· 10 10 11 11 const migrations = [ 12 12 adoptUlids, 13 + removeIndexFiles, 13 14 ]; 14 15 15 16 export async function migrate(notebook: Notebook) { 16 17 for (const migration of migrations) { 17 18 await migration(notebook); 18 19 } 20 + Deno.writeTextFileSync(join(notebook.root, ".hsh"), "version: 2\n"); 19 21 } 20 22 21 23 function walkNotebook(path: string) { ··· 27 29 }); 28 30 } 29 31 30 - async function adoptUlids(notebook: Notebook) { 32 + async function adoptUlids(notebook: Notebook): Promise<void> { 31 33 const root = notebook.root; 32 34 for (const entry of walkNotebook(root)) { 33 35 if (entry.name.startsWith(".")) continue; ··· 47 49 moveFile(entry.path, newpath); 48 50 console.log(`renaming ${entry.path} => ${newpath}`); 49 51 } 50 - if (!existsSync(join(root, ".hsh"))) { 51 - Deno.writeTextFileSync(join(root, ".hsh"), "version: 1\n"); 52 + commit(notebook, "migrated all markdown entries to ULIDs"); 53 + } 54 + 55 + async function removeIndexFiles(notebook: Notebook) { 56 + const root = notebook.root; 57 + for await (const entry of walk(root, { match: [/\.index$/] })) { 58 + Deno.removeSync(entry.path); 52 59 } 53 - commit(notebook, "migrated all markdown entries to ULIDs"); 60 + commit(notebook, "migrated off .index files"); 54 61 }