forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
157 lines (131 loc) · 4.48 KB
/
gulpfile.babel.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
/* eslint no-console: 0, arrow-body-style: 0 */
const gulp = require('gulp');
const path = require('path');
const babel = require('gulp-babel');
const clean = require('gulp-clean');
const gulpWebpack = require('webpack-stream');
const webpackConfig = require('./webpack.config');
const eslint = require('gulp-eslint');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const exec = require('child_process').exec;
const Karma = require('karma').Server;
const mocha = require('gulp-mocha');
const runSequence = require('run-sequence');
const gulpIstanbul = require('gulp-istanbul');
const isparta = require('isparta');
const sourcemaps = require('gulp-sourcemaps');
const packageJSON = require('./package.json');
const gzip = require('gulp-gzip');
const unzip = require('gulp-unzip');
gulp.task('clean', () => {
return gulp.src(['lib', 'dist', 'coverage', 'upload'], { read: false })
.pipe(clean());
});
gulp.task('babel', () => {
return gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('lib'));
});
gulp.task('unzip_titanium_sdk', () => {
return gulp.src('resources/titanium.zip')
.pipe(unzip())
.pipe(gulp.dest('resources/'));
});
gulp.task('compile_web', () => {
return gulp.src('src/web/index.js')
.pipe(gulpWebpack(webpackConfig))
.pipe(gulp.dest('dist/web'));
});
gulp.task('compile_titanium', () => {
return gulp.src('src/titanium/index.js')
.pipe(gulpWebpack(webpackConfig))
.pipe(gulp.dest('dist/titanium'));
});
gulp.task('create_version', () => {
return gulp.src('dist/web/pubnub.js')
.pipe(rename(`pubnub.${packageJSON.version}.js`))
.pipe(gulp.dest('upload/normal'));
});
gulp.task('create_version_gzip', () => {
return gulp.src('upload/normal/*.js')
.pipe(gzip({ append: false }))
.pipe(gulp.dest('upload/gzip'));
});
gulp.task('uglify_web', () => {
return gulp.src('dist/web/pubnub.js')
.pipe(uglify({ mangle: true, compress: true }))
.pipe(rename('pubnub.min.js'))
.pipe(gulp.dest('dist/web'))
.pipe(rename(`pubnub.${packageJSON.version}.min.js`))
.pipe(gulp.dest('upload/normal'));
});
gulp.task('uglify_titanium', () => {
return gulp.src('dist/titanium/pubnub.js')
.pipe(uglify({ mangle: true, compress: true }))
.pipe(rename('pubnub.min.js'))
.pipe(gulp.dest('dist/titanium'));
});
gulp.task('lint_code', [], () => {
return gulp.src(['src/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint_tests', [], () => {
return gulp.src(['test/**/*.js', '!test/dist/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint', ['lint_code', 'lint_tests']);
gulp.task('flow', (cb) => {
return exec('./node_modules/.bin/flow --show-all-errors', (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('validate', ['lint', 'flow']);
gulp.task('pre-test', () => {
return gulp.src(['src/**/*.js'])
.pipe(gulpIstanbul({ instrumenter: isparta.Instrumenter, includeAllSources: true }))
.pipe(gulpIstanbul.hookRequire());
});
gulp.task('test_web', (done) => {
new Karma({
configFile: path.join(__dirname, '/karma/web.config.js'),
}, done).start();
});
gulp.task('test_node', () => {
return gulp.src(['test/**/*.test.js', '!test/dist/*.js'], { read: false })
.pipe(mocha({ reporter: 'spec' }))
.pipe(gulpIstanbul.writeReports({ reporters: ['json', 'lcov', 'text'] }));
});
gulp.task('test_titanium', ['unzip_titanium_sdk'], (done) => {
new Karma({
configFile: path.join(__dirname, '/karma/titanium.config.js'),
}, done).start();
});
gulp.task('test_react-native', () => {
return gulp.src('test/dist/react-native.test.js', { read: false })
.pipe(mocha({ reporter: 'spec' }))
.pipe(gulpIstanbul.writeReports({ reporters: ['json', 'lcov', 'text'] }));
});
gulp.task('test_release', () => {
return gulp.src('test/release/**/*.test.js', { read: false })
.pipe(mocha({ reporter: 'spec' }));
});
gulp.task('test', (done) => {
runSequence('pre-test', 'test_node', 'test_web', 'test_titanium', 'test_react-native', 'test_release', 'validate', () => {
process.exit();
});
});
gulp.task('webpack', (done) => {
runSequence('compile_web', 'compile_titanium', done);
});
gulp.task('compile', (done) => {
runSequence('clean', 'babel', 'webpack', 'uglify_web', 'uglify_titanium', 'create_version', 'create_version_gzip', done);
});