commit 4c35ddd906c6cb40f4cae4f7eee2bbc4bbd61e7a Author: Henry Jameson Date: Mon Jan 13 01:38:55 2025 +0200 Initial Implementation diff --git a/sync.mjs b/sync.mjs new file mode 100644 index 0000000..c3678b0 --- /dev/null +++ b/sync.mjs @@ -0,0 +1,28 @@ +import { readdir, readFile, writeFile, cp } from 'node:fs/promises'; + +try { + const dirs = await readdir('.', { withFileTypes: true }); + for (const dir of dirs) { + if (dir.path.startsWith('.')) continue + if (dir.isDirectory()) { + let pack + try { + const packFile = (await readFile(dir.path + '/pack.json')).toString() + pack = JSON.parse(packFile).pack + } catch { + continue + } + const contents = await readdir(dir.path, { withFileTypes: true }); + const files = Object.fromEntries( + contents + .map(x => [x.name.replace(/\.\w+$/, ''), x.name]) + .filter(([k, v]) => v.match(/\.(a?png|jpe?g|gif)$/) != null) + ) + cp(dir.path + '/pack.json', dir.path + '/pack_backup.json') + const output = { files, pack, files_count: Object.keys(files).length } + await writeFile(dir.path + '/pack.json', JSON.stringify(output, null, 2)) + } + } +} catch (err) { + console.error(err); +}