import fs from 'fs/promises'; /** * Remove all the databases without the use of external tools * TODO: Fix the ts linking issue here. Should just be adding this as a dir in tsconfig.json */ const rmDbs = async (dry = false) => { // First, we need to find all the database base files // These end in either .db.sqlite, .sqlite, .db // Get all the files in the current directory const files = await fs.readdir('./'); // Filter out the files that end in .db.sqlite, .sqlite, .db const dbFiles = files.filter(file => file.endsWith('.db.sqlite') || file.endsWith('.sqlite') || file.endsWith('.db')); // We need to remove all the files await deleteFiles(dbFiles, dry); } const deleteFiles = async (files: string[], dry = false) => { if (dry) { console.log('Dry run, would delete:', files); return } await Promise.all(files.map(file => fs.rm(file))); console.log('All databases removed'); } // Read args const args = process.argv.slice(2); const dry = args.includes('--dry'); // Delete the files await rmDbs(dry);