forked from regularjs/regular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
243 lines (193 loc) · 5.51 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
var fs = require('fs');
var path = require('path');
var karma = require('karma').server;
var _ = require('./src/util.js');
var gulp = require('gulp');
var git = require('gulp-git');
var spawn = require('child_process').spawn;
var shell = require('gulp-shell');
var runSequence = require('run-sequence')
var istanbul = require('gulp-istanbul');
var jshint = require('gulp-jshint');
var webpack = require('gulp-webpack');
var mocha = require('gulp-mocha');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var bump = require('gulp-bump');
var through = require('through2');
var pkg;
function inc(importance) {
// get all the files to bump version in
return gulp.src(['./package.json', './bower.json'])
// bump the version number in those files
.pipe(bump({type: importance}))
// save it back to filesystem
.pipe(gulp.dest('./'))
// commit the changed version number
// .pipe(git.commit('bumps package version'))
// **tag it in the repository**
// .pipe(tag_version());
}
gulp.task('patch', function() { return inc('patch'); })
gulp.task('feature', function() { return inc('minor'); })
gulp.task('release', function() { return inc('major'); })
try{
pkg = require('./package.json')
pkg_bower = require('./bower.json')
}catch(e){}
var wpConfig = {
output: {
filename: "regular.js",
library: "Regular",
libraryTarget: "umd"
}
}
var testConfig = {
devtool: 'source-map',
output: {
filename: "dom.bundle.js"
}
}
gulp.task('default', ['watch'], function() {});
//one could also externalize common config into a separate file,
//ex.: var karmaCommonConf = require('./karma-common-conf.js');
var karmaCommonConf = {
browsers: ['Chrome', 'Firefox', 'IE', 'IE9', 'IE8', 'IE7', 'PhantomJS'],
frameworks: ['mocha'],
files: [
'test/runner/vendor/expect.js',
'test/runner/vendor/jquery.js',
'test/runner/vendor/nes.js',
'test/runner/vendor/util.js',
'test/runner/dom.bundle.js'
],
client: {
mocha: {ui: 'bdd'}
},
customLaunchers: {
IE9: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE9'
},
IE8: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE8'
},
IE7: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE8'
}
},
// coverage reporter generates the coverage
reporters: ['progress', 'coverage'],
preprocessors: {
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
'src/**/*.js': ['coverage']
},
// optionally, configure the reporter
coverageReporter: {
type: 'html'
}
};
/**
* Run test once and exit
*/
gulp.task('karma', function (done) {
var config = _.extend({}, karmaCommonConf);
if(process.argv[3] === '--phantomjs'){
config.browsers=["PhantomJS"]
config.coverageReporter = {type : 'text-summary'}
karma.start(_.extend(config, {singleRun: true}), done);
}else{
karma.start(_.extend(config, {singleRun: true}), done);
}
});
// build after jshint
gulp.task('build',["jshint"], function(){
// form minify
gulp.src('./src/index.js')
.pipe(webpack(wpConfig))
.pipe(wrap(signatrue))
.pipe(gulp.dest('./dist'))
.pipe(wrap(mini))
.pipe(uglify())
.pipe(gulp.dest('./dist'))
.on("error", function(err){
throw err
})
})
gulp.task('testbundle', function(cb){
return gulp.src("test/test.exports.js")
.pipe(webpack(testConfig))
.pipe(gulp.dest('test/runner'))
.on("error", function(err){
throw err
})
})
// gulp v -0.0.1
gulp.task('v', function(fn){
var version = process.argv[3].replace('-',"");
pkg.version = version
pkg_bower.version = version
try{
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2), 'utf8');
fs.writeFileSync('./bower.json', JSON.stringify(pkg_bower, null, 2), 'utf8');
}catch(e){
console.error('update version faild' + e.message)
}
})
gulp.task('watch', ["build", 'testbundle'], function(){
// gulp.watch(['src/**/*.js'], ['build']);
gulp.watch(['test/spec/*.js', 'src/**/*.js'], ['jshint','testbundle'])
})
//
gulp.task('jshint', function(){
// jshint
gulp.src(['src/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'))
})
gulp.task('cover', function(cb){
gulp.src(['src/**/*.js'])
.pipe(istanbul()) // Covering files
.on('end', function () {
gulp.src(['test/spec/test-*.js'])
.pipe(mocha())
.pipe(istanbul.writeReports('./test/coverage')) // Creating the reports after tests runned
.on('end', cb);
});
})
gulp.task('test', ['jshint', 'karma'])
// for travis
gulp.task('travis', function(cb){
runSequence( 'jshint' , 'testbundle', 'karma', cb );
})
gulp.task('casper', function(){
var casperjs = spawn('casperjs', ['test','--concise', 'spec'], {
cwd: path.resolve('test/fixtures')
})
casperjs.stdout.on('data', function (data) {
console.log(""+ data);
});
casperjs.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
casperjs.on('close', function (code) {
console.log('casperjs test compelete!');
});
})
function wrap(fn){
return through.obj(fn);
}
function signatrue(file, enc, cb){
var sign = '/**\n'+ '@author\t'+ pkg.author.name + '\n'+ '@version\t'+ pkg.version +
'\n'+ '@homepage\t'+ pkg.homepage + '\n*/\n';
file.contents = Buffer.concat([new Buffer(sign), file.contents]);
cb(null, file);
}
function mini(file, enc, cb){
file.path = file.path.replace('.js', '.min.js');
cb(null, file)
}