-
Notifications
You must be signed in to change notification settings - Fork 27
/
gulpfile.js
124 lines (109 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
124
/* jshint ignore:start */
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
ngAnnotate = require('gulp-ng-annotate'),
templateCache = require('gulp-angular-templatecache'),
minifyCSS = require('gulp-minify-css'),
sass = require('gulp-sass'),
sourceMaps = require('gulp-sourcemaps'),
notify = require('gulp-notify'),
jade = require('gulp-jade'),
rename = require('gulp-rename'),
jshint = require('gulp-jshint'),
mainBowerFiles = require('main-bower-files'),
connect = require('gulp-connect');
gulp.task('collect-components', function () {
gulp.src(mainBowerFiles(), {base: './bower_components'})
.pipe(gulp.dest('./components'));
});
gulp.task('styles', function () {
gulp.src('./styles/styles.scss')
.pipe(sourceMaps.init())
.pipe(sass()).on('error', notify.onError("Error: <%= error.message %>"))
.pipe(minifyCSS({
keepSpecialComments: 0
}))
.pipe(rename({suffix: '.min'}))
.pipe(sourceMaps.write('./'))
.pipe(gulp.dest('./dist'))
.pipe(connect.reload());
gulp.src('./styles/styles-bower.scss')
.pipe(sourceMaps.init())
.pipe(sass()).on('error', notify.onError("Error: <%= error.message %>"))
.pipe(minifyCSS({
keepSpecialComments: 0
}))
.pipe(rename({suffix: '.min'}))
.pipe(sourceMaps.write('./'))
.pipe(gulp.dest('./dist'))
.pipe(connect.reload());
});
gulp.task('templates', function () {
gulp.src('./templates/**/*.tmpl')
.pipe(templateCache({
module: 'su-templates',
standalone: true
}))
.pipe(gulp.dest('./scripts'))
.pipe(connect.reload());
});
gulp.task('scripts', function () {
gulp.src(['./scripts/**/*.js'])
.pipe(ngAnnotate()).on('error', notify.onError("Error: <%= error.message %>"))
.pipe(sourceMaps.init())
.pipe(concat('app.min.js'))
.pipe(uglify()).on('error', notify.onError("Error: <%= error.message %>"))
.pipe(sourceMaps.write('./'))
.pipe(gulp.dest('./dist'))
.pipe(connect.reload());
});
gulp.task('jshint', function() {
gulp.src(['./scripts/**/*.js', '!./scripts/templates.js'])
.pipe(jshint())
.pipe(notify(function (file) {
if (file.jshint.success) {
return false;
}
var errors = file.jshint.results.map(function (data) {
if (data.error) {
return "(" + data.error.line + ':' + data.error.character + ') ' + data.error.reason;
}
}).join("\n");
return file.relative + " (" + file.jshint.results.length + " errors)\n" + errors;
}));
});
gulp.task('demo-views', function () {
gulp.src('./demo/src/views/*.jade')
.pipe(jade({
locals: require('./demo/src/config')
})).on('error', notify.onError("Error: <%= error.message %>"))
.pipe(gulp.dest('./demo/'))
.pipe(connect.reload());
});
gulp.task('demo-styles', function () {
gulp.src('./demo/src/styles/style.scss')
.pipe(sass()).on('error', notify.onError("Error: <%= error.message %>"))
.pipe(minifyCSS({
keepSpecialComments: 0
}))
.pipe(rename('styles.min.css'))
.pipe(gulp.dest('./demo/res'))
.pipe(connect.reload());
});
gulp.task('connect', function () {
connect.server({
root: './',
port: 3030,
livereload: true
});
});
gulp.task('watch', function () {
gulp.watch(['./styles/**/*.scss'], ['styles']);
gulp.watch(['./templates/**/*.tmpl'], ['templates', 'scripts']);
gulp.watch(['./scripts/**/*.js'], ['scripts', 'jshint']);
gulp.watch(['./demo/src/**/*.jade', './demo/src/js/demo.js'], ['demo-views']);
gulp.watch(['./demo/src/styles/**/*.scss'], ['demo-styles']);
});
gulp.task('default', ['connect', 'collect-components', 'styles', 'templates', 'scripts', 'jshint', 'demo-views', 'demo-styles', 'watch']);
/* jshint ignore:end */