From 88dc9c9334c7dd7e59b9299f9478fbd95b90fa31 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 2 Mar 2021 15:49:10 +0800 Subject: [PATCH] feat:Support debug other source in doric project --- .../src/main/java/pub/doric/devkit/DoricDev.java | 1 + doric-cli/src/server.ts | 12 +++++++++++- doric-iOS/Devkit/Classes/DoricDev.m | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDev.java b/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDev.java index 3415603a..f180cccd 100644 --- a/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDev.java +++ b/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDev.java @@ -145,6 +145,7 @@ public class DoricDev { public void requestDebugging(DoricContext context) { wsClient.sendToServer("DEBUG", new JSONBuilder() .put("source", context.getSource()) + .put("script", context.getScript()) .toJSONObject()); } diff --git a/doric-cli/src/server.ts b/doric-cli/src/server.ts index eb10ca65..3d156884 100644 --- a/doric-cli/src/server.ts +++ b/doric-cli/src/server.ts @@ -4,6 +4,7 @@ import path from "path"; import { glob } from "./util"; import { Shell } from "./shell"; import { ChildProcess, } from "child_process"; +import fs from "fs"; export type MSG = { type: "D2C" | "C2D" | "C2S" | "D2S" | "S2C" | "S2D", @@ -72,10 +73,19 @@ export async function createServer() { const jsFile = await glob(`**/${source}`, { cwd: path.resolve(process.cwd(), "bundle") }) + let debuggingFile: string if (!!!jsFile || jsFile.length === 0) { 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( "node", [ diff --git a/doric-iOS/Devkit/Classes/DoricDev.m b/doric-iOS/Devkit/Classes/DoricDev.m index 8e1b2609..dd017e97 100644 --- a/doric-iOS/Devkit/Classes/DoricDev.m +++ b/doric-iOS/Devkit/Classes/DoricDev.m @@ -229,7 +229,8 @@ - (void)stopDebugging:(BOOL)resume { - (void)requestDebugging:(DoricContext *)context { [self.wsClient sendToServer:@"DEBUG" payload:@{ - @"source": context.source + @"source": context.source, + @"script": context.script, }]; }