forked from scotttrinh/angular-localForage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
120 lines (103 loc) · 3.21 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
var gulp = require('gulp');
gulp.task('karma', function(callback) {
var conf = require('./karma.conf').conf;
conf.browsers = ['Firefox', 'Chrome'];
return require('karma-as-promised').server.start(conf);
});
var build = function(newVer) {
var rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
header = require('gulp-header'),
pkg = require('./package.json'),
banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' * @author <%= pkg.author %>',
' */',
''].join('\n');
return gulp.src('src/angular-localForage.js')
.pipe(header(banner, { pkg: pkg, version: newVer || pkg.version }))
.pipe(gulp.dest('dist'))
.pipe(uglify())
.pipe(header(banner, { pkg: pkg, version: newVer || pkg.version }))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist'));
}
gulp.task('build', ['karma'], function() {
return build();
});
var promptBump = function(callback) {
var prompt = require('gulp-prompt'),
semver = require('semver'),
pkg = require('./package.json');
return gulp.src('')
.pipe(prompt.prompt({
type: 'list',
name: 'bump',
message: 'What type of version bump would you like to do ? (current version is ' + pkg.version + ')',
choices: [
'patch (' + pkg.version + ' --> ' + semver.inc(pkg.version, 'patch') + ')',
'minor (' + pkg.version + ' --> ' + semver.inc(pkg.version, 'minor') + ')',
'major (' + pkg.version + ' --> ' + semver.inc(pkg.version, 'major') + ')',
'none (exit)'
]
}, function(res) {
var newVer;
if(res.bump.match(/^patch/)) {
newVer = semver.inc(pkg.version, 'patch');
} else if(res.bump.match(/^minor/)) {
newVer = semver.inc(pkg.version, 'minor');
} else if(res.bump.match(/^major/)) {
newVer = semver.inc(pkg.version, 'major');
}
if(newVer && typeof callback === 'function') {
return callback(newVer);
} else {
return;
}
}));
}
var makeChangelog = function(newVer) {
var streamqueue = require('streamqueue'),
stream = streamqueue({ objectMode: true }),
exec = require('gulp-exec'),
concat = require('gulp-concat'),
rimraf = require('gulp-rimraf');
stream.queue(gulp.src('').pipe(exec('node ./changelog.js ' + newVer, { pipeStdout: true })));
stream.queue(gulp.src('CHANGELOG.md').pipe(rimraf()));
return stream.done()
.pipe(concat('CHANGELOG.md'))
.pipe(gulp.dest('./'));
}
// Make changelog
gulp.task('changelog', function(event) {
return promptBump(makeChangelog);
})
gulp.task('release', ['karma'], function() {
var jeditor = require("gulp-json-editor");
return promptBump(function(newVer) {
var streamqueue = require('streamqueue');
var stream = streamqueue({ objectMode: true });
// make the changelog
stream.queue(makeChangelog(newVer));
// update the main project version number
stream.queue(
gulp.src('package.json')
.pipe(jeditor({
'version': newVer
}))
.pipe(gulp.dest("./"))
);
stream.queue(
gulp.src('bower.json')
.pipe(jeditor({
'version': newVer
}))
.pipe(gulp.dest("./"))
);
stream.queue(build(newVer));
return stream.done();
});
})