forked from nhn/tui.chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
122 lines (104 loc) · 3.16 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
'use strict';
var gulp = require('gulp'),
gutil = require('gulp-util'),
source = require('vinyl-source-stream'),
sync = require('browser-sync'),
browserify = require('browserify'),
watchify = require('watchify'),
stringify = require('stringify'),
less = require('gulp-less'),
minifiyCss = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
del = require('del'),
header = require('gulp-header'),
pkg = require('./package.json');
var banner = [
'/**',
' * @fileoverview ${name}',
' * @author ${author}',
' * @version ${version}',
' * @license ${license}',
' * @link ${repository.url}',
' */',
''
].join('\n');
gulp.task('browser-sync', function() {
sync({
server: {
baseDir: '.'
},
port: process.env.PORT || 8080
});
});
gulp.task('browserify', function() {
var b = watchify(browserify('./src/js/chart.js', {debug: true})),
rebundle;
gutil.log(gutil.colors.green('rebundle...'));
rebundle = function() {
return b.bundle()
.pipe(source('./chart.js'))
.pipe(gulp.dest('./dist'));
};
b.add('./src/js/plugins/pluginRaphael.js');
b.transform(stringify(['.html']));
return rebundle();
});
gulp.task('compress-js', ['browserify'], function() {
return gulp.src('dist/chart.js')
.pipe(uglify())
.pipe(rename({
extname: '.min.js'
}))
.pipe(header(banner, pkg))
.pipe(gulp.dest('dist'));
});
gulp.task('compile-less', function() {
return gulp.src('src/less/style.less')
.pipe(less())
.pipe(rename('chart.css'))
.pipe(gulp.dest('./dist'));
});
gulp.task('minify-css', ['compile-less'], function() {
return gulp.src('dist/chart.css')
.pipe(minifiyCss())
.pipe(rename({
extname: '.min.css'
}))
.pipe(gulp.dest('./dist'));
});
gulp.task('reload-js', ['browserify'], function() {
sync.reload();
});
gulp.task('reload-less', ['compile-less'], function() {
sync.reload();
});
gulp.task('watch', ['browserify', 'compile-less', 'browser-sync'], function() {
gulp.watch('src/js/**/*', ['reload-js']);
gulp.watch('src/less/**/*', ['reload-less']);
gutil.log(gutil.colors.green('Watching for changes...'));
});
gulp.task('default', ['watch']);
gulp.task('clean-samples', function(callback) {
del([
'dist/chart.min.js',
'dist/chart.min.css',
'samples/dist/*',
'samples/lib/*'
], callback);
});
gulp.task('copy-samples', ['clean-samples', 'compress-js', 'minify-css'], function() {
gulp.src('dist/chart.min.css')
.pipe(gulp.dest('./samples/dist'));
gulp.src('dist/chart.min.js')
.pipe(gulp.dest('./samples/dist'));
gulp.src('lib/tui-code-snippet/code-snippet.min.js')
.pipe(gulp.dest('./samples/lib'));
gulp.src('lib/tui-component-effects/effects.min.js')
.pipe(gulp.dest('./samples/lib'));
return gulp.src('lib/raphael/raphael-min.js')
.pipe(gulp.dest('./samples/lib'));
});
gulp.task('deploy', ['copy-samples'], function() {
process.exit(0);
});