1
1
mirror of https://github.com/primer/css.git synced 2024-11-23 20:38:58 +03:00
css/lib/rename.js
2019-02-04 12:55:18 -08:00

23 lines
594 B
JavaScript

module.exports = function rename(fn, options = {}) {
const {log = noop} = options
return (files, metal, done) => {
for (const [key, file] of Object.entries(files)) {
let dest = fn(file, key, files, metal)
if (dest === true) {
log(`[rename] keep: ${key}`)
} else if (dest && dest !== key) {
log(`[rename] ${key} -> ${dest}`)
file.path = dest
files[dest] = file
delete files[key]
} else if (dest === false) {
log(`[rename] delete ${key}`)
delete files[key]
}
}
done()
}
}
function noop() {}