Created
March 5, 2021 10:28
-
-
Save mariofink/1a4566d8b9bc25994037f515e742148d 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
const { resolve } = require('path'); | |
const { readdir } = require('fs').promises; | |
const fs = require('fs'); | |
const result = []; | |
async function* getFiles(dir) { | |
const dirents = await readdir(dir, { withFileTypes: true }); | |
for (const dirent of dirents) { | |
const res = resolve(dir, dirent.name); | |
if (dirent.isDirectory()) { | |
yield* getFiles(res); | |
} else { | |
yield res; | |
} | |
} | |
} | |
(async () => { | |
for await (const f of getFiles('./src/components')) { | |
if (!f.endsWith('.js')) continue; | |
if (f.endsWith('stories.js') || f.endsWith('.test.js')) { | |
continue; | |
} | |
result.push(f); | |
} | |
result.map((filename) => { | |
fs.readFile(filename, function (err, data) { | |
if (err) throw err; | |
if (data.includes("import React from 'react'")) { | |
let a = filename.split('/'); | |
a.splice(0, 6); | |
const currentName = a.join('/'); | |
const newName = currentName.replace(/\.js$/, '.jsx'); | |
console.log(`git mv ${currentName} ${newName}`); | |
} | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment