const join = require('path').join const glob = require('glob') const fs = require('fs') const jsonPath = join(__dirname, '../src/background-images.json') glob(join(__dirname, '../public/assets/images/background/*.jpg'), (err, paths) => { if (err) throw err let publicPaths = [] publicPaths = paths.map((path) => path.replace(/.*?public/, '')) fs.writeFile(jsonPath, JSON.stringify(publicPaths), 'utf8', (err) => { if (err) throw err console.log(`Images JSON saved to: ${jsonPath}`) process.exit(0) }) })