-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·263 lines (263 loc) · 8.04 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
//'use strict';
// generated on 2016-05-27 using generator-cg-gas 3.3.4
var config = require('./build/build.config.js');
var karmaConfig = require('./build/karma.config.js');
var protractorConfig = require('./build/protractor.config.js');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var pkg = require('./package');
var karma = require('karma').server;
var del = require('del');
var _ = require('lodash');
/* jshint camelcase:false*/
var webdriverStandalone = require('gulp-protractor').webdriver_standalone;
var webdriverUpdate = require('gulp-protractor').webdriver_update;
var modRewrite = require('connect-modrewrite');
//update webdriver if necessary, this task will be used by e2e task
gulp.task('webdriver:update', webdriverUpdate);
// run unit tests and watch files
gulp.task('tdd', function (cb) {
karma.start(_.assign({}, karmaConfig, {
singleRun: false,
action: 'watch',
browsers: ['PhantomJS']
}), cb);
});
// run unit tests with travis CI
gulp.task('travis', ['build'], function (cb) {
karma.start(_.assign({}, karmaConfig, {
singleRun: true,
browsers: ['PhantomJS']
}), cb);
});
// optimize images and put them in the dist folder
gulp.task('images', function () {
console.log(config.images);
return gulp.src(config.images)
.pipe($.imagemin({
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(config.dist + '/assets/images'))
.pipe($.size({
title: 'images'
}));
});
//generate angular templates using html2js
gulp.task('templates', function () {
return gulp.src(config.tpl)
.pipe($.changed(config.tmp))
.pipe($.html2js({
outputModuleName: 'templates',
base: 'app',
useStrict: true
}))
.pipe($.concat('templates.js'))
.pipe(gulp.dest(config.tmp))
.pipe($.size({
title: 'templates'
}));
});
//generate css files from scss sources
gulp.task('sass', function () {
return gulp.src(config.mainScss)
.pipe($.rubySass())
.on('error', function (err) {
console.log(err.message);
})
.pipe(gulp.dest(config.tmp))
.pipe($.size({
title: 'sass'
}));
});
// inject bower components
gulp.task('wiredep', function () {
var wiredep = require('wiredep').stream;
/* gulp.src('app/*.scss')
.pipe(wiredep())
.pipe(gulp.dest('app'));
*/
gulp.src('app/*.html')
.pipe(wiredep({exclude: ['bootstrap-sass-official']}))
.pipe(gulp.dest('app'));
});
//build files for creating a dist release
gulp.task('build:dist', ['clean'], function (cb) {
runSequence([/*'jshint', */'build', 'copy', 'copy:assets', 'copy:partial', 'copy:directive', 'copy:modals', 'copy:modules', 'images'/*,'test:unit'*/], 'html', cb);
});
//build files for development
gulp.task('build', ['clean'], function (cb) {
runSequence(['sass', 'templates', 'wiredep'], cb);
});
//generate a minified css files, 2 js file, change theirs name to be unique, and generate sourcemaps
gulp.task('html', function () {
var assets = $.useref.assets(
{searchPath: '{build,app}'});
// 'build/tmp/templates.js'
return gulp.src(config.index)
.pipe(assets)
.pipe($.sourcemaps.init())
.pipe($.if('**/*app.js', $.ngAnnotate()))
.pipe($.if('**/*.js', $.uglify({
mangle: false,
})))
.pipe($.if('*.css', $.csso()))
.pipe($.if(['**/*app.js', '**/*app.css'], $.header(config.banner, {
pkg: pkg
})))
.pipe($.rev())
.pipe(assets.restore())
.pipe($.useref())
.pipe($.revReplace())
.pipe($.if('*.html', $.minifyHtml({
empty: true
})))
//.pipe($.debug({verbose: true}))
//.pipe($.sourcemaps.write())
.pipe(gulp.dest(config.dist))
.pipe($.size({
title: 'html'
}));
});
//copy assets in dist folder
gulp.task('copy:assets', function () {
return gulp.src(config.assets, {
dot: true
}).pipe(gulp.dest(config.dist + '/assets'))
.pipe($.size({
title: 'copy:assets'
}));
});
//copy partials in dist folder
gulp.task('copy:partial', function () {
return gulp.src([
config.base + '/partial/**/*.html',
]).pipe(gulp.dest(config.dist + '/partial'))
.pipe($.size({
title: 'copy:partial'
}));
});
//copy directives in dist folder
gulp.task('copy:directive', function () {
return gulp.src([
config.base + '/directive/**/*.html',
]).pipe(gulp.dest(config.dist + '/directive'))
.pipe($.size({
title: 'copy:directive'
}));
});
//copy modals in dist folder
gulp.task('copy:modals', function () {
return gulp.src([
config.base + '/modals/**/*.html',
]).pipe(gulp.dest(config.dist + '/modals'))
.pipe($.size({
title: 'copy:modals'
}));
});
//copy modules in dist folder
gulp.task('copy:modules', function () {
return gulp.src([
config.base + '/modules/**/*.html',
]).pipe(gulp.dest(config.dist + '/modules'))
.pipe($.size({
title: 'copy:modules'
}));
});
//copy assets in dist folder
gulp.task('copy', function () {
return gulp.src([
config.base + '/*',
'!' + config.base + '/*.html',
'!' + config.base + '/app*',
'!' + config.base + '/modules',
'!' + config.base + '/vendor',
'!' + config.base + '/test'
]).pipe(gulp.dest(config.dist))
.pipe($.size({
title: 'copy'
}));
});
//copy html templates in dist folder
gulp.task('copy:templates', function () {
return gulp.src([
config.base + '/modules/**/*.html',
]).pipe(gulp.dest(config.dist + '/modules'))
.pipe($.size({
title: 'copy modules'
}));
});
//clean temporary directories
gulp.task('clean', del.bind(null, [config.dist, config.tmp]));
//lint files
gulp.task('jshint', function () {
return gulp.src(config.js)
.pipe(reload({
stream: true,
once: true
}))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
});
/* tasks supposed to be public */
//default task
gulp.task('default', ['serve']); //
//run unit tests and exit
gulp.task('test:unit', ['build'], function (cb) {
karma.start(_.assign({}, karmaConfig, {
singleRun: true
}), cb);
});
// Run e2e tests using protractor, make sure serve task is running.
gulp.task('test:e2e', ['webdriver:update'], function () {
return gulp.src(protractorConfig.config.specs)
.pipe($.protractor.protractor({
configFile: 'build/protractor.config.js'
}))
.on('error', function (e) {
throw e;
});
});
//run the server, watch for file changes and redo tests.
gulp.task('serve:tdd', function (cb) {
runSequence(['serve', 'tdd']);
});
//run the server after having built generated files, and watch for changes
gulp.task('serve', ['build'], function () {
browserSync({
notify: false,
logPrefix: pkg.name,
//server: ['build', 'app']
server: {
baseDir: ['build', 'app'],
middleware: [
modRewrite([
'!\\.\\w+$ /index.html [L]'
])
]
}
});
gulp.watch(config.html, reload);
gulp.watch(config.scss, ['sass', reload]);
gulp.watch(config.js, ['jshint']);
gulp.watch(config.tpl, ['templates', reload]);
gulp.watch(config.assets, reload);
});
//run the app packed in the dist folder
gulp.task('serve:dist', ['build:dist'], function () {
browserSync({
notify: false,
server: {
baseDir: [config.dist],
middleware: [
modRewrite([
'!\\.\\w+$ /index.html [L]'
])
]
}
});
});