-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpFile.js
168 lines (138 loc) · 3.8 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
var gulp = require('gulp');
// js
var browserify = require('browserify');
var uglify = require('gulp-uglify');
var header = require('gulp-header');
var replace = require('gulp-replace');
var collapse = require('bundle-collapser/plugin');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
/////////
/// pages
/////
var rootdirname = __dirname;
gulp.task('page-js', function(){
var headerTxt = '/* ' + new Date().getFullYear() + '- generated at ' + new Date() + '\n*/';
var browserifyOption = {
entries: './pages/pages.js',
extensions: ['.js'],
//debug: true,
};
var b = browserify(browserifyOption);
var bundler = b
.transform('partialify')
.transform('babelify', {
compact: "auto",
ignore: [],
presets: ['es2015', 'react']
});
var rebundle = function() {
var rc = bundler.plugin(collapse)
.bundle()
.pipe(source('page.js'))
.pipe(buffer())
// .pipe(uglify())
.pipe(header(headerTxt))
.pipe(gulp.dest(rootdirname));
return rc;
};
bundler = bundler.on('update', rebundle);
return rebundle();
});
gulp.task('page-css', function(){
return 0;/*gulp.src("./pages/pages.less")
.pipe(less())
.pipe(rename('page.css'))
.pipe(gulp.dest(rootdirname));*/
});
/////////
// dist
/////////
gulp.task('full', function(){
var headerTxt = '/* ' + new Date().getFullYear() + '- generated at ' + new Date() + '\n*/';
var browserifyOption = {
entries: './src/Graph.jsx',
extensions: ['.js','.jsx']
};
var b = browserify(browserifyOption);
var bundler = b
.transform('partialify')
.transform('babelify', {
compact: "auto",
ignore: [],
presets: ['es2015', 'react']
}).external('react');
var rebundle = function() {
var rc = bundler.plugin(collapse)
.bundle()
.pipe(source('reactchart.js'))
.pipe(buffer())
.pipe(header(headerTxt))
.pipe(gulp.dest('./dist'));
return rc;
};
bundler = bundler.on('update', rebundle);
return rebundle();
});
gulp.task('min', function(){
var headerTxt = '/* ' + new Date().getFullYear() + '- generated at ' + new Date() + '\n*/';
var browserifyOption = {
entries: './src/Graph.jsx',
extensions: ['.js','.jsx']
//debug: true,
};
var b = browserify(browserifyOption);
var bundler = b
.transform('partialify')
.transform('babelify', {
compact: "auto",
ignore: [],
presets: ['es2015', 'react']
}).external('react');
var rebundle = function() {
var rc = bundler.plugin(collapse)
.bundle()
.pipe(source('reactchart.min.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(header(headerTxt))
.pipe(gulp.dest('./dist'));
return rc;
};
bundler = bundler.on('update', rebundle);
return rebundle();
});
////////////
// jsx -> js in require
///////////
gulp.task('jsx2js', () => {
return gulp.src(['.lib/*.js',"./lib/**/*.js"])
.pipe(replace(/\.jsx/g,'.js'))
.pipe(gulp.dest('./lib'));
});
////////////
// src -> lib in index
///////////
gulp.task('src2libIdx', () => {
return gulp.src(["./index.js"])
.pipe(replace(/src/g,'lib'))
.pipe(gulp.dest('.'));
});
gulp.task('src2libHlp', () => {
return gulp.src(["./helpers/index.js"])
.pipe(replace(/src/g,'lib'))
.pipe(gulp.dest('./helpers'));
});
gulp.task('src2lib',["src2libIdx","src2libHlp"],() => 0);
//////////////
// .npmignore ignores src/
/////////////
gulp.task('noSrc',() => {
return gulp.src(['./.npmignore'])
.pipe(header('src\n'))
.pipe(gulp.dest('.'));
});
gulp.task('buildNpm',['jsx2js','src2lib','noSrc'],() => 0);
gulp.task('dist',['full','min'],() => 0);
gulp.task('doc',['page-js','page-css'],() => 0);
gulp.task('default',['dist','doc'],() => 0);