-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
180 lines (143 loc) · 4.73 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
/**
* this is the main task runner for managing the SampleSDK
*/
/*
* define requirements
* ***********************************************************************************************
*/
let gulp = require('gulp');
let args = require('yargs').argv;
let concat = require('gulp-concat');
let rename = require('gulp-rename');
let replace = require('gulp-replace');
let uglify = require('gulp-uglify');
let size = require('gulp-size');
let clean = require('gulp-clean');
let bump = require('gulp-bump');
let jshint = require('gulp-jshint');
let stylish = require('jshint-stylish');
let colours = require('colors');
let fs = require('fs');
let exec = require('child_process').exec;
let sys = require('sys');
let tasklist = require('gulp-task-listing');
let runSequence = require('run-sequence');
let PROJECT_BASE_PATH = __dirname + '';
/*
* gulp default task
* ***********************************************************************************************
*/
gulp.task('default', tasklist.withFilters(function(task) {
return (["build","clean","test","bump-major","bump-minor","bump-patch"].indexOf(task) < 0);
}));
/*
* gulp main tasks
* ***********************************************************************************************
*/
gulp.task('clean', function (cb) {
return gulp.src('./dist', { read: false })
.pipe(clean());
});
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 helper tasks
* ***********************************************************************************************
*/
// versioning tasks
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) {
let pkg = require('./package.json');
let v = 'v' + pkg.version;
let message = 'Release ' + v;
let commandLine = 'git tag -a ' + v + ' -m \'' + message + '\'';
executeCommand(commandLine, cb);
});
gulp.task('git-tag-push', function(cb) {
let commandLine = 'git push origin master --tags';
executeCommand(commandLine, cb);
});
gulp.task('git-tag-commit', function(cb) {
let pkg = require('./package.json');
let v = 'v' + pkg.version;
let message = 'Release ' + v;
let commandLine = 'git add -A && git commit -a -m\'' + message + '\'';
executeCommand(commandLine, cb);
});
gulp.task('example-upgrade-tag', function(){
let pkg = require('./package.json');
let v = pkg.version;
let file = 'example/*.html';
});
// continous integration tasks
gulp.task('lint', function (cb) {
return gulp.src('./src/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('karma-tests', function(cb){
console.log();
console.log('Run all the tests now');
let karmaConfigFile = PROJECT_BASE_PATH+'/test/karma.conf.js';
let commandLine = 'karma start '+karmaConfigFile;
executeCommand(commandLine, cb);
console.log();
});
/*
* 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) {
sys.puts(stdout);
}
// will execute the needed stuff to bump successfully
function bumpHelper(bumpType, cb) {
runSequence('npm-bump-'+bumpType, 'build', 'example-upgrade-tag', 'git-tag-commit', 'git-tag', cb);
}
gulp.task('test', gulp.series('lint', 'karma-tests'));
gulp.task('build', gulp.series('clean', function (cb) {
let pkg = require('./package.json');
return gulp.src('./src/*.js')
.pipe(concat(pkg.name.replace('-js','') + '.js'))
.pipe(gulp.dest('./dist'))
.pipe(rename(pkg.name.replace('-js','') + '.min.js'))
.pipe(uglify())
.pipe(size({showFiles:true}))
.pipe(gulp.dest('./dist'));
}));