-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
73 lines (66 loc) · 2.57 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
const gulp = require('gulp');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const through2 = require('through2');
const path = require('path');
const cleanCSS = require('gulp-clean-css');
const sourcemaps = require('gulp-sourcemaps');
// Check if we are in development mode
const isDev = process.env.KARAFKA_RELEASE !== 'true';
// Define JavaScript source files
const jsFiles = [
'lib/karafka/web/ui/public/javascripts/libs/**/*.js',
'lib/karafka/web/ui/public/javascripts/charts/**/*.js',
'lib/karafka/web/ui/public/javascripts/components/**/*.js',
'lib/karafka/web/ui/public/javascripts/application.js'
];
// Define CSS source files
const cssFiles = [
'lib/karafka/web/ui/public/stylesheets/libs/datepicker.min.css',
'lib/karafka/web/ui/public/stylesheets/libs/tailwind.min.css',
'lib/karafka/web/ui/public/stylesheets/application.css'
];
// Custom transform stream to add file location comments for JavaScript
function addFileLocation() {
return through2.obj(function (file, enc, cb) {
if (file.isBuffer()) {
const fileLocationComment = `/*! Source: ${path.relative(__dirname, file.path)} */\n\n`;
const contents = Buffer.concat([Buffer.from(fileLocationComment), file.contents]);
file.contents = contents;
}
cb(null, file);
});
}
// JavaScript task
gulp.task('scripts', function() {
return gulp.src(jsFiles)
.pipe(isDev ? sourcemaps.init() : through2.obj()) // Initialize sourcemaps in dev
.pipe(addFileLocation()) // Add file location comments
.pipe(concat('application.min.js'))
.pipe(uglify({
output: {
comments: function(node, comment) {
const text = comment.value;
const type = comment.type;
if (type == "comment2") {
// Preserve comments starting with `/*!` or `/**`
return /@preserve|@license|@cc_on|^\!/.test(text);
}
return false;
}
}
}))
.pipe(isDev ? sourcemaps.write('.') : through2.obj()) // Write sourcemaps in dev
.pipe(gulp.dest('lib/karafka/web/ui/public/javascripts'));
});
// CSS task
gulp.task('styles', function() {
return gulp.src(cssFiles)
.pipe(isDev ? sourcemaps.init() : through2.obj()) // Initialize sourcemaps in dev
.pipe(concat('application.min.css'))
.pipe(cleanCSS({ level: 2 })) // Minify CSS
.pipe(isDev ? sourcemaps.write('.') : through2.obj()) // Write sourcemaps in dev
.pipe(gulp.dest('lib/karafka/web/ui/public/stylesheets'));
});
// Define default task to run both scripts and styles tasks
gulp.task('default', gulp.series('scripts', 'styles'));