This repository has been archived by the owner on Apr 3, 2022. It is now read-only.
forked from megawebmaster/ui-select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
196 lines (163 loc) · 5.54 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
var fs = require('fs');
var del = require('del');
var gulp = require('gulp');
var streamqueue = require('streamqueue');
var karma = require('karma').server;
var $ = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var conventionalRecommendedBump = require('conventional-recommended-bump');
var titleCase = require('title-case');
var config = {
pkg : JSON.parse(fs.readFileSync('./package.json')),
banner:
'/*!\n' +
' * <%= pkg.name %>\n' +
' * <%= pkg.homepage %>\n' +
' * Version: <%= pkg.version %> - <%= timestamp %>\n' +
' * License: <%= pkg.license %>\n' +
' */\n\n\n'
};
gulp.task('default', ['build','test']);
gulp.task('build', ['scripts', 'styles']);
gulp.task('test', ['build', 'karma']);
gulp.task('watch', ['build','karma-watch'], function() {
gulp.watch(['src/**/*.{js,html}'], ['build']);
});
gulp.task('clean', function(cb) {
del(['dist', 'temp'], cb);
});
gulp.task('scripts', ['clean'], function() {
var buildTemplates = function () {
return gulp.src('src/**/*.html')
.pipe($.minifyHtml({
empty: true,
spare: true,
quotes: true
}))
.pipe($.angularTemplatecache({module: 'ui.select'}));
};
var buildLib = function(){
return gulp.src(['src/common.js','src/*.js'])
.pipe($.plumber({
errorHandler: handleError
}))
.pipe($.concat('select_without_templates.js'))
.pipe($.header('(function () { \n"use strict";\n'))
.pipe($.footer('\n}());'))
.pipe(gulp.dest('temp'))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.jshint.reporter('fail'));
};
return streamqueue({objectMode: true }, buildLib(), buildTemplates())
.pipe($.plumber({
errorHandler: handleError
}))
.pipe($.concat('select.js'))
.pipe($.header(config.banner, {
timestamp: (new Date()).toISOString(), pkg: config.pkg
}))
.pipe(gulp.dest('dist'))
.pipe($.sourcemaps.init())
.pipe($.uglify({preserveComments: 'some'}))
.pipe($.concat('select.min.js'))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('dist'));
});
gulp.task('styles', ['clean'], function() {
return gulp.src(['src/common.css'], {base: 'src'})
.pipe($.sourcemaps.init())
.pipe($.header(config.banner, {
timestamp: (new Date()).toISOString(), pkg: config.pkg
}))
.pipe($.concat('select.css'))
.pipe(gulp.dest('dist'))
.pipe($.minifyCss())
.pipe($.concat('select.min.css'))
.pipe($.sourcemaps.write('../dist', {debug: true}))
.pipe(gulp.dest('dist'));
});
gulp.task('karma', ['build'], function() {
karma.start({configFile : __dirname +'/karma.conf.js', singleRun: true});
});
gulp.task('karma-watch', ['build'], function() {
karma.start({configFile : __dirname +'/karma.conf.js', singleRun: false});
});
gulp.task('pull', function(done) {
$.git.pull();
done();
});
gulp.task('add', function() {
return gulp.src(['./*', '!./node_modules', '!./bower_components'])
.pipe($.git.add());
});
gulp.task('recommendedBump', function(done) {
/**
* Bumping version number and tagging the repository with it.
* Please read http://semver.org/
*
* To bump the version numbers accordingly after you did a patch,
* introduced a feature or made a backwards-incompatible release.
*/
conventionalRecommendedBump({preset: 'angular'}, function(err, importance) {
// Get all the files to bump version in
gulp.src(['./package.json'])
.pipe($.bump({type: importance}))
.pipe(gulp.dest('./'));
done();
});
});
gulp.task('changelog', function() {
return gulp.src('CHANGELOG.md', {buffer: false})
.pipe($.conventionalChangelog({preset: 'angular'}))
.pipe(gulp.dest('./'));
});
gulp.task('push', function(done) {
$.git.push('origin', 'master', {args: '--follow-tags'});
done();
});
gulp.task('commit', function() {
return gulp.src('./')
.pipe($.git.commit('chore(release): bump package version and update changelog', {emitData: true}))
.on('data', function(data) {
console.log(data);
});
});
gulp.task('tag', function() {
return gulp.src('package.json')
.pipe($.tagVersion());
});
gulp.task('bump', function(done) {
runSequence('recommendedBump', 'changelog', 'add', 'commit', 'tag', 'push', done);
});
gulp.task('docs', function (cb) {
runSequence('docs:clean', 'docs:examples', 'docs:assets', 'docs:index', cb);
});
gulp.task('docs:clean', function (cb) {
del(['docs-built'], cb)
});
gulp.task('docs:assets', function () {
gulp.src('./dist/*').pipe(gulp.dest('./docs-built/dist'));
return gulp.src('docs/assets/*').pipe(gulp.dest('./docs-built/assets'));
});
gulp.task('docs:examples', function () {
return gulp.src(['docs/examples/*.html'])
.pipe($.header(fs.readFileSync('docs/partials/_header.html')))
.pipe($.footer(fs.readFileSync('docs/partials/_footer.html')))
.pipe($.filenames('exampleFiles'))
.pipe(gulp.dest('./docs-built/'));
});
gulp.task('docs:index', function () {
var exampleFiles = $.filenames.get('exampleFiles');
exampleFiles = exampleFiles.map(function (filename) {
var cleaned = titleCase(filename.replace('demo-', '').replace('.html', ''));
return '<h4><a href="./' + filename + '">' + cleaned + '</a> <plnkr-opener example-path="' + filename + '"></plnkr-opener></h4>';
});
return gulp.src('docs/index.html')
.pipe($.replace('<!-- INSERT EXAMPLES HERE -->', exampleFiles.join("\n")))
.pipe(gulp.dest('./docs-built/'));
});
var handleError = function (err) {
console.log(err.toString());
this.emit('end');
};