Skip to content

Instantly share code, notes, and snippets.

@ovidiuch
Last active July 8, 2022 21:45
Show Gist options
  • Save ovidiuch/16deb5dfb849c56f4b1b5c86da32c869 to your computer and use it in GitHub Desktop.
Save ovidiuch/16deb5dfb849c56f4b1b5c86da32c869 to your computer and use it in GitHub Desktop.
Rename camelCase files to kebab-files
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.');
}
});
@yadimon
Copy link

yadimon commented Oct 25, 2021

wrong for files like myTest.e2e.spec.ts :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment