import '@johnlindquist/kit'
import { faker } from '@faker-js/faker'
const imageDir = await path({
onlyDirs: true,
placeholder: 'Select a directory with images to rename',
})
const imageFiles = await readdir(imageDir)
.then(files => files.filter(file => /\.(jpe?g|png|gif)$/i.test(file)))
.catch(error => {
console.error('Error reading directory:', error)
exit()
})
if (!imageFiles.length) {
await div(md(`# No images found in ${imageDir}`))
exit()
}
const fakeImageNames = imageFiles.map(() => faker.word.words(3).replace(/\s/g, '-') + '-' + faker.string.alphanumeric(8))
for (let i = 0; i < imageFiles.length; i++) {
const oldImagePath = path.join(imageDir, imageFiles[i])
const ext = path.extname(imageFiles[i])
const newFileName = fakeImageNames[i] + ext
const newImagePath = path.join(imageDir, newFileName)
await rename(oldImagePath, newImagePath)
}
await notify({
title: 'Images Renamed!',
body: `Renamed ${imageFiles.length} images in ${imageDir} with fake names.`,
icon: 'face-smile',
})
await revealFile(imageDir)