-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
154 lines (126 loc) · 3.91 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
var gulp = require('gulp'),
clean = require('gulp-clean'),
replace = require('gulp-replace'),
gutil = require('gulp-util'),
uglify = require('gulp-uglify'),
ngAnnotate = require('gulp-ng-annotate'),
watch = require('gulp-watch'),
concat = require('gulp-concat'),
jeditor = require("gulp-json-editor"),
ngHtml2Js = require("gulp-ng-html2js"),
fs = require('fs'),
pkg = require('./package.json'),
git = require('git-rev'),
semver = require("semver"),
changelog = require('conventional-changelog');
var base = {
base: './src/app/'
};
// =====================================
// Tasks
// =====================================
gulp.task('clean', function() {
gulp
.src(['./dist/*'], {
read: false
})
.pipe(clean());
});
// uglify task
gulp.task('js', function() {
var combined_src = [
'./src/app.js',
'./src/_vendor/ui.bootstrap/src/pagination/pagination.js',
'./build/partials/datatables/*.js',
'./build/_vendor/**/*.js',
'./src/datatables/**/*.js',
'./src/validation/**/*.js',
'!./src/**/*.spec.js'
]
gulp.src(['./build_head.js'])
.pipe(replace(/\{version\}/g, pkg.version))
.pipe(gulp.dest('./build/'));
build('oDirectives', [combined_src]);
function build(outputFileName, sources) {
var combined_build = Array.prototype.concat.apply([], sources)
combined_build.unshift('./build/build_head.js');
//console.log(combined_build);
//
var the_source = gulp.src(combined_build, base);
the_source
.pipe(ngAnnotate())
.pipe(concat(outputFileName + ".js"))
.pipe(gulp.dest('./dist/'));
the_source
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(concat(outputFileName + ".min.js"))
.pipe(gulp.dest('./dist/'));
}
});
// templatify
gulp.task('templatify', function() {
gulp
.src("./src/_vendor/ui.bootstrap/template/pagination/*.html")
.pipe(ngHtml2Js({
moduleName: "envoc",
prefix: "template/pagination/"
}))
.pipe(gulp.dest("./build/_vendor/templates"));
return gulp
.src("./src/**/*.tmpl.html")
.pipe(ngHtml2Js({
moduleName: "envoc",
prefix: "/oTemplates/"
}))
.pipe(gulp.dest("./build/partials"));
});
gulp.task('watch', function() {
gulp.watch('./src/**/*.*', function() {
gulp.run('build');
});
});
gulp.task('watch-testing', function() {
gulp.watch('./src/**/*.*', function() {
gulp.run('templatify');
});
});
gulp.task('bump', function() {
var from = pkg.lastDocHash;
var newVer = semver.inc(pkg.version, 'minor');
git.long(function (str) {
// bump package.json
gulp.src('./package.json')
// .pipe(bump({version:'minor'}))
.pipe(jeditor({
'lastDocHash': str,
'version': newVer
}))
.pipe(gulp.dest('./'));
// create changelog
var opts = {
repository: 'https://github.com/Envoc/envoc.directives',
version: newVer
};
if(from) opts.from = from;
changelog(opts, function(err, log) {
var stream = fs.createWriteStream("changelog.md");
stream.once('open', function(fd) {
stream.write(log);
stream.end();
});
});
})
});
gulp.task('build-bump', function() {
var newVer = semver.inc(pkg.version, 'patch');
// bump package.json
gulp.src('./package.json')
.pipe(jeditor({
'version': newVer
}))
.pipe(gulp.dest('./'));
});
gulp.task('default', ['build-bump', 'templatify', 'js', 'watch']);
gulp.task('build', ['clean', 'templatify', 'js']);
gulp.task('testing', ['js', 'watch-testing']);