Repository navigation
Expand file tree
/
Copy pathlogging.js
More file actions
65 lines (56 loc) · 1.71 KB
/
Copy pathlogging.js
File metadata and controls
65 lines (56 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const chalk = require('chalk');
const isProduction = process.argv.indexOf('--production') > -1;
const isVerbose = process.argv.indexOf('--verbose') > -1;
module.exports.logStartTask = (packageName, task) => {
console.log(`${getTimePrefix(packageName)} Starting: ${chalk.cyan(task)}`);
};
module.exports.logEndTask = (packageName, task, startTime, errorMessage) => {
console.log(
`${getTimePrefix(packageName)} ${getPassFail(errorMessage === undefined)}: ${chalk.cyan(task)} (${getDuration(
startTime,
)})${errorMessage ? chalk.white(': ') + chalk.red(errorMessage) : ''}`,
);
};
module.exports.logStatus = taskStatus => {
if (isProduction || isVerbose) {
console.log(' ' + taskStatus);
}
};
module.exports.logEndBuild = (packageName, passed, startTime) => {
console.log();
console.log(
`${
chalk.grey('============') +
chalk.white('[ ') +
chalk.cyan(packageName) +
chalk.white(' ]') +
chalk.grey('=') +
chalk.white('[ ') +
getPassFail(passed) +
chalk.white(' ]') +
chalk.grey('=') +
chalk.white('[ ') +
getDuration(startTime) +
chalk.white(' ]') +
chalk.grey('============')
}
`,
);
};
function getDuration(startTime) {
let duration = new Date().getTime() - startTime;
return chalk.yellow(formatTime(duration));
}
function getPassFail(passed) {
return passed ? chalk.green('Pass') : chalk.red('Error');
}
function getTimePrefix(packageName) {
return `[${chalk.magenta(packageName)} ${chalk.gray(new Date().toLocaleTimeString([], { hour12: false }))}]`;
}
function formatTime(milliseconds) {
if (milliseconds >= 1000) {
return milliseconds / 1000 + 's';
} else {
return milliseconds + 'ms';
}
}