aboutsummaryrefslogtreecommitdiff
path: root/node_modules/gulp-debug/index.js
blob: ce720ab381174656dad72bb4d135aa2981d3c470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const path = require('path');
const gutil = require('gulp-util');
const through = require('through2');
const tildify = require('tildify');
const stringifyObject = require('stringify-object');
const chalk = require('chalk');
const plur = require('plur');

const prop = chalk.blue;

module.exports = opts => {
	opts = Object.assign({
		title: 'gulp-debug:',
		minimal: true,
		showFiles: true
	}, opts);

	if (process.argv.indexOf('--verbose') !== -1) {
		opts.verbose = true;
		opts.minimal = false;
		opts.showFiles = true;
	}

	let count = 0;

	return through.obj((file, enc, cb) => {
		if (opts.showFiles) {
			const full =
				'\n' +
				(file.cwd ? 'cwd:   ' + prop(tildify(file.cwd)) : '') +
				(file.base ? '\nbase:  ' + prop(tildify(file.base)) : '') +
				(file.path ? '\npath:  ' + prop(tildify(file.path)) : '') +
				(file.stat && opts.verbose ? '\nstat:  ' + prop(stringifyObject(file.stat, {indent: '       '}).replace(/[{}]/g, '').trim()) : '') +
				'\n';

			const output = opts.minimal ? prop(path.relative(process.cwd(), file.path)) : full;

			gutil.log(opts.title + ' ' + output);
		}

		count++;
		cb(null, file);
	}, cb => {
		gutil.log(opts.title + ' ' + chalk.green(count + ' ' + plur('item', count)));
		cb();
	});
};