-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
130 lines (112 loc) · 3.2 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
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
'use strict';
var path = require('path'),
util = require('util'),
gulpTasksLoader = require('./lib/gulpTasksLoader'),
packageConfig = require('./package.json');
var CSSTIME_GULP_TASKS_DIR = 'gulp-tasks';
module.exports = {
/**
* Loads gulp tasks
*/
loadGulpTasks: function (gulp, options) {
options = options || {};
var csstime = new CsstimeGulpTask();
csstime.load(gulp, options);
}
};
/**
* Csstime task loader
* @constructor
*/
function CsstimeGulpTask () {}
/**
* Loads gulp tasks.
* @param {Gulp} gulp
* @param {Object} options
*/
CsstimeGulpTask.prototype.load = function (gulp, options) {
var config = this.getConfig(options),
plugins = this.loadPlugins();
this.loadTasks(gulp, plugins, config);
};
/**
* Loads gulp plugins.
* @returns {Object}
*/
CsstimeGulpTask.prototype.loadPlugins = function () {
var dependencies = packageConfig.dependencies,
plugins = {};
Object.keys(dependencies).forEach(function (pluginName) {
if (!/gulp[\.-].*/.test(pluginName)) {
return;
}
plugins[pluginName.substring(5)] = require(pluginName);
});
plugins.notifier = require('node-notifier');
plugins.del = require('del');
plugins.runSequence = require('run-sequence');
plugins.mergeStream = require('merge-stream');
plugins.postcssProcessors = {
filters: require('pleeease-filters'),
opacity: require('postcss-opacity'),
autoprefixer: require('autoprefixer-core')
};
plugins.lib = {};
plugins.lib.pathHelper = require('./lib/pathHelper');
return plugins;
};
/**
* Loads tasks.
* @param {Gulp} gulp
* @param {Object} plugins
* @param {Object} config
*/
CsstimeGulpTask.prototype.loadTasks = function (gulp, plugins, config) {
gulpTasksLoader.loadAllTasks(gulp,
path.join(config.packagePath, CSSTIME_GULP_TASKS_DIR), plugins, config);
};
/**
* Gets current config.
* @param {Object} options
* @returns {Object}
*/
CsstimeGulpTask.prototype.getConfig = function (options) {
var currentConfig = require('./default.config.json');
currentConfig.imageminConfig = require('./configs/imagemin.json');
currentConfig.spritesmithConfig = require('./configs/spritesmith.json');
currentConfig.postcssConfig = require('./configs/postcss.json');
currentConfig.csscombConfig = require('./configs/csscomb.json');
currentConfig.svstoreConfig = require('./configs/svgstore.json');
currentConfig = this.mergeConfigs(currentConfig, options);
currentConfig.packagePath = __dirname;
currentConfig.preprocessorExt =
currentConfig.preprocessorsConfig[currentConfig.preprocessor].ext;
currentConfig.variables = currentConfig.variables || {};
return currentConfig;
};
/**
* Recursively merge configs.
* @param {Object} currentConfig
* @param {Object} options
* @returns {Object}
*/
CsstimeGulpTask.prototype.mergeConfigs = function (currentConfig, options) {
if (typeof(currentConfig) !== 'object') {
return options;
}
var self = this;
Object.keys(options)
.forEach(function (key) {
if (currentConfig[key] === null) {
return;
}
if (typeof(options[key]) === 'object' &&
typeof(currentConfig[key]) === 'object') {
currentConfig[key] = self
.mergeConfigs(currentConfig[key], options[key]);
} else {
currentConfig[key] = options[key];
}
});
return currentConfig;
};