forked from stellar/js-stellar-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
235 lines (215 loc) · 5.34 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
'use strict';
var gulp = require('gulp');
var isparta = require('isparta');
var plugins = require('gulp-load-plugins')();
var server = require('gulp-develop-server');
var webpack = require('webpack');
var clear = require('clear');
var plumber = require('gulp-plumber');
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
gulp.task('lint:src', function lintSrc() {
return gulp
.src(['src/**/*.js'])
.pipe(plumber())
.pipe(plugins.eslint())
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failAfterError());
});
// Lint our test code
gulp.task('lint:test', function lintTest() {
return gulp
.src(['test/unit/**/*.js', 'gulpfile.js'])
.pipe(plumber())
.pipe(plugins.eslint())
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failAfterError());
});
gulp.task('clean', function clean() {
return gulp
.src('dist', { read: false, allowEmpty: true })
.pipe(plugins.rimraf());
});
gulp.task(
'build:node',
gulp.series('lint:src', function buildNode() {
return gulp
.src('src/**/*.js')
.pipe(plumber())
.pipe(plugins.babel())
.pipe(gulp.dest('lib'));
})
);
gulp.task(
'build:browser',
gulp.series('lint:src', function buildBrowser() {
return gulp
.src('src/browser.js')
.pipe(plumber())
.pipe(
plugins.webpack({
output: { library: 'StellarSdk' },
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{ test: /\.json$/, loader: 'json-loader' }
]
},
plugins: [
// Ignore native modules (ed25519)
new webpack.IgnorePlugin(/ed25519/)
]
})
)
.pipe(plugins.rename('stellar-sdk.js'))
.pipe(gulp.dest('dist'))
.pipe(
plugins.uglify({
output: {
ascii_only: true
}
})
)
.pipe(plugins.rename('stellar-sdk.min.js'))
.pipe(gulp.dest('dist'));
})
);
gulp.task(
'analyze:browser',
gulp.series('lint:src', function analyzeBrowser() {
return gulp
.src('src/browser.js')
.pipe(plumber())
.pipe(
plugins.webpack({
output: { library: 'StellarSdk' },
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{ test: /\.json$/, loader: 'json-loader' }
]
},
plugins: [
// Ignore native modules (ed25519)
new webpack.IgnorePlugin(/ed25519/),
new BundleAnalyzerPlugin()
]
})
);
})
);
gulp.task(
'test:unit',
gulp.series('build:node', function testUnit() {
return gulp.src(['test/test-helper.js', 'test/unit/**/*.js']).pipe(
plugins.mocha({
reporter: ['spec']
})
);
})
);
gulp.task(
'test:browser',
gulp.series('build:browser', function testBrowser(done) {
var Server = require('karma').Server;
var server = new Server(
{ configFile: __dirname + '/karma.conf.js' },
(exitCode) => {
if (exitCode !== 0) {
done(new Error(`Bad exit code ${exitCode}`));
} else {
done();
}
}
);
server.start();
})
);
gulp.task(
'test:sauce',
gulp.series('build:browser', function testSauce(done) {
var Server = require('karma').Server;
var server = new Server(
{ configFile: __dirname + '/karma-sauce.conf.js' },
(exitCode) => {
if (exitCode !== 0) {
done(new Error(`Bad exit code ${exitCode}`));
} else {
done();
}
}
);
server.start();
})
);
gulp.task('clear-screen', function clearScreen(cb) {
clear();
cb();
});
gulp.task('clean-coverage', function cleanCoverage() {
return gulp
.src(['coverage'], { read: false, allowEmpty: true })
.pipe(plugins.rimraf());
});
gulp.task(
'test:init-istanbul',
gulp.series('clean-coverage', function testInitIstanbul() {
return gulp
.src(['src/**/*.js'])
.pipe(
plugins.istanbul({
instrumenter: isparta.Instrumenter
})
)
.pipe(plugins.istanbul.hookRequire());
})
);
gulp.task(
'test:integration',
gulp.series('build:node', 'test:init-istanbul', function testIntegration() {
return gulp
.src([
'test/test-helper.js',
'test/unit/**/*.js',
'test/integration/**/*.js'
])
.pipe(
plugins.mocha({
reporter: ['spec']
})
)
.pipe(plugins.istanbul.writeReports());
})
);
gulp.task('submit-coverage', function submitCoverage() {
return gulp.src('./coverage/**/lcov.info').pipe(plugins.coveralls());
});
gulp.task('build', gulp.series('clean', 'build:node', 'build:browser'));
gulp.task(
'test',
gulp.series('clean', 'test:unit', 'test:browser', function test(done) {
server.kill();
done();
})
);
gulp.task(
'watch',
gulp.series('build', function watch() {
return gulp.watch('lib/**/*', ['clear-screen', 'build']);
})
);
gulp.task(
'hooks:precommit',
gulp.series('build', function hooksPrecommit() {
return gulp.src(['dist/*', 'lib/*']).pipe(plugins.git.add());
})
);
gulp.task('default', gulp.series('build'));