rmDuplicates not dying when its output is piped

This commit is contained in:
mrfry 2021-04-28 17:36:52 +02:00
parent 53bcdf5672
commit 6ef65fb26a

View file

@ -121,12 +121,9 @@ function removePossibleAnswersDuplicates(path) {
count++
})
let removed = 0
dirs.forEach((currDir) => {
const contents = fs.readdirSync(path + '/' + currDir)
let removed = 0
log(
`Processing ${C('green')}${currDir}${C()} (${contents.length} files) ...`
)
contents.forEach((currFile) => {
const currPath = path + '/' + currDir + '/' + currFile
@ -173,10 +170,8 @@ function removePossibleAnswersDuplicates(path) {
})
})
})
log(`Removed ${C('red')}${removed}${C()} files`)
hr()
})
log(`Removed ${C('red')}${removed}${C()} files total`)
log(`${C('green')}Deleting empty directories ...${C()}`)
count = dirs.length
@ -415,14 +410,19 @@ function hr() {
}
function log(text) {
process.stdout.clearLine()
process.stdout.cursorTo(0)
utils.AppendToFile(text, globalLog)
if (process.stdout.isTTY) {
process.stdout.clearLine()
process.stdout.cursorTo(0)
}
console.log(text)
utils.AppendToFile(text, globalLog)
}
function writeInSameLine(text, returnToLineStart) {
if (!process.stdout.isTTY) {
return
}
process.stdout.clearLine()
process.stdout.cursorTo(0)
process.stdout.write(text)
@ -434,6 +434,9 @@ function writeInSameLine(text, returnToLineStart) {
}
function printProgressBar(current, total) {
if (!process.stdout.isTTY) {
return
}
const width = process.stdout.columns - 30
if (width <= 0) {