-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
158 lines (137 loc) · 5.04 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
/**
* gulpfile.js - Watch and automatically process CSS and JS
*
* @version 3.1.0
* @package wp_theme_lyquix
* @author Lyquix
* @copyright Copyright (C) 2015 - 2024 Lyquix
* @license GNU General Public License version 2 or later
* @link https://github.com/Lyquix/wp_theme_lyquix
*/
// .d8888b. 88888888888 .d88888b. 8888888b. 888
// d88P Y88b 888 d88P" "Y88b 888 Y88b 888
// Y88b. 888 888 888 888 888 888
// "Y888b. 888 888 888 888 d88P 888
// "Y88b. 888 888 888 8888888P" 888
// "888 888 888 888 888 Y8P
// Y88b d88P 888 Y88b. .d88P 888 "
// "Y8888P" 888 "Y88888P" 888 888
//
// DO NOT MODIFY THIS FILE!
import gulp from 'gulp';
import fs from 'fs';
import livereload from 'gulp-livereload';
import postcss from 'gulp-postcss';
import cssnano from 'cssnano';
import autoprefixer from 'autoprefixer';
import sourcemaps from 'gulp-sourcemaps';
import rename from 'gulp-rename';
import terser from 'gulp-terser';
import { exec, execSync } from 'child_process';
// Compile SCSS and Tailwind CSS
gulp.task('compile-css', (done) => {
try {
console.log('Running SASS compilation...');
execSync('sass css/custom/custom.scss css/custom.css', { stdio: 'pipe', maxBuffer: 1024 * 500 });
console.log('Running Tailwind CSS (frontend styles)...');
execSync('tailwindcss -i css/custom.css -c css/tailwind/config.js -o css/styles.css', { stdio: 'pipe', maxBuffer: 1024 * 500 });
console.log('Running Tailwind CSS (editor styles)...');
execSync('tailwindcss -i css/tailwind/editor.css -c css/tailwind/editor.config.js -o css/editor.css', { stdio: 'pipe', maxBuffer: 1024 * 500 });
for (let i = 0; i < 5; i++) {
const data = fs.readFileSync('css/styles.css', 'utf8');
const themeRegex = /theme\s*\(\s*['"][^'"]*['"]\s*\)/g;
if (!themeRegex.test(data)) break;
exec('npx tailwindcss -i css/styles.css -c css/tailwind/config.js -o css/styles.css');
}
const postCSSPlugins = [
cssnano({ preset: 'default' }),
autoprefixer()
];
gulp.src('css/styles.css')
.pipe(sourcemaps.init())
.pipe(postcss(postCSSPlugins))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('css'))
.on('end', () => livereload.reload());
console.log('\x1b[41m\x1b[37m%s\x1b[0m', ' >>> PAGE RELOADED <<< ');
done();
} catch (err) {
console.error('Error during CSS compilation:');
console.log(err)
// Convert the error output into a string
const errorOutput = err.stderr ? err.stderr.toString() : err.stdout.toString();
try {
// Match the specific parts of the CssSyntaxError
const reasonMatch = errorOutput.match(/reason:\s*'([^']+)'/);
const fileMatch = errorOutput.match(/file:\s*'([^']+)'/);
const lineMatch = errorOutput.match(/line:\s*(\d+)/);
if (reasonMatch && fileMatch && lineMatch) {
console.error(`Reason: ${reasonMatch[1]}`);
console.error(`File: ${fileMatch[1]}`);
console.error(`Line: ${lineMatch[1]}`);
} else {
// Fallback: Log the error if extraction failed
// Convert the stderr buffer into a string
const errorOutput = err.stderr.toString();
// Extract and print the relevant information
const relevantLines = errorOutput.split('\n').slice(0, 8).join('\n');
console.error(relevantLines);
}
} catch (extractionError) {
console.error('Error processing the error details:', extractionError.message);
}
// Stop further execution and prevent additional error logging
done();
}
});
// Minify JS
gulp.task('lyquixjs', () => {
console.log('Running lyquixjs minification...');
return gulp.src('js/lyquix.js')
.pipe(sourcemaps.init())
.pipe(terser({ output: { comments: false } }))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('js'));
});
gulp.task('scriptsjs', () => {
console.log('Running scriptsjs minification...');
return gulp.src('js/scripts.js')
.pipe(sourcemaps.init())
.pipe(terser({ output: { comments: false } }))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('js'));
});
gulp.task('vuejs', () => {
console.log('Running vuejs minification...');
return gulp.src('js/vue.js', { allowEmpty: true })
.pipe(sourcemaps.init())
.pipe(terser({ output: { comments: false } }))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('js'));
});
// Livereload
gulp.task('livereload', () => {
livereload.listen(35729);
// Watch SCSS files and trigger the compilation sequence
gulp.watch([
'css/custom/**/*.scss',
'js/lyquix.js',
'js/scripts.js',
'page-templates/*.php',
'php/**/*.php',
'custom.php',
'tribe/**/*.php',
'tribe-events/**/*.php',
'css/tailwind/whitelist.html'
], gulp.series('compile-css'));
//Watch for changes in JS files for livereload
gulp.watch(['js/lyquix.js', 'js/scripts.js']).on('change', (path) => {
gulp.parallel('lyquixjs', 'scriptsjs', 'vuejs')(); // Minify JS
});
});
// Default task
gulp.task('default', gulp.parallel('compile-css', 'livereload'));