gulp-stats
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -8,4 +8,6 @@ import { Gulp } from 'gulp'; | ||
}; | ||
export declare const defaultOptions: Required<Options>; | ||
export default function stats(gulp: Gulp, options?: Options): void; | ||
export {}; | ||
declare function stats(gulp: Gulp, options?: Options): void; | ||
declare namespace stats { | ||
var defaultOptions: Required<Options>; | ||
} | ||
export = stats; |
@@ -5,8 +5,6 @@ "use strict"; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultOptions = void 0; | ||
const pretty_hrtime_1 = __importDefault(require("pretty-hrtime")); | ||
const log_1 = __importDefault(require("./reporters/log")); | ||
const hrToMs_1 = __importDefault(require("./utils/hrToMs")); | ||
exports.defaultOptions = { | ||
const defaultOptions = { | ||
elapseBeforeReport: 300, | ||
@@ -17,15 +15,14 @@ includeBranches: false, | ||
function stats(gulp, options = {}) { | ||
const { elapseBeforeReport, includeBranches, reporter } = Object.assign(Object.assign({}, exports.defaultOptions), options); | ||
const { elapseBeforeReport, includeBranches, reporter } = Object.assign(Object.assign({}, defaultOptions), options); | ||
const tasksInProgress = {}; | ||
const report = { tasks: [] }; | ||
let startTime; | ||
let reportTimeout; | ||
gulp.on('start', ({ uid }) => { | ||
clearTimeout(reportTimeout); | ||
if (!startTime) { | ||
startTime = process.hrtime(); | ||
} | ||
tasksInProgress[uid] = uid; | ||
}); | ||
gulp.on('stop', ({ uid, name, duration, branch: isBranch }) => { | ||
delete tasksInProgress[uid]; | ||
const totalRemainingTasksInProgress = Object.keys(tasksInProgress).length; | ||
const isRoot = totalRemainingTasksInProgress === 0; | ||
if (includeBranches || !isBranch) { | ||
@@ -37,11 +34,11 @@ report.tasks.push({ | ||
durationPretty: pretty_hrtime_1.default(duration), | ||
isBranch, | ||
isRoot, | ||
}); | ||
} | ||
delete tasksInProgress[uid]; | ||
if (Object.keys(tasksInProgress).length === 0) { | ||
const totalTime = process.hrtime(startTime); | ||
if (isRoot) { | ||
report.tasks = report.tasks.sort(({ duration: a }, { duration: b }) => b - a); | ||
report.totalTime = hrToMs_1.default(totalTime); | ||
report.totalTimeHr = totalTime; | ||
report.totalTimePretty = pretty_hrtime_1.default(totalTime); | ||
report.totalTime = hrToMs_1.default(duration); | ||
report.totalTimeHr = duration; | ||
report.totalTimePretty = pretty_hrtime_1.default(duration); | ||
reportTimeout = setTimeout(reporter, elapseBeforeReport, report); | ||
@@ -51,2 +48,3 @@ } | ||
} | ||
exports.default = stats; | ||
stats.defaultOptions = defaultOptions; | ||
module.exports = stats; |
@@ -15,5 +15,10 @@ "use strict"; | ||
} | ||
console.log(`${header(`${tasks.length} task${tasks.length === 1 ? '' : 's'}`, totalTimePretty)}\n${text_table_1.default([ | ||
if (tasks.length === 1) { | ||
console.log(header('1 task', totalTimePretty)); | ||
return; | ||
} | ||
const tasksExcludingRoot = tasks.filter(({ isRoot }) => !isRoot); | ||
console.log(`${header(`${tasksExcludingRoot.length} task${tasksExcludingRoot.length === 1 ? '' : 's'}`, totalTimePretty)}\n${text_table_1.default([ | ||
['Task', 'Time', '% of total'].map(header => chalk_1.default.bold.underline(header)), | ||
...tasks.map(({ duration, durationPretty, name }) => [ | ||
...tasksExcludingRoot.map(({ duration, durationPretty, name }) => [ | ||
name, | ||
@@ -20,0 +25,0 @@ chalk_1.default.cyan(durationPretty), |
@@ -9,2 +9,4 @@ export declare type Reporter = (report: Report) => void; | ||
durationPretty: string; | ||
isBranch: boolean; | ||
isRoot: boolean; | ||
}[]; | ||
@@ -11,0 +13,0 @@ totalTime?: number; |
{ | ||
"name": "gulp-stats", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Display task stats summary for Gulp", | ||
@@ -14,4 +14,5 @@ "main": "dist/index.js", | ||
"test": "jest", | ||
"build": "tsc --declaration", | ||
"prepublish": "rm -rf ./dist & npm run build" | ||
"watch": "tsc --watch", | ||
"build": "rm -rf ./dist & tsc", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -18,0 +19,0 @@ "keywords": [ |
@@ -43,2 +43,4 @@ # gulp-stats | ||
durationPretty: string; | ||
isBranch: boolean; | ||
isRoot: boolean; | ||
} | ||
@@ -45,0 +47,0 @@ []; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
32264
122
66
0