2016-10-10 03:43:44 +02:00
|
|
|
'use strict';
|
2017-08-14 05:01:11 +02:00
|
|
|
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({
|
2016-10-10 03:43:44 +02:00
|
|
|
title: 'gulp-debug:',
|
2017-08-14 05:01:11 +02:00
|
|
|
minimal: true,
|
|
|
|
showFiles: true
|
2016-10-10 03:43:44 +02:00
|
|
|
}, opts);
|
|
|
|
|
|
|
|
if (process.argv.indexOf('--verbose') !== -1) {
|
|
|
|
opts.verbose = true;
|
|
|
|
opts.minimal = false;
|
2017-08-14 05:01:11 +02:00
|
|
|
opts.showFiles = true;
|
2016-10-10 03:43:44 +02:00
|
|
|
}
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
let count = 0;
|
2016-10-10 03:43:44 +02:00
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
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';
|
2016-10-10 03:43:44 +02:00
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
const output = opts.minimal ? prop(path.relative(process.cwd(), file.path)) : full;
|
2016-10-10 03:43:44 +02:00
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
gutil.log(opts.title + ' ' + output);
|
|
|
|
}
|
2016-10-10 03:43:44 +02:00
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
count++;
|
2016-10-10 03:43:44 +02:00
|
|
|
cb(null, file);
|
2017-08-14 05:01:11 +02:00
|
|
|
}, cb => {
|
2016-10-10 03:43:44 +02:00
|
|
|
gutil.log(opts.title + ' ' + chalk.green(count + ' ' + plur('item', count)));
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
};
|