-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
123 lines (103 loc) · 3.8 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
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync').create();
var resolve = require('app-root-path').resolve;
var Server = require('karma').Server;
gulp.task('test', function(done) {
new Server({
configFile: resolve('./karma.conf.js')
}, function(status) {
if (status) {
process.exit(1);
}
done();
}).start();
});
gulp.task('lint', ['lint.client', 'lint.server']);
gulp.task('lint.client', function() {
return gulp.src('./src/client/**/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'));
});
gulp.task('lint.server', function() {
return gulp.src('./src/server/**/@(*.js|http|https)')
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'));
});
gulp.task('dist', ['dist.css', 'dist.html', 'dist.img', 'dist.js', 'dist.vendor']);
gulp.task('dist.css', function() {
return gulp.src('./src/client/**/*.css')
.pipe($.sourcemaps.init())
.pipe($.concat('app.min.css'))
.pipe($.autoprefixer())
.pipe($.cssnano())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('./dist/client'));
});
gulp.task('dist.html', ['dist.html.index', 'dist.html.views']);
gulp.task('dist.html.index', function() {
return gulp.src('./src/client/index.html')
.pipe($.htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./dist/client'));
});
gulp.task('dist.html.views', function() {
return gulp.src('./src/client/**/!(index).html')
.pipe($.flatten())
.pipe($.htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./dist/client/views'));
});
gulp.task('dist.img', function() {
return gulp.src('./src/client/**/*.@(png|jpg|gif|svg|ico)')
.pipe($.flatten())
.pipe($.imagemin())
.pipe(gulp.dest('./dist/client/img'));
});
gulp.task('dist.js', function() {
return gulp.src(['./src/client/**/*.module.js', './src/client/**/!(*.spec).js'])
.pipe($.sourcemaps.init())
.pipe($.concat('app.min.js'))
.pipe($.ngAnnotate())
.pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('./dist/client'));
});
gulp.task('dist.vendor', function() {
return gulp.src([
'./node_modules/angular-material/angular-material.min.css',
'./node_modules/angular/angular.min.@(js|js.map)',
'./node_modules/angular-aria/angular-aria.min.@(js|js.map)',
'./node_modules/angular-animate/angular-animate.min.@(js|js.map)',
'./node_modules/angular-material/angular-material.min.js',
'./node_modules/angular-ui-router/release/angular-ui-router.min.js'
], {base: './node_modules'})
.pipe(gulp.dest('./dist/client/vendor'));
});
gulp.task('dev', ['dev.client'], function() {
gulp.watch('./src/client/**/*.css', ['dist.css']);
gulp.watch('./src/client/index.html', ['dist.html.index']);
gulp.watch('./src/client/**/!(index).html', ['dist.html.views']);
gulp.watch('./src/client/**/*.@(png|jpg|gif|svg|ico)', ['dist.img']);
gulp.watch('./src/client/**/!(*.spec).js', ['dist.js']);
});
gulp.task('dev.client', ['dev.server'], function() {
var port = process.env.PORT || 3000;
browserSync.init({
ui: false,
files: './dist/client',
proxy: 'localhost:' + port,
port: port + 1,
online: false,
notify: false,
reloadDelay: 500,
minify: false
});
});
gulp.task('dev.server', ['dist'], function() {
$.nodemon({
script: './src/server/bin/http',
watch: resolve('./src/server/**/@(*.js|http|https)'),
env: { 'NODE_ENV': 'development' }
}).on('restart', browserSync.reload);
});
gulp.task('default', ['dev']);