-
Notifications
You must be signed in to change notification settings - Fork 78
/
gulpfile.js
114 lines (98 loc) · 2.77 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
var DIST_DIR = 'dist',
SRC_FILES = 'src/**/*.js',
path = require('path'),
date = require('moment'),
del = require('del'),
karma = require('karma').server,
runSequence = require('run-sequence'),
gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
banner = [
'/*!',
' * <%= package.title || package.name %> :: v<%= package.version %> :: <%= package.todayDate %>',
' * web: <%= package.homepage %>',
' *',
' * Copyright (c) <%= package.todayYear %> | <%= package.author %>',
' * License: <%= package.license %>',
' */',
''
].join('\n'),
pkg = require('./package.json');
pkg.todayDate = date().format('YYYY-MM-DD');
pkg.todayYear = date().format('YYYY');
gulp.task('clean', function(done) {
del(DIST_DIR, done);
});
gulp.task('scripts', function() {
var filename = pkg.name + '.js';
return gulp.src(SRC_FILES)
.pipe($.angularFilesort())
.pipe($.addSrc.prepend('module.prefix'))
.pipe($.addSrc.append('module.suffix'))
.pipe($.concat(filename))
.pipe($.preprocess({
context: {
VERSION: pkg.version
}
}))
.pipe($.header(banner, {
package: pkg
}))
.pipe($.ngAnnotate({
add: true,
remove: true,
single_quotes: true
}))
.pipe(gulp.dest(DIST_DIR))
.pipe($.sourcemaps.init())
.pipe($.uglify({
preserveComments: 'some'
}))
.pipe($.rename({
suffix: '.min'
}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(DIST_DIR));
});
gulp.task('styles', function() {
var filename = pkg.name + '.css';
return gulp.src('src/**/*.less')
.pipe($.sourcemaps.init())
.pipe($.less())
.pipe($.concat(filename))
.pipe($.header(banner, {
package: pkg
}))
.pipe(gulp.dest(DIST_DIR))
.pipe($.rename({
suffix: '.min'
}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(DIST_DIR));
});
gulp.task('default', function(done) {
runSequence(['scripts', 'styles'], done)
});
gulp.task('test', ['lint'], function(done) {
karma.start({
configFile: path.join(__dirname, 'karma.conf.js')
}, function() {
done();
});
});
gulp.task('lint', function() {
return gulp.src(SRC_FILES)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'));
});
gulp.task('serve', ['clean', 'default'], function() {
return gulp.src('.')
.pipe($.webserver({
directoryListing: {
enable:true,
path: '.'
},
open: 'app/index.html'
}));
});