This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
63 lines (52 loc) · 1.62 KB
/
index.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
'use strict';
// Set up environmental vars from .env
require('dotenv').load({ silent: true });
var browserSync = require('browser-sync');
var vinyl = require('vinyl-fs');
var plugins = require('gulp-load-plugins')();
// Default error handler. Sends to browser-sync, and logs to console.
var errorHandler = function (err) {
browserSync.notify(err.message, 3000);
plugins.util.log(err.toString());
if (process.argv.indexOf('--fail') !== -1) {
throw new Error('Failed');
}
};
/**
* Get a task. This function just gets a task from the tasks directory, and
* sets some sane default options used on all tasks such as the error handler
* and the `rev` option.
*
* @param {string} name The name of the task.
* @param {object} [options] Options to pass to the task.
* @returns {function} The task!
*/
module.exports = function getTask(name, options) {
if (typeof options !== 'object') {
options = {};
}
if (typeof options.onError !== 'function') {
options.onError = errorHandler;
}
if (typeof options.rev !== 'boolean') {
options.rev = (process.env.NODE_ENV === 'production');
}
if (typeof options.manifest !== 'string') {
options.manifest = process.env.MANIFEST_DEST;
}
// This means that you don't have to call this.emit('end') yourself
var actualErrorHandler = options.onError;
options.onError = function () {
actualErrorHandler.apply(this, arguments);
this.emit('end');
};
return require('./tasks/' + name)(vinyl, plugins, options);
};
/**
* Set default error handler.
*
* @param newHandler
*/
module.exports.setErrorHandler = function (newHandler) {
errorHandler = newHandler;
};