a zip code crypto-currency system good for red ONLY

live-reload.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var logger_diagnostics_1 = require("../logger/logger-diagnostics");
  4. var path = require("path");
  5. var tinylr = require("tiny-lr");
  6. var events = require("../util/events");
  7. function createLiveReloadServer(config) {
  8. var liveReloadServer = tinylr();
  9. liveReloadServer.listen(config.liveReloadPort, config.host);
  10. function fileChange(changedFiles) {
  11. // only do a live reload if there are no diagnostics
  12. // the notification server takes care of showing diagnostics
  13. if (!logger_diagnostics_1.hasDiagnostics(config.buildDir)) {
  14. liveReloadServer.changed({
  15. body: {
  16. files: changedFiles.map(function (changedFile) { return '/' + path.relative(config.wwwDir, changedFile.filePath); })
  17. }
  18. });
  19. }
  20. }
  21. events.on(events.EventType.FileChange, fileChange);
  22. events.on(events.EventType.ReloadApp, function () {
  23. fileChange([{ event: 'change', ext: '.html', filePath: 'index.html' }]);
  24. });
  25. }
  26. exports.createLiveReloadServer = createLiveReloadServer;
  27. function injectLiveReloadScript(content, host, port) {
  28. var contentStr = content.toString();
  29. var liveReloadScript = getLiveReloadScript(host, port);
  30. if (contentStr.indexOf('/livereload.js') > -1) {
  31. // already added script
  32. return content;
  33. }
  34. var match = contentStr.match(/<\/body>(?![\s\S]*<\/body>)/i);
  35. if (!match) {
  36. match = contentStr.match(/<\/html>(?![\s\S]*<\/html>)/i);
  37. }
  38. if (match) {
  39. contentStr = contentStr.replace(match[0], liveReloadScript + "\n" + match[0]);
  40. }
  41. else {
  42. contentStr += liveReloadScript;
  43. }
  44. return contentStr;
  45. }
  46. exports.injectLiveReloadScript = injectLiveReloadScript;
  47. function getLiveReloadScript(host, port) {
  48. var src = "//" + host + ":" + port + "/livereload.js?snipver=1";
  49. return " <!-- Ionic Dev Server: Injected LiveReload Script -->\n <script src=\"" + src + "\" async=\"\" defer=\"\"></script>";
  50. }