Skip to content

Instantly share code, notes, and snippets.

@uinz
Created November 17, 2019 12:47
Show Gist options
  • Save uinz/3c075dbee62fb144380ad3effa80671d to your computer and use it in GitHub Desktop.
Save uinz/3c075dbee62fb144380ad3effa80671d to your computer and use it in GitHub Desktop.
// 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