This repository has been archived by the owner on Jun 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
144 lines (128 loc) · 5.7 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
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
del = require('del'),
p = {
allfiles : [
'./laterpay-migrator/**/*.php',
'./laterpay-migrator/asset_sources/scss/**/*.scss',
'./laterpay-migrator/asset_sources/js/*.js'
],
phpfiles : ['./laterpay-migrator/**/*.php', '!./laterpay-migrator/library/**/*.php'],
srcSCSS : './laterpay-migrator/asset_sources/scss/*.scss',
srcJS : './laterpay-migrator/asset_sources/js/',
srcSVG : './laterpay-migrator/asset_sources/img/**/*.svg',
srcPNG : './laterpay-migrator/asset_sources/img/**/*.png',
distJS : './laterpay-migrator/built_assets/js/',
distCSS : './laterpay-migrator/built_assets/css/',
distIMG : './laterpay-migrator/built_assets/img/',
};
// TASKS ---------------------------------------------------------------------------------------------------------------
// clean up all files in the target directories
gulp.task('clean', function(cb) {
del([p.distJS + '*.js', p.distCSS + '*.css'], cb);
});
// CSS-related tasks
gulp.task('css-watch', function() {
gulp.src(p.srcSCSS)
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass({
errLogToConsole : true,
sourceComments : 'normal'
}))
.pipe(plugins.autoprefixer('last 3 versions', '> 2%', 'ff > 23', 'ie > 8')) // vendorize properties for supported browsers
.on('error', plugins.notify.onError())
.pipe(plugins.sourcemaps.write('./maps')) // write sourcemaps
.pipe(gulp.dest(p.distCSS)); // move to target folder
});
gulp.task('css-build', function() {
gulp.src(p.srcSCSS)
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass({
errLogToConsole : true,
sourceComments : 'normal'
}))
.on('error', plugins.notify.onError())
.pipe(plugins.autoprefixer('last 3 versions', '> 2%', 'ff > 23', 'ie > 8')) // vendorize properties for supported browsers
.pipe(plugins.csso()) // compress
.pipe(gulp.dest(p.distCSS)); // move to target folder
});
// Javascript-related tasks
gulp.task('js-watch', function() {
gulp.src(p.srcJS + '*.js')
.pipe(plugins.cached('hinting')) // only process modified files
.pipe(plugins.jshint('.jshintrc'))
.pipe(plugins.jshint.reporter(plugins.stylish))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sourcemaps.write('./maps')) // write sourcemaps
.pipe(gulp.dest(p.distJS)); // move to target folder
});
gulp.task('js-build', function() {
gulp.src(p.srcJS + '*.js')
.pipe(plugins.jshint('.jshintrc'))
.pipe(plugins.jshint.reporter(plugins.stylish))
.pipe(plugins.uglify()) // compress with uglify
.pipe(gulp.dest(p.distJS)); // move to target folder
});
gulp.task('js-format', function() {
return gulp.src(p.srcJS + '*.js')
.pipe(plugins.sourcemaps.init())
.pipe(plugins.prettify({
config : '.jsbeautifyrc',
mode : 'VERIFY_AND_WRITE',
}))
.pipe(plugins.sourcemaps.write('./maps')) // write sourcemaps
.pipe(gulp.dest(p.srcJS));
});
// Image-related tasks
gulp.task('img-build', function() {
gulp.src(p.srcSVG)
.pipe(plugins.svgmin()) // compress with svgmin
.pipe(gulp.dest(p.distIMG)); // move to target folder
gulp.src(p.srcPNG)
.pipe(plugins.tinypng('6r1BdukU9EqrtUQ5obGa-6VpaH2ZlI-a')) // compress with TinyPNG
.pipe(gulp.dest(p.distIMG)); // move to target folder
});
// ensure consistent whitespace etc. in files
gulp.task('fileformat', function() {
return gulp.src(p.allfiles)
.pipe(plugins.lintspaces({
indentation : 'spaces',
spaces : 4,
trailingspaces : true,
newline : true,
newlineMaximum : 2,
}))
.pipe(plugins.lintspaces.reporter());
});
// check PHP coding standards
gulp.task('sniffphp', function() {
return gulp.src(p.phpfiles)
.pipe(plugins.phpcs({
bin : '/usr/local/bin/phpcs',
standard : 'WordPress',
warningSeverity : 0,
}))
.pipe(plugins.phpcs.reporter('log'));
});
// COMMANDS ------------------------------------------------------------------------------------------------------------
gulp.task('default', ['clean', 'img-build', 'css-watch', 'js-watch'], function() {
// watch for changes
// gulp.watch(p.allfiles, ['fileformat']);
gulp.watch(p.srcSCSS, ['css-watch']);
gulp.watch(p.srcJS + '*.js', ['js-watch']);
});
// check code quality before git commit
gulp.task('precommit', ['sniffphp', 'js-format'], function() {
gulp.src(p.srcJS + '*.js')
.pipe(plugins.jshint('.jshintrc'))
.pipe(plugins.jshint.reporter(plugins.stylish));
gulp.src(p.distCSS + '*.css')
.pipe(plugins.csslint())
.pipe(plugins.csslint.reporter());
});
// build project for release
gulp.task('build', ['clean'], function() {
gulp.start('img-build');
gulp.start('css-build');
gulp.start('js-build');
});