forked from cytoscape/cytoscape.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
646 lines (512 loc) · 15.4 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
var gulp = require('gulp');
var path = require('path');
var tap = require('gulp-tap');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var replace = require('gulp-replace');
var inject = require('gulp-inject');
var zip = require('gulp-zip');
var mocha = require('gulp-mocha');
var child_process = require('child_process');
var fs = require('fs');
var htmlmin = require('gulp-htmlmin');
var cssmin = require('gulp-cssmin');
var shell = require('gulp-shell');
var jshint = require('gulp-jshint');
var jshStylish = require('jshint-stylish');
var exec = require('child_process').exec;
var runSequence = require('run-sequence');
var browserify = require('browserify');
var source = require('vinyl-source-stream'); // converts node streams into vinyl streams
var benchmark = require('gulp-benchmark');
var download = require("gulp-download");
var del = require('del');
var vinylPaths = require('vinyl-paths');
var clean = function(){ return vinylPaths(del) };
var decompress = require('gulp-decompress');
var rename = require("gulp-rename");
var benchmarkVersion = '2.3.15'; // old version to test against for benchmarks
var benchmarkVersionUrl = 'https://raw.githubusercontent.com/cytoscape/cytoscape.js/v' + benchmarkVersion + '/dist/cytoscape.js';
var weaverVersion = 'master';
var weaverUrlBase = 'https://raw.githubusercontent.com/maxkfranz/weaver/' + weaverVersion + '/';
var addWeaverUrlBase = function( path ){
return weaverUrlBase + path;
};
var weaverSrc = [
'src/thread.js',
'src/fabric.js',
'src/thread-node-fork.js'
].map( addWeaverUrlBase );
var weaverTest = [
'test/thread.js',
'test/fabric.js',
'test/requires/foo.js'
].map( addWeaverUrlBase );
var weaverTestReqs = [
'test/requires/foo.js'
].map( addWeaverUrlBase );
var version; // used for marking builds w/ version etc
var paths = {
sources: [
'src/preamble.js',
'src/namespace.js',
'src/promise.js',
'src/is.js',
'src/util.js',
'src/math.js',
'src/extension.js',
'src/jquery-plugin.js',
'src/event.js',
'src/define.js',
'src/selector.js',
'src/style.js',
'src/style-*.js',
'src/thread.js',
'src/fabric.js',
'src/core.js',
'src/core-*.js',
'src/collection.js',
'src/collection-*.js',
'src/heap.js',
'src/extensions/renderer.canvas.define-and-init-etc.js',
'src/extensions/renderer.canvas.*.js',
'src/extensions/*.js'
],
nodethreadName: 'thread-node-fork.js',
nodethreadSrc: [
'src/preamble.js',
'src/thread-node-fork.js'
],
docs: {
js: [
'documentation/js/fastclick.js',
'documentation/js/jquery.js',
'documentation/js/cytoscape.js',
'documentation/js/load.js',
'documentation/js/script.js'
],
css: [
'documentation/css/reset.css',
'documentation/css/font-awesome.css',
'documentation/css/highlight/github.css',
'documentation/css/style.css'
]
}
};
// update these if you don't have a unix like env or these programmes aren't in your $PATH
var $GIT = 'git';
var $RM = 'rm -rf';
var $CP = 'cp -R';
var $TEMP_DIR = '/tmp';
var $DOC_DIR = 'documentation';
var $DL_DIR = 'download';
var $NPM = 'npm';
var $METEOR = 'meteor';
var $SPM = 'spm';
var replaceShellVars = function( cmds ){
return cmds.map(function( cmd ){
return cmd
//.replace(/\$VERSION/g, version)
.replace(/\$GIT/g, 'git')
.replace(/\$RM/g, 'rm -rf')
.replace(/\$CP/g, 'cp -R')
.replace(/\$TEMP_DIR/g, '/tmp')
.replace(/\$DOC_DIR/g, 'documentation')
.replace(/\$DL_DIR/g, 'download')
.replace(/\$NPM/g, 'npm')
.replace(/\$METEOR/g, 'meteor')
.replace(/\$SPM/g, 'spm')
;
});
};
gulp.task('default', ['build'], function(){
});
gulp.task('version', function( next ){
var now = new Date();
version = process.env['VERSION'];
if( version ){
done();
} else {
exec('git rev-parse HEAD', function( error, stdout, stderr ){
var sha = stdout.substring(0, 10); // shorten so not huge filename
version = [ 'snapshot', sha, +now ].join('-');
done();
});
}
function done(){
console.log('Using version number `%s` for building', version);
next();
}
});
gulp.task('clean', function(){
return gulp.src(['build'])
.pipe( clean({ read: false }) )
;
});
gulp.task('concat', ['version', 'nodeworker'], function(){
return gulp.src( paths.sources )
.pipe( replace('{{VERSION}}', version) )
.pipe( concat('cytoscape.js') )
.pipe( gulp.dest('build') )
;
});
gulp.task('build', ['version', 'nodeworker'], function(){
return gulp.src( paths.sources )
.pipe( replace('{{VERSION}}', version) )
.pipe( concat('cytoscape.js') )
.pipe( gulp.dest('build') )
.pipe( uglify({
mangle: true,
preserveComments: 'some'
}) )
.pipe( concat('cytoscape.min.js') )
.pipe( gulp.dest('build') )
;
});
gulp.task('nodeworker', function(){
return gulp.src( paths.nodethreadSrc )
.pipe( replace('{{VERSION}}', version) )
.pipe( concat(paths.nodethreadName) )
.pipe( gulp.dest('build') )
;
});
gulp.task('debugrefs', function(){
return gulp.src('debug/index.html')
.pipe( inject( gulp.src(paths.sources, { read: false }), {
addPrefix: '..',
addRootSlash: false
} ) )
.pipe( gulp.dest('debug') )
;
});
gulp.task('testrefs', function(){
return gulp.src('test/index.html')
.pipe( inject( gulp.src(paths.sources, { read: false }), {
addPrefix: '..',
addRootSlash: false
} ) )
.pipe( gulp.dest('test') )
;
});
gulp.task('testlist', function(){
return gulp.src('test/index.html')
.pipe( inject( gulp.src('test/*.js', { read: false }), {
addPrefix: '',
ignorePath: 'test',
addRootSlash: false,
starttag: '<!-- inject:test:{{ext}} -->'
} ) )
.pipe( gulp.dest('test') )
;
});
gulp.task('refs', function(next){
runSequence( 'debugrefs', 'testrefs', 'testlist', next );
});
gulp.task('zip', ['version', 'build'], function(){
return gulp.src(['build/cytoscape.js', 'build/cytoscape.min.js', 'LGPL-LICENSE.txt', 'lib/*.js'])
.pipe( zip('cytoscape.js-' + version + '.zip') )
.pipe( gulp.dest('build') )
;
});
gulp.task('test', ['concat'], function(next){
return gulp.src('test/*.js')
.pipe( mocha({
reporter: 'spec'
}) )
;
});
gulp.task('weaver-src', function(){
return download( weaverSrc )
.pipe( replace('weaver', 'cytoscape') )
.pipe( gulp.dest('src') )
;
});
gulp.task('weaver-test', function(){
return download( weaverTest )
.pipe( replace('weaver', 'cytoscape') )
.pipe( gulp.dest('test') )
;
});
gulp.task('weaver-test-reqs', function(){
return download( weaverTestReqs )
.pipe( gulp.dest('test/requires') )
;
});
gulp.task('weaver', function(next){
return runSequence(['weaver-src', 'weaver-test', 'weaver-test-reqs'], next);
});
gulp.task('benchmark-old-ver', function(){
return download( benchmarkVersionUrl )
.pipe(gulp.dest("benchmark/CySuite"));
});
gulp.task('benchmark', ['concat', 'benchmark-old-ver'], function(next){
gulp.src('benchmark/*.js')
.pipe( benchmark() )
;
});
gulp.task('benchmark-single', ['concat', 'benchmark-old-ver'], function(next){
gulp.src('benchmark/single/index.js')
.pipe( benchmark() )
;
});
gulp.task('docsver', ['version'], function(){
return gulp.src('documentation/docmaker.json')
.pipe( replace(/\"version\"\:\s*\".*?\"/, '"version": "' + version + '"') )
.pipe( gulp.dest('documentation') )
;
});
gulp.task('docsjs', ['version', 'build'], function(){
return gulp.src([
'build/cytoscape.js',
'build/cytoscape.min.js',
'lib/*.js'
])
.pipe( gulp.dest('documentation/js') )
.pipe( gulp.dest('documentation/api/cytoscape.js-' + version) )
.pipe( gulp.dest('documentation/api/cytoscape.js-latest') )
;
});
gulp.task('docsdl', ['version', 'zip'], function(){
return gulp.src('build/cytoscape.js-' + version + '.zip')
.pipe( gulp.dest('documentation/download') )
;
});
gulp.task('docsbuildlist', ['docsdl'], function(next){
var cwd = process.cwd();
process.chdir('./documentation/download');
require('./documentation/download/dlmaker')(function(){
process.chdir( cwd );
next();
});
});
gulp.task('snapshotpush', ['docsdl'], function(){
return gulp.src('')
.pipe( shell( replaceShellVars([
'$RM $TEMP_DIR/cytoscape.js',
'$GIT clone -b gh-pages https://github.com/cytoscape/cytoscape.js.git $TEMP_DIR/cytoscape.js',
'$CP $DOC_DIR/$DL_DIR/* $TEMP_DIR/cytoscape.js/$DL_DIR',
]) ) )
.pipe( shell( replaceShellVars([
'$GIT add -A',
'$GIT commit -a -m "updating list of builds"',
'$GIT push origin'
]), { cwd: $TEMP_DIR + '/cytoscape.js' } ) )
;
});
gulp.task('docs', function(next){
var cwd = process.cwd();
process.chdir('./documentation');
require('./documentation/docmaker')( function(){
process.chdir( cwd );
next();
} );
});
gulp.task('docsmin', function(next){
runSequence( 'docs', 'docsminrefs', 'docshtmlmin', next );
});
gulp.task('docsclean', function(next){
return gulp.src(['documentation/js/all.min.js', 'documentation/css/all.min.css', 'documentation/index.html'])
.pipe( clean({ read: false }) )
;
});
gulp.task('docshtmlmin', function(){
return gulp.src('documentation/index.html')
.pipe( htmlmin({
collapseWhitespace: true,
keepClosingSlash: true
}) )
.pipe( gulp.dest('documentation') )
;
});
gulp.task('docsjsmin', function(){
return gulp.src( paths.docs.js )
.pipe( concat('all.min.js') )
.pipe( uglify({
mangle: true
}) )
.pipe( gulp.dest('documentation/js') )
;
});
gulp.task('docscssmin', function(){
return gulp.src( paths.docs.css )
.pipe( concat('all.min.css') )
.pipe( cssmin() )
.pipe( gulp.dest('documentation/css') )
;
});
gulp.task('docsminrefs', ['docscssmin', 'docsjsmin'], function(){
return gulp.src('documentation/index.html')
.pipe( inject( gulp.src([ 'documentation/js/all.min.js', 'documentation/css/all.min.css' ] ), {
addRootSlash: false,
ignorePath: 'documentation'
} ) )
.pipe( gulp.dest('documentation') )
;
});
gulp.task('docsrefs', function(){
return gulp.src([ 'documentation/index.html', 'documentation/template.html' ])
.pipe( inject( gulp.src(paths.docs.js.concat( paths.docs.css ), { read: false }), {
addRootSlash: false,
ignorePath: 'documentation'
} ) )
.pipe( gulp.dest('documentation') )
;
});
gulp.task('docsdemoshots', function(next){ return next(); // disable for now since phantomjs doesn't work for this usecase
var cwd = process.cwd();
process.chdir('./documentation');
require('./documentation/demoshots')( function(){
process.chdir( cwd );
next();
} );
});
var demoGistUrls = function(){
var demos = require('./documentation/docmaker.json').sections.filter(function(s){
return s.demos != null;
})[0].demos.map(function(d){
return 'https://gist.github.com/' + d.id + '/download';
});
return demos;
}
gulp.task('docsdemodl', function(){
var demos = demoGistUrls();
return download( demos )
.pipe( decompress() )
.pipe( rename(function( path ){
path.dirname = path.dirname.match(/^gist(.+)\-/)[1]
}) )
.pipe( replace(/".*cytoscape(\.min){0,1}\.js"/, '"../../js/cytoscape.min.js"') )
.pipe( gulp.dest('documentation/demos') )
;
});
gulp.task('docsdemodltest', function(){
var demos = demoGistUrls();
return download( demos )
.pipe( decompress() )
.pipe( rename(function( path ){
path.dirname = path.dirname.match(/^gist(.+)\-/)[1]
}) )
.pipe( replace(/".*cytoscape(\.min){0,1}\.js"/, '"../../../build/cytoscape.js"') )
.pipe( gulp.dest('documentation/demos') )
;
});
gulp.task('docspub', function(next){
runSequence( 'version', 'docsver', 'docsjs', 'docsbuildlist', 'docsdemoshots', 'docsdemodl', 'docsmin', next );
});
gulp.task('docsrebuild', function(next){
runSequence( 'docsmin', next );
});
gulp.task('pkgver', ['version'], function(){
return gulp.src([
'package.json',
'bower.json'
])
.pipe( replace(/\"version\"\:\s*\".*?\"/, '"version": "' + version + '"') )
.pipe( gulp.dest('./') )
;
});
gulp.task('dist', ['build'], function(){
return gulp.src([
'build/cytoscape.js',
'build/cytoscape.min.js',
'build/' + paths.nodethreadName
])
.pipe( gulp.dest('dist') )
;
});
gulp.task('pubprep', function(next){
runSequence('pkgver', 'dist', 'docspub', 'pubpush', next);
});
gulp.task('pubpush', shell.task( replaceShellVars([
'$GIT add -A',
'$GIT commit -m "preparing to publish $VERSION"',
'$GIT push'
]) ));
gulp.task('publish', ['pubprep'], function(next){
runSequence('tag', 'docspush', 'npm', 'spm', 'meteor', next);
});
gulp.task('tag', shell.task( replaceShellVars([
'$GIT tag -a v$VERSION -m "v$VERSION"',
'$GIT push origin v$VERSION'
]) ));
gulp.task('docspush', function(){
return gulp.src('')
.pipe( shell( replaceShellVars([
'$RM $TEMP_DIR/cytoscape.js',
'$GIT clone -b gh-pages https://github.com/cytoscape/cytoscape.js.git $TEMP_DIR/cytoscape.js',
'$CP $DOC_DIR/* $TEMP_DIR/cytoscape.js',
]) ) )
.pipe( shell( replaceShellVars([
'$GIT add -A',
'$GIT commit -a -m "updating docs to $VERSION"',
'$GIT push origin'
]), { cwd: $TEMP_DIR + '/cytoscape.js' } ) )
;
});
gulp.task('unstabledocspush', function(){
return gulp.src('')
.pipe( shell( replaceShellVars([
'$RM $TEMP_DIR/cytoscape.js',
'$GIT clone -b gh-pages https://github.com/cytoscape/cytoscape.js.git $TEMP_DIR/cytoscape.js',
'$CP $DOC_DIR/* $TEMP_DIR/cytoscape.js/unstable',
]) ) )
.pipe( shell( replaceShellVars([
'$GIT add -A',
'$GIT commit -a -m "updating unstable docs to $VERSION"',
'$GIT push origin'
]), { cwd: $TEMP_DIR + '/cytoscape.js' } ) )
;
});
// browserify debug build
gulp.task('browserify', ['build'], function(){
var b = browserify({ debug: true, hasExports: true });
b.add('./build/cytoscape.js', { expose: "cytoscape" });
return b.bundle()
.pipe( source('cytoscape.browserify.js') )
.pipe( gulp.dest('build') )
;
});
gulp.task('sniper', ['browserify'], shell.task( replaceShellVars([
'$NPM run sniper'
]) ));
gulp.task('npm', shell.task( replaceShellVars([
'$NPM publish .'
]) ));
gulp.task('meteor', shell.task( replaceShellVars([
'$METEOR publish'
]) ));
gulp.task('spm', shell.task( replaceShellVars([
'$SPM publish'
]) ));
gulp.task('watch', function(next){
var refWatcher = gulp.watch(paths.sources, ['testrefs','debugrefs']);
refWatcher.on('added deleted', function(event){
console.log('File ' + event.path + ' was ' + event.type + ', updating lib refs in pages...');
});
var testWatcher = gulp.watch('test/*.js', ['testlist']);
testWatcher.on('added deleted', function(event){
console.log('File ' + event.path + ' was ' + event.type + ', updating test refs in pages...');
});
var watcher = gulp.watch(paths.sources, ['concat']);
watcher.on('change', function(event){
console.log('File ' + event.path + ' was changed, building...');
});
next();
});
// http://www.jshint.com/docs/options/
gulp.task('lint', function(){
return gulp.src( paths.sources )
.pipe( jshint({
funcscope: true,
laxbreak: true,
loopfunc: true,
strict: true,
unused: 'vars',
eqnull: true,
sub: true,
shadow: true,
laxcomma: true
}) )
.pipe( jshint.reporter(jshStylish) )
;
});