forked from mbaez/bubbletree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
128 lines (109 loc) · 3.62 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
123
124
125
126
127
128
'use strict';
var path = require('path');
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var nunjucks = require('nunjucks');
var marked = require('marked');
var file = require('gulp-file');
var fs = require('fs');
var nodeModulesDir = path.join(__dirname, '/node_modules');
var readmeFileName = path.join(__dirname, '/readme.md');
var demosPath = path.join(__dirname, '/demos');
var srcDistDir = path.join(__dirname, 'dist');
var srcFiles = [
path.join(__dirname, '/src/js/module/intro.js'),
path.join(__dirname, '/src/js/lib/vis4.js'),
path.join(__dirname, '/src/js/bubbletree.js'),
path.join(__dirname, '/src/js/layout.js'),
path.join(__dirname, '/src/js/line.js'),
path.join(__dirname, '/src/js/loader.js'),
path.join(__dirname, '/src/js/mouseeventgroup.js'),
path.join(__dirname, '/src/js/ring.js'),
path.join(__dirname, '/src/js/transitioner.js'),
path.join(__dirname, '/src/js/utils.js'),
path.join(__dirname, '/src/js/vector.js'),
path.join(__dirname, '/src/js/bubbles/plain.js'),
path.join(__dirname, '/src/js/bubbles/donut.js'),
path.join(__dirname, '/src/js/bubbles/icon.js'),
path.join(__dirname, '/src/js/bubbles/icondonut.js'),
path.join(__dirname, '/src/js/module/outro.js')
];
var cssFiles = [
path.join(__dirname, 'src/css/bubbletree.css')
];
var vendorScriptFiles = [
path.join(nodeModulesDir, '/jquery/dist/jquery.min.js'),
path.join(nodeModulesDir, '/jquery-migrate/dist/jquery-migrate.min.js'),
path.join(nodeModulesDir, '/raphael/raphael-min.js'),
path.join(nodeModulesDir, '/tween.js/src/Tween.js'),
path.join(srcDistDir, '/bubbletree.js')
];
var templatesPath = path.join(__dirname, 'demos/assets/templates');
var templateRenderer = nunjucks.configure(templatesPath, {
autoescape: false
});
gulp.task('default', [
'dist',
'update-demos'
]);
gulp.task('dist', [
'sources',
'sources-minified',
'styles'
]);
gulp.task('update-demos', [
'demos',
'readme',
'vendor-scripts',
'custom-styles'
]);
gulp.task('sources', function() {
return gulp.src(srcFiles)
.pipe(concat('bubbletree.js'))
.pipe(gulp.dest(srcDistDir));
});
gulp.task('sources-minified', function() {
return gulp.src(srcFiles)
.pipe(sourcemaps.init())
.pipe(concat('bubbletree.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(srcDistDir));
});
gulp.task('styles', function() {
return gulp.src(cssFiles)
.pipe(concat('bubbletree.css'))
.pipe(gulp.dest(srcDistDir));
});
gulp.task('demos', function() {
var demos = fs.readdirSync(demosPath).filter(function(file) {
if (file == 'assets') {
return false;
}
return fs.statSync(path.join(demosPath, file)).isDirectory();
}).map(function(item) {
return '* [' + item + '](' + item + '/index.html)';
}).join('\r\n');
var content = templateRenderer.render('demos.html', {
content: marked(demos)
});
return file('index.html', content, { src: true })
.pipe(gulp.dest(path.join(__dirname, '/demos')));
});
gulp.task('readme', function() {
var content = templateRenderer.render('readme.html', {
content: marked(fs.readFileSync(readmeFileName, 'utf8'))
});
return file('index.html', content, { src: true })
.pipe(gulp.dest(__dirname));
});
gulp.task('vendor-scripts', ['sources', 'sources-minified'], function() {
return gulp.src(vendorScriptFiles)
.pipe(gulp.dest(path.join(__dirname, '/demos/assets/scripts')));
});
gulp.task('custom-styles', function() {
return gulp.src(path.join(__dirname, '/src/css') + '/*')
.pipe(gulp.dest(path.join(__dirname, '/demos/assets/styles')));
});