-
Notifications
You must be signed in to change notification settings - Fork 186
/
gulpfile.js
227 lines (208 loc) · 5.27 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
var pkg = require('./package.json')
var gulp = require('gulp')
var eslint = require('gulp-eslint')
var browserify = require('gulp-browserify')
var header = require('gulp-header')
var pump = require('pump')
var uglify = require('gulp-uglify')
var concat = require('gulp-concat')
var sourcemaps = require('gulp-sourcemaps')
var spawn = require('child_process').spawn
var _ = require('./src/utils')
var Server = require('karma').Server
var name = 'uploader'
var NAME = name.charAt(0).toUpperCase() + name.substr(1)
var fname = name + '.js'
var mname = name + '.min.js'
var paths = {
src: 'src/',
dist: 'dist/'
}
var allFiles = paths.src + '*.js'
var banner = [
'/*!',
' * ' + NAME + ' - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @author <%= pkg.author %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''
].join('\n')
gulp.task('eslint', function () {
return gulp.src(allFiles)
.pipe(eslint({
useEslintrc: true
}))
.pipe(eslint.format())
.pipe(eslint.failOnError())
})
gulp.task('scripts', ['eslint'], function() {
return gulp.src(paths.src + fname)
.pipe(browserify({
debug: false,
standalone: 'Uploader',
transform: ['browserify-versionify']
}))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(gulp.dest(paths.dist))
});
gulp.task('build', ['scripts'], function (cb) {
pump([
gulp.src(paths.dist + fname),
sourcemaps.init(),
uglify({
output: {
comments: /^!/
}
}),
concat(mname),
sourcemaps.write('./', {
includeContent: false
}),
gulp.dest(paths.dist)
], cb)
})
var karmaBaseConfig = {
basePath: '',
frameworks: ['jasmine', 'commonjs'],
files: [
'node_modules/sinon/pkg/sinon-1.7.3.js',
'test/unit/lib/fakeFile.js',
'test/unit/lib/FakeXMLHttpRequestUpload.js',
'src/**/*.js',
'test/unit/specs/**/*.js'
],
// list of files to exclude
exclude: [
],
preprocessors: {
'src/**/*.js': ['commonjs'],
'test/unit/specs/**/*.js': ['commonjs']
},
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
autoWatch: false,
captureTimeout: 60000,
singleRun: true
}
gulp.task('unit', function (done) {
var karmaUnitConfig = _.extend({}, karmaBaseConfig, {
browsers: ['Chrome', 'Firefox'],
reporters: ['progress']
})
new Server(karmaUnitConfig, done).start()
})
gulp.task('cover', function (done) {
var karmaCoverageConfig = _.extend({}, karmaBaseConfig, {
browsers: ['PhantomJS'],
reporters: ['progress', 'coverage'],
preprocessors: {
'src/**/*.js': ['commonjs', 'coverage'],
'test/unit/specs/**/*.js': ['commonjs']
},
coverageReporter: {
reporters: [
{
type: 'lcov',
subdir: '.'
},
{
type: 'text-summary',
subdir: '.'
}
]
}
})
new Server(karmaCoverageConfig, done).start()
})
gulp.task('sauce', function (done) {
var customLaunchers = {
sl_chrome: {
base: 'SauceLabs',
browserName: 'chrome',
platform: 'Windows 7'
},
sl_firefox: {
base: 'SauceLabs',
browserName: 'firefox',
platform: 'Windows 7'
},
sl_mac_safari: {
base: 'SauceLabs',
browserName: 'safari',
platform: 'OS X 10.10'
},
sl_ie_10: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 7',
version: '10'
},
sl_ie_11: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 8.1',
version: '11'
},
sl_edge: {
base: 'SauceLabs',
browserName: 'MicrosoftEdge',
platform: 'Windows 10'
},
sl_ios_safari_10_3: {
base: 'SauceLabs',
browserName: 'iphone',
version: '10.3'
},
sl_android_6_0: {
base: 'SauceLabs',
browserName: 'android',
version: '6.0'
}
}
new Server(_.extend({}, karmaBaseConfig, {
sauceLabs: {
testName: 'uploader unit tests',
recordScreenshots: false,
build: process.env.TRAVIS_BUILD_NUMBER || process.env.SAUCE_BUILD_ID || Date.now(),
username: 'uploader',
accessKey: 'e2dd6126-05c4-422e-9cfb-4c4e9735e2ab'
},
// mobile。。。 slow
captureTimeout: 300000,
browserNoActivityTimeout: 300000,
browsers: Object.keys(customLaunchers),
customLaunchers: customLaunchers,
reporters: ['progress', 'saucelabs']
}), done).start()
})
gulp.task('test', ['unit', 'cover'])
gulp.task('watch', function () {
gulp.watch(allFiles, ['scripts'])
})
gulp.task('default', ['build', 'test'])
var git = require('gulp-git')
var tag_version = require('gulp-tag-version')
gulp.task('git', ['build'], function (done) {
var v = require('./package.json').version
gulp.src('./')
.pipe(git.add({args: '-A'}))
.pipe(git.commit('[release] ' + v))
.pipe(tag_version({version: v}))
.on('end', function () {
git.push('origin', 'master', {args: '--tags'})
done()
})
})
gulp.task('npm-publish', ['git'], function (done) {
spawn('npm', ['publish'], {stdio: 'inherit'}).on('close', done)
})
gulp.task('release', ['npm-publish'])
// console.log(typeof process.env.TRAVIS_PULL_REQUEST)
// string
gulp.task('ci', ['eslint', 'cover', 'sauce'])