mart-w.de/static/fonts/lato-font-3.0.0/bin/rename.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-04-03 03:44:07 +02:00
var path = require('path');
var fs = require('fs');
var file = require('file');
var _ = require('underscore');
var changeCase = require('change-case');
var filterExtensions = ['.eot', '.ttf', '.woff'];
var map = {
'lato-regular' : 'lato-normal',
'lato-italic' : 'lato-normal-italic'
};
var fontsPath = path.resolve(__dirname + '/../fonts');
file.walk(fontsPath, function() {
var files = arguments[3];
_.each(files, function(filePath) {
var extension = path.extname(filePath);
if (-1 !== filterExtensions.indexOf(extension)) {
renameFile(filePath);
}
});
});
function renameFile(filePath) {
var dirName = path.dirname(filePath);
var filename = path.basename(filePath);
var baseFileName = filename.replace(/\.[^/.]+$/, '');
var extension = path.extname(filePath);
var newBaseFileName = changeCase.paramCase(baseFileName);
// Handling exceptional cases.
if (map[newBaseFileName]) {
newBaseFileName = map[newBaseFileName];
}
var newFileName = newBaseFileName + extension;
var newFilePath = dirName + '/' + newFileName;
console.log('Renaming: ' + filename + ' to: ' + newFileName);
// Re-naming the file.
fs.rename(filePath, newFilePath);
}