-
Notifications
You must be signed in to change notification settings - Fork 34
/
gulpfile.js
76 lines (65 loc) · 2.66 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
// Modified from https://github.com/gulpjs/gulp/blob/master/docs/recipes/automate-release-workflow.md
var fs = require("fs");
var parseArgs = require("minimist");
var gulp = require("gulp");
var runSequence = require("run-sequence");
var gutil = require("gulp-util");
var git = require("gulp-git");
var bump = require("gulp-bump");
var conventionalChangelog = require("gulp-conventional-changelog");
var conventionalGithubReleaser = require("conventional-github-releaser");
var conventionalRecommendedBump = require("conventional-recommended-bump");
// Load CONVENTIONAL_GITHUB_RELEASER_TOKEN from .env
require("dotenv").config();
var options = parseArgs(process.argv.slice(2), {string: ["github_token"], default: {github_token: process.env.CONVENTIONAL_GITHUB_RELEASER_TOKEN}});
// Changelogs use AngularJS convention (https://github.com/ajoslin/conventional-changelog/blob/master/conventions/angular.md)
gulp.task("changelog", function() {
return gulp.src("CHANGELOG.md", {buffer: false})
.pipe(conventionalChangelog({preset: "angular"}))
.pipe(gulp.dest("./"));
});
gulp.task("github-release", function(cb) {
conventionalGithubReleaser({type: "oauth", token: options.github_token}, {preset: "angular"}, cb);
});
// Abides by semantic versioning rules (http://semver.org/)
gulp.task("bump-version", function() {
// Valid bump types are major|minor|patch|prerelease
conventionalRecommendedBump({preset: "angular"}, function(err, releaseType) {
return gulp.src(["./bower.json", "./package.json"])
.pipe(bump({type: releaseType}).on("error", gutil.log))
.pipe(gulp.dest("./"));
});
});
gulp.task("commit-changes", function() {
return gulp.src(".")
.pipe(git.add())
.pipe(git.commit("chore: bump version number [ci skip]"));
});
gulp.task("push-changes", function(cb) {
git.push("origin", "master", cb);
});
gulp.task("create-new-tag", function(cb) {
// Parses the JSON file instead of using require as require caches multiple calls so the version number won't be updated
var getPackageJsonVersion = function() {
return JSON.parse(fs.readFileSync("./package.json", "utf8")).version;
};
var version = getPackageJsonVersion();
git.tag(version, "Created tag for version: " + version, function(err) {
if (err) {
return cb(err);
}
git.push("origin", "master", {args: "--tags"}, cb);
});
});
gulp.task("release", function(cb) {
runSequence("bump-version", "changelog", "commit-changes", "push-changes", "create-new-tag", "github-release", function(err) {
if (err) {
console.log(err.message);
} else {
console.log("RELEASE FINISHED SUCCESSFULLY");
}
cb(err);
});
});
// Default task
gulp.task("default", function() {});