Skip to content

Commit

Permalink
chore(scripts): simple script that will rename all .js files to .tsx
Browse files Browse the repository at this point in the history
improves #37
  • Loading branch information
aneurysmjs committed Oct 3, 2019
1 parent b3423ac commit aac9344
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions scripts/rename.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit aac9344

Please sign in to comment.