Skip to content
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