-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
198 lines (162 loc) · 5.34 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* this is the main task runner for managing the GeoSpockWeb
*/
/*
* define requirements
* ***********************************************************************************************
*/
var gulp = require('gulp-help')(require('gulp'), {hideEmpty:true, hideDepsMessage:true});
var argv = require('yargs').argv;
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var size = require('gulp-size');
var del = require('del');
var bump = require('gulp-bump');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var exec = require('child_process').exec;
var sys = require('sys');
var runSequence = require('run-sequence');
var jeditor = require("gulp-json-editor");
var browserify = require('gulp-browserify');
var wait = require('gulp-wait');
var jasmine = require('gulp-jasmine');
var reporters = require('jasmine-reporters');
var pkg = require('./package.json');
/*
* gulp main tasks
* ***********************************************************************************************
*/
gulp.task('build', 'Run all the tests and if they pass create the final js files', ['clean'], function(cb) {
runSequence('package', 'update-version', cb);
});
gulp.task('browserify', function() {
gulp.src('src/standalone.js')
.pipe(browserify({
insertGlobals : true,
debug : argv.debug // TODO: document it
}))
.pipe(rename(pkg.name + '.js'))
.pipe(gulp.dest('./build/js'))
;
});
gulp.task('package', ['lint', 'test'], function (cb) {
return gulp.src('./build/js/' + pkg.name + '.js')
.pipe(gulp.dest('./dist'))
.pipe(rename(pkg.name + '.min.js'))
.pipe(uglify())
.pipe(size({showFiles:true}))
.pipe(gulp.dest('./dist'));
});
gulp.task('clean', 'Delete dist and build folders',function (cb) {
return del([
'./dist',
'./build'
], cb);
});
gulp.task('lint', 'JS quality code check', function (cb) {
return gulp.src('./src/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('node-tests', 'run the tests on a node app',function () {
return gulp.src(['test/node/*Spec.js', 'src/js/main.js'])
// .pipe(jasmine({
// reporter: new reporters.TapReporter()
// }));
.pipe(jasmine({
}));
});
gulp.task('test', 'Run all the tests', ['karma-tests']);
gulp.task('karma-tests', 'Run all the Karma tests', ['browserify'], function(cb){
// this is a workaround. For some reason the file generated by
// browserify is not being detected by karma.
setTimeout(function () {
var karma = require('karma').server;
karma.start({
configFile: __dirname + '/test/karma.conf.js',
singleRun: true
}, cb );
}, 500);
});
// versioning tasks
gulp.task('bump-patch', function(cb) {
bumpHelper('patch', cb);
});
gulp.task('bump-minor', function(cb) {
bumpHelper('minor', cb);
});
gulp.task('bump-major', function(cb) {
bumpHelper('major', cb);
});
gulp.task('npm-bump-patch', function () {
return gulp.src(['./package.json'])
.pipe(bump({type:'patch'}))
.pipe(gulp.dest('./'));
});
gulp.task('npm-bump-minor', function () {
return gulp.src(['./package.json'])
.pipe(bump({type:'minor'}))
.pipe(gulp.dest('./'));
});
gulp.task('npm-bump-major', function () {
return gulp.src(['./package.json'])
.pipe(bump({type:'major'}))
.pipe(gulp.dest('./'));
});
gulp.task('git-describe', function (cb) {
console.log('Current release is now:');
executeCommand('git describe --abbrev=0 --tags', cb);
});
gulp.task('git-tag', function(cb) {
runSequence('git-tag-create', 'git-tag-push', 'git-describe', cb);
});
gulp.task('git-tag-create', function(cb) {
var v = 'v' + pkg.version;
var message = 'Release ' + v;
var commandLine = 'git tag -a ' + v + ' -m \'' + message + '\'';
executeCommand(commandLine, cb);
});
gulp.task('git-tag-push', function(cb) {
var commandLine = 'git push upstream master --tags';
executeCommand(commandLine, cb);
});
gulp.task('git-tag-commit', function(cb) {
var message = 'Release v' + pkg.version;
var commandLine = 'git add -A && git commit -a -m\'' + message + '\'';
executeCommand(commandLine, cb);
});
gulp.task('update-version-bower', function(){
return gulp.src("bower.json")
.pipe(jeditor({
'version': pkg.version
}))
.pipe(gulp.dest("."));
});
gulp.task('update-version', ['update-version-js', 'update-version-bower']);
gulp.task('update-version-js', function() {
return gulp.src('./dist/*')
.pipe(replace(/.GeoSpockWeb.VERSION="REPLACE_ME_PLEASE"/g, '.GeoSpockWeb.VERSION="' + pkg.version + '"'))
.pipe(gulp.dest('./dist/'));
});
/*
* helper functions
* ***********************************************************************************************
*/
// execute the command line command in the shell
function executeCommand(commandLine, cb) {
exec(commandLine, function(error, stdout, stderr) {
puts(error, stdout, stderr);
cb(null); // will allow gulp to exit the task successfully
});
}
// well display console expressions
function puts(error, stdout, stderr) {
console.log(stdout);
}
// will execute the needed stuff to bump successfully
function bumpHelper(bumpType, cb) {
runSequence('npm-bump-'+bumpType, 'build', 'git-tag-commit', 'git-tag', cb);
}