mirror of
https://github.com/primer/css.git
synced 2024-11-23 20:38:58 +03:00
23 lines
594 B
JavaScript
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() {}
|