Add browser reload on file change/rebuild

Add browser reload on file change/rebuild
This commit is contained in:
StevenJNPearce 2018-09-16 02:26:37 +02:00 committed by Pascal Precht
parent fef793c5ef
commit 3aad35209a
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
5 changed files with 78 additions and 10 deletions

View File

@ -0,0 +1,6 @@
const ws = new WebSocket(`ws://${location.hostname}:${location.port}`);
ws.addEventListener('message', (evt) => {
if(evt.data === 'outputDone') {
location.reload(true);
}
});

View File

@ -311,6 +311,7 @@ class CodeGenerator {
code += self.generateCommunicationInitialization(true); code += self.generateCommunicationInitialization(true);
code += self.generateStorageInitialization(true); code += self.generateStorageInitialization(true);
code += self.generateNamesInitialization(true); code += self.generateNamesInitialization(true);
code += self.getReloadPageCode();
next(); next();
}, },
@ -324,6 +325,10 @@ class CodeGenerator {
}); });
} }
getReloadPageCode() {
return this.env === 'development' ? fs.readFileSync(require('path').join(__dirname,'/code/reload-on-change.js'), 'utf8') : '';
}
getEmbarkJsProviderCode() { getEmbarkJsProviderCode() {
return this.plugins.getPluginsFor('embarkjsCode').reduce((code, plugin) => ( return this.plugins.getPluginsFor('embarkjsCode').reduce((code, plugin) => (
code += plugin.embarkjs_code.join('\n') code += plugin.embarkjs_code.join('\n')

View File

@ -4,6 +4,7 @@ const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host')
const express = require('express'); const express = require('express');
const fs = require('../../core/fs'); const fs = require('../../core/fs');
require('http-shutdown').extend(); require('http-shutdown').extend();
const webSocket = require('ws');
class Server { class Server {
constructor(options) { constructor(options) {
@ -32,6 +33,15 @@ class Server {
this.app.use(main); this.app.use(main);
this.app.use('/coverage', coverage); this.app.use('/coverage', coverage);
this.app.use(coverageStyle); this.app.use(coverageStyle);
//this.wss = new webSocket.Server({server: this.server});
//this.events.on('outputDone', () => {
// this.wss.clients.forEach((ws) => {
// if (ws.readyState === webSocket.OPEN) {
// ws.send('outputDone');
// }
// });
//});
const self = this; const self = this;

View File

@ -25,4 +25,12 @@
</svg> </svg>
<h1 class="loading-msg"><%- buildingMsg %></h1> <h1 class="loading-msg"><%- buildingMsg %></h1>
</body> </body>
<script>
const ws = new WebSocket(`ws://${location.hostname}:${location.port}`);
ws.addEventListener('message', (evt) => {
if(evt.data === 'outputDone') {
location.reload(true);
}
});
</script>
</html> </html>

59
npm-shrinkwrap.json generated
View File

@ -3957,11 +3957,13 @@
}, },
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true "bundled": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -3979,11 +3981,13 @@
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true "bundled": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true "bundled": true,
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -4110,17 +4114,20 @@
"minimatch": { "minimatch": {
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
}, },
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true "bundled": true,
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -4137,6 +4144,7 @@
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -4220,6 +4228,7 @@
"once": { "once": {
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -8741,7 +8750,7 @@
"serve-static": { "serve-static": {
"version": "1.13.2", "version": "1.13.2",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz",
"integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==", "integrity": "sha1-CV6Ecv1bRiN9tQzkhqQ/S4bGzsE=",
"requires": { "requires": {
"encodeurl": "~1.0.2", "encodeurl": "~1.0.2",
"escape-html": "~1.0.3", "escape-html": "~1.0.3",
@ -9708,6 +9717,18 @@
"servify": "^0.1.12", "servify": "^0.1.12",
"ws": "^3.0.0", "ws": "^3.0.0",
"xhr-request-promise": "^0.1.2" "xhr-request-promise": "^0.1.2"
},
"dependencies": {
"ws": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz",
"integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==",
"requires": {
"async-limiter": "~1.0.0",
"safe-buffer": "~5.1.0",
"ultron": "~1.1.0"
}
}
} }
} }
} }
@ -10851,6 +10872,18 @@
"servify": "^0.1.12", "servify": "^0.1.12",
"ws": "^3.0.0", "ws": "^3.0.0",
"xhr-request-promise": "^0.1.2" "xhr-request-promise": "^0.1.2"
},
"dependencies": {
"ws": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz",
"integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==",
"requires": {
"async-limiter": "~1.0.0",
"safe-buffer": "~5.1.0",
"ultron": "~1.1.0"
}
}
} }
}, },
"underscore": { "underscore": {
@ -11069,13 +11102,19 @@
} }
}, },
"ws": { "ws": {
"version": "3.3.3", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-3.0.0.tgz",
"integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", "integrity": "sha1-mN2wAFbIOQy3Ued4h4hJf5kQO2w=",
"requires": { "requires": {
"async-limiter": "~1.0.0", "safe-buffer": "~5.0.1",
"safe-buffer": "~5.1.0",
"ultron": "~1.1.0" "ultron": "~1.1.0"
},
"dependencies": {
"safe-buffer": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.0.1.tgz",
"integrity": "sha1-0mPKVGls2KMGtcplUekt5XkY++c="
}
} }
}, },
"xhr": { "xhr": {