Last active
May 1, 2023 16:23
-
-
Save manzt/47c8fb3ac20ccdca98d48c060a9295ec to your computer and use it in GitHub Desktop.
Utility script to rename React files with .js to .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"; | |
let matchingReactString = "from 'react'"; | |
let BLUE = "\u001b[34m"; | |
let YELLOW = "\u001b[33m"; | |
let 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) => { | |
let result = await fsp.readFile(path); | |
if (!result.includes(matchingReactString)) return; | |
// Just add 'x' to the end to make it 'jsx' | |
let 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