-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
154 lines (134 loc) · 4.16 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
var gulp = require('gulp'),
concat = require('gulp-concat'),
connect = require('gulp-connect'),
mbf = require('main-bower-files'),
less = require('gulp-less'),
jshint = require('gulp-jshint'),
karma = require('karma').server,
sourcemaps = require('gulp-sourcemaps'),
del = require('del'),
uglify = require('gulp-uglify'),
minifyCss = require('gulp-minify-css'),
rename = require('gulp-rename'),
ngAnnotate = require('gulp-ng-annotate');
var paths = {
styles: ['./app/stylesheets/*.less'],
scripts: ['./app/modules/**/*.js'],
html: ['./app/modules/**/*.html'],
tests: ['./tests/*.js']
};
// clean
gulp.task('clean', function () {
return del([
'./build/**/*'
]);
});
// vendor scripts
gulp.task('vendor-js', ['clean'], function () {
var jsRegex = (/.*\.js$/i);
return gulp.src(mbf({ filter: jsRegex }))
.pipe(concat('vendor.js'))
.pipe(gulp.dest('./build/scripts'));
});
// vendor css
gulp.task('vendor-css', ['clean'], function () {
return gulp.src('./bower_components/**/*.min.css')
.pipe(concat('vendor.min.css'))
.pipe(gulp.dest('./build/stylesheets'));
});
// vendor fonts
gulp.task('fontawesome', ['clean'], function () {
return gulp.src('./bower_components/fontawesome/fonts/**/*.{ttf,woff,woff2,eof,svg}')
.pipe(gulp.dest('./build/fonts'));
});
gulp.task('vendor-fonts', ['fontawesome']);
gulp.task('vendor-build', ['vendor-js', 'vendor-css', 'vendor-fonts']);
// app
var appJs = function () {
return gulp.src(paths.scripts)
.pipe(concat('app.js'))
.pipe(ngAnnotate({ single_quotes: true }))
.pipe(connect.reload())
.pipe(gulp.dest('./build/scripts'));
};
gulp.task('app-js', ['clean'], appJs);
gulp.task('app-js-watch', appJs);
var appHtml = function () {
return gulp.src(paths.html)
.pipe(connect.reload())
.pipe(gulp.dest('./build/modules'));
};
gulp.task('app-html', ['clean'], appHtml);
gulp.task('app-html-watch', appHtml);
var appCss = function () {
return gulp.src(paths.styles)
.pipe(less())
.pipe(connect.reload())
.pipe(gulp.dest('./build/stylesheets'));
};
gulp.task('app-css', ['clean'], appCss);
gulp.task('app-css-watch', appCss);
gulp.task('app-build', ['app-js', 'app-html', 'app-css']);
// code linting
gulp.task('lint', function () {
return gulp.src(paths.scripts)
.pipe(jshint({ devel: true, debug: true }))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
// uglify
gulp.task('uglify-vendor-js', ['build'], function () {
gulp.src('./build/scripts/vendor.js')
.pipe(uglify())
.pipe(gulp.dest('./build/scripts'));
});
gulp.task('uglify-app-js', ['build'], function () {
gulp.src('./build/scripts/app.js')
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build/scripts'));
});
gulp.task('uglify-app-css', ['build'], function () {
gulp.src('./build/stylesheets/style.css')
.pipe(sourcemaps.init())
.pipe(minifyCss())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build/stylesheets'));
});
gulp.task('uglify', ['uglify-vendor-js', 'uglify-app-js', 'uglify-app-css']);
// tests
gulp.task('test', function (done) {
karma.start({
configFile: 'karma.conf.js',
singleRun: true
}, done);
});
// dev server
gulp.task('connect', ['build'], function () {
connect.server({
port: 3000,
root: 'build',
livereload: true
});
});
// watch files
gulp.task('watch', ['connect'], function () {
gulp.watch(paths.html, ['app-html-watch']);
gulp.watch(paths.scripts, ['lint', 'app-js-watch']);
gulp.watch(paths.styles, ['app-css-watch']);
});
// build
gulp.task('build', ['vendor-build', 'app-build', 'lint'], function () {
return gulp.src('app/index.html')
.pipe(gulp.dest('build'));
});
// deploy
gulp.task('deploy', ['build'], function () {
del(['./dist/**/*']).then(function () {
return gulp.src('./build/**/*')
.pipe(gulp.dest('dist'));
});
});
// default gulp task
gulp.task('default', ['build', 'connect', 'watch']);