-
//- Format bytes
function binarySize(size) {
let total;
let unit;
let mega = 1024 * 1024
let kilo = 1024
//- In Megabytes
if (size >= mega) {
total = (size / mega).toFixed(1);
unit = 'MB';
//- In Kilobytes
} else if (size >= kilo) {
total = (size / kilo).toFixed(1);
unit = 'KB';
//- In bytes
} else {
total = size;
unit = ' bytes';
}
return `${total}${unit}`;
}
function getFiles(dir, ignored, filelist) {
//- Don't get ignored files
if (!ignored.ignores(dir)) {
//- Get current directory's files
let files = fs.readdirSync(`${__dirname}/${dir}`);
//- Create file list if it doesn't exist
filelist = filelist || [];
files.forEach(function(file) {
let stats = fs.statSync(`${__dirname}/${dir}/${file}`);
if (stats.isDirectory()) {
//- Get directory's files
filelist = getFiles(`${dir}/${file}`, ignored, filelist);
} else {
//- Add file to file list
filelist.push(stats);
}
});
}
return filelist;
};
function directoryModified(path, ignored) {
let files = getFiles(path, ignored);
files.sort(function(a, b) {
return b.mtime - a.mtime;
})
return files[0].mtime;
}