Mercurial > piecrust2
annotate piecrust/resources/server/piecrust-debug-info.js @ 1188:a7c43131d871
bake: Fix file write flushing problem with Python 3.8+
Writing the cache files fails in Python 3.8 because it looks like flushing
behaviour has changed. We need to explicitly flush. And even then, in very
rare occurrences, it looks like it can still run into racing conditions,
so we do a very hacky and ugly "retry" loop when fetching cached data :(
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 15 Jun 2021 22:36:23 -0700 |
parents | 8d5b8a3dca02 |
children |
rev | line source |
---|---|
552
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
1 /////////////////////////////////////////////////////////////////////////////// |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
2 // PieCrust debug info and features |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
3 // |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
4 // This stuff is injected by PieCrust's preview server and shouldn't show up |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
5 // in production. It should all be self-contained in this one file. |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
6 /////////////////////////////////////////////////////////////////////////////// |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
7 |
219
d7a548ebcd58
serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 var eventSource = new EventSource("/__piecrust_debug/pipeline_status"); |
d7a548ebcd58
serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 |
552
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
10 if (eventSource != null) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
11 eventSource.onerror = function(e) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
12 console.log("Error with SSE, closing.", e); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
13 eventSource.close(); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
14 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
15 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
16 eventSource.addEventListener('ping', function(e) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
17 }); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
18 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
19 eventSource.addEventListener('pipeline_success', function(e) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
20 var obj = JSON.parse(e.data); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
21 console.log("Got pipeline success", obj); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
22 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
23 // Check which assets were processed, and whether they are referenced |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
24 // by the current page for the usual use-cases. |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
25 for (var i = 0; i < obj.assets.length; ++i) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
26 a = obj.assets[i]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
27 if (assetReloader.reloadAsset(a)) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
28 notification.flashSuccess("Reloaded " + a); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
29 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
30 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
31 }); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
32 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
33 eventSource.addEventListener('pipeline_error', function(e) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
34 var obj = JSON.parse(e.data); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
35 console.log("Got pipeline error", obj); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
36 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
37 var outer = document.createElement('div'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
38 outer.style = 'padding: 1em;'; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
39 for (var i = 0; i < obj.assets.length; ++i) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
40 var item = obj.assets[i]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
41 var markup = ( |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
42 '<p>Error processing: <span style="font-family: monospace;">' + |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
43 item.path + '</span></p>\n' + |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
44 '<ul>'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
45 for (var j = 0; j < item.errors.length; ++j) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
46 markup += ( |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
47 '<li style="font-family: monospace;">' + |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
48 item.errors[j] + |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
49 '</li>\n'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
50 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
51 markup += '</ul>\n'; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
52 var entry = document.createElement('div'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
53 entry.innerHTML = markup; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
54 outer.appendChild(entry); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
55 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
56 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
57 var placeholder = document.getElementById('piecrust-debug-info-pipeline-status'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
58 placeholder.appendChild(outer); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
59 }); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
60 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
61 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
62 /////////////////////////////////////////////////////////////////////////////// |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
63 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
64 NotificationArea = function() { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
65 var area = document.createElement('div'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
66 area.id = 'piecrust-debug-notifications'; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
67 area.className = 'piecrust-debug-notifications'; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
68 document.querySelector('body').appendChild(area); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
69 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
70 this._area = area; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
71 this._lastId = 0; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
72 }; |
219
d7a548ebcd58
serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
73 |
552
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
74 NotificationArea.prototype.flashSuccess = function(msg) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
75 this.flashMessage(msg, 'success'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
76 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
77 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
78 NotificationArea.prototype.flashError = function(msg) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
79 this.flashMessage(msg, 'error'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
80 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
81 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
82 NotificationArea.prototype.flashMessage = function(msg, css_class) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
83 this._lastId += 1; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
84 var thisId = this._lastId; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
85 this._area.insertAdjacentHTML( |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
86 'afterbegin', |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
87 '<div id="piecrust-debug-notification-msg' + thisId + '" ' + |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
88 'class="piecrust-debug-notification ' + |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
89 'piecrust-debug-notification-' + css_class + '">' + |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
90 msg + '</div>'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
91 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
92 window.setTimeout(this._discardNotification, 2000, thisId); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
93 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
94 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
95 NotificationArea.prototype._discardNotification = function(noteId) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
96 var added = document.querySelector('#piecrust-debug-notification-msg' + noteId); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
97 added.remove(); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
98 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
99 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
100 /////////////////////////////////////////////////////////////////////////////// |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
101 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
102 function _get_extension(name) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
103 var ext = null; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
104 var dotIdx = name.lastIndexOf('.'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
105 if (dotIdx > 0) |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
106 ext = name.substr(dotIdx + 1); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
107 return ext; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
108 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
109 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
110 function _get_basename(name) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
111 var filename = name; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
112 var slashIdx = name.lastIndexOf('/'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
113 if (slashIdx > 0) |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
114 filename = name.substr(slashIdx + 1); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
115 return filename; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
116 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
117 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
118 var _regex_cache_bust = /\?\d+$/; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
119 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
120 function _is_path_match(path1, path2) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
121 path1 = path1.replace(_regex_cache_bust, ''); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
122 console.log("Matching:", path1, path2) |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
123 return path1.endsWith(path2); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
124 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
125 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
126 function _add_cache_bust(path, cache_bust) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
127 path = path.replace(_regex_cache_bust, ''); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
128 return path + cache_bust; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
129 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
130 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
131 /////////////////////////////////////////////////////////////////////////////// |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
132 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
133 AssetReloader = function() { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
134 this._imgExts = ['jpg', 'jpeg', 'png', 'gif', 'svg']; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
135 this._imgReloader = new ImageReloader(); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
136 this._cssReloader = new CssReloader(); |
219
d7a548ebcd58
serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
137 }; |
d7a548ebcd58
serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
138 |
552
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
139 AssetReloader.prototype.reloadAsset = function(name) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
140 var ext = _get_extension(name); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
141 var filename = _get_basename(name); |
219
d7a548ebcd58
serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
142 |
552
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
143 if (ext == 'css') { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
144 return this._cssReloader.reloadStylesheet(filename); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
145 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
146 if (this._imgExts.indexOf(ext) >= 0) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
147 return this._imgReloader.reloadImage(filename); |
219
d7a548ebcd58
serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
148 } |
d7a548ebcd58
serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
149 |
552
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
150 console.log("Don't know how to reload", filename); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
151 return false; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
152 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
153 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
154 /////////////////////////////////////////////////////////////////////////////// |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
155 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
156 CssReloader = function() { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
157 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
158 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
159 CssReloader.prototype.reloadStylesheet = function(name) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
160 var result = false; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
161 var sheets = document.styleSheets; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
162 var cacheBust = '?' + new Date().getTime(); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
163 for (var i = 0; i < sheets.length; ++i) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
164 var sheet = sheets[i]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
165 if (_is_path_match(sheet.href, name)) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
166 sheet.ownerNode.href = _add_cache_bust(sheet.href, cacheBust); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
167 result = true; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
168 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
169 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
170 return result; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
171 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
172 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
173 /////////////////////////////////////////////////////////////////////////////// |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
174 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
175 ImageReloader = function() { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
176 this._imgStyles = [ |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
177 { selector: 'background', styleNames: ['backgroundImage'] }, |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
178 ]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
179 this._regexCssUrl = /\burl\s*\(([^)]+)\)/; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
180 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
181 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
182 ImageReloader.prototype.reloadImage = function(name) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
183 var result = false; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
184 var imgs = document.images; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
185 var cacheBust = '?' + new Date().getTime(); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
186 for (var i = 0; i < imgs.length; ++i) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
187 var img = imgs[i]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
188 if (_is_path_match(img.src, name)) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
189 img.src = _add_cache_bust(img.src, cacheBust); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
190 result = true; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
191 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
192 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
193 for (var i = 0; i < this._imgStyles.length; ++i) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
194 var imgInfo = this._imgStyles[i]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
195 var domImgs = document.querySelectorAll( |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
196 "[style*=" + imgInfo.selector + "]"); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
197 for (var j = 0; j < domImgs.length; ++j) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
198 var img = domImgs[j]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
199 result |= this._reloadStyleImage(img.style, imgInfo.styleNames, |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
200 name, cacheBust); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
201 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
202 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
203 for (var i = 0; i < document.styleSheets.length; ++i) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
204 var styleSheet = document.styleSheets[i]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
205 result |= this._reloadStylesheetImage(styleSheet, name, cacheBust); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
206 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
207 return result; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
208 }; |
219
d7a548ebcd58
serve: Add server sent events for showing pipeline errors in the debug window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
209 |
552
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
210 ImageReloader.prototype._reloadStyleImage = function(style, styleNames, path, |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
211 cacheBust) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
212 var result = false; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
213 for (var i = 0; i < styleNames.length; ++i) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
214 var value = style[styleNames[i]]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
215 if ((typeof value) == 'string') { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
216 m = this._regexCssUrl.exec(value); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
217 if (m != null) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
218 var m_clean = m[1].replace(/^['"]/, ''); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
219 m_clean = m_clean.replace(/['"]$/, ''); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
220 if (_is_path_match(m_clean, path)) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
221 m_clean = _add_cache_bust(m_clean, cacheBust); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
222 style[styleNames[i]] = 'url("' + m_clean + '")'; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
223 result = true; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
224 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
225 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
226 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
227 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
228 return result; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
229 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
230 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
231 ImageReloader.prototype._reloadStylesheetImage = function(styleSheet, path, |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
232 cacheBust) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
233 try { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
234 var rules = styleSheet.cssRules; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
235 } catch (e) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
236 // Things like remote CSS stylesheets (e.g. a Google Fonts ones) |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
237 // will triger a SecurityException here, so just ignore that. |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
238 return; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
239 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
240 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
241 var result = false; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
242 for (var i = 0; i < rules.length; ++i) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
243 var rule = rules[i]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
244 switch (rule.type) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
245 case CSSRule.IMPORT_RULE: |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
246 result |= this._reloadStylesheetImage(rule.styleSheet, path, |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
247 cacheBust); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
248 break; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
249 case CSSRule.MEDIA_RULE: |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
250 result |= this._reloadStylesheetImage(rule, path, cacheBust); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
251 break; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
252 case CSSRule.STYLE_RULE: |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
253 for (var j = 0; j < this._imgStyles.length; ++j) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
254 var imgInfo = this._imgStyles[j]; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
255 result |= this._reloadStyleImage( |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
256 rule.style, imgInfo.styleNames, path, cacheBust); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
257 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
258 break; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
259 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
260 } |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
261 return result; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
262 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
263 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
264 /////////////////////////////////////////////////////////////////////////////// |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
265 |
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
266 function toggleDebugInfo() { |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
267 var info = document.querySelector('.piecrust-debug-info'); |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
268 if (info.classList.contains('piecrust-debug-info-unloaded')) { |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
269 loadDebugInfo(); |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
270 info.classList.remove('piecrust-debug-info-unloaded'); |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
271 } |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
272 if (this.innerHTML == '[+]') { |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
273 this.innerHTML = '[-]'; |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
274 info.style = ""; |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
275 } else { |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
276 this.innerHTML = '[+]'; |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
277 info.style = "display: none;"; |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
278 } |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
279 } |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
280 |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
281 function loadDebugInfo() { |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
282 var xmlHttp = new XMLHttpRequest(); |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
283 |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
284 xmlHttp.onreadystatechange = function() { |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
285 if (xmlHttp.readyState == XMLHttpRequest.DONE) { |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
286 var info = document.querySelector('.piecrust-debug-info'); |
1082
8d5b8a3dca02
serve: Show debug info, report errors when debug info isn't available.
Ludovic Chabant <ludovic@chabant.com>
parents:
556
diff
changeset
|
287 if(xmlHttp.status < 500) { |
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
288 info.innerHTML = xmlHttp.responseText; |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
289 } |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
290 else { |
1082
8d5b8a3dca02
serve: Show debug info, report errors when debug info isn't available.
Ludovic Chabant <ludovic@chabant.com>
parents:
556
diff
changeset
|
291 console.log(xmlHttp); |
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
292 info.innerHTML = "Unknown error."; |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
293 } |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
294 } |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
295 } |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
296 |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
297 var pageUrl = window.location.pathname; |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
298 xmlHttp.open("GET", "/__piecrust_debug/debug_info?page=" + pageUrl, true); |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
299 xmlHttp.send(); |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
300 } |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
301 |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
302 /////////////////////////////////////////////////////////////////////////////// |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
303 |
552
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
304 var notification = new NotificationArea(); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
305 var assetReloader = new AssetReloader(); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
306 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
307 window.onload = function() { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
308 var cacheBust = '?' + new Date().getTime(); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
309 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
310 var style = document.createElement('link'); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
311 style.rel = 'stylesheet'; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
312 style.type = 'text/css'; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
313 style.href = '/__piecrust_static/piecrust-debug-info.css' + cacheBust; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
314 document.head.appendChild(style); |
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
315 |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
316 var expander = document.querySelector('.piecrust-debug-expander'); |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
552
diff
changeset
|
317 expander.onclick = toggleDebugInfo; |
552
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
318 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
319 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
320 |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
321 window.onbeforeunload = function(e) { |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
322 if (eventSource != null) |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
323 eventSource.close(); |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
324 }; |
9612cfc6455a
serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents:
219
diff
changeset
|
325 |