-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
150 lines (139 loc) · 3.92 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
var args = require('yargs').argv;
var autoprefixer = require('gulp-autoprefixer');
var babel = require('gulp-babel');
var bump = require('gulp-bump');
var checktextdomain = require('gulp-checktextdomain');
var concat = require('gulp-concat');
var cssnano = require('gulp-cssnano');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var jshint = require('gulp-jshint');
var mergeStream = require('merge-stream');
var potomo = require('gulp-potomo');
var pottopo = require('gulp-pottopo');
var pump = require('pump');
var sass = require('gulp-sass');
var sort = require('gulp-sort');
var terser = require('gulp-terser');
var wpPot = require('gulp-wp-pot');
var yaml = require('yamljs');
var config = yaml.load('+/config.yml');
gulp.task('bump', function(cb) {
var type = 'patch';
['prerelease','patch','minor','major'].some(function(arg) {
if( !args[arg] )return;
type = arg;
return true;
});
pump([
gulp.src(config.bump),
bump({type:type,keys:['stable tag','version']}),
gulp.dest('.'),
], cb);
});
gulp.task('css', function(cb) {
var streams = mergeStream();
for(var key in config.styles) {
if(!config.styles.hasOwnProperty(key))continue;
streams.add(gulp.src(config.styles[key]).pipe(concat(key)));
}
pump([
streams,
gulpif(args.production, cssnano()),
gulp.dest(config.dest.css),
], cb);
});
gulp.task('js', function(cb) {
var streams = mergeStream();
for(var key in config.scripts) {
if(!config.scripts.hasOwnProperty(key))continue;
streams.add(gulp.src(config.scripts[key]).pipe(concat(key)));
}
pump([
streams,
// babel({
// compact: false,
// presets: ['@babel/preset-env'],
// }),
gulpif(args.production, terser({
output: {comments: 'some'},
})),
gulp.dest(config.dest.js),
], cb);
});
gulp.task('jshint', function(cb) {
pump([
gulp.src(config.watch.js),
jshint(),
jshint.reporter('jshint-stylish'),
jshint.reporter('fail'),
], cb);
});
gulp.task('po-to-mo', function(cb) {
pump([
gulp.src(config.dest.lang + '*.po'),
potomo(),
gulp.dest(config.dest.lang),
], cb);
});
gulp.task('pot', function(cb) {
pump([
gulp.src(config.watch.php),
checktextdomain({
text_domain: config.language.domain,
keywords: [
'__:1,2d',
'_e:1,2d',
'_x:1,2c,3d',
'esc_html__:1,2d',
'esc_html_e:1,2d',
'esc_html_x:1,2c,3d',
'esc_attr__:1,2d',
'esc_attr_e:1,2d',
'esc_attr_x:1,2c,3d',
'_ex:1,2c,3d',
'_n:1,2,4d',
'_nx:1,2,4c,5d',
'_n_noop:1,2,3d',
'_nx_noop:1,2,3c,4d',
],
}),
sort(),
wpPot({
domain: config.language.domain,
lastTranslator: config.language.translator,
team: config.language.team,
}),
gulp.dest(config.dest.lang + config.language.domain + '.pot'),
], cb);
});
gulp.task('pot-to-po', function(cb) {
pump([
gulp.src(config.dest.lang + '*.pot'),
pottopo(),
gulp.dest(config.dest.lang),
], cb);
});
gulp.task('scss', function(cb) {
pump([
gulp.src(config.watch.scss),
sass({
outputStyle: 'expanded',
}).on('error', sass.logError),
autoprefixer('last 2 versions'),
gulpif(args.production, cssnano({
minifyFontValues: false,
discardComments: {removeAll: true},
zindex: false,
})),
gulp.dest(config.dest.css),
], cb);
});
gulp.task('watch', function() {
gulp.watch(config.watch.css, gulp.parallel('css'));
gulp.watch(config.watch.js, gulp.parallel('jshint', 'js'));
gulp.watch(config.watch.scss, gulp.parallel('scss'));
});
gulp.task('languages', gulp.series('pot', 'pot-to-po', 'po-to-mo'));
gulp.task('default', gulp.parallel('css', 'js', 'jshint', 'scss'));
gulp.task('build', gulp.parallel('default', 'languages'));