forked from laravel/elixir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.js
78 lines (65 loc) · 1.55 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
75
76
77
78
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
* @return {Logger}
*/
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
* @return {Logger}
*/
Logger.message = function(message) {
console.log(message);
return Logger;
};
/**
* Log a set of files to the console.
*
* @param {string|Array} files
* @param {boolean} checkForFiles
* @return {Logger}
*/
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
* @return {boolean}
*/
var assertFileExists = function(file) {
// If this file begins with a !, then the user
// intends to exclude it from their src set.
if (file.indexOf('!') == 0) {
file = file.slice(1);
}
return file.match(/\*/) || fs.existsSync(file);
};
module.exports = Logger;