-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
executable file
·113 lines (91 loc) · 2.78 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
var es = require('event-stream');
var gulp = require('gulp');
var concat = require('gulp-concat');
var connect = require('gulp-connect');
var templateCache = require('gulp-angular-templatecache');
var ngAnnotate = require('gulp-ng-annotate');
var uglify = require('gulp-uglify');
var fs = require('fs');
var _ = require('lodash');
var scripts = require('./app.scripts.json');
var source = {
js: {
main: 'app/main.js',
src: [
// application config
'app.config.js',
// application bootstrap file
'app/main.js',
// main module
'app/app.js',
// module files
'app/**/module.js',
// other js files [controllers, services, etc.]
'app/**/!(module)*.js'
],
tpl: 'app/**/*.tpl.html'
}
};
var destinations = {
js: 'build'
};
gulp.task('build', function(){
return es.merge(gulp.src(source.js.src) , getTemplateStream())
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(concat('app.js'))
.pipe(gulp.dest(destinations.js));
});
gulp.task('js', function(){
return es.merge(gulp.src(source.js.src) , getTemplateStream())
.pipe(concat('app.js'))
.pipe(gulp.dest(destinations.js));
});
gulp.task('watch', function(){
gulp.watch(source.js.src, ['js']);
gulp.watch(source.js.tpl, ['js']);
});
gulp.task('connect', function() {
connect.server({
port: 8888
});
});
gulp.task('vendor', function(){
_.forIn(scripts.chunks, function(chunkScripts, chunkName){
var paths = [];
chunkScripts.forEach(function(script){
var scriptFileName = scripts.paths[script];
if (!fs.existsSync(__dirname + '/' + scriptFileName)) {
throw console.error('Required path doesn\'t exist: ' + __dirname + '/' + scriptFileName, script)
}
paths.push(scriptFileName);
});
gulp.src(paths)
.pipe(concat(chunkName + '.js'))
//.on('error', swallowError)
.pipe(gulp.dest(destinations.js))
})
});
var stubby = require('gulp-stubby-server');
gulp.task('stubby', function(cb) {
var options = {
files: [
'mocks/*.{yaml,js}'
]
};
stubby(options, cb);
});
gulp.task('prod', ['vendor', 'build']);
gulp.task('dev', ['vendor', 'js', 'watch', 'stubby','connect']);
gulp.task('default', ['dev']);
var swallowError = function(error){
console.log(error.toString());
this.emit('end')
};
var getTemplateStream = function () {
return gulp.src(source.js.tpl)
.pipe(templateCache({
root: 'app/',
module: 'app'
}))
};