diff --git a/scripts/rename.js b/scripts/rename.js new file mode 100644 index 00000000..137f62f3 --- /dev/null +++ b/scripts/rename.js @@ -0,0 +1,27 @@ +const path = require('path'); +const fs = require('fs'); + +const listDir = (dir, fileList = []) => { + const files = fs.readdirSync(dir); + + files.forEach((file) => { + if (fs.statSync(path.join(dir, file)).isDirectory()) { + fileList = listDir(path.join(dir, file), fileList); + } else if (/\.txt$/.test(file)) { + const name = file.replace(/\.(js)/, '.tsx'); + const src = path.join(dir, file); + const newSrc = path.join(dir, name); + fileList.push({ + oldSrc: src, + newSrc, + }); + } + }); + + return fileList; +}; + +const foundFiles = listDir('./src'); +foundFiles.forEach((f) => { + fs.renameSync(f.oldSrc, f.newSrc); +});