-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
276 lines (257 loc) · 9 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
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
/*
* -------------------------------------------------------------------------------
* gulpfile.js
*
* Automated tasks for Midwife-EMR.
* -------------------------------------------------------------------------------
*/
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var ngAnnotate = require('gulp-ng-annotate');
var minifyCss = require('gulp-minify-css');
var templateCache = require('gulp-angular-templatecache');
var Promise = require('bluebird');
var del = require('del');
var jshint = require('gulp-jshint');
var gutil = require('gulp-util');
// --------------------------------------------------------
// Global configuration options for various gulp packages.
// --------------------------------------------------------
var cfg = {
uglify: {
mangle: false,
compress: true
},
ngAnnotate: {},
minifyCss: {
advanced: false,
agressiveMerging: false,
roundingPrecision: -1
},
templateCacheViews: {
root: '/angular/views/',
module: 'midwifeEmr',
filename: 'templateViews.js',
moduleSystem: 'IIFE'
},
templateCacheComponents: {
root: '/angular/components/',
module: 'midwifeEmr',
filename: 'templateComponents.js',
moduleSystem: 'IIFE'
}
};
// --------------------------------------------------------
// test - run Mocha tests.
// --------------------------------------------------------
gulp.task('test', function() {
var origEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'test';
return gulp
.src(['test/test.*.js'], {read: false})
.pipe(mocha({
reporter: 'spec',
require: ['should']
}))
.once('error', function() {
process.exit(1);
})
.once('end', function() {
process.env.NODE_ENV = origEnv;
process.exit();
});
});
// --------------------------------------------------------
// Test the React client.
// --------------------------------------------------------
gulp.task('test-client', function() {
var babel = require('babel-core/register')
return gulp
.src(['client/js/react/**/*_spec.js'], {read: false})
.pipe(mocha({
reporter: 'spec',
require: ['expect'],
compilers: {js: babel}
}))
.once('error', function(err) {
//console.log(err);
process.exit(1);
})
.once('end', function() {
process.exit();
});
});
// --------------------------------------------------------
// Concat and uglify the js to include in the header.
// --------------------------------------------------------
gulp.task('uglify-header', function() {
return gulp
.src(['client/js/html5shiv.js'
, 'client/js/respond.min.js'
])
.pipe(concat('midwife-emr-header.min.js'))
.pipe(uglify(cfg.uglify))
.pipe(gulp.dest('static/js/'));
});
// --------------------------------------------------------
// Concat and uglify the js to include in the footer.
// Note: source order is important.
// --------------------------------------------------------
gulp.task('uglify-footer', function() {
return gulp
.src(['node_modules/jquery/dist/jquery.js'
, 'node_modules/bootstrap/dist/js/bootstrap.js'
, 'node_modules/underscore/underscore.js'
, 'node_modules/moment/min/moment.min.js'
, 'static/js-resources/jquery.flot.js'
, 'static/js-resources/jquery.flot.categories.js'
, 'static/js-resources/jquery.are-you-sure.js'
, 'client/js/responsive-tables.js'
, 'client/js/jquery-ui.min.js'
, 'client/js/midwife-emr.js'
, 'client/js/midwife-emr-home.js'
, 'client/js/priorityList.js'
])
.pipe(concat('midwife-emr-footer.min.js'))
.pipe(uglify(cfg.uglify))
.pipe(gulp.dest('static/js/'));
});
// --------------------------------------------------------
// Concat and uglify the js to include in the footer for
// the SPA portion of the application.
// Note: source order is important.
// --------------------------------------------------------
gulp.task('uglify-footer-spa', function() {
return gulp
.src(['node_modules/angular/angular.js'
, 'node_modules/angular-moment/angular-moment.js'
, 'node_modules/angular-ui-router/release/angular-ui-router.js'
, 'node_modules/ui-router-extras/release/modular/ct-ui-router-extras.core.js'
, 'node_modules/ui-router-extras/release/modular/ct-ui-router-extras.future.js'
, 'client/js/angular/app.js'
, 'client/js/angular/router.js'
, 'client/js/angular/services/minPubSubNg/minPubSubNg.js'
, 'client/js/angular/services/historyService/historyService.js'
, 'client/js/angular/services/changeRoutingService/changeRoutingService.js'
, 'client/js/angular/services/templateService/templateService.js'
, 'client/js/angular/services/loggingService/loggingService.js'
, 'client/js/angular/components/historyControl/historyControl.js'
, 'client/js/angular/components/patientWell/patientWell.js'
])
.pipe(ngAnnotate(cfg.ngAnnotate))
.pipe(concat('midwife-emr-footer-spa.min.js'))
.pipe(uglify(cfg.uglify))
.pipe(gulp.dest('static/js/'));
});
// --------------------------------------------------------
// Handle the Angular view templates by enabling them to be
// loaded into $templateCache.
// --------------------------------------------------------
gulp.task('templateCache-views', function() {
return gulp
.src([
'client/js/angular/views/*.html',
])
.pipe(templateCache(cfg.templateCacheViews))
.pipe(gulp.dest('static/js/'));
});
// --------------------------------------------------------
// Handle the Angular component templates by enabling them
// to be loaded into $templateCache.
// --------------------------------------------------------
gulp.task('templateCache-components', function() {
return gulp
.src([
'client/js/angular/components/**/*.tmpl',
])
.pipe(templateCache(cfg.templateCacheComponents))
.pipe(gulp.dest('static/js/'));
});
// --------------------------------------------------------
// Concat both template files into one.
// TODO: refactor these template cache tasks.
// --------------------------------------------------------
gulp.task('templateCache',
['templateCache-views', 'templateCache-components'], function() {
return gulp
.src(['static/js/' + cfg.templateCacheViews.filename,
'static/js/' + cfg.templateCacheComponents.filename])
.pipe(concat('templates.js'))
.pipe(gulp.dest('static/js/'));
});
// --------------------------------------------------------
// Clean up temporary template cache files.
// --------------------------------------------------------
gulp.task('cleanupTemplateCache', ['templateCache'], function() {
return del(['static/js/' + cfg.templateCacheViews.filename,
'static/js/' + cfg.templateCacheComponents.filename]);
});
// --------------------------------------------------------
// Concat and minimize the CSS.
// --------------------------------------------------------
gulp.task('css', function() {
return gulp
.src(['node_modules/bootstrap/dist/css/bootstrap.css'
, 'client/css/sb-admin.css'
, 'client/css/responsive-tables.css'
, 'client/css/jquery-ui.min.css'
, 'client/css/jquery-ui.structure.min.css'
, 'client/css/jquery-ui.theme.min.css'
, 'client/css/midwife-emr.css'
])
.pipe(minifyCss(cfg.minifyCss))
.pipe(concat('midwife-emr-combined.css'))
.pipe(gulp.dest('static/css/'));
});
// --------------------------------------------------------
// Copy the images required into place.
// --------------------------------------------------------
gulp.task('images', function() {
return gulp
.src('client/css/images/*')
.pipe(gulp.dest('static/css/images/'));
});
// --------------------------------------------------------
// Copy the favicon to the required place.
// --------------------------------------------------------
gulp.task('favicon', function() {
return gulp
.src('client/favicon.ico')
.pipe(gulp.dest('static/'));
});
// --------------------------------------------------------
// Copy the font-awesome into place.
// --------------------------------------------------------
gulp.task('font-awesome', function() {
return gulp
.src('client/font-awesome/**/*')
.pipe(gulp.dest('static/font-awesome/'));
});
// --------------------------------------------------------
// JSHint
// --------------------------------------------------------
gulp.task('jshint', function() {
return gulp
.src(['client/js/midwife-emr-home.js',
'client/js/midwife-emr.js',
'client/js/priorityList.js',
'client/js/angular/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// --------------------------------------------------------
// The default tasks.
// --------------------------------------------------------
gulp.task('default', [
'uglify-header',
'uglify-footer',
'uglify-footer-spa',
'templateCache',
'css',
'images',
'favicon',
'font-awesome',
'cleanupTemplateCache',
]);