-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (36 loc) · 1.04 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
/*
gulpfile.js
*/
module.exports = function(gulp) {
const appRoot = require('app-root-path');
const fs = require('fs');
const requireDir = require('require-dir');
/* eslint-disable max-len */
const configFile = fs.existsSync(appRoot + '/config.js') ? appRoot + '/config.js' : './config';
const pkgFile = fs.existsSync(appRoot + '/package.json') ? appRoot + '/package.json' : './package.json';
/* eslint-enable max-len */
// Require configs and all tasks in gulp/tasks, including sub-folders.
const config = require(configFile);
const pkg = require(pkgFile);
const tasks = requireDir('./tasks', {
recurse: true,
});
/**
* Requires all tasks in gulpfile.js/tasks, including subfolders.
*
* @param {*} tasks
*/
function resolveTasks(tasks) {
for (const task in tasks) {
if ({}.hasOwnProperty.call(tasks, task)) {
const fn = tasks[task];
if (typeof fn !== 'function') {
resolveTasks(fn);
continue;
}
fn(config, pkg);
}
}
}
resolveTasks(tasks);
};