-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutil.js
More file actions
82 lines (70 loc) · 2.13 KB
/
Copy pathutil.js
File metadata and controls
82 lines (70 loc) · 2.13 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
var path = require('path');
var util = exports = module.exports = {};
// dependencies
util.type = require('utils-type');
util.clone = require('lodash.clone');
util.archy = require('archy');
util.merge = require('lodash.merge');
util.gutil = require('gulp-util');
util.chalk = util.gutil.colors;
util.tildify = require('tildify');
util.dateFormat = require('dateformat');
util.prettyTime = require('pretty-hrtime');
// refs
var xargs = process.argv.slice(2).join(' ');
var isSilent = /(^|[\s])(--silent|--tasks-simple)/.test(xargs);
var execFile = path.extname(process.argv[1])
? process.argv[1]
: process.argv[1] + '.js';
// assorted
util.docs = {
task: 'http://git.io/vVYKS'
};
// logging helpers
util.silent = function () {};
util.logger = function (/* arguments */) {
process.stdout.write(util.format.date());
console.log.apply(console, arguments);
};
// assign the initial logger according to cli args
util.log = util.gutil.log = isSilent ? util.silent : util.logger;
util.format = {
time: function (hrtime) {
var time = util.prettyTime(process.hrtime(hrtime || []));
return util.chalk.magenta(time);
},
path: function (pahtname) {
return util.chalk.magenta(util.tildify(pahtname));
},
task: function (task) {
if (task && task.label) {
var name = '';
var label = task.label.split(',').map(function (taskName) {
return util.chalk.cyan(taskName);
}).join(',');
if (task.match && task.siteProps) {
name = task.match + ':' + (task.siteProps.wait ? 'series' : 'parallel');
} else if (task.props) {
name = task.props.wait ? 'parallel' : 'series';
}
return name ? name + '(' + label + ')' : label;
} else {
return task;
}
},
date: function (date) {
var value = util.dateFormat(date || new Date(), 'HH:MM:ss');
return '[' + util.chalk.grey(value) + '] ';
},
error: function (value) {
return util.chalk.red(value);
}
};
util.isFromCLI = function (gulp) {
return gulp.gulpfile === execFile;
};
util.getGulpFile = function () {
var match = new Error().stack.match(/\/([^:()]+)/g);
return match && match[3] || '';
};