-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
125 lines (105 loc) · 3.86 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
let gulp = require('gulp');
let fs = require('fs');
let sass = require('gulp-sass')(require('sass'));
let rename = require('gulp-rename');
let concat = require('gulp-concat');
let terser = require('gulp-terser');
let replace = require('gulp-replace');
let fancy = require('fancy-log');
let injectString = require('gulp-inject-string');
let stripCssComments = require('gulp-strip-css-comments');
let postcss = require('gulp-postcss');
let zip = require('gulp-zip');
let packagejson = require('./package.json');
let sourceHeader = fs.readFileSync(packagejson.buildOpts.common.sourceHeader, 'utf8')
.replace('{VERSION}', packagejson.version)
.replace('{YEAR}', (new Date()).getFullYear().toString())
.replace('{AUTHOR}', packagejson.author);
gulp.task('scss:build', function () {
return gulp.src('./src/sass/style.scss')
.pipe(sass({
outputStyle: 'expanded'
}).on('error', fancy))
.pipe(gulp.dest('./src/css'));
});
gulp.task('css:build', function () {
return gulp.src(['./src/css/style.css'])
.pipe(postcss([
require('autoprefixer')(),
require('postcss-sort-media-queries')(),
]))
.pipe(replace(/([\r\n]{2,})/igm, '\r\n'))
.pipe(injectString.prepend(sourceHeader + '\n'))
.pipe(gulp.dest('./css'));
});
gulp.task('css:minify', function () {
return gulp.src(['./css/style.css'])
.pipe(postcss([
require('cssnano')
]))
.pipe(stripCssComments({
preserve: false
}))
.pipe(injectString.prepend(sourceHeader + '\n'))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./css'));
});
gulp.task('js:build', function () {
return gulp.src([
'./src/js/workarounds.js',
'./src/js/vendor/popper.min.js',
'./src/js/vendor/bootstrap.min.js',
'./src/js/vendor/bootstrap-fileselect.min.js',
'./src/js/vendor/jquery.datetimepicker.full.min.js',
'./src/js/vendor/jquery.easing.min.js',
'./src/js/vendor/jquery.nicescroll.min.js',
'./src/js/vendor/select2.min.js',
'./src/js/vendor/jquery-insert.js',
'./src/js/vendor/jquery-migrate.min.js',
'./src/js/vendor/jquery.browser.js',
'./src/js/theme/base.js',
'./src/js/theme/functions.js',
'./src/js/theme/navigation.js',
'./src/js/theme/collapse-history.js',
'./src/js/theme/init/select2.js',
'./src/js/theme/init/fileselect.js',
'./src/js/theme/init/datetimepicker.js'
])
.pipe(concat('script.js'))
.pipe(injectString.prepend(sourceHeader + '\n'))
.pipe(gulp.dest('./js'));
});
gulp.task('js:minify', function () {
return gulp.src(['./js/script.js'])
.pipe(terser())
.pipe(rename({
suffix: '.min'
}))
.pipe(injectString.prepend(sourceHeader + '\n'))
.pipe(gulp.dest('./js'));
});
gulp.task('zip:build', function () {
return gulp.src([
'./**',
'!./api/cache/{,/**}',
'!./package*',
'!./gulpfile.js',
'!./node_modules{,/**}',
'!./nbproject{,/**}',
'!./src{,/**}',
'!./README.md',
'!*.zip'
])
.pipe(zip(packagejson.name + '-' + packagejson.version + '.zip'))
.pipe(gulp.dest('./'));
});
gulp.task('src:watch', function () {
gulp.watch(['./src/sass/**/*.scss'], gulp.series('css:rebuild'));
gulp.watch(['./src/js/**/*.js'], gulp.series('js:rebuild'));
});
gulp.task('css:rebuild', gulp.series('scss:build', 'css:build', 'css:minify'));
gulp.task('js:rebuild', gulp.series('js:build', 'js:minify'));
gulp.task('src:rebuild', gulp.series('js:rebuild', 'css:rebuild'));
gulp.task('src:release', gulp.series('src:rebuild', 'zip:build'));