forked from regularjs/regular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
250 lines (207 loc) · 5.87 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
244
245
246
247
248
249
250
var fs = require('fs');
var path = require('path');
var karma = require('karma').server;
var _ = require('./src/util.js');
var gulp = require('gulp');
var spawn = require('child_process').spawn;
var shell = require('gulp-shell');
var component = require('gulp-component');
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 through = require('through2');
var before_mocha = require('./test/before_mocha.js');
var pkg;
try{
pkg = require('./package.json')
pkg_bower = require('./bower.json')
pkg_component = require('./component.json')
}catch(e){}
gulp.task('node', function() {
return gulp.src('src/node.js')
.pipe(webpack({
output: {
filename: 'regular-parser.js',
libraryTarget: "umd"
}
}
))
.pipe(gulp.dest('dist/'));
});
gulp.task('default', ['test'], 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/regular.js',
'test/karma.js',
'test/runner/vendor/expect.js',
'test/runner/vendor/jquery.js',
'test/runner/vendor/nes.js',
'test/runner/vendor/util.js',
'test/spec/test-*.js',
'test/spec/browser-*.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)
'test/regular.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", 'node'], function(){
// form minify
gulp.src('./component.json')
.pipe(component.scripts({
standalone: 'Regular',
name: 'regular'
}))
.pipe(wrap(signatrue))
.pipe(gulp.dest('dist'))
.pipe(wrap(mini))
.pipe(uglify())
.pipe(gulp.dest('dist'))
.on('error', function(err){
console.log(err)
})
// for test
gulp.src('./component.json')
.pipe(component.scripts({
name: 'regular'
}))
.pipe(wrap(signatrue))
.pipe(gulp.dest('test'))
})
// gulp v -0.0.1
gulp.task('v', function(fn){
var version = process.argv[3].replace('-',"");
pkg.version = version
pkg_component.version = version
pkg_bower.version = version
try{
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2), 'utf8');
fs.writeFileSync('./component.json', JSON.stringify(pkg_component, null, 2), 'utf8');
fs.writeFileSync('./bower.json', JSON.stringify(pkg_bower, null, 2), 'utf8');
}catch(e){
console.error('update version faild' + e.message)
}
})
// watch file then build
gulp.task('dev', ['build'], function(){
gulp.watch(['component.json', 'src/**/*.js'], ['build'])
// var puer = spawn('puer', ["--no-reload"], {})
// puer.stdout.on('data', function (data) {
// console.log(""+ data);
// });
// puer.stderr.on('data', function (data) {
// console.log('stderr: ' + data);
// });
// puer.on('close', function (code) {
// console.log('puer test compelete!');
// });
})
gulp.task('dev-test', function(){
gulp.watch(['src/**/*.js', 'test/spec/**/*.js'], ['build','mocha'])
})
//
gulp.task('jshint', function(){
// jshint
gulp.src(['src/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'))
})
gulp.task('cover', function(cb){
before_mocha.dirty();
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','mocha', 'karma'])
// for travis
gulp.task('travis', ['jshint' ,'build','mocha', 'karma']);
gulp.task('mocha', function() {
before_mocha.dirty();
return gulp.src(['test/spec/test-*.js'])
.pipe(mocha({reporter: 'spec' }) )
.on('error', function(){
gutil.log.apply(this, arguments);
console.log('\u0007');
})
.on('end', function(){
before_mocha.clean();
});
});
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)
}