-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile_config.js
374 lines (334 loc) · 7.27 KB
/
gulpfile_config.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
var util = require( 'gulp-util' );
var path = require('path');
var filesystem = require("fs");
var notifier = require('node-notifier');
var bowerDir = __dirname + '/bower_components';
/**
* Configure object class
*
*/
function Configure (node) {
this.node = node;
this.tasks = {};
//
// Base.
//
this.name= process.cwd().split('\\').pop();
this.cms= ''; // ex. 'wordpress'
// save style.css to main folder
//
// Files.
//
this.local= { // local server ex: xampp
use: true,
host: 'localhost/' + this.name,
dir: 'C:\\xampp\\htdocs\\' + this.name + '\\',
};
this.archive = {
use: false,
dir: 'archives',
dir2: 'C:\\DEV\\___archives\\' + this.name + '\\',
//dir: "C:\\",
};
//
// Files places.
//
//
// DEV: '!**/_*', '!_*'
//
this.source = {
folder: 'source',
folder_style: 'styles',
folder_script: 'js',
folder_image: 'img',
php: ['**/*.php'],
html: ['**/*.{html, htm}'],
style: ['styles/*.css', 'styles/sass/*.scss'],
style_watch: ['styles/**/*.css', 'styles/sass/**/*.scss'],
// php: [
// '*.php',
// 'lib/**',
// 'templates/*.php',
// ],
// html: ['*.html', '*.htm'],
// style: ['styles/**/*.css', 'styles/sass/**/*.scss'],
script: ['js/*.js'],
script_lint: ['js/*.js','!js/*.min.js'],
script_watch: ['js/**/*.js'],
image: ['img/**'],
rest: [
'fonts/**',
'languages/**'
],
};
this.build = {
folder: 'build',
folder_style: 'css',
folder_script: 'js',
folder_image: 'img',
};
this.master = {
folder: 'master',
folder_style: 'css',
folder_script: 'js',
folder_image: 'img',
};
this.import = {
// src: dest,
// use '\\'' not '/'
};
this.mustache = {},
//
//Image.
//
this.image = {
quality: 93,
progressive: true, // jpg,png
withMetadata: true,
errorOnEnlargement: false,
interlaced: true, // (gif)
compressionLevel: 7,
};
//
// Style.
//
this.autoprefixer = [ // https://github.com/ai/autoprefixer
// 'last 2 versions',
'ie >= 11',
'ie_mob >= 10',
'ff >= 40',
'chrome >= 44',
'safari >= 8',
'opera >= 33',
'ios >= 8.4',
'android >= 4.1',
'bb >= 10'
];
this.bower = {
dir: bowerDir,
// We can @import in scss file
includesForScss: [
// bowerDir + '/bootstrap-sass-official/assets/stylesheets',
// bowerDir + '/fontawesome/scss',
bowerDir+'/',
],
};
return this;
}
/**
* Deep merge objects.
*
* @param {object} output One or more object. First object
* is output object.
* @return {object} this (merged object).
*/
Configure.prototype.merge = function () {
var object, key, value;
for (var i = 0; i < arguments.length; i++) {
object = arguments[i];
for (key in object) {
value = object[key];
if (typeof this[key]==='undefined') {
this[key] = value;
} else {
if (!!(value && typeof value === 'object')) {
this[key] = arguments.callee.call(this[key], value);
} else {
this[key] = value;
}
}
}
}
return this;
};
/**
* Load or Reload local configuration files.
*
* @return {[type]} [description]
*/
Configure.prototype.load = function (filePath, callback) {
var localConfigFile = path.resolve(filePath);
if (typeof require.cache[localConfigFile]!=='undefined') {
delete require.cache[localConfigFile];
}
try{
this.merge(require(localConfigFile));
}catch(error){
console.log('\nWARNING: Local config file error.\n');
}
if (typeof callback==='function') {
callback();
}
return this;
};
/**
* getFilesInFolder
*
* @param {string} dir Path.
* @param {boolean} deep Subfolders too.
* @return {array} files
*/
Configure.prototype.getFilesInFolder = function (dir, deep) {
var self = this;
var results = [];
filesystem.readdirSync(dir).forEach(function(file) {
var f = dir+'/'+file;
if (self.isDirectory(f)) {
if (deep) {
results = results.concat(self.getFilesInFolder(f, true));
}
} else {
results.push(path.normalize(f));
}
});
return results;
};
/**
* Verify that path is file or not.
*
* @param {string} file Path.
* @return {Boolean}
*/
Configure.prototype.isFile = function (filePath) {
var stat = filesystem.statSync(filePath);
if (stat && stat.isFile()) {
return true;
}
return false;
};
/**
* Verify that path is directory or not.
*
* @param {string} dirPath Path.
* @return {Boolean}
*/
Configure.prototype.isDirectory = function (dirPath) {
var stat = filesystem.statSync(dirPath);
if (stat && stat.isDirectory()) {
return true;
}
return false;
};
/**
* Check is gulp master task.
*
* @return {Boolean}
*/
Configure.prototype.isMaster = function () {
if (typeof this.masterTask==='undefined') {
this.masterTask = false;
if (this.node) {
if (this.node.seq!==undefined) {
var taskName = this.node.seq.slice(-1)[0];
if (/master/i.test(taskName)) {
this.masterTask = true;
}
}
}
}
return this.masterTask;
};
/**
* Check is browser sync. task (& watch files).
*
* @return {Boolean}
*/
Configure.prototype.isSync = function () {
if (typeof this.syncTask==='undefined') {
this.syncTask = false;
if (this.node) {
if (this.node.seq!==undefined) {
var taskName = this.node.seq.slice(-1)[0];
if (/_sync/i.test(taskName)) {
this.syncTask = true;
}
}
}
}
return this.syncTask;
};
/**
* Add path to sting or array
* @param {string} where source/build/jquery/
* jquery-ui/local.
* @param {string} type image/script/rest/html/style/php
* @return {string or aray}
*/
function globs (p, dir) {// where, type) {
if (typeof dir==='undefined') {
return path.normalize(p);
} else if (typeof dir === 'string') {
return path.normalize(p+'/'+dir);
} else if(Array.isArray(dir)) {
return dir.map(function (d){
return path.normalize(p+'/'+d);
});
}
return null;
}
Configure.prototype.getSource = function (type) {
var dir = type;
if (this.source[type]!==undefined) {
dir = this.source[type];
}
return globs(this.source.folder, dir);
};
Configure.prototype.getBuild = function (type) {
var dir = type;
if (this.isMaster()) {
if (this.master[type]!==undefined) {
dir = this.master[type];
}
return globs(this.master.folder, dir);
}
if (this.build[type]!==undefined) {
dir = this.build[type];
}
return globs(this.build.folder, dir);
};
Configure.prototype.getBuildLocal = function (type) {
var dir = type;
if (this.isMaster()) {
if (this.master[type]!==undefined) {
dir = this.master[type];
}
return globs(this.local.dir, dir);
}
if (this.build[type]!==undefined) {
dir = this.build[type];
}
return globs(this.local.dir, dir);
};
Configure.prototype.notify = function (opts, that) {
if (!opts.title) {
if (opts.error && opts.error.plugin) {
opts.title = opts.error.plugin.substring(0, 60);
} else {
opts.title = 'Error';
}
}
if (!opts.message) {
if (opts.error && opts.error.message) {
opts.message = opts.error.message.substring(0, 160);
} else {
opts.message = '';
}
}
opts.icon = opts.icon || '';
opts.sound = typeof opts.sound!=='undefined' ? opts.sound : true;
notifier.notify({
'wait': false,
'sound': opts.sound,
'title': opts.title,
'message': opts.message,
'icon': opts.icon
});
if (that) {
that.emit('end');
}
if (opts.error) {
// util.log(opts.error);
console.error(opts.error);
}
};
module.exports = Configure;