wallet-core/node_modules/gulp-debug/index.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-10-10 03:43:44 +02:00
'use strict';
2017-08-14 05:01:11 +02:00
const path = require('path');
2018-09-20 02:56:13 +02:00
const fancyLog = require('fancy-log');
2017-08-14 05:01:11 +02:00
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;
2018-09-20 02:56:13 +02:00
module.exports = options => {
options = 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
2018-09-20 02:56:13 +02:00
}, options);
2016-10-10 03:43:44 +02:00
if (process.argv.indexOf('--verbose') !== -1) {
2018-09-20 02:56:13 +02:00
options.verbose = true;
options.minimal = false;
options.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) => {
2018-09-20 02:56:13 +02:00
if (options.showFiles) {
2017-08-14 05:01:11 +02:00
const full =
'\n' +
(file.cwd ? 'cwd: ' + prop(tildify(file.cwd)) : '') +
(file.base ? '\nbase: ' + prop(tildify(file.base)) : '') +
(file.path ? '\npath: ' + prop(tildify(file.path)) : '') +
2018-09-20 02:56:13 +02:00
(file.stat && options.verbose ? '\nstat: ' + prop(stringifyObject(file.stat, {indent: ' '}).replace(/[{}]/g, '').trim()) : '') +
2017-08-14 05:01:11 +02:00
'\n';
2016-10-10 03:43:44 +02:00
2018-09-20 02:56:13 +02:00
const output = options.minimal ? prop(path.relative(process.cwd(), file.path)) : full;
2016-10-10 03:43:44 +02:00
2018-09-20 02:56:13 +02:00
module.exports._log(options.title + ' ' + output);
2017-08-14 05:01:11 +02:00
}
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 => {
2018-09-20 02:56:13 +02:00
module.exports._log(options.title + ' ' + chalk.green(count + ' ' + plur('item', count)));
2016-10-10 03:43:44 +02:00
cb();
});
};
2018-09-20 02:56:13 +02:00
// Internal: Log function used by gulp-debug exposed for testing
module.exports._log = fancyLog;