-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
163 lines (128 loc) · 3.87 KB
/
gulpfile.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
// Gulp
var gulp = require('gulp'),
gutil = require('gulp-util'),
sass = require('gulp-ruby-sass'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
compass = require('gulp-compass'),
uglify = require('gulp-uglifyjs'),
concat = require('gulp-concat'),
autoprefixer = require('gulp-autoprefixer'),
minifyCss = require('gulp-minify-css'),
clean = require('gulp-clean'),
livereload = require('gulp-livereload'),
sourcemaps = require('gulp-sourcemaps'),
cmq = require('gulp-combine-media-queries'),
cssGlobbing = require('gulp-css-globbing');
// Others
var fs = require('fs'),
_ = require('lodash');
// Settings
var settings = {
build: './_',
source: 'src'
};
var bowerJson = (JSON.parse(fs.readFileSync('bower.json', "utf8"))) || false;
var bowerPath = (JSON.parse(fs.readFileSync('.bowerrc', "utf8"))).directory + '/' || 'bower_components/';
// Lint js files
gulp.task('lint', function () {
'use strict';
gulp.src(settings.source + '**/*.js')
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
// Minify js files
gulp.task('js', function () {
'use strict';
gulp.src([settings.source + '/js/**/*.js'])
.pipe(uglify('snow.min.js', {
outSourceMap: true
}))
.on('error', gutil.log)
.pipe(gulp.dest(settings.build + '/js'));
});
// Minify libs
gulp.task('lib', function () {
gulp.src([settings.source + '/lib/**/*.js'])
.pipe(uglify('lib.min.js'))
.pipe(gulp.dest(settings.build + '/js'));
})
// Minify Vendor (Bower)
gulp.task('vendor', function () {
gulp.src(bowerFiles())
.pipe(uglify('vendor.min.js'))
.pipe(gulp.dest(settings.build + '/js'));
})
// Compile vendor css and scss
gulp.task('css', function () {
'use strict';
gulp.src(settings.source + '/scss/*.scss')
// .pipe(sass({
// style: 'compressed'
// }))
.pipe(cssGlobbing({
extensions: ['.scss'],
}))
.pipe(compass({
config_file: './config.rb',
css: './_/css',
sass: './src/scss'
}))
.on('error', gutil.log)
.pipe(autoprefixer('last 1 version', 'ie 9', 'ios 7'))
// .pipe(cmq({
// log: true
// }))
//.pipe(minifyCss())
.pipe(gulp.dest(settings.build + '/css'));
});
// Default task and watch files
gulp.task('default', ['build'], function () {
'use strict';
livereload.listen();
gulp.watch([settings.source + '/scss/**/*.scss'], ['css']);
gulp.watch([settings.source + '/js/*.js'], ['lint','js']);
gulp.watch([settings.source + '/lib/**/*.js'], ['lint','lib']);
gulp.watch([settings.source + '/vendor/**/*.js'], ['lint','vendor']);
gulp.watch([settings.build + '/**/*.css',
settings.build + '/**/*.js',
settings.build + '/view/**/*.php',
settings.build + '/components/**/*.php',
settings.build + '/wp/**/*.php',
'*.php',
'*.html']).on('change', livereload.changed);
});
gulp.task('build', ['css', 'lint', 'js', 'lib', 'vendor']);
gulp.task('build-vendor', ['lint', 'vendor', 'lib']);
function bowerFiles() {
if (!bowerJson) return "";
var dependencies = [];
for (var name in bowerJson.devDependencies) {
/*
* Check if is in exclude
* Do it in bower.json
*/
if(_.filter(bowerJson.exclude, function(el){ return el.package == undefined || el.package != name ? false : true; }).length){
continue;
}
/*
* Get JS files
*/
var devBowerJsonPath = bowerPath + name + '/';
var devBowerJson;
try{
devBowerJson = (JSON.parse(fs.readFileSync(devBowerJsonPath + 'bower.json', "utf8")));
}catch (err){
devBowerJson = (JSON.parse(fs.readFileSync(devBowerJsonPath + 'package.json', "utf8")));
}
if (typeof (devBowerJson.main) == "string") {
var string = devBowerJson.main.replace(/\.\//gi, '');
if (string.match(/.js/)) dependencies.push(devBowerJsonPath + string);
} else {
_.each(devBowerJson.main, function (el, i) {
if (el.match(/.js/)) dependencies.push(devBowerJsonPath + el);
})
}
}
return dependencies.length ? dependencies : "";
}