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
|
var path = require('path');
var glob = require('glob');
var browserify = require('browserify');
var watchify = require('watchify');
var es = require('event-stream');
var gulp = require('gulp');
var gutil = require('gulp-util');
var buffer = require('vinyl-buffer');
var concat = require('gulp-concat');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
function getAppName (file) {
return file
.substr(0, file.length - 7)
.substr(17);
}
function doBrowserify (entry, sourceName, dest, customize, output, flags) {
var bundler = browserify({
entries: [entry],
debug: flags.dev,
cache: {},
packageCache: {}
});
// do all .require(), .external()
if (typeof customize === 'function') {
bundler = customize(bundler);
}
if (flags.watch) {
bundler = watchify(bundler);
}
var rebundle = function () {
return bundler.bundle()
.pipe(source(sourceName))
.pipe(gulpif(flags.production, buffer()))
.pipe(gulpif(flags.production, uglify()))
.pipe(gulp.dest(path.join(output, dest)));
};
bundler.on('update', rebundle);
// logs
var logBefore = function (ids) {
var message = '' + ids.length + ' files changed, bundling...';
gutil.log(message);
ids.forEach(function (id) {
gutil.log(gutil.colors.yellow(id));
});
};
var logAfter = function (msg) {
gutil.log(gutil.colors.green(msg));
};
bundler.on('update', logBefore);
bundler.on('log', logAfter);
return rebundle();
}
module.exports.main = function (output, production, dev, watch) {
return doBrowserify(
'src/main/js/main/app.js',
'main.js',
'js/bundles',
function (bundle) {
return bundle
.require('react', { expose: 'react' })
.require('react-dom', { expose: 'react-dom' })
.require('backbone', { expose: 'backbone' })
.require('backbone.marionette', { expose: 'backbone.marionette' })
.require('moment/min/moment-with-locales', { expose: 'moment' });
},
output,
{ production: production, dev: dev, watch: watch });
};
module.exports.apps = function (output, production, dev, watch, done) {
glob('src/main/js/apps/*/app.js', function (err, files) {
if (err) {
done(err);
}
var tasks = files.map(function (entry) {
return doBrowserify(
entry,
getAppName(entry) + '.js',
'js/bundles',
function (bundle) {
return bundle
.external('react')
.external('react-dom')
.external('backbone')
.external('backbone.marionette')
.external('moment');
},
output,
{ production: production, dev: dev, watch: watch });
});
es.merge(tasks).on('end', done);
});
};
module.exports.widgets = function (output, production, dev, watch) {
return doBrowserify(
'src/main/js/widgets/widgets.js',
'widgets.js',
'js/bundles',
function (bundle) {
return bundle
.external('react')
.external('react-dom')
.external('backbone')
.external('backbone.marionette')
.require('moment/min/moment-with-locales', { expose: 'moment' })
.require('./src/main/js/widgets/issue-filter/widget.js', { expose: 'issue-filter-widget' });
},
output,
{ production: production, dev: dev, watch: watch });
};
module.exports.sonar = function (output, production) {
return gulp.src([
'src/main/js/libs/translate.js',
'src/main/js/libs/third-party/jquery.js',
'src/main/js/libs/third-party/jquery-ui.js',
'src/main/js/libs/third-party/d3.js',
'src/main/js/libs/third-party/underscore.js',
'src/main/js/libs/third-party/select2.js',
'src/main/js/libs/third-party/keymaster.js',
'src/main/js/libs/third-party/numeral.js',
'src/main/js/libs/third-party/numeral-languages.js',
'src/main/js/libs/third-party/bootstrap/tooltip.js',
'src/main/js/libs/third-party/bootstrap/dropdown.js',
'src/main/js/libs/select2-jquery-ui-fix.js',
'src/main/js/libs/graphics/pie-chart.js',
'src/main/js/libs/graphics/barchart.js',
'src/main/js/libs/sortable.js',
'src/main/js/libs/inputs.js',
'src/main/js/libs/jquery-isolated-scroll.js',
'src/main/js/libs/application.js'
])
.pipe(concat('sonar.js'))
.pipe(gulpif(production, buffer()))
.pipe(gulpif(production, uglify()))
.pipe(gulp.dest(path.join(output, 'js')));
};
|