Created
February 24, 2025 09:38
-
-
Save hatemhosny/f5b691dbe102b12f8b6d6e5b731402b6 to your computer and use it in GitHub Desktop.
change extension from md to mdx using git
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 { exec } = require('child_process'); | |
const DIRECTORY = 'docs'; | |
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; | |
} | |
} | |
} | |
const rename = (oldPath, newPath) => exec(`git mv ${oldPath} ${newPath}`); | |
(async () => { | |
for await (const originalFilePath of getFiles(DIRECTORY)) { | |
const parts = originalFilePath.split('.'); | |
if (parts[parts.length - 1] !== 'md') continue; | |
parts[parts.length - 1] = 'mdx'; | |
const newFilePath = parts.join('.'); | |
rename(originalFilePath, newFilePath); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment