Skip to content

Commit 194ca0b

Browse files
author
Ovidiu Barabula
committed
feat(core): output task timestamps and duration
1 parent 0cf30a6 commit 194ca0b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/plugin-manager/installable.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import chalk from 'chalk';
99
import * as gulp from 'gulp';
10+
import * as moment from 'moment';
1011
import ConfigManager, { Config, IConfigManager } from '../config-manager';
1112
import ConfigManagerProxy from '../config-manager/config-manager-proxy';
1213
import { ConfigQuestionnaire, QuestionnaireSubscriber } from '../config-wizard';
@@ -92,10 +93,25 @@ export async function provideUtilities(taskFn: AnyFunction, name: string): Promi
9293
const provider = await getUtilitiesProvider(name);
9394

9495
return async function (cb) {
96+
// Get start date
9597
const startTime = Date.now();
96-
await taskFn(cb, provider);
97-
const duration = (Date.now() - startTime) / 1000;
98-
provider.logger.debug(chalk.bold(`took ${duration.toFixed(1)}s`));
98+
// Run task function and catch any errors
99+
// Provide plugin utilities and callback function
100+
try {
101+
await taskFn(cb, provider);
102+
} catch (error) {
103+
provider.logger.fatal(error.message);
104+
}
105+
// Get timestamp when task finishes
106+
const endTime = Date.now();
107+
// Get timestamp delta and convert to seconds
108+
const duration = (endTime - startTime) / 1000;
109+
// Style duration time console log output
110+
const durationMessage = chalk.hex('#7AC0DA')(`${duration.toFixed(1)}s`);
111+
// Format timestamp
112+
const formatedTimestamp = chalk.gray(moment(endTime).format('H:mm:ss'));
113+
// Finally, output the message
114+
provider.logger.debug(`${formatedTimestamp} took ${durationMessage}`);
99115
};
100116
}
101117

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy