-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
106 lines (86 loc) · 2.67 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
'use strict';
var http = require('http');
var path = require('path');
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var sourcemaps = require('gulp-sourcemaps');
var lr = require('gulp-livereload');
var cached = require('gulp-cached');
var deploy = require('gulp-gh-pages');
var merge = require('merge-stream');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var watchify = require('watchify');
var browserify = require('browserify');
var ecstatic = require('ecstatic');
//var reactify = require('reactify');
var paths = {
js: 'src/**/*.js'
};
var bundleCache = {};
var pkgCache = {};
var bundler = watchify(browserify('./src/index.js', {
cache: bundleCache,
packageCache: pkgCache,
fullPaths: true,
standalone: 'react-sidetap',
debug: true
}));
var sampleBundler = watchify(browserify('./samples/sandbox/src/index.js', {
cache: bundleCache,
packageCache: pkgCache,
fullPaths: true,
standalone: 'sample',
debug: true
}));
//sampleBundler.transform(reactify);
gulp.task('js', function(){
var browserifyStream = bundler.bundle()
// browserify -> gulp transfer
.pipe(source('react-sidetap.js'))
.pipe(buffer())
.pipe(cached('js'))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
var lintStream = gulp.src(paths.js)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
return merge(browserifyStream, lintStream);
});
gulp.task('samples', function(){
var browserifyStream = sampleBundler.bundle()
// browserify -> gulp transfer
.pipe(source('sample.js'))
.pipe(buffer())
.pipe(cached('samples'))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('samples/sandbox/dist'))
.pipe(lr());
var staticStream = gulp.src(['samples/sandbox/src/**/*', '!samples/sandbox/src/**/*.js'])
.pipe(cached('static-samples'))
.pipe(gulp.dest('samples/sandbox/dist'))
.pipe(lr());
return merge(staticStream, browserifyStream);
});
gulp.task('sample-server', function(cb){
var port = parseInt(process.env.PORT) || 9090;
var rootFolder = path.join(__dirname, './samples/sandbox/dist');
var server = http.createServer(ecstatic({root: rootFolder}));
server.listen(port, cb);
});
gulp.task('deploy', function(){
return gulp.src('./samples/sandbox/dist/**/*')
.pipe(deploy());
});
gulp.task('watch', function(){
gulp.watch(['samples/sandbox/src/**/*'], ['samples']);
bundler.on('update', function(){
gulp.start('js');
});
sampleBundler.on('update', function(){
gulp.start('samples');
});
});
gulp.task('default', ['js', 'samples', 'sample-server', 'watch']);