|
1 | | -var http = require('http'); |
2 | | -var ecstatic = require('ecstatic'); |
3 | | -var browserify = require('browserify'); |
4 | | -var open = require('open'); |
5 | 1 | var fs = require('fs'); |
6 | | -var watchify = require('watchify'); |
| 2 | +var http = require('http'); |
7 | 3 | var path = require('path'); |
8 | | -var outpipe = require('outpipe'); |
9 | | -var outfile = path.join(__dirname, '../shelly/plotlyjs/static/plotlyjs/build/plotlyjs-bundle.js'); |
10 | | - |
11 | | -var testFile = './test'; |
12 | | - |
13 | | -switch(process.argv[2]) { |
14 | | - case 'geo': |
15 | | - testFile = './test-geo'; |
16 | | - break; |
17 | | - case '2d': |
18 | | - testFile = './test-2d'; |
19 | | - break; |
20 | | -} |
21 | | - |
22 | | -console.log('using ' + testFile); |
23 | | - |
24 | | -var b = browserify(path.join(__dirname, '../shelly/plotlyjs/static/plotlyjs/src/plotly.js'), { |
25 | | - debug: true, |
26 | | - verbose: true, |
27 | | - standalone: 'Plotly', |
28 | | - transform: path.join(__dirname, '../shelly/plotlyjs/static/plotlyjs/compress_attributes.js'), |
29 | | - cache: {}, |
30 | | - packageCache: {} |
31 | | -}); |
32 | | - |
33 | | - |
34 | | -var w = watchify(b); |
35 | 4 |
|
36 | | -var bytes, time; |
37 | | -w.on('bytes', function (b) { bytes = b }); |
38 | | -w.on('time', function (t) { time = t }); |
39 | | - |
40 | | -w.on('update', bundle); |
41 | | -bundle(); |
| 5 | +var browserify = require('browserify'); |
| 6 | +var ecstatic = require('ecstatic'); |
| 7 | +var _open = require('open'); |
42 | 8 |
|
43 | | -var firstBundle = true; |
| 9 | +var makeWatchifiedBundle = require('../../tasks/watch_plotly'); |
| 10 | +var shortcutPaths = require('../../tasks/util/shortcut_paths'); |
| 11 | +var constants = require('../../tasks/util/constants'); |
44 | 12 |
|
45 | | -function bundle () { |
46 | | - var didError = false; |
47 | | - var outStream = process.platform === 'win32' |
48 | | - ? fs.createWriteStream(outfile) |
49 | | - : outpipe(outfile); |
50 | 13 |
|
51 | | - var wb = w.bundle(); |
52 | | - wb.on('error', function (err) { |
53 | | - console.error(String(err)); |
54 | | - didError = true; |
55 | | - outStream.end('console.error('+JSON.stringify(String(err))+');'); |
56 | | - }); |
57 | | - wb.pipe(outStream); |
| 14 | +// TODO make this an optional argument |
| 15 | +var PORT = '8080'; |
58 | 16 |
|
59 | | - outStream.on('error', function (err) { |
60 | | - console.error(err); |
61 | | - }); |
62 | | - outStream.on('close', function () { |
63 | | - if (!didError) { |
64 | | - console.error(bytes + ' bytes written to ' + outfile |
65 | | - + ' (' + (time / 1000).toFixed(2) + ' seconds)' |
66 | | - ); |
67 | | - if(firstBundle) { |
68 | | - open('http://localhost:8080/test-dashboard'); |
69 | | - firstBundle = false; |
70 | | - } |
71 | | - } |
72 | | - }); |
| 17 | +var testFile; |
| 18 | +switch(process.argv[2]) { |
| 19 | + case 'geo': |
| 20 | + testFile = './test-geo'; |
| 21 | + break; |
| 22 | + case '2d': |
| 23 | + testFile = './test-2d'; |
| 24 | + break; |
| 25 | + default: |
| 26 | + testFile = './test-3d'; |
73 | 27 | } |
74 | 28 |
|
75 | | -////// build the test examples |
| 29 | +console.log('Using ' + testFile); |
| 30 | +console.log('Listening on :' + PORT + '\n'); |
76 | 31 |
|
77 | | -fs.unlink('./test-bundle.js', function(error) { |
78 | | - browserify({ |
| 32 | +// watch plotly.js |
| 33 | +var watchifiedBundle = makeWatchifiedBundle(function onFirstBundleCallback() { |
| 34 | + _open('http://localhost:' + PORT + '/devtools/test_dashboard'); |
| 35 | +}); |
| 36 | +watchifiedBundle(); |
| 37 | + |
| 38 | +// build the test examples |
| 39 | +fs.unlink(constants.pathToTestDashboardBundle, function() { |
| 40 | + browserify(path.join(__dirname, testFile), { |
79 | 41 | debug: true, |
80 | | - verbose: true |
81 | | - }).add(testFile).bundle() |
82 | | - .pipe(fs.createWriteStream('test-bundle.js')); |
| 42 | + transform: [shortcutPaths] |
| 43 | + }) |
| 44 | + .bundle(function(err) { |
| 45 | + if(err) throw err; |
| 46 | + }) |
| 47 | + .pipe(fs.createWriteStream(constants.pathToTestDashboardBundle)); |
83 | 48 | }); |
84 | 49 |
|
| 50 | +// boot up server |
85 | 51 | http.createServer( |
86 | | - ecstatic({ root: '../.' }) |
87 | | -).listen(8080); |
88 | | - |
89 | | -console.log('Listening on :8080'); |
| 52 | + ecstatic({ root: constants.pathToRoot }) |
| 53 | +).listen(PORT); |
0 commit comments