-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
246 lines (201 loc) · 7.57 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
'use strict';
var gulp = require('gulp');
var templateCache = require('gulp-angular-templatecache');
var browserify = require('gulp-browserify');
var jshint = require('gulp-jshint');
var nodemon = require('gulp-nodemon');
var connect = require('gulp-connect');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var clean = require('gulp-clean');
var mocha = require('gulp-mocha');
var karma = require('gulp-karma');
var protractor = require('gulp-protractor').protractor;
var shell = require('gulp-shell');
var runSequence = require('run-sequence');
/*******************************************************
* File Paths and Values
******************************************************/
var paths = {
clientScripts: {
//All js files except the compiled templateCache.js file
src: ['client/app/**/*.js', '!client/app/modules/templateCache.js', '!client/app/lib/**/*.js'],
//Destination of browserified files
dest: 'client/ionic/www'
},
htmlTemplates: {
//All html files in the modules folder
src: ['client/app/modules/**/*.html'],
//Destination of templateCached file
dest: 'client/app/modules',
//Name of templateCached file
templateCacheName: 'templateCache.js'
},
index: {
//Location of index.html file
src: ['client/app/index.html'],
//Public location of index.html file
dest: 'client/ionic/www'
},
oauthcallback: {
src: ['client/app/oauthcallback.html']
},
sassFiles: {
//sassfiles
src: ['client/app/**/*.scss'],
mainSrc: ['client/app/styles.scss'],
dest: 'client/ionic/www'
},
serverScripts: {
//Server side scripts
src: ['./server.js', 'server/**/*.js']
},
//Location of files to serve for livereload
livereloadRoot: 'client/ionic/www',
//Main js file client side
mainClientAppFile: 'client/app/app.js',
//Name of main app module in main client js file
ngAppName: 'app',
//Main js file server side
mainServerAppFile: 'server.js',
//Nodemon files to not watch
nodemonIgnoreFiles: ['node_modules/**/*.js', 'client/**/*.js'],
publicPathsToClean: ['client/ionic/www/**/*.html', 'client/ionic/www/**/*.js', 'client/ionic/www/**/*.css', '!client/ionic/www/ionic.bundle.js'],
buildPathsToClean: ['client/ionic/platforms/**/*'],
serverSideMochaTestFiles: ['server/**/*.unit.test.js'],
karmaTestFiles: ['client/app/**/*.unit.test.js'],
karmaConfigFile: 'client/app/config/karma.config.js',
//Protractor Setup
//Make sure you update the webdriver-manager after a clean npm install (it will add the Jar file and chrome driver):
// ./node_modules/protractor/bin/webdriver-manager update
//Make sure the line 28 in the protractor config file is pointing to the right Jar file
// seleniumServerJar: '../../../node_modules/protractor/selenium/selenium-server-standalone-2.42.2.jar'
//Make Sure the chromium driver on line 40 is pointing to the correct path
// chromeDriver: '../../../node_modules/protractor/selenium/chromedriver'
protractorTestFiles: ['client/app/**/*.e2e.test.js'],
protractorConfigFile: 'client/app/config/protractor.config.js'
};
/*******************************************************
* Client Side Build Tasks
******************************************************/
//Gulp connect
gulp.task('connect', function() {
connect.server({
root: paths.livereloadRoot,
livereload: true
});
});
//Convert all html partials for the app and add them to the $templateCache in the 'app' module
gulp.task('templateCache', function(){
return gulp
.src(paths.htmlTemplates.src)
.pipe(templateCache(paths.htmlTemplates.templateCacheName,{module: paths.ngAppName}))
.pipe(gulp.dest(paths.htmlTemplates.dest));
});
//Concatenate all of the dependencies in app.js via Browserify
gulp.task('browserify', ['templateCache'], function(){
gulp
.src([paths.mainClientAppFile])
.pipe(browserify())
.pipe(gulp.dest(paths.clientScripts.dest))
.pipe(connect.reload());
});
//Lint files with jshint
gulp.task('clientLint', function(){
gulp
.src(paths.clientScripts.src)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
//Watch files and recompile when changes occur
gulp.task('clientWatch', function(){
gulp.watch(paths.clientScripts.src, ['clientLint', 'browserify']);
gulp.watch(paths.htmlTemplates.src, ['templateCache', 'browserify']);
gulp.watch(paths.sassFiles.src, ['styles']);
gulp.watch(paths.index.src, ['index']);
gulp.watch(paths.oauthcallback.src, ['oauthcallback']);
});
//Move index.html file into public folder
gulp.task('index', function() {
gulp
.src(paths.index.src)
.pipe(gulp.dest(paths.index.dest))
.pipe(connect.reload());
});
//Move oauthcallback.html file into public folder
gulp.task('oauthcallback', function() {
gulp
.src(paths.oauthcallback.src)
.pipe(gulp.dest(paths.index.dest))
.pipe(connect.reload());
});
//Compile styles
gulp.task('styles', function() {
gulp
.src(paths.sassFiles.mainSrc)
// The onerror handler prevents Gulp from crashing when you make a mistake in your SASS
.pipe(sass({onError: function(e) { console.log('Sass Compilation Error: ',e); } }))
// Optionally add autoprefixer
.pipe(autoprefixer("last 2 versions", "> 1%"))
.pipe(gulp.dest(paths.sassFiles.dest))
.pipe(connect.reload());
});
//Delete Public Files
gulp.task('clean', function(){
return gulp
.src(paths.publicPathsToClean, {read:false})
.pipe(clean());
});
/*******************************************************
* Client Side Testing Tasks
******************************************************/
gulp.task('karma', function(){
return gulp
.src(paths.karmaTestFiles)
.pipe(karma({configFile: paths.karmaConfigFile, action: 'run'}));
});
gulp.task('protractor', function(){
gulp.src(paths.protractorTestFiles)
.pipe(protractor({
configFile: paths.protractorConfigFile
}))
.on('error', function(e) {console.log('Protractor Error: ', e);});
});
/*******************************************************
* Server Side Build Tasks
******************************************************/
//Lint files with jshint
gulp.task('serverLint', function(){
gulp
.src(paths.serverScripts.src)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
//Start nodemon server
gulp.task('serve', function() {
nodemon({script: paths.mainServerAppFile, ignore: [paths.nodemonIgnoreFiles]})
.on('change', ['serverLint'])
.on('restart', function () {
//live reload
connect.reload();
});
});
/*******************************************************
* Server Side Testing Tasks
******************************************************/
gulp.task('serverUnitTests', function(){
return gulp
.src(paths.serverSideMochaTestFiles, {read: false})
.pipe(mocha({reporter: 'min'}));
// .on('error', function(){console.log('Error');});
});
/*******************************************************
* Defined Task Groups
******************************************************/
//Delete Ionic Platform Files
gulp.task('buildIos', shell.task(['npm run-script rebuild']));
gulp.task('clientBuildTasks', ['clean', 'connect', 'clientLint', 'templateCache', 'browserify', 'styles', 'oauthcallback', 'index', 'clientWatch']);
gulp.task('serverBuildTasks', ['serverLint', 'serverUnitTests', 'serve']);
gulp.task('clientTestingTasks', ['karma', 'protractor']);
gulp.task('serverTestingTasks', ['serverUnitTests']);
gulp.task('default', ['serverBuildTasks', 'clientBuildTasks']);