-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
81 lines (67 loc) · 2.27 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
// gulp pot
const gulp = require('gulp');
const gulpif = require('gulp-if');
const del = require('del');
const wpPot = require('gulp-wp-pot');
const replace = require('gulp-replace');
const rename = require('gulp-rename');
const config = {
"text_domain" : "urban-carnival-theme",
"twig_files" : "views/**/*.twig",
"php_files" : "**/*.php",
"cacheFolder" : "views/temp",
"destFolder" : "languages",
};
const gettext_regex = {
simple: /(__|_e|translate|esc_attr__|esc_attr_e|esc_html__|esc_html_e)\(\s*?['"].+?['"]\s*?,\s*?['"].+?['"]\s*?\)/g,
plural: /_n\(\s*?['"].*?['"]\s*?,\s*?['"].*?['"]\s*?,\s*?.+?\s*?,\s*?['"].+?['"]\s*?\)/g,
disambiguation: /(_x|_ex|_nx|esc_attr_x|esc_html_x)\(\s*?['"].+?['"]\s*?,\s*?['"].+?['"]\s*?,\s*?['"].+?['"]\s*?\)/g,
noop: /(_n_noop|_nx_noop)\((\s*?['"].+?['"]\s*?),(\s*?['"]\w+?['"]\s*?,){0,1}\s*?['"].+?['"]\s*?\)/g,
};
gulp.task('compile-twig', () => {
return gulp.src(config.twig_files)
.pipe(replace(gettext_regex.simple, match => `<?php ${match}; ?>`))
.pipe(replace(gettext_regex.plural, match => `<?php ${match}; ?>`))
.pipe(replace(gettext_regex.disambiguation, match => `<?php ${match}; ?>`))
.pipe(replace(gettext_regex.noop, match => `<?php ${match}; ?>`))
.pipe(rename({
extname: '.php',
}))
.pipe(gulp.dest(config.cacheFolder));
});
gulp.task('generate-pot', () => {
const output = gulp.src(config.php_files)
.pipe(wpPot({
domain: config.text_domain
}))
.pipe(gulp.dest(`${config.destFolder}/${config.text_domain}.pot`))
return output;
});
gulp.task('clean-temp', function(){
return del('views/temp/**', {force:true});
});
gulp.task('pot', gulp.series('compile-twig', 'generate-pot', 'clean-temp'));
// gulp style
'use strict';
var sass = require("gulp-sass"),
postcss = require("gulp-postcss"),
autoprefixer = require("autoprefixer"),
cssnano = require("cssnano");
var paths = {
styles: {
src: "assets/sass/*.scss",
dest: "assets/css/"
}
};
function style() {
return gulp
.src(paths.styles.src)
.pipe(sass())
.on("error", sass.logError)
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(gulp.dest(paths.styles.dest));
}
exports.style = style;
var build = gulp.parallel(style);
gulp.task('build', build);
gulp.task('default', build);