-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
119 lines (103 loc) · 2.67 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
/*jslint node: true */ // allow 'require' global
'use strict';
var gulp = require('gulp'),
concat = require('gulp-concat'),
del = require('del'),
util = require('gulp-util'),
es = require('event-stream'),
ts = require('gulp-typescript'),
bump = require('gulp-bump'),
git = require('gulp-git'),
filter = require('gulp-filter'),
tagVersion = require('gulp-tag-version'),
inquirer = require('inquirer'),
sourcemaps = require('gulp-sourcemaps'),
ngAnnotate = require('gulp-ng-annotate'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
browserSync = require('browser-sync');
var sources = {
app: {
ts: ['./src/**/*.ts'],
},
example: './examples/'
};
var destinations = {
js: './dist/'
};
gulp.task('js:app', function() {
var tsStream = gulp.src(sources.app.ts)
.pipe(sourcemaps.init())
.pipe(ts({
declarationFiles: false,
noExternalResolve: false,
noLib: false,
sortOutput: true
}));
es.merge(
tsStream.dts
.pipe(gulp.dest(destinations.js)),
tsStream.js
.pipe(concat('main.js'))
.pipe(ngAnnotate())
.pipe(sourcemaps.write())
.pipe(gulp.dest(destinations.js))
.pipe(uglify({
angular: true
}))
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest(destinations.js))
);
});
// deletes the dist folder for a clean build
gulp.task('clean', function() {
del(['./dist'], function(err, deletedFiles) {
if(deletedFiles.length) {
util.log('Deleted', util.colors.red(deletedFiles.join(' ,')) );
} else {
util.log(util.colors.yellow('/dist directory empty - nothing to delete'));
}
});
});
gulp.task('serve', function () {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: [sources.example]
}
});
gulp.watch([
sources.example + '**/*'
]).on('change', browserSync.reload);
});
gulp.task('build', [
'js:app'
]);
gulp.task('bump', function() {
var questions = [
{
type: 'input',
name: 'bump',
message: 'Are you sure you want to bump the patch version? [Y/N]'
}
];
inquirer.prompt( questions, function( answers ) {
if(answers.bump === 'Y') {
return gulp.src(['./package.json', './bower.json'])
.pipe(bump({type: 'patch'}))
.pipe(gulp.dest('./'))
.pipe(git.commit('bump patch version'))
.pipe(filter('package.json')) // read package.json for the new version
.pipe(tagVersion()); // create tag
}
});
});
// watch scripts, styles, and templates
gulp.task('watch', function() {
gulp.watch(sources.app.ts, ['js:app']);
});
// default
gulp.task('default', ['build', 'watch']);