/
gulpfile.js
93 lines (83 loc) · 3.18 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
var path = require('path');
var fs = require('fs');
var del = require('del');
var _ = require('underscore');
var gulp = require('gulp');
var babel = require('gulp-babel');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var beautify = require('gulp-beautify');
var gulpif = require('gulp-if');
var cached = require('gulp-cached');
var plumber = require('gulp-plumber');
var paths = {
node_modules: './node_modules',
scripts: [
'galaxy/scripts/**/*.js',
'!galaxy/scripts/qunit/**/*',
'!galaxy/scripts/apps/**/*',
'!galaxy/scripts/libs/**/*'
],
lib_locs: {
// This is a stepping stone towards having all this staged
// automatically. Eventually, this dictionary and staging step will
// not be necessary.
'backbone': [ 'backbone.js', 'backbone.js' ],
'd3': [ 'd3.js', 'd3.js' ],
'bibtex-parse-js': [ 'bibtexParse.js', 'bibtexParse.js' ],
'jquery': ['dist/jquery.js', 'jquery/jquery.js'],
'jquery.complexify': [ 'jquery.complexify.js', 'jquery/jquery.complexify.js' ],
'jquery.cookie': [ 'jquery.cookie.js', 'jquery/jquery.cookie.js' ],
'jquery-migrate': [ 'dist/jquery-migrate.js', 'jquery/jquery.migrate.js' ],
'jquery-mousewheel': [ 'jquery.mousewheel.js', 'jquery/jquery.mousewheel.js' ],
'raven-js': ['dist/raven.js', 'raven.js'],
'requirejs': [ 'require.js', 'require.js' ],
'underscore': [ 'underscore.js', 'underscore.js' ]
},
libs: ['galaxy/scripts/libs/**/*.js']
};
var dev_mode = function(){
return process.env.NODE_ENV != "production";
};
var source_maps = function(){
return dev_mode() || process.env.GXY_BUILD_SOURCEMAPS !== undefined;
};
gulp.task('scripts', function() {
return gulp.src(paths.scripts)
.pipe(plumber())
.pipe(cached('scripts'))
.pipe(gulpif(source_maps, sourcemaps.init()))
.pipe(babel({
plugins: ['transform-es2015-modules-amd']
}))
.pipe(gulpif(dev_mode, beautify(), uglify()))
.pipe(gulpif(source_maps, sourcemaps.write('../maps/')))
.pipe(gulp.dest('../static/scripts/'));
});
gulp.task('stage-libs', function(callback){
_.each(_.keys(paths.lib_locs), function(lib){
var p1 = path.resolve(path.join(paths.node_modules, lib, paths.lib_locs[lib][0]));
var p2 = path.resolve(path.join('galaxy', 'scripts', 'libs', paths.lib_locs[lib][1]));
if (fs.existsSync(p1)) {
del.sync(p2);
fs.createReadStream(p1).pipe(fs.createWriteStream(p2));
} else {
callback(p1 + " does not exist, yet it is a required library. This is an error. Check that the package in question exists in node_modules.");
}
});
});
gulp.task('libs', function() {
return gulp.src(paths.libs)
.pipe(uglify())
.pipe(gulp.dest('../static/scripts/libs/'));
});
gulp.task('clean', function(){
//Wipe out all scripts that aren't handled by webpack
return del(['../static/scripts/**/*.js',
'!../static/scripts/bundled/**.*.js'],
{force: true});
});
gulp.task('watch', function(){
gulp.watch(paths.scripts, ['scripts']);
});
gulp.task('default', ['scripts', 'libs']);