Skip to content

Commit 1d6f218

Browse files
committed
modif watch script to watch_plotly,
- run with `npm run watch` - supports 'require' (for test_dashboard)
1 parent a509445 commit 1d6f218

File tree

4 files changed

+102
-55
lines changed

4 files changed

+102
-55
lines changed

tasks/util/format_bundle_msg.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var prettySize = require('prettysize');
2+
3+
4+
/**
5+
* Format the on-bundle output message
6+
*
7+
* @param {browserify instance} b
8+
* @param {string} bundleName name of the bundle built
9+
*/
10+
module.exports = function formatBundleMsg(b, bundleName) {
11+
var msgParts = [
12+
bundleName, ':', '',
13+
'written', 'in', '', 'sec',
14+
'[', '', '', '', ']'
15+
];
16+
17+
b.on('bytes', function(bytes) {
18+
msgParts[2] = prettySize(bytes, true);
19+
});
20+
21+
b.on('time', function(time) {
22+
msgParts[5] = (time / 1000).toFixed(2);
23+
});
24+
25+
b.on('log', function() {
26+
var date = new Date();
27+
28+
// get locale date
29+
msgParts[msgParts.length-4] = date.toLocaleDateString();
30+
31+
// get locale time
32+
msgParts[msgParts.length-3] = date.toLocaleTimeString();
33+
34+
// get time zone code
35+
msgParts[msgParts.length-2] = date.toString().match(/\(([A-Za-z\s].*)\)/)[1];
36+
37+
console.log(msgParts.join(' '));
38+
});
39+
};

tasks/util/set_watchify_output.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

tasks/watch.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

tasks/watch_plotly.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var fs = require('fs');
2+
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;

0 commit comments

Comments
 (0)