Skip to content

Commit ad53d65

Browse files
committed
deploy: 0b2f639
1 parent b08eac6 commit ad53d65

File tree

33 files changed

+316
-334
lines changed

33 files changed

+316
-334
lines changed

LiveDevelopment/LiveDevMultiBrowser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ define(function (require, exports, module) {
498498
doc._ensureMasterEditor();
499499
_liveDocument = _createLiveDocument(doc, doc._masterEditor);
500500
_server.add(_liveDocument);
501+
_server.addVirtualContentAtPath(
502+
`${_liveDocument.doc.file.parentPath}${LiveDevProtocol.LIVE_DEV_REMOTE_SCRIPTS_FILE_NAME}`,
503+
_protocol.getRemoteScriptContents());
501504
}
502505

503506

LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@
3939
define(function (require, exports, module) {
4040

4141

42-
var EventDispatcher = require("utils/EventDispatcher");
42+
const EventDispatcher = require("utils/EventDispatcher");
4343

4444
// Text of the script we'll inject into the browser that handles protocol requests.
45-
var LiveDevProtocolRemote = require("text!LiveDevelopment/BrowserScripts/LiveDevProtocolRemote.js"),
45+
const LiveDevProtocolRemote = require("text!LiveDevelopment/BrowserScripts/LiveDevProtocolRemote.js"),
4646
DocumentObserver = require("text!LiveDevelopment/BrowserScripts/DocumentObserver.js"),
4747
RemoteFunctions = require("text!LiveDevelopment/BrowserScripts/RemoteFunctions.js"),
4848
EditorManager = require("editor/EditorManager"),
4949
LiveDevMultiBrowser = require("LiveDevelopment/LiveDevMultiBrowser"),
5050
HTMLInstrumentation = require("LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation"),
5151
FileViewController = require("project/FileViewController");
5252

53+
const LIVE_DEV_REMOTE_SCRIPTS_FILE_NAME = "phoenix_live_preview_scripts_instrumented_345Tt96G4.js";
54+
5355
/**
5456
* @private
5557
* Active connections.
@@ -232,13 +234,13 @@ define(function (require, exports, module) {
232234
* Includes the <script> tags.
233235
* @return {string}
234236
*/
235-
function getRemoteFunctionsScript() {
236-
var script = "";
237+
function _getRemoteFunctionsScript() {
238+
let script = "";
237239
// Inject DocumentObserver into the browser (tracks related documents)
238240
script += DocumentObserver;
239241
// Inject remote functions into the browser.
240-
script += "window._LD=(" + RemoteFunctions + "(" + JSON.stringify(LiveDevMultiBrowser.config) + "))";
241-
return "<script>\n" + script + "</script>\n";
242+
script += "\nwindow._LD=(" + RemoteFunctions + "(" + JSON.stringify(LiveDevMultiBrowser.config) + "))";
243+
return "\n" + script + "\n";
242244
}
243245

244246
/**
@@ -247,14 +249,25 @@ define(function (require, exports, module) {
247249
* This script will also include the script required by the transport, if any.
248250
* @return {string}
249251
*/
250-
function getRemoteScript() {
251-
var transportScript = _transport.getRemoteScript() || "";
252-
var remoteFunctionsScript = getRemoteFunctionsScript() || "";
252+
function getRemoteScriptContents() {
253+
const transportScript = _transport.getRemoteScript() || "";
254+
const remoteFunctionsScript = _getRemoteFunctionsScript() || "";
253255
return transportScript +
254-
"<script>\n" + LiveDevProtocolRemote + "</script>\n" +
256+
"\n" + LiveDevProtocolRemote + "\n" +
255257
remoteFunctionsScript;
256258
}
257259

260+
/**
261+
* Returns a script that should be injected into the HTML that's launched in the
262+
* browser in order to handle protocol requests. Includes the <script> tags.
263+
* This script will also include the script required by the transport, if any.
264+
* @return {string}
265+
*/
266+
function getRemoteScript() {
267+
// give a wrong random file name that wont have a possibility of an actual file name
268+
return `\n\t\t<script src="${LIVE_DEV_REMOTE_SCRIPTS_FILE_NAME}"></script>`;
269+
}
270+
258271
/**
259272
* Protocol method. Evaluates the given script in the browser (in global context), and returns a promise
260273
* that will be fulfilled with the result of the script, if any.
@@ -374,6 +387,7 @@ define(function (require, exports, module) {
374387
// public API
375388
exports.setTransport = setTransport;
376389
exports.getRemoteScript = getRemoteScript;
390+
exports.getRemoteScriptContents = getRemoteScriptContents;
377391
exports.evaluate = evaluate;
378392
exports.setStylesheetText = setStylesheetText;
379393
exports.getStylesheetText = getStylesheetText;
@@ -382,4 +396,5 @@ define(function (require, exports, module) {
382396
exports.close = close;
383397
exports.getConnectionIds = getConnectionIds;
384398
exports.closeAllConnections = closeAllConnections;
399+
exports.LIVE_DEV_REMOTE_SCRIPTS_FILE_NAME = LIVE_DEV_REMOTE_SCRIPTS_FILE_NAME;
385400
});

LiveDevelopment/MultiBrowserImpl/transports/ServiceWorkerTransport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ define(function (require, exports, module) {
6767
* @return {string}
6868
*/
6969
function getRemoteScript() {
70-
return "<script>\n" +
70+
return "\n" +
7171
`window.LIVE_PREVIEW_BROADCAST_CHANNEL_ID = "${BROADCAST_CHANNEL_ID}";\n` +
7272
`window.LIVE_PREVIEW_DEBIG_ENABLED = ${window.loggingOptions.logLivePreview};\n` +
7373
ServiceWorkerTransportRemote +
74-
"</script>\n";
74+
"\n";
7575
}
7676

7777
EventDispatcher.makeEventDispatcher(exports);

LiveDevelopment/Servers/BaseServer.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ define(function (require, exports, module) {
4040
this._root = config.root; // ProjectManager.getProjectRoot().fullPath
4141
this._pathResolver = config.pathResolver; // ProjectManager.makeProjectRelativeIfPossible(doc.file.fullPath)
4242
this._liveDocuments = {};
43+
this._virtualServingDocuments = {};
4344
}
4445

4546
/**
@@ -176,6 +177,15 @@ define(function (require, exports, module) {
176177
this._liveDocuments[key] = liveDocument;
177178
};
178179

180+
/**
181+
* This will add the given text to be served when the path is hit in server. You can use this to either
182+
* serve a file that doesn't exist in project, or to override a given path to the contents you give.
183+
*/
184+
BaseServer.prototype.addVirtualContentAtPath = function (fullPath, docText) {
185+
let key = this._documentKey(fullPath);
186+
this._virtualServingDocuments[key] = docText;
187+
};
188+
179189
/**
180190
* Removes a live document from the server
181191
* @param {Object} liveDocument
@@ -192,6 +202,16 @@ define(function (require, exports, module) {
192202
}
193203
};
194204

205+
/**
206+
* removes path added by addVirtualContentAtPath()
207+
*/
208+
BaseServer.prototype.removeVirtualContentAtPath = function (fullPath) {
209+
let key = this._documentKey(fullPath);
210+
if(this._virtualServingDocuments[key]) {
211+
delete this._virtualServingDocuments[key];
212+
}
213+
};
214+
195215
/**
196216
* Lookup a live document using it's full path key
197217
* @param {string} path Absolute path to covert to a URL
@@ -207,6 +227,7 @@ define(function (require, exports, module) {
207227
*/
208228
BaseServer.prototype.clear = function () {
209229
this._liveDocuments = {};
230+
this._virtualServingDocuments = {};
210231
};
211232

212233
/**

assets/default-project/en.zip

0 Bytes
Binary file not shown.

assets/sample-projects/HTML5.zip

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

assets/sample-projects/explore.zip

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)