feat:Support debug other source in doric project

This commit is contained in:
pengfei.zhou 2021-03-02 15:49:10 +08:00 committed by osborn
parent cd74a60c9e
commit 88dc9c9334
3 changed files with 14 additions and 2 deletions

View File

@ -145,6 +145,7 @@ public class DoricDev {
public void requestDebugging(DoricContext context) { public void requestDebugging(DoricContext context) {
wsClient.sendToServer("DEBUG", new JSONBuilder() wsClient.sendToServer("DEBUG", new JSONBuilder()
.put("source", context.getSource()) .put("source", context.getSource())
.put("script", context.getScript())
.toJSONObject()); .toJSONObject());
} }

View File

@ -4,6 +4,7 @@ import path from "path";
import { glob } from "./util"; import { glob } from "./util";
import { Shell } from "./shell"; import { Shell } from "./shell";
import { ChildProcess, } from "child_process"; import { ChildProcess, } from "child_process";
import fs from "fs";
export type MSG = { export type MSG = {
type: "D2C" | "C2D" | "C2S" | "D2S" | "S2C" | "S2D", type: "D2C" | "C2D" | "C2S" | "D2S" | "S2C" | "S2D",
@ -72,10 +73,19 @@ export async function createServer() {
const jsFile = await glob(`**/${source}`, { const jsFile = await glob(`**/${source}`, {
cwd: path.resolve(process.cwd(), "bundle") cwd: path.resolve(process.cwd(), "bundle")
}) })
let debuggingFile: string
if (!!!jsFile || jsFile.length === 0) { if (!!!jsFile || jsFile.length === 0) {
console.error(`Cannot find ${source} in ${path.resolve(process.cwd(), "bundle")}`); console.error(`Cannot find ${source} in ${path.resolve(process.cwd(), "bundle")}`);
let script = resultObject.payload.script as string;
const debuggingDir = path.resolve(process.cwd(), "debug");
if (!fs.existsSync(debuggingDir)) {
await fs.promises.mkdir(debuggingDir);
}
debuggingFile = path.resolve(debuggingDir, source);
await fs.promises.writeFile(debuggingFile, script, "utf-8");
} else {
debuggingFile = path.resolve(process.cwd(), "bundle", jsFile[0]);
} }
const debuggingFile = path.resolve(process.cwd(), "bundle", jsFile[0]);
debugProcess = await Shell.execProcess( debugProcess = await Shell.execProcess(
"node", "node",
[ [

View File

@ -229,7 +229,8 @@ - (void)stopDebugging:(BOOL)resume {
- (void)requestDebugging:(DoricContext *)context { - (void)requestDebugging:(DoricContext *)context {
[self.wsClient sendToServer:@"DEBUG" payload:@{ [self.wsClient sendToServer:@"DEBUG" payload:@{
@"source": context.source @"source": context.source,
@"script": context.script,
}]; }];
} }