this repo has no description
at main 1.7 kB view raw
1import { $ } from "bun"; 2 3const database = Bun.file("./works.json"); 4 5// Get current works.json 6const newDatabase = await database 7 .text() 8 .then((text) => JSON.parse(text)) 9 .then((parsed) => Object.values(parsed)); 10 11// Get works.json before whats staged 12// Hide staged changes 13await $`git stash push --staged`; 14 15const oldDatabase = await database 16 .text() 17 .then((text) => JSON.parse(text)) 18 .then((parsed) => Object.values(parsed)); 19 20// Reapply staged changes 21await $`git stash apply`; 22await $`git add works.json`; 23 24const added = new Set<string>(); 25const removed = new Set<string>(); 26const changed = new Set<string>(); 27 28function compareEntries(a: any, b: any) { 29 delete a.builtAt; 30 delete a.descriptionHash; 31 delete b.builtAt; 32 delete b.descriptionHash; 33 return JSON.stringify(a) === JSON.stringify(b); 34} 35 36for (const newEntry of newDatabase) { 37 const oldEntry = oldDatabase.find((e: any) => e.id === newEntry.id); 38 if (!oldEntry) { 39 added.add(newEntry.id); 40 } else if (!compareEntries(newEntry, oldEntry)) { 41 changed.add(newEntry.id); 42 } 43} 44 45for (const oldEntry of oldDatabase) { 46 const newEntry = newDatabase.find((e: any) => e.id === oldEntry.id); 47 if (!newEntry) { 48 removed.add(oldEntry.id); 49 } 50} 51 52let message = []; 53 54if (added.size > 0) { 55 message.push(`add ${Array.from(added).sort().join(", ")}`); 56} 57 58if (removed.size > 0) { 59 message.push(`remove ${Array.from(removed).sort().join(", ")}`); 60} 61 62if (changed.size > 0) { 63 message.push(`update ${Array.from(changed).sort().join(", ")}`); 64} 65 66if (message.length === 0) { 67 message.push("no significant changes"); 68} 69 70message[0] = message[0][0].toUpperCase() + message[0].slice(1); 71 72Bun.spawnSync(["git", "commit", "-m", `🗃️ ${message.join(", ")}`]);