From 643b38f1d1afa8c205a056f1f825e70067dbec1c Mon Sep 17 00:00:00 2001 From: Juyeong Maing Date: Wed, 23 Jul 2025 20:22:48 +0900 Subject: [PATCH 1/2] remove ANSI escape codes on `[ ! -t 1 ]` --- bin/cli.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 1ad4546..840d813 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -11,12 +11,14 @@ const argv = require('minimist')(process.argv.slice(2), { rename: { _: 'files' } }); -const moduleDir = dim(`<${path.dirname(__dirname)}>`); -const name = pkg => bold(`delete-empty v${pkg.version}`); +const color = (colorFn, text) => process.stdout.isTTY ? colorFn(text) : text; + +const moduleDir = color(dim, `<${path.dirname(__dirname)}>`); +const name = pkg => color(bold, `delete-empty v${pkg.version}`); const help = pkg => ` Path: <${path.dirname(__dirname)}> -Usage: ${cyan('$ delete-empty [options]')} +Usage: ${color(cyan, '$ delete-empty [options]')} Directory: (optional) Initial directory to begin the search for empty directories. Otherwise, cwd is used. @@ -34,7 +36,7 @@ if (argv.help) { process.exit(); } -const ok = green(symbols.check); +const ok = color(green, symbols.check); const cwd = path.resolve(argv._[0] || argv.cwd || process.cwd()); const relative = filepath => { if (filepath.startsWith(cwd)) { From 88165d3814637575bd19182506bdb2b5d5a35079 Mon Sep 17 00:00:00 2001 From: Juyeong Maing Date: Wed, 23 Jul 2025 20:29:54 +0900 Subject: [PATCH 2/2] add missing files --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index edcd6f7..393fe19 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,8 @@ const startsWith = require('path-starts-with'); const colors = require('ansi-colors'); const readdir = util.promisify(fs.readdir); +const color = (colorFn, text) => process.stdout.isTTY ? colorFn(text) : text; + /** * Helpers */ @@ -80,7 +82,7 @@ const deleteEmpty = (cwd, options, cb) => { await deleteDir(dir, opts); if (opts.verbose === true) { - console.log(colors.red('Deleted:'), path.relative(cwd, dir)); + console.log(color(colors.red, 'Deleted:'), path.relative(cwd, dir)); } if (typeof opts.onDelete === 'function') { @@ -125,7 +127,7 @@ deleteEmpty.sync = (cwd, options) => { deleteDirSync(dir, opts); if (opts.verbose === true) { - console.log(colors.red('Deleted:'), path.relative(cwd, dir)); + console.log(color(colors.red, 'Deleted:'), path.relative(cwd, dir)); } if (typeof opts.onDelete === 'function') {