Skip to content

Commit 06e3227

Browse files
committed
dev, fix: cleanup lib/util a bit; fix bug on init for the repl
1 parent 27fb015 commit 06e3227

File tree

2 files changed

+23
-41
lines changed

2 files changed

+23
-41
lines changed

lib/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ exports = module.exports = function (gulp) {
9595
}
9696

9797
if (gulp.repl) {
98-
gulp.repl.emit('line', argv.join(' '));
98+
gulp.repl.emit('line', argv.length ? argv.join(' ') : 'default');
9999
} else {
100100
gulp.start.apply(gulp, [argv].concat(args));
101101
}

lib/util.js

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@ var path = require('path');
44

55
var util = exports = module.exports = {};
66

7-
var xargs = process.argv.slice(2).join(' ');
8-
var isSilent = /(^|[\s])(--silent|--tasks-simple)/.test(xargs);
9-
var execFile = path.extname(process.argv[1])
10-
? process.argv[1]
11-
: process.argv[1] + '.js';
12-
137
// dependencies
14-
//
158
util.type = require('utils-type');
9+
util.clone = require('lodash.clone');
1610
util.archy = require('archy');
1711
util.merge = require('lodash.merge');
1812
util.gutil = require('gulp-util');
@@ -21,56 +15,44 @@ util.tildify = require('tildify');
2115
util.dateFormat = require('dateformat');
2216
util.prettyTime = require('pretty-hrtime');
2317

18+
// refs
19+
var xargs = process.argv.slice(2).join(' ');
20+
var isSilent = /(^|[\s])(--silent|--tasks-simple)/.test(xargs);
21+
var execFile = path.extname(process.argv[1])
22+
? process.argv[1]
23+
: process.argv[1] + '.js';
24+
2425
// assorted
25-
//
2626
util.docs = {
2727
task: 'http://git.io/vVYKS'
2828
};
2929

30+
// logging helpers
3031
util.silent = function () {};
31-
3232
util.logger = function (/* arguments */) {
3333
process.stdout.write(util.format.date());
3434
console.log.apply(console, arguments);
3535
};
3636

37-
if (isSilent) {
38-
util.log = util.gutil.log = util.silent;
39-
} else {
40-
util.log = util.gutil.log = util.logger;
41-
}
37+
// assign the initial logger according to cli args
38+
util.log = util.gutil.log = isSilent ? util.silent : util.logger;
4239

4340
util.format = {
4441
time: function (hrtime) {
45-
return util.chalk.magenta(hrtime
46-
? util.prettyTime(process.hrtime(hrtime))
47-
: util.prettyTime(process.hrtime())
48-
);
49-
},
50-
link: function (link) {
51-
return util.chalk.underline(
52-
util.chalk.green(link)
53-
);
42+
var time = util.prettyTime(process.hrtime(hrtime || []));
43+
return util.chalk.magenta(time);
5444
},
55-
path: function (filename) {
56-
return util.chalk.magenta(
57-
util.tildify(filename)
58-
);
45+
path: function (pahtname) {
46+
return util.chalk.magenta(util.tildify(pahtname));
5947
},
6048
task: function (task) {
61-
if (!task.mode) {
62-
return util.chalk.cyan(task && task.label || task);
49+
if (task && task.label) {
50+
return task.label.split(',').map(function (name) {
51+
return util.chalk.cyan(name);
52+
}).join(',');
53+
} else {
54+
return task;
6355
}
64-
65-
return (
66-
(task.name ? util.chalk.cyan(task.name) + ' => ' : '') +
67-
task.mode + '(' +
68-
task.label.split(/\,/).map(function (name) {
69-
return util.chalk.cyan(name)
70-
}).join(',') +
71-
')'
72-
);
73-
7456
},
7557
date: function (date) {
7658
var value = util.dateFormat(date || new Date(), 'HH:MM:ss');
@@ -87,5 +69,5 @@ util.isFromCLI = function (gulp) {
8769

8870
util.getGulpFile = function () {
8971
var match = new Error().stack.match(/\/([^:()]+)/g);
90-
return match && match[4] || '';
72+
return match && match[3] || '';
9173
};

0 commit comments

Comments
 (0)