-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
110 lines (97 loc) · 3.52 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
const gulp = require('gulp');
const vulcanize = require('gulp-vulcanize');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const replace = require('gulp-replace')
// const htmlmin = require('gulp-htmlmin');
const htmlmin = require('gulp-html-minifier');
const pump = require('pump');
const dest = require('dest');
const del = require('del');
const cleanCSS = require('gulp-clean-css');
const fs = require('fs');
var elementsPath = 'build/elements/nextprot-elements';
var rootPath = 'build';
gulp.task('clean', function (cb) {
del(['./build/**'], cb);
});
gulp.task('vulcanize', function () {
return gulp.src('./bower_components/nextprot-elements/nextprot-elements.html')
.pipe(vulcanize({
strip: true,
inlineScripts: true,
inlineCss: true,
stripComments : true
}))
.pipe(htmlmin({
// collapseWhitespace: true
minifyJS:true,
minifyCSS:true,
removeComments: true
}))
.pipe(gulp.dest('./build/elements/'));
});
gulp.task('copy-elements', function () {
var elementsTask = gulp.src('./bower_components/nextprot-elements/*.html')
.pipe(dest(elementsPath));
var biovizTask = gulp.src('./bower_components/nextprot-elements/bio-viz-v2/**')
.pipe(dest(elementsPath + '/bio-viz-v2'));
var colorbarTask = gulp.src('./bower_components/nextprot-elements/colorbar/**')
.pipe(dest(elementsPath + '/colorbar'));
return [elementsTask, biovizTask, colorbarTask];
});
function getVendorVersion() {
var filename = "";
fs.readdirSync('./build/js/').forEach(file => {
if ((/^vendor.*.js$/).test(file)){
filename = file.split("_")[1].split(".")[0];
}
});
return filename;
}
gulp.task('build-elements', function () {
var extElemFileName = getVendorVersion();
return gulp.src('./bower_components/nextprot-elements/external-elements.html')
.pipe(vulcanize({
stripExcludes: ['./bower_components/font-roboto/roboto.html'],
strip: true,
inlineScripts: true,
inlineCss: true
}))
.pipe(htmlmin({
collapseWhitespace: true,
minifyJS:true,
minifyCSS:true,
removeComments: true
}))
.pipe(rename('external-elements_'+extElemFileName+'.html'))
.pipe(gulp.dest('./build/elements/'));
// var indexReplaceTask = gulp.src(['build/index.html'])
// .pipe(replace('extElemVersion', extElemFileName))
// .pipe(gulp.dest('build/'));
// return [buildExtElem, indexReplaceTask]
});
gulp.task('copy-vendor', () => {
return gulp.src('build/css/vendor_*.css')
.pipe(rename("vendor_sparql.css"))
.pipe(gulp.dest('./build/css/'));
});
gulp.task('build-app', ['build-elements','copy-vendor']);
gulp.task('minify-css', () => {
return gulp.src('build/css/*.css')
.pipe(cleanCSS())
.pipe(gulp.dest('build/css'));
});
gulp.task('compress', ['minify-css'] , () => {
return gulp.src('build/js/*.js')
.pipe(uglify({ mangle: false }))
.pipe(gulp.dest('./build/js'));
});
/**
* bio-viz folder has to be in the root web directory, so it has to be copied
*/
gulp.task('copy-bio-viz', function() {
return gulp.src(['./bower_components/nextprot-elements/bio-viz-v2/**'])
.pipe(dest(rootPath + '/bio-viz-v2'));
});
gulp.task('default', ['copy-elements', 'build-app', 'compress']);