This repository has been archived by the owner on Jul 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
gulpfile.js
128 lines (112 loc) · 3.18 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
var argv = require('yargs').argv,
gulp = require('gulp'),
gulpif = require('gulp-if'),
protractor = require("gulp-angular-protractor"),
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(concat('angular-validation.js'))
.pipe(header(jsHeaderComment, { pkg : pkg, version: newVersion } ))
.pipe(gulp.dest('dist'));
// 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'));
});
gulp.task('e2e', function() {
gulp.src(["./protractor/*_spec.js"])
.pipe(protractor({
configFile: "protractor/conf.js",
args: ['--baseUrl', 'http://127.0.0.1'],
'debug': false,
'autoStartStopServer': true
}))
.on('error', function(e) {
console.log(e);
});
});