Last active
July 8, 2022 21:45
-
-
Save ovidiuch/16deb5dfb849c56f4b1b5c86da32c869 to your computer and use it in GitHub Desktop.
Rename camelCase files to kebab-files
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 fs = require('fs'); | |
const path = require('path'); | |
const glob = require('glob'); | |
const { kebabCase } = require('lodash'); | |
glob | |
.sync('**/*', { ignore: '**/{coverage,node_modules}/**' }) | |
.forEach(filePath => { | |
const pathParts = filePath.split('/'); | |
const fileName = pathParts.pop(); | |
if ( | |
fileName.toLowerCase() !== fileName && | |
fileName[0].toUpperCase() !== fileName[0] | |
) { | |
const ext = path.extname(fileName); | |
const newName = `${kebabCase(path.basename(fileName, ext))}${ext}`; | |
const newPath = pathParts.concat(newName).join('/'); | |
console.log('Renaming...'); | |
console.log('Old', filePath); | |
console.log('New', newPath); | |
fs.renameSync(filePath, newPath); | |
console.log('Renamed.'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wrong for files like
myTest.e2e.spec.ts
:/