doric-cli:debug source add suffix
This commit is contained in:
parent
3fa9124801
commit
915f840cd7
@ -2,6 +2,9 @@ import fs from "fs";
|
|||||||
import { exec, spawn } from "child_process";
|
import { exec, spawn } from "child_process";
|
||||||
import ws from "nodejs-websocket";
|
import ws from "nodejs-websocket";
|
||||||
import "colors";
|
import "colors";
|
||||||
|
import path from "path";
|
||||||
|
import { delay, glob } from "./util";
|
||||||
|
import { Shell } from "./shell";
|
||||||
|
|
||||||
export async function createServer() {
|
export async function createServer() {
|
||||||
console.log("Create Server")
|
console.log("Create Server")
|
||||||
@ -22,7 +25,7 @@ export async function createServer() {
|
|||||||
} else {
|
} else {
|
||||||
console.log(`Client ${thisDeviceId} attached to dev kit`.green)
|
console.log(`Client ${thisDeviceId} attached to dev kit`.green)
|
||||||
}
|
}
|
||||||
connection.on('text', function (result: string) {
|
connection.on('text', async function (result: string) {
|
||||||
let resultObject = JSON.parse(result)
|
let resultObject = JSON.parse(result)
|
||||||
switch (resultObject.cmd) {
|
switch (resultObject.cmd) {
|
||||||
case 'DEBUG':
|
case 'DEBUG':
|
||||||
@ -30,20 +33,27 @@ export async function createServer() {
|
|||||||
(server as any).debugging = true;
|
(server as any).debugging = true;
|
||||||
console.log("Enter debugging");
|
console.log("Enter debugging");
|
||||||
contextId = resultObject.data.contextId;
|
contextId = resultObject.data.contextId;
|
||||||
let projectHome = '.';
|
const projectHome = '.';
|
||||||
|
await fs.promises.writeFile(path.resolve(projectHome, "build", "context"), contextId, "utf-8");
|
||||||
fs.writeFileSync(projectHome + '/build/context', contextId, 'utf8');
|
let source = resultObject.data.source as string;
|
||||||
|
if (source.startsWith(".js")) {
|
||||||
let source = resultObject.data.source;
|
source = source.replace(".js", ".ts");
|
||||||
console.log(connection.key + " request debug, project home: " + projectHome);
|
} else if (!source.startsWith(".ts")) {
|
||||||
spawn('code', [projectHome, projectHome + "/src/" + source]);
|
source = source + ".ts"
|
||||||
setTimeout(() => {
|
}
|
||||||
exec('osascript -e \'tell application "System Events"\ntell application "Visual Studio Code" to activate\nkey code 96\nend tell\'', (err, stdout, stderr) => {
|
let sourceFile = path.resolve(projectHome, "src", source);
|
||||||
if (err) {
|
if (!fs.existsSync(sourceFile)) {
|
||||||
console.log(`stdout: ${err}`)
|
const tsFiles = await glob(source, {
|
||||||
}
|
cwd: path.resolve(projectHome, "src")
|
||||||
})
|
})
|
||||||
}, 1500);
|
if (!!!tsFiles || tsFiles.length === 0) {
|
||||||
|
console.error(`Cannot find ${source} in ${path.resolve(projectHome)}`);
|
||||||
|
}
|
||||||
|
sourceFile = tsFiles[0];
|
||||||
|
}
|
||||||
|
console.log(connection.key + " request debug, project home: " + projectHome);
|
||||||
|
await Shell.exec("code", [projectHome, sourceFile]);
|
||||||
|
await delay(1500);
|
||||||
break;
|
break;
|
||||||
case 'EXCEPTION':
|
case 'EXCEPTION':
|
||||||
console.log(resultObject.data.source.red);
|
console.log(resultObject.data.source.red);
|
||||||
|
Reference in New Issue
Block a user