Skip to content

remove ANSI escape codes on [ ! -t 1 ] #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <directory> [options]')}
Usage: ${color(cyan, '$ delete-empty <directory> [options]')}

Directory: (optional) Initial directory to begin the search for empty
directories. Otherwise, cwd is used.
Expand All @@ -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)) {
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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') {
Expand Down