Created
November 17, 2019 12:47
-
-
Save uinz/3c075dbee62fb144380ad3effa80671d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// yarn add fs-extra glob | |
const { promisify } = require('util'); | |
const glob = promisify(require('glob')); | |
const fse = require('fs-extra'); | |
const path = require('path'); | |
async function replace(ext, newExt) { | |
const pattern = path.resolve(__dirname, `**/*.${ext}`); | |
const filenames = await glob(pattern); | |
const promises = filenames.map(filename => { | |
const reg = new RegExp(`\\.${ext}$`); | |
const newFilename = filename.replace(reg, `.${newExt}`); | |
console.log(filename) | |
console.log(newFilename) | |
console.log('--------------------------------') | |
return fse.rename(filename, newFilename); | |
}); | |
await Promise.all(promises); | |
console.log('[DONE]'); | |
} | |
replace('ttss', 'wxss'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment