-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
152 lines (134 loc) · 4.13 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
var gulp = require("gulp");
var mainBowerFiles = require("main-bower-files");
var concat = require("gulp-concat");
var uglifyCSS = require("gulp-uglifycss");
var inject = require("gulp-inject");
var templateCache = require("gulp-angular-templatecache");
var uglify = require("gulp-uglify");
var ngAnnotate = require("gulp-ng-annotate");
var angularFilesort = require("gulp-angular-filesort");
var del = require("del");
var git = require("gulp-git");
var runSequence = require("gulp-run-sequence");
var injectVersion = require("gulp-inject-version");
var bump = require("gulp-bump");
var jsonminify = require("gulp-jsonminify");
var argv = require('yargs').argv;
var babel = require('gulp-babel');
gulp.task("clean", function () {
return del.sync([
"dist"
]);
});
gulp.task("build-template-cache", function () {
return gulp.src([
"./app/**/*.html",
"!./app/index.html"])
.pipe(templateCache("app.templates.js", {
module: "calendarApp"
}))
.pipe(gulp.dest("./dist"));
});
gulp.task("build-js", ["build-vendor-js", "build-app-js"]);
gulp.task("build-vendor-js", function () {
return gulp.src(mainBowerFiles({
filter: "**/*.js"
}))
.pipe(uglify())
.pipe(concat("vendor.min.js"))
.pipe(gulp.dest("./dist"));
});
gulp.task("build-app-js", ["build-template-cache"], function () {
return gulp.src([
"./app/**/*.js",
"!./app/bower_components/**"])
.pipe(ngAnnotate())
.pipe(babel({
presets: ['es2015']
}))
.pipe(uglify())
.pipe(angularFilesort())
.pipe(concat("app.min.js"))
.pipe(gulp.dest("./dist"));
});
gulp.task("build-css", ["build-vendor-css", "build-app-css"]);
gulp.task("build-vendor-css", function () {
return gulp.src(mainBowerFiles({
filter: "**/*.css"
}))
.pipe(uglifyCSS())
.pipe(concat("vendor.min.css"))
.pipe(gulp.dest("./dist"));
});
gulp.task("build-app-css", function () {
return gulp.src([
"./app/**/*.css",
"!./app/bower_components/**"])
.pipe(uglifyCSS())
.pipe(concat("app.min.css"))
.pipe(gulp.dest("./dist"));
});
gulp.task("build-json", function () {
return gulp.src([
"./app/**/*.json",
"!./app/bower_components/**"
])
.pipe(jsonminify())
.pipe(gulp.dest("./dist"));
});
gulp.task("inject", ["build-js", "build-css", "build-json"], function () {
return gulp.src("./app/index.html")
.pipe(inject(gulp.src("./dist/vendor.min.**", { read: false }), { name: "vendor", ignorePath: "dist", addRootSlash: false }))
.pipe(inject(gulp.src("./dist/app.**", { read: false }), { ignorePath: "dist", addRootSlash: false }))
.pipe(gulp.dest("./dist"));
});
gulp.task("build", ["clean", "inject"]);
gulp.task("setup", function (done) {
process.chdir("./dist");
return git.init(function (err) {
if (err) throw err;
return git.checkout("gh-pages", { args: "--orphan" }, function (err) {
if (err) throw err;
return git.addRemote("origin", "https://github.com/Tommatheussen/calendar-app.git", function (err) {
if (err) throw err;
return git.fetch("origin", "gh-pages", function (err) {
if (err) throw err;
return git.exec({ args: "branch --track gh-pages origin/gh-pages" }, function (err, stdout) {
if (err) throw err;
done();
});
});
});
});
});
});
gulp.task("commit", function () {
var pjson = require(__dirname + "/package.json");
return gulp.src("./*")
.pipe(git.add())
.pipe(git.commit("New version " + pjson.version));
});
gulp.task("push", function (done) {
return git.push("origin", "gh-pages", function (err) {
if (err) throw err;
process.chdir("..");
done();
});
});
gulp.task("bump", function (done) {
runSequence("bump-v", "inject-v", done);
});
gulp.task("bump-v", function () {
var type = argv.version || 'patch';
return gulp.src("./package.json")
.pipe(bump({ type: type }))
.pipe(gulp.dest("./"));
});
gulp.task("inject-v", function (done) {
return gulp.src("./dist/app.templates.js")
.pipe(injectVersion())
.pipe(gulp.dest("./dist"));
});
gulp.task("publish", ["build"], function (done) {
runSequence("bump", "setup", "commit", "push", done);
});