Skip to content

Commit 3f948f9

Browse files
committed
--
1 parent d7c2e68 commit 3f948f9

File tree

4 files changed

+55
-37
lines changed

4 files changed

+55
-37
lines changed

core/Settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Moduless
1111
/**
1212
* Reads the name of the function to run.
1313
*/
14-
export function readActiveFunction(cwd: string): IRunMeta | null
14+
export function readActiveFunction(cwd = process.cwd()): IRunMeta | null
1515
{
1616
const targets = readTargetsFile();
1717
return targets.get(Util.toDirectory(cwd)) || null;

core/Util.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@ namespace Moduless
2121
* Returns the path to the tsconfig.json file that exists in the containing
2222
* folder that is nearest to the specified file.
2323
*/
24-
export function getContainingConfigFile(nestedFilePath: string)
24+
export function getContainingConfigFile(nestedDirectory: string)
2525
{
26-
let current = nestedFilePath;
26+
let current = nestedDirectory;
2727

28-
do
28+
for (let i = -1; ++i < 101;)
2929
{
30-
current = Path.join(current, "../tsconfig.json");
30+
const check = Path.join(current, "tsconfig.json");
3131

32-
if (Fs.existsSync(current))
33-
return current;
32+
if (Fs.existsSync(check))
33+
return check;
34+
35+
current = Path.join(current, "..");
36+
37+
if (i >= 100 || current === "/")
38+
throw new Error("Could not find containing config file from path: " + nestedDirectory);
3439
}
35-
while (current !== "/tsconfig.json");
3640

3741
return null;
3842
}

core/Zenith.ts

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ namespace Moduless
2424
});
2525

2626
cli
27-
.command("call <function_name>", "Run a specific cover function by name.")
28-
.action(async (function_name: string) =>
27+
.command("call <qualified_path>", "Run a specific cover function by name, " +
28+
"with the path to the project, in the form: /path/to/project:Name.Space.runThis")
29+
.action(async (qualified_path: string) =>
2930
{
30-
console.log("Running cover function: " + function_name);
31-
await run(function_name);
31+
const parts = qualified_path.split(":");
32+
const projectPath = parts[0];
33+
const functionName = parts[1];
34+
console.log("Running cover function: " + functionName);
35+
await run(projectPath, functionName);
3236
});
3337

3438
cli
@@ -75,8 +79,7 @@ namespace Moduless
7579
/** */
7680
async function runActive()
7781
{
78-
const cwd = process.cwd();
79-
const active = Settings.readActiveFunction(cwd);
82+
const active = Settings.readActiveFunction();
8083
if (!active)
8184
{
8285
console.error("No active cover function has been set.");
@@ -98,11 +101,18 @@ namespace Moduless
98101
}
99102

100103
/** */
101-
async function run(qualifiedName: string)
104+
async function run(projectPath: string, functionNameQualified: string)
102105
{
103-
if (1) throw new Error("Not implemented");
106+
const nameParts = functionNameQualified.split(".");
107+
const functionNamespace = nameParts.slice(0, -1);
108+
const functionName = nameParts.slice(-1)[0];
109+
110+
await Moduless.run({
111+
functionName,
112+
functionNamespace,
113+
projectPath,
114+
});
104115

105-
await Moduless.run({} as any);
106116
Util.separate();
107117
}
108118

@@ -133,7 +143,6 @@ namespace Moduless
133143
if (parsed === RunGroup.all)
134144
{
135145
throw "Not implemented";
136-
run("");
137146
}
138147

139148
else if (parsed === RunGroup.active)
@@ -161,7 +170,7 @@ namespace Moduless
161170
const [x, y] = PersistentVars.lastWindowPosition;
162171
const [width, height] = PersistentVars.lastWindowSize;
163172

164-
Electron.contextBridge.exposeInMainWorld("electron", { require });
173+
//Electron.contextBridge.exposeInMainWorld("electron", { require });
165174

166175
const window = new Electron.BrowserWindow({
167176
title: "Moduless",
@@ -196,15 +205,28 @@ namespace Moduless
196205
window.webContents.session.clearCache();
197206
window.webContents.session.clearHostResolverCache();
198207

199-
const indexFile = [
200-
`<!DOCTYPE html>`,
201-
`<script src="${__dirname}/moduless.js"></script>`,
202-
].join("\n");
203-
204-
const indexPath = __dirname + "/index.html";
205-
Fs.writeFileSync(indexPath, indexFile);
206-
const url = "file://" + indexPath + composeQueryString();
207-
await window.webContents.loadURL(url);
208+
let debugUrl = process.env.DEBUG_URL;
209+
if (debugUrl)
210+
{
211+
await window.webContents.loadURL(debugUrl);
212+
await window.webContents.executeJavaScript(`{
213+
const script = document.createElement("script");
214+
script.src = "${__filename}";
215+
document.head.append(script);
216+
}`);
217+
}
218+
else
219+
{
220+
const indexFile = [
221+
`<!DOCTYPE html>`,
222+
`<script src="${__filename}"></script>`,
223+
].join("\n");
224+
225+
const indexPath = __dirname + "/index.html";
226+
Fs.writeFileSync(indexPath, indexFile);
227+
const url = "file://" + indexPath + composeQueryString();
228+
await window.webContents.loadURL(url);
229+
}
208230
}
209231

210232
const expressionPrefix = "expression=";

example/coverage/CoverExample.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11

2-
namespace Name.Space
3-
{
4-
export function runThisFunction()
5-
{
6-
return () => "Success";
7-
}
8-
}
9-
102
namespace Cover
113
{
124
/** */
@@ -49,5 +41,5 @@ namespace Cover
4941
}
5042

5143
if (typeof module === "object")
52-
module.exports = { Cover, Name };
44+
module.exports = { Cover };
5345
}

0 commit comments

Comments
 (0)