-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
196 lines (176 loc) · 5.6 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
var gulp = require('gulp'),
gutil = require('gulp-util'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps'),
ngAnnotate = require('gulp-ng-annotate'),
sass = require('gulp-sass'),
karma = require('karma').Server,
connect = require('gulp-connect');
/**
* Help
* This task prints out the available commands
*/
gulp.task('help', function(){
gutil.log('');
gutil.log('Usage: ' + gutil.colors.magenta('gulp') + ' [<tasks>] [<options>]');
gutil.log('');
gutil.log('Tasks:');
gutil.log('\t build \t\t Builds the app into the dist directory');
gutil.log('\t connect \t Serves the production app from the dist directory');
gutil.log('\t test \t\t Run all tests then exits');
gutil.log('\t tdd \t\t Watches for file changes and runs all test on each change, useful for TDD');
gutil.log('\t default \t Run a local dev environment');
gutil.log('\t help \t\t Prints out this command');
});
/**
* Build
* Builds all files for production and moves them into the dist directory
*/
gulp.task('build', ['html', 'images', 'css', 'js', 'vendor', 'buildIndex']);
/**
* Default
* The default task is a development server which watches all source
* files and builds upon each file change.
*/
gulp.task('default', ['build', 'connect', 'watch']);
//--------------------------------------------------------------
// BUILD TASKS
//--------------------------------------------------------------
/**
* Html
* Copies all of the partials into the dist directory
*/
gulp.task('html', function () {
gulp.src('src/partials/**/*.html')
.pipe(connect.reload())
.pipe(gulp.dest('dist/partials'));
});
/**
* Images
* Copies all of the images into the dist directory
*/
gulp.task('images', function () {
gulp.src('src/images/**/*')
.pipe(connect.reload())
.pipe(gulp.dest('dist/images'));
});
/**
* Css
* Builds all sass into a single file and moves it into the dist directory
*/
gulp.task('css', function () {
gulp.src('src/css/main.scss')
.pipe(sass.sync().on('error', sass.logError))
.pipe(connect.reload())
.pipe(gulp.dest('dist/css'));
});
/**
* Js
* Concat and uglify all of our javascript into a single file and move to dist
*/
gulp.task('js', function () {
// We load our js files in a specific order to make sure our base dependencies
// are available before use
gulp.src(['src/components/base/Class.js',
'src/components/base/EventDispatcher.js',
'src/components/base/Events.js',
'src/components/base/BaseDirective.js',
'src/components/base/*',
'src/lang/en/lang.js', //Include our lang strings
'src/**/*.*js'])
.pipe(sourcemaps.init())
.pipe(concat('app.js'))
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(connect.reload())
.pipe(gulp.dest('dist'));
});
/**
* Vendor
* Concat and uglify all third party javascript and move to dist
*/
gulp.task('vendor', function () {
gulp.src(['bower_components/angular/angular.js',
'bower_components/angular-translate/angular-translate.js',
'bower_components/angular-ui-router/release/angular-ui-router.js'])
.pipe(sourcemaps.init())
.pipe(concat('vendor.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(connect.reload())
.pipe(gulp.dest('dist'));
});
/**
* BuildIndex
* Simply copies index.html file over to dist
* Could be used for move advanced replacements eventually
*/
gulp.task('buildIndex', [], function () {
gulp.src('src/index.html')
.pipe(connect.reload())
.pipe(gulp.dest('dist'));
});
//--------------------------------------------------------------
// SERVER TASKS
//--------------------------------------------------------------
/**
* Connect
* Makes a server which points to our dist directory
*/
gulp.task('connect', ['build'], function() {
connect.server({
root: 'dist',
port: 1234,
livereload: true,
fallback: 'dist/index.html'
});
});
/**
* Watch
* Looks for changes in our source files and rebuilds and reloads
* whenever a change is detected
*/
gulp.task('watch', ['build'], function () {
gulp.watch(['src/partials/**/*.html'], ['html']);
gulp.watch(['src/css/**/*.scss'], ['css']);
gulp.watch(['src/images/**/*'], ['images']);
gulp.watch(['src/**/*.js'], ['js']);
gulp.watch(['bower_components/**/*.js'], ['vendor']);
gulp.watch(['src/index.html'], ['buildIndex']);
});
//--------------------------------------------------------------
// TESTING TASKS
//--------------------------------------------------------------
/**
* Test
* Runs the karma tests once and exists upon completion
*/
gulp.task('test', ['build'], function (cb) {
runKarma(cb, true);
});
/**
* TDD
* Runs the karma tests and sets up a watcher to rerun the
* tests each time a source file is updated
*/
gulp.task('tdd', ['build'], function (cb) {
runKarma(cb, false);
});
/**
* RunKarma
* The actual task which runs the karma tests
* @param {Function} cb callback to signal to gulp when the task is complete
* @param {bool} single whether to run tests once or setup a watcher
*/
function runKarma(cb, single) {
new karma({
configFile: __dirname + '/karma.conf.js',
singleRun: single
}, function(status) {
// Hack to make sure karma exits immediately with its error code
process.exit(status);
// cb(status ? "Karma tests did not pass" : undefined);
}).start();
}