UNPKG

landers.gulp-helper

Version:

landers.gulp-helper

80 lines (75 loc) 2.36 kB
require('colors'); // 输出log module.exports = { helper: null, use: function(helper){ this.helper = helper; return this; }, _time: function(){ var date = new Date(); var hour = date.getHours(); hour = hour < 10 ? "0" + hour : hour; var minute = date.getMinutes(); minute = minute < 10 ? "0" + minute : minute; var second = date.getSeconds(); second = second < 10 ? "0" + second : second; var time = [hour, minute, second].join(':'); return '['.white + time.gray + ']'.white; }, success: function(message){ console.log(this._time() + ' ' + message.green); }, info: function(message){ console.log(this._time() + ' ' + message.blue); }, normal: function(message) { console.log(this._time() + ' ' + message); }, notice: function(message){ console.log(this._time() + ' ' + message.yellow); }, error: function(message){ console.log(this._time() + ' ' + message.red); }, exception: function(message){ throw message.red; }, bool: function(bool, message) { if (bool) { this.error(message.replace('%s', '失败')); } else { this.error(message.replace('%s', '成功')); } }, showList: function(list){ var that = this; list.map(function(item){ that.notice(item); }); that.notice('共计 ' + list.length + ' 项'); }, // 显示单项完成 showItemDone: function(subject){ subject = subject || '任务'; this.success(subject + '完成'); }, // 显示全部完成 showAllDone: function(){ // 'All the tasks have been completed. ', var messages = [ '所有打包任务均已完成'.green, ]; if (this.helper.options.watch) { messages.push('当前处于文件变化监控中'.yellow + '...'); } this.normal(messages.join(',')); if (!this.helper.options.notify) return; require('node-notifier').notify({ title: '任务完成', message: '所有打包任务均已完成', icon: require('path').join(__dirname + '/../', 'resources', 'notify-icon.jpg'), sound: true }); } };