-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
143 lines (119 loc) · 3.99 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
'use strict';
var gulp = require('gulp');
var merge = require('event-stream').merge;
var series = require('stream-series');
var stylish = require('jshint-stylish');
var plugins = require('gulp-load-plugins')();
var options = require('minimist')(process.argv.slice(2));
var dependencies = [
'bower_components/angular/angular.min.js',
'bower_components/highlightjs/highlight.pack.min.js',
'bower_components/highlightjs/styles/solarized_dark.css'
];
function isValidType(bump) {
return bump === 'patch' || bump === 'minor' || bump === 'major';
}
gulp.task('build', ['uglify', 'cleanCss', 'dependencies'], function () {
gulp.src('app/images/logo.svg')
.pipe(gulp.dest('build/images'));
var orderedStream = series([
gulp.src('build/dependencies/angular.min.js'),
gulp.src('build/dependencies/!(angular.min.js)'),
gulp.src('build/*.{js,css}')
]);
gulp.src('./app/index.html')
.pipe(plugins.inject(orderedStream, {ignorePath: 'build', addRootSlash: false}))
.pipe(plugins.template(require('./package.json')))
.pipe(gulp.dest('build'));
});
gulp.task('bump', function () {
if(isValidType(options.bump)) {
delete require.cache[require.resolve('./package.json')];
return gulp.src(['bower.json', 'package.json'])
.pipe(plugins.bump({type: options.bump}))
.pipe(gulp.dest('.'));
}
});
gulp.task('cleanCss', ['less'], function () {
return gulp.src('app/app.css')
.pipe(plugins.cleanCss())
.pipe(plugins.concat('app.min.css'))
.pipe(gulp.dest('build'));
});
gulp.task('connect', function () {
return plugins.connect.server({
port: 3000,
host: '0.0.0.0',
root: ['bower_components', 'src', 'app'],
livereload: true
});
});
gulp.task('deploy', ['build'], function () {
gulp.src('build/**/*')
.pipe(plugins.ghPages());
});
gulp.task('distribute', ['wrap'], function () {
return gulp.src('dist/sortable.js')
.pipe(plugins.uglify())
.pipe(plugins.concat('sortable.min.js'))
.pipe(gulp.dest('dist'));
});
gulp.task('html', function () {
return gulp.src('app/**/*.html')
.pipe(plugins.changed('html'))
.pipe(plugins.connect.reload());
});
gulp.task('inject', ['less'], function () {
var options = {
ignorePath: ['bower_components', 'src', 'app'],
addRootSlash: false
};
var orderedStream = series([
gulp.src(dependencies),
gulp.src('src/sortable.js'),
gulp.src('app/**/*.{js,css}')
]);
gulp.src('./app/index.html')
.pipe(plugins.inject(orderedStream, options))
.pipe(gulp.dest('app'));
});
gulp.task('jshint', function () {
return gulp.src(['app/**/*.js', 'src/sortable.js'])
.pipe(plugins.changed('scripts'))
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter(stylish))
.pipe(plugins.connect.reload());
});
gulp.task('less', function () {
return gulp.src('app/app.less')
.pipe(plugins.less())
.pipe(plugins.autoprefixer('last 2 version'))
.pipe(gulp.dest('app'))
.pipe(plugins.connect.reload());
});
gulp.task('uglify', function () {
var templateStream = gulp.src('app/**/!(index).html')
.pipe(plugins.ngHtml2js({moduleName: 'blvd'}));
var javaScriptStream = gulp.src('app/**/*.js')
.pipe(plugins.ngAnnotate());
return merge(javaScriptStream, templateStream)
.pipe(plugins.concat('app.min.js'))
.pipe(plugins.uglify())
.pipe(plugins.replace(/(?!^)('|")use strict\1;|('|")ngInject\2;/g, ''))
.pipe(gulp.dest('build'));
});
gulp.task('dependencies', ['distribute'], function () {
return gulp.src(dependencies.concat('dist/sortable.min.js'))
.pipe(gulp.dest('build/dependencies'));
});
gulp.task('wrap', ['bump'], function () {
return gulp.src('src/sortable.js')
.pipe(plugins.wrap({src: 'wrap.txt'}, require('./package.json'), {parse: false}))
.pipe(gulp.dest('./dist'));
});
gulp.task('watch', function () {
gulp.watch(['app/**/*.less'], ['less']);
gulp.watch(['app/**/*.html'], ['html']);
gulp.watch(['app/**/*.js', 'src/sortable.js'], ['jshint']);
});
gulp.task('default', ['connect', 'inject', 'jshint', 'watch']);