in src/server/server.js [301:350]
SimulationServer.prototype._streamSimHostHtml = function (request, response) {
// If we haven't ever prepared, do so before we try to generate sim-host, so we know our list of plugins is up-to-date.
// Then create sim-host.js (if it is out-of-date) so it is ready when it is requested.
var project = this._project;
var config = this._simulatorProxy.config;
project.prepare()
.then(function () {
var simulationFilePath = config.simulationFilePath;
return this._simulationFiles.createSimHostJsFile(project, simulationFilePath);
}.bind(this))
.then(function () {
// Inject references to simulation HTML files
var panelsHtmlBasename = pluginSimulationFiles['sim-host']['panels'];
var dialogsHtmlBasename = pluginSimulationFiles['sim-host']['dialogs'];
var panelsHtml = [];
var dialogsHtml = [];
var pluginList = project.getPlugins();
Object.keys(pluginList).forEach(function (pluginId) {
var pluginPath = pluginList[pluginId];
if (pluginPath) {
var lang = config.lang;
var panelsHtmlFile = path.join(pluginPath, panelsHtmlBasename);
if (fs.existsSync(panelsHtmlFile)) {
panelsHtml.push(processPluginHtml(panelsHtmlFile, pluginId, lang));
}
var dialogsHtmlFile = path.join(pluginPath, dialogsHtmlBasename);
if (fs.existsSync(dialogsHtmlFile)) {
dialogsHtml.push(processPluginHtml(dialogsHtmlFile, pluginId, lang));
}
}
});
// Note that this relies on a custom version of send that supports a 'transform' option.
var that = this;
send(request, path.join(this._hostRoot['sim-host'], 'sim-host.html'), {
transform: function (stream) {
return stream
.pipe(replaceStream('<!-- TITLE -->', that._simulatorProxy.config.simHostOptions.title))
.pipe(replaceStream('<!-- PANELS -->', panelsHtml.join('\n')))
.pipe(replaceStream('<!-- DIALOGS -->', dialogsHtml.join('\n')));
}
}).pipe(response);
}.bind(this));
};