-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
196 lines (166 loc) · 5.05 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
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
/* Remove jQuery as $ so it can be used by gulp-load-plugins */
/* globals require, -$ */
var {series,dest,src,task,watch, parallel} = require('gulp'),
args = require('yargs').argv,
concat = require('gulp-concat'),
ignore = require('gulp-ignore'),
del = require('del'),
terser = require('gulp-terser'),
rename = require('gulp-rename'),
$ = require('gulp-load-plugins')({lazy:true}),
config = require('./gulp.config')();
// *** Code analysis ***
task('vet', function () {
$.util.log('Running static code analysis.');
return src(config.alljs)
.pipe($.if(args.verbose, $.print()))
.pipe($.jscs())
.pipe($.jscs.reporter())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish', { verbose: true }));
});
// *** cleaning tasks ***
function clean(path) {
$.util.log('Cleaning: ' + $.util.colors.blue(path));
return del(path);
}
// ** clean styles
function cleanStyles(done) {
var files = config.tmpDir + '**/*.css';
clean(files);
done();
};
/**
* Utility that merges multiple .js files into one output and additionally outputs
* the minified version.
*
*/
function processJs(fileLocation, fileName){
return src(fileLocation)
.pipe(concat(`${fileName}.js`))
.pipe(dest(config.buildJs, {overwrite:true}))
.pipe(rename(`${fileName}.min.js`))
.pipe(terser())
.pipe(dest(config.buildJs, {overwrite:true}))
}
// ** clean Dist
function cleanDist(done) {
clean('./dist/*');
done();
};
// ** Copying custom styles ***
function compileStyles(cb){
$.util.log('Compiling Less to CSS.');
compileLess()
cb();
};
// Copies less files from src folder to dist folders (used to copy to tmpDir too)
function compileLess(){
return src(config.less)
.pipe($.plumber(function (err) {
$.util.log(err);
this.emit('end');
}))
.pipe($.less())
.pipe($.autoprefixer())
.pipe(concat('genomap.css'))
.pipe(dest(config.buildCss))
.pipe(rename('genomap.min.css'))
.pipe($.csso())
.pipe(dest(config.buildCss),{append:true})
}
// ** Copying bootstrap and jquery styles **
async function copyLibCss(){
return src(config.libCss)
.pipe(concat('jquery-bstrap.css'))
.pipe(dest(config.buildCss),{append:true})
.pipe(rename('jquery-bstrap.min.css'))
.pipe($.csso())
.pipe(dest(config.buildCss),{append:true});
};
function copyLibJs(cb){
$.util.log('Moving js lib unordered files into place');
processJs(config.libsJs, 'genomap-lib');
cb()
}
// ** Copying Boostrap and Jquery related dependencies where ordering is required **
async function copyJqueryBstrapJs(){
$.util.log('Moving js lib ordered files into place');
processJs(config.libsOrderJs,'jquery-bstrap')
}
//** Copying a replicate of jquery-bstrap.js file without Jquery **
// TODO: use processJs?
function copyNoJquery(){
return src(config.libsOrderJs)
.pipe(ignore.exclude('jquery.js'))
.pipe(concat('nonjquery-bstrap.js'))
.pipe(dest(config.buildJs, {overwrite:true}))
.pipe(rename('nonjquery-bstrap.js.min.js'))
.pipe(terser())
.pipe(dest(config.buildJs, {overwrite:true}))
}
// *** custom JS copying ***
function copyJs(done){
$.util.log('Moving js files into place');
processJs(config.srcJS,'genomap')
done()
};
// *** copying images
function copyAssets(){
return src('./assets/img/*', {'base' :'./assets'})
.pipe(dest(config.tmpDir,{overwrite : true}))
.pipe(dest(config.build,{overwrite : true}));
};
// ** Copying Html file to dist folder**
function copyProdHtml(cb){
copyHtml(config.distHtml, config.build)
cb();
}
// ** Copying Html file to tmp folder **
function copydevHtml(cb){
copyHtml(config.devHtml, config.srcDir)
cb()
}
function copyHtml(fileLocation, outputLocation){
return src(fileLocation)
.pipe(rename('index.html'))
.pipe(dest(outputLocation))
}
// launching dev server
async function launchProdServer(){
return $.connect.server({
root: [ config.build, config.testDataDir ],
port: '8000',
livereload: false,
});
};
function launchDevServer(cb){
// TODO this used to have tmpDir only, but now many files aren't copied into tmpDir anymore
// Also, it's not clear why We have to add testDataDir, which is a subdir of testDir
//
return $.connect.server({
root: [ config.build, config.tmpDir, config.testDir, config.testDataDir ],
port: '8000',
livereload: true,
});
cb()
}
function reload (cb) {
src(config.devHtml)
.pipe($.connect.reload());
cb()
}
function watchFiles(cb){
watch(config.less, series(cleanStyles,compileStyles, reload))
watch(config.srcJS,series(copyJs, reload))
watch(config.devHtml, series(copydevHtml, reload))
watch(config.xmlFiles,reload)
cb()
}
const coreTasks = series(cleanStyles,cleanDist,compileStyles,copyLibCss,copyLibJs,copyJqueryBstrapJs,copyNoJquery,copyJs,copyAssets,copydevHtml,copyProdHtml)
// create a default task and just log a message
task('help', $.taskListing);
exports.default = task('default', series('help'));
exports.build = series(coreTasks)
exports.demo = series(launchProdServer)
exports.demoDev = parallel(series(coreTasks,series(launchDevServer)),series(watchFiles))