-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
112 lines (101 loc) · 3.92 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
var gulp = require("gulp");
var git = require("simple-git");
var $ = require("gulp-load-plugins")();
var ngHtml2Js = require("gulp-ng-html2js"); // don't know why it's not captured by gulp-load-plugins!
var runSequence = require('gulp-run-sequence');
var pkg = require("./bower.json");
var streamqueue = require('streamqueue');
var srcPath = "src";
var distPath = "dist";
var outputName = "ame-lightbox";
var banner = '/*\n' +
' * <%= pkg.name %> <%= pkg.version %>\n' +
' * <%= pkg.description %>\n' +
' * <%= pkg.repository %>\n' +
'*/\n\n';
gulp.task("build", ["build-js", "build-css"]);
gulp.task("watch", watch);
gulp.task("build-js", buildJs);
gulp.task("build-css", buildCss);
gulp.task("bump-version-patch", bumpVersion("patch"));
gulp.task("bump-version-minor", bumpVersion("minor"));
gulp.task("bump-version-major", bumpVersion("major"));
function watch(){
gulp.watch([srcPath + "/**/*.js", srcPath + "/**/*.html"], buildJs);
gulp.watch(srcPath + "/**/*.scss", buildCss);
}
function bumpVersion(type){
return function () {
git().status(function (error, statusSummary) {
var dirtyFiles = statusSummary.files.filter(notInDist);
if (dirtyFiles.length > 0) {
console.error("Working directory is not clean! Please first commit your changes and try again.");
statusSummary.modified.length && console.warn("Modified", statusSummary.modified);
statusSummary.created.length && console.warn("Created", statusSummary.created);
statusSummary.not_added.length && console.warn("Not added", statusSummary.not_added);
statusSummary.renamed.length && console.warn("Renamed", statusSummary.renamed);
statusSummary.deleted.length && console.warn("Deleted", statusSummary.deleted);
return
}
gulp.src(['bower.json', 'package.json'])
.pipe($.bump({type: type}))
.pipe(gulp.dest('./'))
.on('end', function () {
runSequence("build", function () {
git()
.add('./*')
.commit('chore(all): bump version', function (error) {
if (error) {
console.log("Changes not committed. Error: ", error)
}
else {
gulp.src("package.json")
.pipe($.tagVersion({prefix: ""}))
}
});
})
})
.on('error', function (error) {
console.error("Error in bumping version: ", error.message)
});
function notInDist(file) {
return file.path.indexOf(distPath) !== 0;
}
})
};
}
function buildJs(){
return streamqueue(
{
objectMode: true
},
gulp.src(srcPath + "/**/*.js")
.pipe($.angularFilesort())
.pipe($.ngAnnotate()),
getHtmlAndSvgJsStream()
)
.pipe($.plumber())
.pipe($.concat(outputName + ".js"))
.pipe($.stripBanner())
.pipe($.banner(banner,{
pkg: pkg
}))
.pipe(gulp.dest(distPath))
.pipe($.uglify())
.pipe($.rename({suffix: ".min"}))
.pipe(gulp.dest(distPath));
}
function buildCss(){
gulp.src(srcPath + "/**/*.scss")
.pipe($.plumber())
.pipe($.sass())
.pipe($.concatCss(outputName + ".css"))
.pipe(gulp.dest(distPath))
.pipe($.minifyCss())
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(distPath));
}
function getHtmlAndSvgJsStream(){
return gulp.src([srcPath + "/**/*.html", srcPath + "/**/*.svg"])
.pipe(ngHtml2Js({base: srcPath, moduleName: 'ame.lightbox'}));
}