Socket
Socket
Sign inDemoInstall

gulp-stats

Package Overview
Dependencies
9
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

70

index.js
'use strict';
var chalk = require('chalk'),
figures = require('figures'),
prettyTime = require('pretty-hrtime'),

@@ -10,9 +9,22 @@ table = require('text-table');

var tableData = [],
startTime = process.hrtime();
var tableData, startTime;
function reset() {
tableData = null;
startTime = null;
}
reset();
gulp.on('task_start', function () {
if (tableData === null || startTime === null) {
tableData = [];
startTime = process.hrtime();
}
});
gulp.on('task_stop', function (e) {
// Build entry
var entry = {
index: tableData.length,
finishIndex: tableData.length,
task: e.task,

@@ -27,3 +39,3 @@ duration: prettyTime(e.hrDuration),

gulp.on('stop', function (e) {
gulp.on('stop', function () {
var totalTime = process.hrtime(startTime),

@@ -34,14 +46,50 @@ timeDiff = totalTime[0] + (totalTime[1] / 1e9); // 1 times 10 to the power of 9

function formatTable(data) {
function ordinalSuffixOf(i) {
var j = i % 10,
k = i % 100;
if (j === 1 && k !== 11) {
return i + 'st';
}
if (j === 2 && k !== 12) {
return i + 'nd';
}
if (j === 3 && k !== 13) {
return i + 'rd';
}
return i + 'th';
}
// Sort table by duration
data.sort(function(a, b) {
if (a.durationFloat == b.durationFloat) return 0;
if (a.durationFloat === b.durationFloat) {
return 0;
}
return (a.durationFloat > b.durationFloat) ? -1 : 1;
});
// Map objects
var tableDataProcessed = data.map(function(entry) {
return [entry.task, chalk.cyan(entry.duration), chalk.magenta(Math.round((entry.durationFloat / timeDiff) * 100) + '%')];
var outHead = ['Task', 'Time', '% of total', 'Finished'].map(function(heading) {
return chalk.bold.underline(heading);
});
return table(tableDataProcessed);
var outList = data.map(function(entry) {
return [
entry.task,
chalk.cyan(entry.duration),
chalk.magenta(Math.round((entry.durationFloat / timeDiff) * 100) + '%'),
ordinalSuffixOf(entry.finishIndex + 1),
];
});
var outTable = [outHead].concat(outList);
var tableOpts = {
align: ['l', 'r', 'r', 'r'],
stringLength: function(str) {
var r = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g');
return str.replace(r, '').length;
}
};
return table(outTable, tableOpts);
}

@@ -54,4 +102,6 @@

console.log('\n' + formatTable(tableData) + '\n');
reset();
});
};
{
"name": "gulp-stats",
"version": "0.0.2",
"version": "0.0.3",
"description": "Display stats for Gulp tasks",
"main": "index.js",
"scripts": {
"pre-test": "jshint *.js",
"test": "echo \"Error: no test specified\" && exit 1"

@@ -25,7 +26,8 @@ },

"chalk": "^0.5.1",
"figures": "^1.3.5",
"pretty-hrtime": "^1.0.0",
"text-table": "^0.2.0"
},
"devDependencies": {},
"devDependencies": {
"jshint": "^2.6.0"
},
"repository": {

@@ -38,3 +40,19 @@ "type": "git",

},
"homepage": "https://github.com/simmo/gulp-stats"
"homepage": "https://github.com/simmo/gulp-stats",
"jshintConfig": {
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"latedef": true,
"newcap": true,
"noarg": true,
"node": true,
"quotmark": "single",
"strict": true,
"undef": true,
"unused": true
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc