Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a4f5ee

Browse files
committed
tasks: add formatTime common util
- use in watchified bundle module
1 parent c479fe6 commit 8a4f5ee

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

tasks/util/common.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ exports.doesFileExist = function(filePath) {
3838
return false;
3939
};
4040

41+
exports.formatTime = function(date) {
42+
return [
43+
date.toLocaleDateString(),
44+
date.toLocaleTimeString(),
45+
date.toString().match(/\(([A-Za-z\s].*)\)/)[1]
46+
].join(' ');
47+
};
48+
4149
exports.touch = function(filePath) {
4250
fs.closeSync(fs.openSync(filePath, 'w'));
4351
};

tasks/util/watchified_bundle.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var watchify = require('watchify');
55
var prettySize = require('prettysize');
66

77
var constants = require('./constants');
8+
var common = require('./common');
89
var compressAttributes = require('./compress_attributes');
910

1011
/**
@@ -61,7 +62,7 @@ function formatBundleMsg(b, bundleName) {
6162
var msgParts = [
6263
bundleName, ':', '',
6364
'written', 'in', '', 'sec',
64-
'[', '', '', '', ']'
65+
'[', '', ']'
6566
];
6667

6768
b.on('bytes', function(bytes) {
@@ -73,16 +74,9 @@ function formatBundleMsg(b, bundleName) {
7374
});
7475

7576
b.on('log', function() {
76-
var date = new Date();
77+
var formattedTime = common.formatTime(new Date());
7778

78-
// get locale date
79-
msgParts[msgParts.length - 4] = date.toLocaleDateString();
80-
81-
// get locale time
82-
msgParts[msgParts.length - 3] = date.toLocaleTimeString();
83-
84-
// get time zone code
85-
msgParts[msgParts.length - 2] = date.toString().match(/\(([A-Za-z\s].*)\)/)[1];
79+
msgParts[msgParts.length - 2] = formattedTime;
8680

8781
console.log(msgParts.join(' '));
8882
});

0 commit comments

Comments
 (0)