Created
September 11, 2023 23:12
-
-
Save scarf005/cb820319d6e6d76a216dcb5bc7348f0d to your computer and use it in GitHub Desktop.
rename all files to be snake_case
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
import { walk } from "https://deno.land/[email protected]/fs/walk.ts" | |
import { join } from "https://deno.land/[email protected]/path/join.ts" | |
import { parse } from "https://deno.land/[email protected]/path/parse.ts" | |
import { asynciter } from "https://deno.land/x/[email protected]/mod.ts" | |
import { snakeCase } from "https://deno.land/x/[email protected]/mod.ts" | |
if (import.meta.main) { | |
// walk all markdown files in doc/src/content, and rename filenames to snake_case | |
await asynciter(walk("doc/src/content", { exts: ["md"], includeDirs: false })) | |
.map(({ path }) => ({ path, ...parse(path) })) | |
.concurrentUnorderedMap(({ path, dir, name, ext }) => { | |
const newPath = join(dir, snakeCase(name) + ext) | |
console.log(`${path} -> ${newPath}`) | |
return Deno.rename(path, newPath) | |
}) | |
.collect() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment