Skip to content

Instantly share code, notes, and snippets.

@manzt
Last active May 1, 2023 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manzt/47c8fb3ac20ccdca98d48c060a9295ec to your computer and use it in GitHub Desktop.
Save manzt/47c8fb3ac20ccdca98d48c060a9295ec to your computer and use it in GitHub Desktop.
Utility script to rename React files with .js to .jsx
// @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