-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
160 lines (137 loc) · 4.31 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
var gulp = require('gulp'),
karma = require('karma').server,
less = require('gulp-less'),
uglify = require('gulp-uglify'),
ngAnnotate = require('gulp-ng-annotate'),
jshint = require('gulp-jshint'),
cssmin = require('gulp-cssmin'),
minifyHTML = require('gulp-minify-html'),
stylish = require('jshint-stylish'),
path = require('path'),
browserify = require('browserify'),
sourcemaps = require('gulp-sourcemaps'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
runSequence = require('run-sequence').use(gulp),
nodemon = require('gulp-nodemon');
//builds less into css files and move them to release
gulp.task('less', function () {
return gulp.src('app/less/*.less')
.pipe(less({
paths: [path.join(__dirname, 'less', 'includes')]
}))
.pipe(gulp.dest('release/css'));
});
// Run test once and exit
gulp.task('test', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function (exitStatus) {
done();
});
});
// Watch for file changes and re-run tests on each change
gulp.task('tdd', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js'
}, function (exitStatus) {
done();
});
});
// JSHint task
gulp.task('jshint', function () {
gulp.src(['app/*.js', 'app/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
//moves all the static content (images/* fonts/*)
gulp.task('static_content', function () {
return gulp.src(['app/static_content/**/', 'app/static_content/*'])
.pipe(gulp.dest('release/static_content'));
});
//creates the bundle file and bundle.js.map
gulp.task('js', function () {
var bundle = function () {
return browserify({
entries: ['./app/index.js'],
paths: ['./node_modules', '.js'],
debug: true
})
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({
loadMaps: true
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./release/js/'));
};
return bundle();
});
//minifies the bundle file and annotates angular injected modules
gulp.task('uglify', function () {
gulp.src('./release/js/*.js')
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(gulp.dest('./release/js'));
});
//minifies the css generated
gulp.task('cssmin', function () {
gulp.src('./release/css/*.css')
.pipe(cssmin())
.pipe(gulp.dest('./release/css'));
});
//minifies the html views
gulp.task('minify-html', function () {
var opts = {
conditionals: true,
spare: true
};
return gulp.src('./release/views/**/*.html')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('./release/views'));
});
// Views task
gulp.task('views', function () {
//index should be moved separately
gulp.src('./app/index.html')
.pipe(gulp.dest('release/'));
// Any other view files from /views
gulp.src('./app/modules/**/*.html')
.pipe(gulp.dest('release/views'));
});
//default task run it use: gulp
gulp.task('default', ['build', 'watch']);
// 1. gulp build -> builds the project
gulp.task('build', ['jshint', 'test', 'js', 'views', 'less', 'static_content']);
//2. gulp release -> then minifies the generated files into release
gulp.task('release', ['uglify', 'cssmin', 'minify-html']);
// builds and releases, in sequence
gulp.task('build:release', function () {
runSequence(
['js', 'views', 'less', 'static_content'],
['uglify', 'cssmin', 'minify-html']
);
});
// starts the node server.js
gulp.task('start-server', function () {
nodemon({
script: 'server.js',
ext: 'js html'
});
});
//builds, releases and starts the server
gulp.task('deploy', function () {
runSequence(
['js', 'views', 'less', 'static_content'],
['uglify', 'minify-html'],
'start-server'
);
});
// Re-run the task when a file changes
gulp.task('watch', function () {
gulp.watch('app/less/**/*.less', ['less']);
gulp.watch(['app/*.js', 'app/**/*.js'], ['jshint', 'test', 'js']);
gulp.watch(['app/modules/**/*', 'app/*.html'], ['views', 'static_content']);
});