forked from laravel/elixir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.js
74 lines (56 loc) · 1.3 KB
/
Logger.js
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
66
67
68
69
70
71
72
73
74
var fs = require('fs');
var path = require('path');
var gutil = require('gulp-util');
/**
* Create a new Logger constructor.
*/
var Logger = function() {};
/**
* Log a heading to the console.
*
* @param {string} heading
*/
Logger.heading = function(heading) {
console.log(''); // line break
console.log(
gutil.colors.black(gutil.colors.bgGreen(heading))
);
return Logger;
};
/**
* Log a general message to the console.
*
* @param {string} message
*/
Logger.message = function(message) {
console.log(message);
return Logger;
};
/**
* Log a set of files to the console.
*
* @param {string|array} files
* @param {boolean} checkForFiles
*/
Logger.files = function(files, checkForFiles) {
files = Array.isArray(files) ? files : [files];
var spacer = ' - ';
files.forEach(function(file) {
if ( ! checkForFiles || assertFileExists(file)) {
console.log(spacer + file);
} else {
console.log(spacer + gutil.colors.bgRed(file) + ' <-- Not Found');
}
});
console.log(); // For a line break.
return Logger;
};
/**
* Assert that the given file exists.
*
* @param {string} file
*/
var assertFileExists = function(file) {
return file.match(/\*/) || fs.existsSync(file);
};
module.exports = Logger;