-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
265 lines (233 loc) · 8.61 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
var gulp = require('gulp');
var babel = require('gulp-babel');
var debug = require('gulp-debug');
var sourcemaps = require('gulp-sourcemaps');
var marked = require('gulp-marked');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var watchify = require('watchify');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify');
var notify = require('gulp-notify');
var concat = require('gulp-concat');
var cssmin = require('gulp-cssmin');
var gutil = require('gulp-util');
var fs = require('fs');
var replace = require('gulp-replace');
var chalk = require('chalk');
var S = require('string');
var yuidoc = require('gulp-yuidoc');
var flatten = require('gulp-flatten');
var n2a = require('gulp-native2ascii');
var specific_rollup = (process.argv[3]) ? process.argv[3].replace('--', '') : undefined;
var dependencies = [];
//helper function for exporting modules into a global namespace
var _namespace = function(module){
var base = "NetSage.Sankey.";
return base + module;
};
//helper function to log build notifications in a consistent manner
var _notifyComplete = function(options){
var name = options.name;
var start = options.start;
var type = (options.type == 'css') ? 'css' : 'js';
var min = (options.dev) ? '' : '.min';
console.log(
S('['+chalk.yellow(options.name+min+'.'+type)+']').padRight(40, '.').toString() +
'built in ' +
chalk.magenta((Date.now() - start) + 'ms')
);
};
var createJS = function(options){
options = options || {};
// if a specific rollup was requested and this is not it just return
if(specific_rollup !== undefined && options.name != specific_rollup){
return;
}
var start = new Date();
var namespace = _namespace(options.name);
var name_lower = options.name.toLowerCase();
var file_name = (options.dev) ? 'sankeynetsage_'+name_lower+'.js' : 'sankeynetsage_'+name_lower+'.min.js';
return browserify('./src/js/index/'+options.name+'.js', {
standalone: namespace
})
.bundle()
.on('error', gutil.log)
//Pass desired output filename to vinyl-source-stream
.pipe(source(file_name))
//get rid of windows newline cancer
.pipe(replace(/\r\n/g,'\n'))
//force ascii b/c mike bostock insists on putting
//math symbols in his code
.pipe(n2a({reverse: false}))
//minify if not development
.pipe(gulpif(!options.dev, streamify(uglify({
output: {
ascii_only: true
}
}))))
//write the completed stream to dist
.pipe(gulp.dest('./dist/js/'))
.pipe(notify(function () {
_notifyComplete({
name: name_lower,
start: start,
dev: options.dev
});
}));
};
var createCSS = function(options){
options = options || {};
// if a specific rollup was requested and this is not it just return
if(specific_rollup !== undefined && options.name != specific_rollup){
return;
}
var start = new Date();
var name_lower = options.name.toLowerCase();
var file_name = (options.dev) ? 'sankeynetsage_'+name_lower+'.css' : 'sankeynetsage_'+name_lower+'.min.css';
gulp.src(options.files,{base: 'src/css/'})
.pipe(concat(file_name))
//get rid of windows newline cancer
.pipe(replace(/\r\n/g,'\n'))
//minify if not development
.pipe(gulpif(!options.dev, streamify(cssmin())))
.pipe(gulp.dest('./dist/css/'))
.pipe(notify(function () {
_notifyComplete({
name: name_lower,
start: start,
type: 'css',
dev: options.dev
});
}));
};
var createPlugin = function(options){
options = options || {};
gulp.src(options.files)
.pipe(debug())
.pipe(sourcemaps.init())
.pipe(babel({
presets: ["es2015"],
plugins: ['transform-es2015-modules-systemjs', "transform-es2015-for-of"],
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist'));
}
//build all widgets
var buildAll = function(options){
options = options || {};
options.dev = options.dev || false;
gulp.src('plugin.json').pipe(gulp.dest('./dist'));
gulp.src('src/module.html').pipe(gulp.dest('./dist'));
gulp.src('src/editor.html').pipe(gulp.dest('./dist'));
gulp.src('src/docs_editor.html').pipe(gulp.dest('./dist'));
gulp.src('src/table_editor.html').pipe(gulp.dest('./dist'));
//gulp.src('src/display_editor.html').pipe(gulp.dest('./dist'));
createPlugin({ files: [ './src/*.js',]});
//create the d3.v3
createJS({
name: 'd3.v3',
dev: options.dev
});
//create the sankey
createJS({
name: 'sankey',
dev: options.dev
});
//create the sankey css
createCSS({
name: 'sankey',
files: [
'./src/css/sankey.css'
],
dev: options.dev
});
};
//create api documentation with gulp-yuidoc
var _generateYuiAPIDocs = function(options){
options = options || {};
//generate our api documentation with the yuidoc plugin
return gulp.src("./js/**/*.js")
.pipe(yuidoc.parser({
project: {
"name": "NetSage Sankey",
"description": "NetSage Sankey API ",
"version": "1.0.3",
"url": "http://www.netsage.global/",
"themedir": "./node_modules/yuidoc-bootstrap-theme",
"helpers": ["./node_modules/yuidoc-bootstrap-theme/helpers/helpers.js"]
}
}))
.pipe(yuidoc.reporter())
.pipe(yuidoc.generator())
.pipe(gulp.dest('./dist/api_docs'));
};
//apply the bootstrap yui doc theme to the generated docs
var _applyBootstrapAPIDocTheme = function(){
//copy over vendor assets from bootstrap theme
gulp.src("./node_modules/yuidoc-bootstrap-theme/assets/vendor/**", { base: './node_modules/yuidoc-bootstrap-theme/vendor/*' })
.pipe(gulp.dest('./dist/api_docs/assets/vendor/'));
//copy over js assets from bootstrap theme
gulp.src("./node_modules/yuidoc-bootstrap-theme/assets/js/**", { base: './node_modules/yuidoc-bootstrap-theme/js/*' })
.pipe(gulp.dest('./dist/api_docs/assets/vendor/'));
//copy over css assets from bootstrap theme
return gulp.src("./node_modules/yuidoc-bootstrap-theme/assets/css/*")
.pipe(flatten())
.pipe(gulp.dest('./dist/api_docs/assets/css/'));
};
//apply some custom tweaks to the api documentation
var _applyCustomAPIDocTheme = function(){
//copy over custom logo
gulp.src("./images/netsage_atlas_logo_60o.png", { base: './images/' })
.pipe(gulp.dest('./dist/api_docs/assets/css/'));
//concatinate my custom css for the api docs onto the end of the custom
//bootstrap docs
return gulp.src([
'./dist/api_docs/assets/css/custom.css',
'./docs/css/api.css'
],{base: 'css/'})
.pipe(concat('custom.css'))
.pipe(gulp.dest('./dist/api_docs/assets/css/'))
};
//generate our landing doc page from the markdown document
var buildDocs = function(options){
return gulp.src('./docs/index.md')
.pipe(marked({}))
.pipe(gulp.dest('./dist/'))
};
//sample to include extra tasks
var _sampleExtraTask = function(){
//gulp.src("./node_modules/cesium/Build/Cesium/**", { base: './node_modules/cesium/Build/Cesium/' }).pipe(gulp.dest('./dist/vendors/cesium/'));
console.log("running sample extra task");
};
//hack to copy images
var _copyImages = function(){
gulp.src("./src/**", { base: './src/' }).pipe(gulp.dest('./dist/src/'));
};
// build the documentation
gulp.task('_generate_yui_api_docs', _generateYuiAPIDocs);
gulp.task('_apply_bootstrap_api_doc_theme', ['_generate_yui_api_docs'], _applyBootstrapAPIDocTheme);
gulp.task('_apply_custom_api_doc_theme', ['_apply_bootstrap_api_doc_theme'], _applyCustomAPIDocTheme);
gulp.task('docs', ['_apply_custom_api_doc_theme'], function(){
buildDocs();
});
gulp.task('_sample_extra_task', function(){
_sampleExtraTask();
});
gulp.task('_copy_images', function(){
_copyImages();
});
// Starts our development workflow
gulp.task('default', ['_sample_extra_task','_copy_images'], function () {
//_copyCesium();
buildAll({
dev: true
});
});
// Builds our minified production rollups
gulp.task('deploy', ['_sample_extra_task','_copy_images', 'docs'], function () {
//_copyCesium();
buildAll();
buildAll({dev: true});
});