Last active
August 9, 2022 13:37
-
-
Save manzt/8d85c605bedcdb1f839f1933cd87e595 to your computer and use it in GitHub Desktop.
rename .js -> .jsx for JS files containing JSX
This file contains 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
// @ts-check | |
import * as fsp from "node:fs/promises"; | |
import * as util from "node:util"; | |
import glob from "glob"; | |
const matchingReactString = "from 'react'"; | |
const BLUE = "\u001b[34m"; | |
const YELLOW = "\u001b[33m"; | |
const RESET = "\u001b[0m"; | |
let matches = await util.promisify(glob)(process.argv[2]); | |
console.log(`${BLUE}Found these files matching the globs specified:${RESET}`); | |
console.log(matches); | |
matches.forEach(async (path) => { | |
const result = await fsp.readFile(path); | |
if (!result.includes(matchingReactString)) return; | |
// Just add 'x' to the end to make it 'jsx' | |
const newPath = path.concat("x"); | |
console.log(`${YELLOW}Renaming ${path} to ${newPath}${RESET}`); | |
fsp.rename(path, newPath); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment