Skip to content

Commit 8131509

Browse files
committed
split watch_plotly into module and run-script
1 parent f3646da commit 8131509

File tree

3 files changed

+59
-63
lines changed

3 files changed

+59
-63
lines changed

devtools/test_dashboard/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var browserify = require('browserify');
66
var ecstatic = require('ecstatic');
77
var _open = require('open');
88

9-
var makeWatchifiedBundle = require('../../tasks/watch_plotly');
9+
var makeWatchifiedBundle = require('../../tasks/util/make_watchified_bundle');
1010
var shortcutPaths = require('../../tasks/util/shortcut_paths');
1111
var constants = require('../../tasks/util/constants');
1212

tasks/util/make_watchified_bundle.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var fs = require('fs');
2+
3+
var browserify = require('browserify');
4+
var watchify = require('watchify');
5+
6+
var compressAttributes = require('./compress_attributes');
7+
var formatBundleMsg = require('./format_bundle_msg');
8+
var constants = require('./constants');
9+
10+
/**
11+
* Make a plotly.js browserify bundle function watched by watchify.
12+
*
13+
* @param {function} onFirstBundleCallback executed when first bundle is completed
14+
*
15+
*/
16+
module.exports = function makeWatchifiedBundle(onFirstBundleCallback) {
17+
var b = browserify(constants.pathToPlotlySrc, {
18+
debug: true,
19+
standalone: 'Plotly',
20+
transform: [compressAttributes],
21+
cache: {},
22+
packageCache: {},
23+
plugin: [watchify]
24+
});
25+
26+
var firstBundle = true;
27+
28+
if(firstBundle) {
29+
console.log([
30+
'***',
31+
'Building the first bundle, this should take ~10 seconds',
32+
'***\n'
33+
].join(' '));
34+
}
35+
36+
b.on('update', bundle);
37+
formatBundleMsg(b, 'plotly.js');
38+
39+
function bundle() {
40+
b.bundle(function(err) {
41+
if(err) console.error(JSON.stringify(String(err)));
42+
43+
if(firstBundle) {
44+
onFirstBundleCallback();
45+
firstBundle = false;
46+
}
47+
})
48+
.pipe(
49+
fs.createWriteStream(constants.pathToPlotlyDist)
50+
);
51+
}
52+
53+
return bundle;
54+
};

tasks/watch_plotly.js

+4-62
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,5 @@
1-
var fs = require('fs');
1+
var makeWatchifiedBundle = require('./util/make_watchified_bundle');
22

3-
var browserify = require('browserify');
4-
var watchify = require('watchify');
5-
6-
var compressAttributes = require('./util/compress_attributes');
7-
var formatBundleMsg = require('./util/format_bundle_msg');
8-
var constants = require('./util/constants');
9-
10-
/**
11-
* Make a browserify bundle function watched by watchify.
12-
*
13-
* @param {function} onFirstBundleCallback executed when first bundle is completed
14-
*
15-
*/
16-
function makeWatchifiedBundle(onFirstBundleCallback) {
17-
var b = browserify(constants.pathToPlotlySrc, {
18-
debug: true,
19-
standalone: 'Plotly',
20-
transform: [compressAttributes],
21-
cache: {},
22-
packageCache: {},
23-
plugin: [watchify]
24-
});
25-
26-
var firstBundle = true;
27-
28-
if(firstBundle) {
29-
console.log([
30-
'***',
31-
'Building the first bundle, this should take ~10 seconds',
32-
'***\n'
33-
].join(' '));
34-
}
35-
36-
b.on('update', bundle);
37-
formatBundleMsg(b, 'plotly.js');
38-
39-
function bundle() {
40-
b.bundle(function(err) {
41-
if(err) console.error(JSON.stringify(String(err)));
42-
43-
if(firstBundle) {
44-
onFirstBundleCallback();
45-
firstBundle = false;
46-
}
47-
})
48-
.pipe(
49-
fs.createWriteStream(constants.pathToPlotlyDist)
50-
);
51-
}
52-
53-
return bundle;
54-
}
55-
56-
// call watchifiedBundle if ran in CLI
57-
if(process.argv[1] === __filename) {
58-
var watchifiedBundle = makeWatchifiedBundle(function() {});
59-
watchifiedBundle();
60-
}
61-
62-
// export if required in
63-
module.exports = makeWatchifiedBundle;
3+
// make watchified bundle and run it!
4+
var watchifiedBundle = makeWatchifiedBundle(function() {});
5+
watchifiedBundle();

0 commit comments

Comments
 (0)