-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
224 lines (202 loc) · 7.7 KB
/
gulpfile.mjs
File metadata and controls
224 lines (202 loc) · 7.7 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import gulp from 'gulp';
import cleancss from '@sequencemedia/gulp-clean-css';
import concat from 'gulp-concat';
import download from 'gulp-fetch';
import header from 'gulp-header';
import less from 'gulp-less';
import phplint from 'gulp-phplint';
import rename from 'gulp-rename';
import replace from 'gulp-replace';
import * as dartSass from 'sass';
import gulpSass from 'gulp-sass';
import sourcemaps from '@sequencemedia/gulp-sourcemaps';
import uglify from 'gulp-uglify';
import packageData from './package.json' with { type: 'json' };
const sass = gulpSass(dartSass);
const banner = [
'/*!',
' * <%= pkg.title %> v<%= pkg.version %> - <%= pkg.description %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' * @author <%= pkg.author.name %>',
' */',
'',
'',
].join('\n');
gulp.task('less-framework', function() {
return gulp.src(['public_html/assets/litecore/less/*.less'])
.pipe(sourcemaps.init())
.pipe(less())
.on('error', function (err) {
console.error('LESS Error:', err.message);
this.emit('end'); // Prevents Gulp from stopping
})
.pipe(gulp.dest('public_html/assets/litecore/css/', { overwrite: true }))
.pipe(cleancss())
.pipe(header(banner, { pkg: packageData }))
.pipe(rename({ extname: '.min.css' }))
.pipe(sourcemaps.write('.', { includeContent: false }))
.pipe(gulp.dest('public_html/assets/litecore/css/', { overwrite: true }));
});
// Build and uglify JS files
gulp.task('js-framework', function() {
return gulp
.src('public_html/assets/litecore/js/components/*.js')
.pipe(concat('framework.js', {'newLine': '\r\n\r\n'}))
.pipe(header(banner, { pkg: packageData }))
.pipe(gulp.dest('public_html/assets/litecore/js/', { overwrite: true }))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(sourcemaps.write('.', { includeContent: false }))
.pipe(gulp.dest('public_html/assets/litecore/js/', { overwrite: true }));
});
// Compile LESS files
gulp.task('less-backend', function() {
gulp.src('public_html/backend/template/less/vari*bles.less') // non-globstar pattern will fail on some windows paths
.pipe(less())
.on('error', function (err) {
console.error('LESS Error:', err.message);
this.emit('end'); // Prevents Gulp from stopping
})
.pipe(header(banner, { pkg: packageData }))
.pipe(gulp.dest('public_html/backend/template/css/', { overwrite: true }));
return gulp.src(['public_html/backend/template/less/*.less', '!public_html/backend/template/less/vari*bles.less'])
.pipe(sourcemaps.init())
.pipe(less())
.on('error', function (err) {
console.error('LESS Error:', err.message);
this.emit('end'); // Prevents Gulp from stopping
})
.pipe(header(banner, { pkg: packageData }))
.pipe(cleancss())
.pipe(rename({ extname: '.min.css' }))
.pipe(sourcemaps.write('.', { includeContent: false }))
.pipe(gulp.dest('public_html/backend/template/css', { overwrite: true }));
});
// Build and uglify JS files
gulp.task('js-backend', function() {
return gulp
.src('public_html/backend/template/js/components/*.js')
.pipe(concat('app.js', {'newLine': '\r\n\r\n'}))
.pipe(header(banner, { pkg: packageData }))
.pipe(gulp.dest('public_html/backend/template/js/', { overwrite: true }))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(sourcemaps.write('.', { includeContent: false }))
.pipe(gulp.dest('public_html/backend/template/js/', { overwrite: true }));
});
gulp.task('less-frontend', function() {
gulp.src('public_html/frontend/template/less/vari*bles.less') // non-globstar pattern will fail on some windows paths
.pipe(less())
.on('error', function (err) {
console.error('LESS Error:', err.message);
this.emit('end'); // Prevents Gulp from stopping
})
.pipe(header(banner, { pkg: packageData }))
.pipe(gulp.dest('public_html/frontend/template/css/', { overwrite: true }))
return gulp.src(['public_html/frontend/template/less/*.less', '!**/variables.less'])
.pipe(sourcemaps.init())
.pipe(less())
.on('error', function (err) {
console.error('LESS Error:', err.message);
this.emit('end'); // Prevents Gulp from stopping
})
.pipe(gulp.dest('public_html/frontend/template/css/', { overwrite: true }));
.pipe(cleancss())
.pipe(header(banner, { pkg: packageData }))
.pipe(rename({ extname: '.min.css' }))
.pipe(sourcemaps.write('.', { includeContent: false })
.pipe(gulp.dest('public_html/frontend/template/css/', { overwrite: true }));
})
gulp.task('js-frontend', function() {
return gulp.src('public_html/frontend/template/js/components/*.js');
.pipe(sourcemaps.init())
.pipe(concat('app.js', {'newLine': '\r\n\r\n'}))
.pipe(header(banner, { pkg: packageData }))
.pipe(gulp.dest('public_html/frontend/template/js/', { overwrite: true }));
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(sourcemaps.write(('.', { includeContent: false }), { includeContent: false }))
.pipe(gulp.dest('public_html/frontend/template/js/', { overwrite: true }));
})
// Task to compile and minify Trumbowyg SCSS
gulp.task('sass-trumbowyg', function() {
return gulp
.src('public_html/assets/trumbowyg/ui/*.scss')
.pipe(sass({ silenceDeprecations: ['legacy-js-api'] })
.on('error', sass.logError))
//.pipe(gulp.dest('public_html/assets/trumbowyg/ui/'))
//.pipe(sourcemaps.write('.', { includeContent: false }))
.pipe(cleancss())
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('public_html/assets/trumbowyg/ui/'))
.pipe(sourcemaps.write('.', { includeContent: false }));
});
// Lint PHP files
gulp.task('phplint', function() {
return gulp
.src(paths.php)
.pipe(phplint())
.pipe(phplint.reporter('fail'));
});
gulp.task('iconly', function() {
download({ url: 'https://dev.iconly.io/public/OoTc8FJRmnEY/iconly.woff2', filename: 'fonticons.woff2' })
.pipe(gulp.dest('public_html/assets/litecore/fonts/'));
return download({ url: 'https://dev.iconly.io/public/OoTc8FJRmnEY/iconly.css', filename: 'fonticons.less' })
.pipe(replace(/^\/\*\!.*?(?=\n.icon-)/gs, [
'',
'@font-face {',
' font-display: auto;',
' font-family: "LiteCore";',
' font-style: normal;',
' font-weight: 400;',
` src: url("../fonts/fonticons.woff2?${Math.floor(Date.now() / 1000)}") format("woff2");`,
'}',
'',
'[class^="icon-"], [class*=" icon-"] {',
' display: inline-block;',
' font-family: "LiteCore" !important;',
' font-weight: 400;',
' font-style: normal;',
' font-variant: normal;',
' text-rendering: auto;',
' text-align: center;',
' vertical-align: middle;',
' line-height: 1;',
' width: 1em;',
' height: 1em;',
' -moz-osx-font-smoothing: grayscale;',
' -webkit-font-smoothing: antialiased;',
'}',
'',
].join('\n')))
.pipe(replace(/(\.icon-[^:]+:before)\s*\{\s*([^}]+?)\s*\}\s*/g, '$1 { $2 }\n'))
.pipe(gulp.dest('public_html/assets/litecore/less/framework/'));
});
// Watch files for changes
gulp.task('watch', function() {
gulp.watch('public_html/assets/litecore/less/**/*.less', gulp.series('less-framework'))
gulp.watch('public_html/assets/litecore/js/components/*.js', gulp.series('js-framework'))
gulp.watch('public_html/assets/trumbowyg/**/*.scss', gulp.series('sass-trumbowyg'))
gulp.watch('public_html/backend/template/less/**/*.less', gulp.series('less-backend'))
gulp.watch('public_html/backend/template/js/components/*.js', gulp.series('js-backend'))
gulp.watch('public_html/frontend/template/less/**/*.less', gulp.series('less-frontend'))
gulp.watch('public_html/frontend/template/js/components/*.js', gulp.series('js-frontend'))
});
// Task aliases
gulp.task('build', gulp.series(
'js-framework',
'js-backend',
'js-frontend',
'less-framework',
'less-backend',
'less-frontend',
'sass-trumbowyg',
'watch',
));
gulp.task('default', gulp.series(
'build',
'watch',
));