Last active
July 31, 2024 23:16
-
-
Save finalclass/5697373 to your computer and use it in GitHub Desktop.
recursively renames every file and directory in the script path from camelCase and UpperCamelCase to dash-case
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
/*jshint node:true*/ | |
'use strict'; | |
/** | |
* This scripts recursively renames every file and directory in the script path | |
* from camelCase and UpperCamelCase to dash-case | |
* | |
* Do a backup before executing this script | |
* | |
* @lecense MIT | |
* @author Szymon Wygnański <[email protected]> | |
*/ | |
var fs = require('fs'), | |
path = require('path'); | |
function camelToDash(text) { | |
return text.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); | |
} | |
function renameDir(dir) { | |
var files = fs.readdirSync(dir), | |
f, | |
fileName, | |
path, | |
newPath, | |
file; | |
for (f = 0; f < files.length; f += 1) { | |
fileName = files[f]; | |
path = dir + '/' + fileName; | |
file = fs.statSync(path); | |
newPath = dir + '/' + camelToDash(fileName); | |
fs.renameSync(path, newPath); | |
if (file.isDirectory()) { | |
renameDir(newPath); | |
} | |
} | |
} | |
renameDir(__dirname); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! very handy to have in certain cases!
Other than that I did not backup the .git folder and had to re-clone the repo.....
That's on me though.
An ignore array wouldn't hurt I guess