Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs'),
- resolve = require('path').resolve,
- promisify = require('util').promisify,
- readdir = promisify(fs.readdir),
- stat = promisify(fs.stat),
- path = require('path'),
- colors = require('@colors/colors/safe')
- Scandir = async (dir) => {
- let subdirs = await readdir(dir)
- let files = await Promise.all(subdirs.map(async (subdir) => {
- let res = resolve(dir, subdir)
- return (await stat(res)).isDirectory() ? Scandir(res) : res
- }))
- return files.reduce((a, f) => a.concat(f), [])
- }
- Scandir('./').then(files => {
- if (files.length == 0) return console.log(colors.red('Files empty'))
- let old = new Date()
- files.map(v => {
- let str = fs.readFileSync(v, 'utf-8')
- .replace(new RegExp('[OLD_STRING]', 'g'), '[NEW_STRING')
- .replace(new RegExp('[OLD_STRING]', 'g'), 'NEW_STRING')
- // and more ...
- fs.writeFileSync(v, str, 'utf-8')
- })
- let result = `\n${files.map(v => `${colors.cyan('-')} ${colors.yellow(`${v.split('/')[v.split('/').length - 2]}/${v.split('/')[v.split('/').length - 1]}`)}`).join('\n')}\n\n`
- result += colors.green(`✅ ${files.length} files, completed within ${colors.green((new Date - old) * 1)} ms`)
- console.log(result)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement