Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 294cad0

Browse files
committed
DRY: use watchified bundle util in test dashboard server
1 parent f662025 commit 294cad0

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

devtools/test_dashboard/server.js

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ var http = require('http');
44
var ecstatic = require('ecstatic');
55
var open = require('open');
66
var browserify = require('browserify');
7-
var watchify = require('watchify');
87

98
var constants = require('../../tasks/util/constants');
10-
var compress = require('../../tasks/util/compress_attributes');
9+
var makeWatchifiedBundle = require('../../tasks/util/watchified_bundle');
1110
var shortcutPaths = require('../../tasks/util/shortcut_paths');
1211

1312
var PORT = process.argv[2] || 3000;
@@ -20,31 +19,22 @@ var server = http.createServer(ecstatic({
2019
gzip: true
2120
}));
2221

23-
// Bundle development source code
24-
var b = browserify(constants.pathToPlotlyIndex, {
25-
debug: true,
26-
standalone: 'Plotly',
27-
transform: [compress],
28-
cache: {},
29-
packageCache: {},
30-
plugin: [watchify]
22+
// Make watchified bundle for plotly.js
23+
var bundlePlotly = makeWatchifiedBundle(function() {
24+
// open up browser window on first bundle callback
25+
open('http://localhost:' + PORT + '/devtools/test_dashboard');
3126
});
32-
b.on('update', bundlePlotly);
3327

3428
// Bundle devtools code
3529
var devtoolsPath = path.join(constants.pathToRoot, 'devtools/test_dashboard');
3630
var devtools = browserify(path.join(devtoolsPath, 'devtools.js'), {
3731
transform: [shortcutPaths]
3832
});
3933

40-
var firstBundle = true;
41-
42-
4334
// Start the server up!
4435
server.listen(PORT);
4536

4637
// Build and bundle all the things!
47-
console.log('Building the first bundle. This might take a little while...\n');
4838
getMockFiles()
4939
.then(readFiles)
5040
.then(createMocksList)
@@ -140,21 +130,6 @@ function writeFilePromise(path, contents) {
140130
});
141131
}
142132

143-
function bundlePlotly() {
144-
b.bundle(function(err) {
145-
if(err) {
146-
console.error('Error while bundling!', JSON.stringify(String(err)));
147-
} else {
148-
console.log('Bundle updated at ' + new Date().toLocaleTimeString());
149-
}
150-
151-
if(firstBundle) {
152-
open('http://localhost:' + PORT + '/devtools/test_dashboard');
153-
firstBundle = false;
154-
}
155-
}).pipe(fs.createWriteStream(constants.pathToPlotlyBuild));
156-
}
157-
158133
function bundleDevtools() {
159134
return new Promise(function(resolve, reject) {
160135
devtools.bundle(function(err) {

0 commit comments

Comments
 (0)