forked from felixrieseberg/React-Spreadsheet-Component
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (78 loc) · 2.9 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
var browserify = require('browserify');
var del = require('del');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var header = require('gulp-header');
var jshint = require('gulp-jshint');
var rename = require('gulp-rename');
var plumber = require('gulp-plumber');
var react = require('gulp-react');
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var connect = require('gulp-connect');
var babel = require('gulp-babel');
var babelify = require('babelify');
var pkg = require('./package.json');
var devBuild = (process.env.NODE_ENV === 'production') ? '' : ' (dev build at ' + (new Date()).toUTCString() + ')';
var distHeader = '/*!\n\
* <%= pkg.name %> <%= pkg.version %><%= devBuild %> - <%= pkg.homepage %>\n\
* <%= pkg.license %> Licensed\n\
*/\n';
var jsSrcPaths = './src/*.js*'
var jsLibPaths = './lib/*.js'
gulp.task('clean-lib', function (cb) {
del(jsLibPaths).then(function () {
cb();
});
});
gulp.task('transpile-js', ['clean-lib'], function () {
return gulp.src(jsSrcPaths)
.pipe(plumber())
.pipe(react({harmony: false, es6module: true}))
.pipe(babel())
.pipe(gulp.dest('./lib'));
});
gulp.task('lint-js', ['transpile-js'], function () {
return gulp.src(jsLibPaths)
.pipe(jshint('./.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('bundle-js', ['lint-js'], function () {
var b = browserify(pkg.main, {
debug: !!gutil.env.debug
, standalone: pkg.standalone
, detectGlobals: false
});
b.transform('browserify-shim')
var stream = b.bundle()
.pipe(source('spreadsheet.js'))
.pipe(streamify(header(distHeader, { pkg: pkg, devBuild: devBuild })))
.pipe(gulp.dest('./dist'));
if (process.env.NODE_ENV === 'production') {
stream = stream
.pipe(rename('spreadsheet.min.js'))
.pipe(streamify(uglify()))
.pipe(streamify(header(distHeader, { pkg: pkg, devBuild: devBuild })))
.pipe(gulp.dest('./dist'));
}
return stream;
});
gulp.task('watch', function () {
gulp.watch(jsSrcPaths, ['bundle-js']);
});
gulp.task('connect', function () {
connect.server();
gutil.log('--------------------------------------------')
gutil.log(gutil.colors.magenta('To see the example, open up a browser and go'));
gutil.log(gutil.colors.bold.red('to http://localhost:8080/example'));
gutil.log('--------------------------------------------');
});
gulp.task('example', ['transpile-js'], function () {
return browserify('./example.js')
.transform("babelify", {presets: ["es2015", "react"]})
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./example'));
});
gulp.task('default', ['bundle-js', 'connect', 'watch']);