-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
162 lines (143 loc) · 4.13 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
const gulp = require('gulp');
const rtlcss = require('gulp-rtlcss');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const jshint = require('gulp-jshint');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const sort = require('gulp-sort');
const wppot = require('gulp-wp-pot');
const gettext = require('gulp-gettext');
const plumber = require('gulp-plumber');
const autoprefixer = require('gulp-autoprefixer');
const gutil = require('gulp-util');
const rename = require('gulp-rename');
const map = require('map-stream');
const browserlist = ['last 2 version', '> 1%'];
const errorreporter = map(function(file, cb) {
if (file.jshint.success) {
return cb(null, file);
}
console.log('JSHINT fail in', file.path);
file.jshint.results.forEach(function (result) {
if (!result.error) {
return;
}
const err = result.error
console.log(` line ${err.line}, col ${err.character}, code ${err.code}, ${err.reason}`);
});
cb(null, file);
});
gulp.task('default', function() {
console.log('Use the following commands');
console.log('--------------------------');
console.log('gulp compile-css to compile the scss to css');
console.log('gulp compile-js to compile the js to min.js');
console.log('gulp watch to continue watching the files for changes');
console.log('gulp wordpress-lang to compile the lsx-currencies.pot, en_EN.po and en_EN.mo');
});
gulp.task('styles', function () {
return gulp.src('assets/css/scss/*.scss')
.pipe(plumber({
errorHandler: function(err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compact',
includePaths: ['assets/css/scss']
}).on('error', gutil.log))
.pipe(autoprefixer({
browsers: browserlist,
casacade: true
}))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('assets/css'))
});
gulp.task('styles-rtl', function () {
return gulp.src('assets/css/scss/*.scss')
.pipe(plumber({
errorHandler: function(err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sass({
outputStyle: 'compact',
includePaths: ['assets/css/scss']
}).on('error', gutil.log))
.pipe(autoprefixer({
browsers: browserlist,
casacade: true
}))
.pipe(rtlcss())
.pipe(rename({
suffix: '-rtl'
}))
.pipe(gulp.dest('assets/css'))
});
gulp.task('compile-css', ['styles', 'styles-rtl']);
gulp.task('js', function() {
return gulp.src('assets/js/src/lsx-currencies.js')
.pipe(plumber({
errorHandler: function(err) {
console.log(err);
this.emit('end');
}
}))
.pipe(jshint())
//.pipe(errorreporter)
.pipe(concat('lsx-currencies.min.js'))
.pipe(uglify())
.pipe(gulp.dest('assets/js'))
});
gulp.task('admin-js', function() {
return gulp.src('assets/js/src/lsx-currencies-admin.js')
.pipe(plumber({
errorHandler: function(err) {
console.log(err);
this.emit('end');
}
}))
.pipe(jshint())
//.pipe(errorreporter)
.pipe(concat('lsx-currencies-admin.min.js'))
.pipe(uglify())
.pipe(gulp.dest('assets/js'))
});
gulp.task('compile-js', ['js', 'admin-js']);
gulp.task('watch-css', function () {
return gulp.watch('assets/css/**/*.scss', ['compile-css']);
});
gulp.task('watch-js', function () {
return gulp.watch('assets/js/src/**/*.js', ['compile-js']);
});
gulp.task('watch', ['watch-css', 'watch-js']);
gulp.task('wordpress-pot', function() {
return gulp.src('**/*.php')
.pipe(sort())
.pipe(wppot({
domain: 'lsx-currencies',
package: 'lsx-currencies',
team: 'LightSpeed <[email protected]>'
}))
.pipe(gulp.dest('languages/lsx-currencies.pot'))
});
gulp.task('wordpress-po', function() {
return gulp.src('**/*.php')
.pipe(sort())
.pipe(wppot({
domain: 'lsx-currencies',
package: 'lsx-currencies',
team: 'LightSpeed <[email protected]>'
}))
.pipe(gulp.dest('languages/en_EN.po'))
});
gulp.task('wordpress-po-mo', ['wordpress-po'], function() {
return gulp.src('languages/en_EN.po')
.pipe(gettext())
.pipe(gulp.dest('languages'))
});
gulp.task('wordpress-lang', (['wordpress-pot', 'wordpress-po-mo']));