Skip to content

Commit 70195fb

Browse files
committed
Automatically run the active function now from the HTTP server
1 parent c1cf048 commit 70195fb

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

core/Run.ts

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,46 @@ namespace Moduless
132132
if (!startingProject)
133133
throw new Error("No projects found at location: " + target.projectPath);
134134

135-
startHttpServer(graph.map(entry => entry.project));
135+
target.functionNamespace + target.functionName
136+
137+
// Starts an HTTP server that serves the outFiles loaded
138+
// from the discovered set of projects.
139+
{
140+
const projects = graph.map(entry => entry.project)
141+
const outFiles = projects.map(p => p.outFile);
142+
let charIndex = 0;
143+
for (;;)
144+
{
145+
if (outFiles.some(f => f.length <= charIndex))
146+
break;
147+
148+
if (!outFiles.every(f => f[charIndex] === outFiles[0][charIndex]))
149+
break;
150+
151+
charIndex++;
152+
}
153+
154+
const path = outFiles[0].slice(0, charIndex);
155+
const runJs = target.functionNamespace + "." + target.functionName + "()";
156+
const runScript = `<script>setTimeout(() => ${runJs})</script>`;
157+
158+
Moduless.createServer({
159+
path,
160+
route: path =>
161+
{
162+
if (path === "/")
163+
{
164+
return [
165+
"<!DOCTYPE html>",
166+
...outFiles.map(f => `<script src="${f.slice(charIndex)}"></script>`),
167+
runScript
168+
].join("\n");
169+
}
170+
}
171+
});
172+
173+
console.log("HTTP server is available at: http://localhost:" + Moduless.defaultHttpPort);
174+
}
136175

137176
const tryResolveNamepace = (root: object) =>
138177
{
@@ -184,44 +223,6 @@ namespace Moduless
184223
return true;
185224
}
186225

187-
/**
188-
* Starts an HTTP server that serves the outFiles associated with the specified
189-
* list of projects.
190-
*/
191-
function startHttpServer(projects: Project[])
192-
{
193-
const outFiles = projects.map(p => p.outFile);
194-
let charIndex = 0;
195-
for (;;)
196-
{
197-
if (outFiles.some(f => f.length <= charIndex))
198-
break;
199-
200-
if (!outFiles.every(f => f[charIndex] === outFiles[0][charIndex]))
201-
break;
202-
203-
charIndex++;
204-
}
205-
206-
const path = outFiles[0].slice(0, charIndex);
207-
208-
Moduless.createServer({
209-
path,
210-
route: path =>
211-
{
212-
if (path === "/")
213-
{
214-
return [
215-
"<!DOCTYPE html>",
216-
...outFiles.map(f => `<script src="${f.slice(charIndex)}"></script>`),
217-
].join("\n");
218-
}
219-
}
220-
});
221-
222-
console.log("HTTP server is available at: http://localhost:" + Moduless.defaultHttpPort);
223-
}
224-
225226
/**
226227
* Returns the name of the cover function currently being tested.
227228
*/

0 commit comments

Comments
 (0)