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