Initial Implementation
This commit is contained in:
commit
4c35ddd906
1 changed files with 28 additions and 0 deletions
28
sync.mjs
Normal file
28
sync.mjs
Normal file
|
@ -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);
|
||||
}
|
Loading…
Add table
Reference in a new issue