-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
262 lines (240 loc) · 9.12 KB
/
Copy pathgulpfile.mjs
File metadata and controls
262 lines (240 loc) · 9.12 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
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 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 sassOptions = { charset: false, silenceDeprecations: ['legacy-js-api'] };
const banner = [
'/*!',
' <%= pkg.title %> v<%= pkg.version %> - <%= pkg.description %>',
' Link: <%= pkg.homepage %>',
' License: <%= pkg.license %>',
' Author: <%= pkg.author.name %>',
'*/',
'',
'',
].join('\n');
const tabify = function() {
const indentSize = 2;
return new Transform({
objectMode: true,
transform(file, _, cb) {
if (file.isBuffer()) {
let contents = file.contents.toString();
const newline = contents.indexOf('\r\n') !== -1 ? '\r\n' : '\n';
const lines = contents.split(/\r\n|\n/);
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const m = line.match(/^([ \t]*)/);
if (!m) continue;
const ws = m[1];
if (!ws) continue;
let spaceCount = 0;
for (const ch of ws) {
if (ch === '\t') spaceCount += indentSize;
else spaceCount += 1;
}
const tabs = Math.floor(spaceCount / indentSize);
let leftover = spaceCount % indentSize;
const rest = line.slice(ws.length);
// For comment lines that start with '*', ensure there is at least one space
// after the tabs so the asterisk remains separated ("\t * ...").
if (rest.startsWith('*') && leftover === 0) leftover = 1;
lines[i] = '\t'.repeat(tabs) + (leftover ? ' '.repeat(leftover) : '') + rest;
}
contents = lines.join(newline);
file.contents = Buffer.from(contents);
}
cb(null, file);
}
});
}
gulp.task('scss-framework', function() {
return gulp.src('public_html/assets/litecore/scss/{framework/main,email,printable}.scss', { allowEmpty: true })
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(rename(function(path) {
if (path.dirname == 'framework' && path.basename == 'main') {
path.dirname = '';
path.basename = 'framework';
}
}))
.pipe(header(banner, { pkg: packageData }))
.pipe(tabify()) // Use tab indentation
.pipe(gulp.dest('public_html/assets/litecore/css/', { overwrite: true }))
.pipe(cleancss())
.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 }));
});
gulp.task('scss-backend', function() {
gulp.src('public_html/backend/template/scss/vari*bles.scss')
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(header(banner, { pkg: packageData }))
.pipe(tabify())
.pipe(gulp.dest('public_html/backend/template/css/', { overwrite: true }));
return gulp.src(['public_html/backend/template/scss/*.scss', '!**/variables.scss'])
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(header(banner, { pkg: packageData }))
.pipe(tabify()) // Use tab indentation
.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(tabify()) // Use tab indentation
.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 }));
});
// Build and uglify JS files
gulp.task('js-trumbowyg', function() {
return gulp
.src('public_html/assets/trumbowyg/trumb*wyg.js')
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
//.pipe(sourcemaps.write('.', { includeContent: false }))
.pipe(gulp.dest('public_html/assets/trumbowyg/', { overwrite: true }));
});
gulp.task('scss-frontend', function() {
gulp.src('public_html/frontend/template/scss/variables*.scss', { allowEmpty: true })
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(header(banner, { pkg: packageData }))
.pipe(tabify()) // Use tab indentation
.pipe(gulp.dest('public_html/frontend/template/css/', { overwrite: true }));
return gulp.src(['public_html/frontend/template/scss/*.scss', '!**/variables.scss'], { allowEmpty: true })
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(tabify()) // Use tab indentation
.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', { allowEmpty: true })
.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 }))
.pipe(gulp.dest('public_html/frontend/template/js/', { overwrite: true }));
});
// Task to compile and minify Trumbowyg SCSS
gulp.task('scss-trumbowyg', function() {
return gulp
.src('public_html/assets/trumbowyg/ui/*.scss')
.pipe(sass(sassOptions))
.on('error', sass.logError)
.pipe(tabify()) // Use tab indentation
.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('public_html/**/*.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.scss' })
.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(tabify()) // Use tab indentation
.pipe(gulp.dest('public_html/assets/litecore/scss/framework/'));
});
// Watch files for changes
gulp.task('watch', function() {
gulp.watch('public_html/assets/litecore/scss/**/*.scss', gulp.series('scss-framework'))
gulp.watch('public_html/assets/litecore/js/components/*.js', gulp.series('js-framework'))
gulp.watch('public_html/assets/trumbowyg/trumbowyg.js', gulp.series('js-trumbowyg'))
gulp.watch('public_html/assets/trumbowyg/**/*.scss', gulp.series('scss-trumbowyg'))
gulp.watch('public_html/backend/template/scss/**/*.scss', gulp.series('scss-backend'))
gulp.watch('public_html/backend/template/js/components/*.js', gulp.series('js-backend'))
gulp.watch('public_html/frontend/template/scss/**/*.scss', gulp.series('scss-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',
'js-trumbowyg',
'scss-framework',
'scss-backend',
'scss-frontend',
'scss-trumbowyg',
'watch',
));
gulp.task('default', gulp.series(
'build',
'watch'
));