-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathgulpfile.js
executable file
·237 lines (183 loc) · 4.93 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
var through = require('through2');
var deploy = require("gulp-gh-pages");
var shell = require("gulp-shell");
var gulp = require('gulp');
var webpack = require('gulp-webpack');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var uglify = require('gulp-uglify');
var _ = require("./src/util.js");
var karma = require("karma").server;
var translate = require("./scripts/gulp-trans.js")
var pkg = require("./package.json");
// release
require("./scripts/release.js")(gulp);
var wpConfig = {
output: {
filename: "stateman.js",
library: "StateMan",
libraryTarget: "umd"
}
}
var testConfig = {
output: {
filename: "dom.bundle.js"
}
}
var karmaCommonConf = {
browsers: ['Chrome', 'Firefox', 'IE', 'IE9', 'IE8', 'IE7', 'PhantomJS'],
frameworks: ['mocha', 'commonjs'],
files: [
'test/runner/vendor/expect.js',
'src/**/*.js',
'test/spec/test-*.js',
'test/spec/dom-*.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=EmulateIE7'
}
},
preprocessors: {
'src/**/*.js': ['commonjs', 'coverage'],
'test/spec/test-*.js': ['commonjs'],
'test/spec/dom-*.js': ['commonjs'],
'test/runner/vendor/expect.js': ['commonjs']
},
// 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'
}
};
gulp.task('jshint', function(){
// jshint
gulp.src(['src/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'))
})
gulp.task('build', ['jshint'], function() {
gulp.src("src/index.js")
.pipe(webpack(wpConfig))
.pipe(wrap(signatrue))
.pipe(gulp.dest('./'))
.pipe(wrap(mini))
.pipe(uglify())
.pipe(gulp.dest('./'))
.on("error", function(err){
throw err
})
});
gulp.task('testbundle', function(){
gulp.src("test/spec/dom.exports.js")
.pipe(webpack(testConfig))
.pipe(gulp.dest('test/runner'))
.on("error", function(err){
throw err
})
})
gulp.task('mocha', function(){
return gulp.src(['test/spec/test-*.js'])
.pipe(mocha({reporter: 'spec' }) )
.on('error', function(err){
console.log(err)
console.log('\u0007');
})
.on('end', function(){
// before_mocha.clean();
});
})
gulp.task('watch', ["build", 'testbundle'], function(){
gulp.watch(['src/**/*.js'], ['build']);
gulp.watch(['docs/src/*.md'], ['doc']);
gulp.watch(['test/spec/*.js', 'src/**/*.js'], ['testbundle'])
})
gulp.task('default', [ 'watch']);
gulp.task('mocha', function() {
return gulp.src(['test/spec/test-*.js', 'test/spec/node-*.js' ])
.pipe(mocha({reporter: 'spec' }) )
.on('error', function(){
// gutil.log.apply(this, arguments);
console.log('\u0007');
})
.on('end', function(){
global.expect = null;
});
});
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 if(process.argv[3] === '--browser'){
config.browsers = null;
karma.start(_.extend(config, {singleRun: true}), done);
}else{
karma.start(_.extend(config, {singleRun: true}), done);
}
});
gulp.task("test", ["mocha", "karma"])
gulp.task('doc', function(){
return gulp.src(["docs/src/API*.md"])
.pipe(translate({}))
.pipe(gulp.dest("docs/pages/document"))
})
//
gulp.task("release", ["tag"])
gulp.task('travis', ['jshint' ,'build','mocha', 'karma']);
gulp.task('server', ['build'], shell.task([
"./node_modules/puer/bin/puer"
]))
gulp.task('example', function(){
gulp.src("example/*.html")
.pipe(
gulp.dest('docs/pages/example')
);
gulp.src("./stateman.js")
.pipe(
gulp.dest('docs/pages')
);
})
gulp.task('gh-pages', ['example', 'doc'], function () {
gulp.src("docs/pages/**/*.*")
.pipe(deploy({
remoteUrl: "[email protected]:leeluolee/stateman",
branch: "gh-pages"
}))
.on("error", function(err){
console.log(err)
})
});
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)
}