forked from IMA-WorldHealth/bhima-1.X
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
306 lines (252 loc) · 9.96 KB
/
gulpfile.js
File metadata and controls
306 lines (252 loc) · 9.96 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
// Build, Lint, and Test bhima
// TODO
// Should we make these requires dependent on what path is being taken, so that
// not all are required to build bhima? In this format, there is no difference
// between the install requirements of a developer and a production environment.
var gulp = require('gulp'),
gulpif = require('gulp-if'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
flatten = require('gulp-flatten'),
spawn = require('child_process').spawn,
path = require('path'),
iife = require('gulp-iife'),
rimraf = require('rimraf'),
gutil = require('gulp-util'),
less = require('gulp-less'),
// mocha for server-side testing
mocha = require('gulp-mocha'),
// protractor for e2e tests
protractor = require('gulp-protractor').protractor,
// child process for custom scripts
exec = require('child_process').exec;
// constants
// toggle client javascript minification
var UGLIFY = false,
// path to the jshintrc to use
JSHINT_PATH = '.jshintrc',
// TODO - remove this link
PLUGIN_FOLDER = './bin/plugins',
// the output folder for built server files
SERVER_FOLDER = './bin/server/',
// the output folder for built client files
CLIENT_FOLDER = './bin/client/';
// resource paths
var paths = {
client : {
javascript : ['client/src/js/define.js', 'client/src/js/app.js', 'client/src/**/*.js', '!client/src/i18n/**/*.js', '!client/src/lib/**/*.js'],
excludeLint: ['!client/src/lib/**/*.js'],
css : ['client/src/partials/**/*.css', 'client/src/css/*.css'],
vendor : ['client/vendor/**/*.js', 'client/vendor/**/*.css', 'client/vendor/**/*.ttf', 'client/vendor/**/*.wof*', 'client/vendor/**/*.eot','client/vendor/**/*.svg', '!client/vendor/**/src{,/**}', '!client/vendor/**/js{,/**}'],
e2etest : ['client/test/e2e/**/*.spec.js'],
unittest : [],
// these must be globs ("**" syntax) to retain their folder structures
static : ['client/src/index.html', 'client/src/js/app.js', 'client/src/**/*', '!client/src/js/**/*.js', '!client/src/partials/**/*.js', '!client/src/**/*.css']
},
server : {
javascript : ['server/*.js', 'server/**/*.js'],
files : ['server/*', 'server/**/*'],
plugins : ['plugins/*', 'plugins/**/*'],
unittest : []
}
};
/* -------------------------------------------------------------------------- */
/*
* Client Builds
*
* The client build process takes files from the client/src/ folder
* and writes them to the /bin/client/ folder. There are tasks to do
* the following:
* - [client-lint-js] lint the client javascript code (via jshint)
* - [client-minify-css] minify (via minify css) the css
* - [client-minify-js] minify (via uglify) the clientside js code
* - [client-lint-i18n] compares translation files for missing values
* - [client-mv-static] moves the static files (html, img) to the client
* folder
* - [client-mv-vendor] copy the vendor files into the client/vendor folder
*
* To run all of the above, run the gulp task `gulp build-client`.
*
* Other options include
* - [client-watch] watch the client/src/ for changes and run the build
*/
// removes files with del, and continues
gulp.task('client-clean', function (cb) {
rimraf(CLIENT_FOLDER, cb);
});
// run jshint on the client javascript code
gulp.task('client-lint-js', function () {
return gulp.src(paths.client.javascript.concat(paths.client.excludeLint))
.pipe(jshint(JSHINT_PATH))
.pipe(jshint.reporter('default'));
});
// minify the client javascript code via uglify
// writes output to bhima.min.js
gulp.task('client-minify-js', function () {
return gulp.src(paths.client.javascript)
.pipe(gulpif(UGLIFY, uglify({ mangle: true })))
.pipe(concat('js/bhima.min.js'))
.pipe(iife())
.pipe(gulp.dest(CLIENT_FOLDER));
});
// minify the client css styles via minifycss
// writes output to style.min.css
gulp.task('client-minify-css', function () {
return gulp.src(paths.client.css)
.pipe(minifycss())
.pipe(concat('style.min.css'))
.pipe(gulp.dest(CLIENT_FOLDER + 'css/'));
});
// move vendor files over to the /vendor directory
gulp.task('client-mv-vendor', function () {
return gulp.src(paths.client.vendor)
// .pipe(flatten())
.pipe(gulp.dest(CLIENT_FOLDER + 'vendor/'));
});
// SlickGrid repository is very modular and does not include distribution folder
// This build process combines all required components for BHIMA and optionally
// minifies the output
gulp.task('client-vendor-build-slickgrid', function () {
// Specifiy components required by BHIMA
var slickgridComponents = [
'client/vendor/slickgrid/lib/jquery.event.*.js',
'client/vendor/slickgrid/*.js',
'client/vendor/slickgrid/plugins/*.js'
];
return gulp.src(slickgridComponents)
.pipe(concat('bhima.slickgrid.js'))
.pipe(gulp.dest(CLIENT_FOLDER + 'vendor/slickgrid'));
});
gulp.task('client-vendor-build-bootstrap', function () {
/**
* For now this just moves the latest version of bootstrap into the repository
* This build process should compile the latest bhima less definition with the
* latest vendor files
* - move less file to bootstrap vendor folder
* - compile with lessc
* - copy CSS into static file folder
*/
var bhimaDefinition = 'client/src/less/bhima-bootstrap.less';
return gulp.src(bhimaDefinition)
.pipe(gulp.dest('client/vendor/bootstrap/less'))
.pipe(less({
paths : ['./client/vendor/bootstrap/less/mixins']
}))
.pipe(gulp.dest(CLIENT_FOLDER + 'css'));
});
// move static files to the public directory
gulp.task('client-mv-static', ['client-lint-i18n'], function () {
return gulp.src(paths.client.static)
.pipe(gulp.dest(CLIENT_FOLDER));
});
// custom task: compare the English and French for missing tokens
gulp.task('client-lint-i18n', function (cb) {
var progPath = './utilities/translation/tfcomp.js',
enPath = 'client/src/i18n/en.json',
frPath = 'client/src/i18n/fr.json';
exec('node ' + [progPath, enPath, frPath].join(' '), function(err, _, warning) {
if (warning) { console.error(warning); }
cb();
});
});
// watchs for any change and builds the appropriate route
gulp.task('watch-client', function () {
gulp.watch(paths.client.css, ['client-minify-css']);
gulp.watch(paths.client.javascript, ['client-minify-js']);
gulp.watch(paths.client.static, ['client-mv-static']);
gulp.watch(paths.client.vendor, ['client-mv-vendor']);
});
// TODO This message can be removed once the lint/build process has been transitioned
gulp.task('notify-lint-process', function () {
gutil.log(gutil.colors.yellow('REMINDER: Please ensure you have run the command `gulp lint` before submitting a pull request to github'));
});
// builds the client with all the options available
gulp.task('build-client', ['client-clean'], function () {
gulp.start('client-minify-js', 'client-minify-css', 'client-mv-vendor', 'client-vendor-build-slickgrid', 'client-vendor-build-bootstrap', 'client-mv-static', 'notify-lint-process');
});
// Lint client code seperately from build process
// TODO Processes for linting server code - requires uncategorised commit update
gulp.task('lint', ['client-clean'], function () {
gulp.start('client-lint-js', 'client-lint-i18n');
});
/* -------------------------------------------------------------------------- */
/*
* Server Builds
*
* The server build process takes files from the server/ folder and
* writes them to the /bin/server/ folder. It also copies the package.json
* folder for convenience.
*
* Building will run the following tasks:
* - [server-lint-js] lint the server javascript code (via jshint)
* - [server-mv-files] move the server files into the /bin/server folder
* - [server-mv-plugins] move the server plugins into the /bin/server folder
*
* To run all of the above, run the gulp task `gulp build-server`.
*/
gulp.task('server-clean', function (cb) {
rimraf(SERVER_FOLDER, function () {
rimraf(PLUGIN_FOLDER, cb);
});
});
// run jshint on all server javascript files
gulp.task('server-lint-js', function () {
return gulp.src(paths.server.javascript)
.pipe(jshint(JSHINT_PATH))
.pipe(jshint.reporter('default'));
});
// move the server files into /bin/server
gulp.task('server-mv-files', function () {
return gulp.src(paths.server.files)
.pipe(gulp.dest(SERVER_FOLDER));
});
// move plugins
gulp.task('server-mv-plugins', function () {
return gulp.src(paths.server.plugins)
.pipe(gulp.dest(PLUGIN_FOLDER));
});
// build the server
gulp.task('build-server', function () {
gulp.start('server-mv-files', 'server-mv-plugins');
});
/* -------------------------------------------------------------------------- */
/* Testing Client Builds
*
* The following tasks will run unit and end-to-end tests
* on bhima.
*/
// run the selenium server for e2e tests
gulp.task('client-test-e2e', function () {
return gulp.src(paths.client.e2etest)
.pipe(protractor({
configFile : 'protractor.conf.js'
}))
.on('error', function (e) { throw e; });
});
/* -------------------------------------------------------------------------- */
/* Testing Server Builds
*
* TODO
*
* The following tasks will run unit tests on the bhima server using gulp-mocha
*/
// ensure that the server actually runs
gulp.task('server-test-run', function () {
spawn('node', [path.join(SERVER_FOLDER, 'app.js')], {stdio: 'inherit'});
});
/* -------------------------------------------------------------------------- */
gulp.task('clean', function (cb) {
rimraf('./bin/', cb);
});
gulp.task('build', function () {
gulp.start('build-client', 'build-server');
});
gulp.task('test', ['build'], function () {
gulp.start('client-test-e2e');
});
// run the build-client and build-server tasks when no arguments
gulp.task('default', [], function () {
gulp.start('build-client', 'build-server');
});