This repository has been archived by the owner on Mar 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaseGulp.js
130 lines (111 loc) · 3.21 KB
/
baseGulp.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import Base from './base'
import notify from 'gulp-notify'
import Util from 'gulp-util'
export const Default = {
debug: false,
watch: true,
task: {
name: undefined,
description: '',
prefix: '', // task name prefix
suffix: '' // task name suffix
}
}
const BaseGulp = class extends Base {
/**
*
* @param gulp - gulp instance
* @param config - customized overrides
*/
constructor(gulp, ...configs) {
super(Default, ...configs)
this.requireValue(gulp, 'gulp')
this.gulp = gulp
}
taskName() {
if (!this.config.task || !this.config.task.name) {
return ''
}
//if (!this.config.task.name) {
// this.notifyError(`Expected ${this.constructor.name} to have a task name in the configuration.`)
//}
return `${this.config.task.prefix}${this.config.task.name}${this.config.task.suffix}`
}
watchTaskName() {
if (this.config.watch && this.config.watch.name) {
return this.config.watch.name
}
else {
return `${this.taskName()}:watch`
}
}
notifyError(error, done, watching = false) {
let isWatching = (this.gulp ? this.gulp.watching : undefined) || watching
this.debug(`isWatching: ${isWatching}`)
//this.debugDump('notifyError', error)
let lineNumber = (error.lineNumber) ? `Line ${error.lineNumber} -- ` : ''
let taskName = error.task || ((this.config.task && this.config.task.name) ? this.taskName() : this.constructor.name)
let title = `Task [${taskName}] failed`
if (error.plugin) {
title += ` in [${error.plugin}]`
}
notify({
title: title,
message: `${lineNumber}See console.`,
sound: 'Sosumi' // See: https://github.com/mikaelbr/node-notifier#all-notification-options-with-their-defaults
}).write(error)
let tag = Util.colors.black.bgRed
let report = `\n${tag(' Task:')} [${Util.colors.cyan(taskName)}]\n`
if (error.plugin) {
report += `${tag(' Plugin:')} [${error.plugin}]\n`
}
report += `${tag(' Error:')} `
if (error.message) {
report += `${error.message}\n`
}
else {
report += `${error}\n`
}
if (error.lineNumber) {
report += `${tag(' Line:')} ${error.lineNumber}\n`
}
if (error.fileName) {
report += `${tag(' File:')} ${error.fileName}\n`
}
this.log(report)
// Prevent the 'watch' task from stopping
if (isWatching) {
// do nothing
this.debug(`notifyError: watching, so not doing anything`)
}
else if (this.gulp) {
// if this is not used, we see "Did you forget to signal async completion?", it also unfortunately logs more distracting information below. But we need to exec the callback with an error to halt execution.
this.donezo(done, error)
}
else {
this.debug(`notifyError: throwing error`)
throw error
}
}
/**
* if done is provided, run it
*
* @param done
*/
donezo(done, error = null) {
if (done) {
if (error) {
this.debug('executing callback with error')
done(error)
}
else {
this.debug('executing callback without error')
done()
}
}
else {
this.debug(`done callback was not provided`)
}
}
}
export default BaseGulp