-
Notifications
You must be signed in to change notification settings - Fork 33
/
gulpfile.js
121 lines (93 loc) · 3.52 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
// Gulp Dependencies
var gulp = require('gulp');
var babel = require('gulp-babel');
var babelify = require('babelify');
var browserify = require('browserify');
var del = require('del');
var gutil = require('gulp-util');
var rename = require('gulp-rename');
var shim = require('browserify-shim');
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var connect = require('gulp-connect');
var header = require('gulp-header');
var path = require('path');
var pkgJSON = JSON.parse(require('fs').readFileSync('./package.json'));
var BANNER = `
/**!
* RedRaphael <%= version %> - JavaScript Vector Library
* Copyright (c) 2012-2013 FusionCharts, Inc. <http://www.fusioncharts.com>
*
* Raphael <%= rversion %>
* Copyright (c) 2008-2012 Dmitry Baranovskiy <http://raphaeljs.com>
* Copyright © 2008-2012 Sencha Labs <http://sencha.com>
*
* Licensed under the MIT license.
*/
`;
// Build task
gulp.task('clean:dist', function () {
return del([pkgJSON.build.dist]);
});
gulp.task('create:dist', ['clean:dist'], function () {
var standalone = browserify(pkgJSON.source.src + '/' + pkgJSON.source.name, {
})
.transform(babelify.configure({}))
return standalone.bundle()
.on('error', function (e) {
gutil.log('Browserify Error', e);
})
.pipe(source(pkgJSON.build.name + '.js'))
.pipe(header(BANNER, pkgJSON ))
.pipe(gulp.dest(pkgJSON.build.dist))
.pipe(rename(pkgJSON.build.name + '-min.js'))
.pipe(streamify(uglify()))
.pipe(header(BANNER, pkgJSON ))
.pipe(gulp.dest(pkgJSON.build.dist));
});
gulp.task('clean:lib', function () {
return del([pkgJSON.lib]);
});
gulp.task('create:lib', ['clean:lib'], function () {
return gulp.src([ pkgJSON.source.src + '/**/*.js' ])
.pipe(babel({}))
.pipe(gulp.dest(pkgJSON.lib));
});
gulp.task('watch', ['create:dist', 'create:lib'], function () {
return gulp.watch([pkgJSON.source.src + '/**/*.js'], ['create:dist', 'create:lib']);
});
// Web server task
gulp.task('start:server', function () {
connect.server({
root: pkgJSON.samples.root,
fallback: path.join(pkgJSON.samples.root + '/' + pkgJSON.samples.dist, 'index.html'),
port: pkgJSON.samples.port || process.env.PORT || 8000,
livereload: true
});
// Reload the browser
return connect.reload();
});
gulp.task('copy:html', function () {
return gulp.src([ pkgJSON.samples.root + '/' + pkgJSON.samples.src + '/index.html' ])
.pipe(gulp.dest(pkgJSON.samples.root + '/' + pkgJSON.samples.dist));
});
gulp.task('build:sample', ['create:lib', 'copy:html'], function () {
var standalone = browserify(pkgJSON.samples.root + '/' + pkgJSON.samples.src + '/index.js')
.transform(babelify.configure());
return standalone.bundle()
.on('error', function (e) {
gutil.log('Browserify Error', e);
})
.pipe(source('bundle.js'))
.pipe(gulp.dest(pkgJSON.samples.root + '/' + pkgJSON.samples.dist))
.pipe(connect.reload());
});
gulp.task('watch:samples', ['create:dist', 'create:lib', 'build:sample'], function () {
// Watch source file to create build and lib
gulp.watch(['./samples/src/*.js'], ['build:sample']);
gulp.watch(['./samples/src/*.html'], ['build:sample']);
gulp.watch([pkgJSON.source.src + '/**/*.js'], ['create:lib', 'build:sample']);
});
gulp.task('build', [ 'create:dist', 'create:lib' ]);
gulp.task('start', ['start:server', 'watch:samples']);