-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
116 lines (99 loc) · 2.75 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
'use strict';
var gulp = require('gulp'),
util = require('gulp-util'),
gulpif = require('gulp-if'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
jscs = require('gulp-jscs'),
rename = require('gulp-rename'),
htmlreplace = require('gulp-html-replace'),
sass = require('gulp-sass'),
cssglobbing = require('gulp-css-globbing'),
csso = require('gulp-csso'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer-core'),
options = require('./config'),
sourcePath = options.sourcePath,
templateOutputPath = options.templateOutputPath,
assetOutputPath = options.assetOutputPath,
sassOptions = options.sass,
processors = [
autoprefixer({
browsers: ['last 2 versions', '> 1% in FI', 'ie 9']
})
],
isProd = Boolean(util.env.prod);
gulp.task('assets', function() {
return gulp.src(sourcePath + '/assets/**/*')
.pipe(gulp.dest(assetOutputPath));
});
gulp.task('build:page-templates', function() {
var timestamp = Date.now();
return gulp.src(sourcePath + '/pages/*.php')
.pipe(htmlreplace({
js: {
src: 'scripts.js?' + timestamp,
tpl: '<script type="text/javascript" src="assets/js/%s"></script>'
},
css: {
src: 'style.css?' + timestamp,
tpl: '<link rel="stylesheet" type="text/css" href="assets/css/%s">'
}
}))
.pipe(gulp.dest(templateOutputPath));
});
gulp.task('build:components', function() {
return gulp.src(sourcePath + '/components/*.php')
.pipe(gulp.dest('.'));
});
gulp.task('jscs', function() {
return gulp.src(sourcePath + '/**/*.js')
.pipe(jscs());
});
gulp.task('build:js', ['jscs'], function() {
return gulp.src([
sourcePath + '/js/**/*.js',
sourcePath + '/components/**/*.js'
])
.pipe(concat('scripts.js'))
.pipe(gulpif(isProd, uglify()))
.pipe(gulp.dest(assetOutputPath + '/js'));
});
gulp.task('build:css', function() {
return gulp.src(sourcePath + '/*.scss')
.pipe(cssglobbing({
extensions: ['.css', '.scss']
}))
.pipe(sass(sassOptions))
.pipe(postcss(processors))
.pipe(gulpif(isProd, csso()))
.pipe(gulp.dest('.'));
});
gulp.task('watch', ['build:all'], function() {
gulp.watch([
sourcePath + '/*.scss',
sourcePath + '/**/*.scss',
'!' + sourcePath + '/vendor/**'
], ['build:css']);
gulp.watch([
sourcePath + '/*.js',
sourcePath + '/**/*.js'
], ['build:js']);
gulp.watch([
sourcePath + '/pages/*.php'
], ['build:page-templates']);
gulp.watch([
sourcePath + '/components/*.php'
], ['build:components']);
gulp.watch([
sourcePath + '/assets/**/*'
], ['assets']);
});
gulp.task('build:all', [
'build:css',
'build:js',
'build:page-templates',
'build:components',
'assets'
]);
gulp.task('default', ['watch']);