forked from ghiscoding/angular-validation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
102 lines (88 loc) · 2.43 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
var argv = require('yargs').argv,
gulp = require('gulp'),
gulpif = require('gulp-if'),
bump = require('gulp-bump'),
del = require('del'),
concat = require('gulp-concat'),
order = require('gulp-order'),
header = require('gulp-header'),
replace = require('gulp-replace-task'),
semver = require('semver'),
stripdebug = require('gulp-strip-debug'),
uglify = require('gulp-uglify');
var d = new Date()
src = 'src/',
dest = 'dist';
var jsHeaderComment = [
'/**',
' * <%= pkg.description %>',
' * <%= pkg.homepage %>',
' * @author: <%= pkg.author %>',
' * @version: <%= version %>',
' * @license: <%= pkg.license %>',
' * @build: ' + d,
' */',
''].join('\n');
var readmeHeader = [
'#Angular Validation (Directive / Service)',
'`Version: <%= version %>`',
''].join('\n');
var getPackageJson = function () {
var fs = require('fs');
return JSON.parse(fs.readFileSync('./package.json', 'utf8'));
};
//-- Register tasks
//------------------
// default gulp
gulp.task('default', ['compress'], function() {
});
// bump the version of Bower and NPM packages
gulp.task('bump', function () {
return gulp.src(['./package.json', './bower.json'])
.pipe(bump())
.pipe(gulp.dest('./'));
});
// clean the dist folder
gulp.task('clean', function() {
del([
dest + '*'
])
});
// compress our src folder
gulp.task('compress', ['clean'], function() {
var pkg = getPackageJson();
var oldVersion = pkg.version;
var newVersion = pkg.version;
// if user wants to bump revision at same time
if(argv.bump == 1) {
// bump version for js file header
newVersion = semver.inc(oldVersion, 'patch');
// bump version for both: package & bower
gulp.src(['./package.json', './bower.json'])
.pipe(bump())
.pipe(gulp.dest('./'));
// bump the README version as well
gulp.src('README.md')
.pipe(replace({
patterns: [
{
match: /Version: [.0-9]+/g,
replacement: 'Version: ' + newVersion
}
]
}))
.pipe(gulp.dest('./'));
}
// compress (src/*.js) into 1 single minified file
gulp.src(src + '*.js')
.pipe(order([
'validation-directive.js',
'validation-common.js',
'validation-rules.js',
'validation-service.js'
]))
.pipe(uglify())
.pipe(concat('angular-validation.min.js'))
.pipe(header(jsHeaderComment, { pkg : pkg, version: newVersion } ))
.pipe(gulp.dest('dist'));
});