From bdd392e455757045d1205dd4075a1a60c165f449 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 2 Mar 2021 10:57:44 +0800 Subject: [PATCH] feat:optimize doric-cli --- doric-cli/src/dev.ts | 83 +++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/doric-cli/src/dev.ts b/doric-cli/src/dev.ts index 72368696..1f9b905f 100644 --- a/doric-cli/src/dev.ts +++ b/doric-cli/src/dev.ts @@ -31,47 +31,8 @@ function getIPAdress() { export default async function dev() { const server = await createServer() - const tscProcess = exec("node node_modules/.bin/tsc -w -p .", { - env: process.env, - }); - const rollupProcess = exec("node node_modules/.bin/rollup -c -w", { - env: process.env, - }); - [tscProcess, rollupProcess].forEach(e => { - e.stdout?.on("data", (data) => { - console.log(data.toString()); - }); - e.stderr?.on("data", (data) => { - console.log(data.toString()); - }); - }) - console.warn("Waiting ..."); - const ips = getIPAdress(); - ips.forEach((e) => { - console.log(`IP:${e}`); - qrcode.generate(e, { small: true }); - }); - keypress(process.stdin); - process.stdin.on("keypress", function (ch, key) { - if (key && key.ctrl && key.name == "r") { - ips.forEach((e) => { - console.log(`IP:${e}`); - qrcode.generate(e, { small: true }); - }); - } - if (key && key.ctrl && key.name == "c") { - process.stdin.pause(); - tscProcess.kill("SIGABRT"); - rollupProcess.kill("SIGABRT"); - process.exit(0); - } - }); - process.stdin.setRawMode(true); - process.stdin.resume(); - await delay(3000); - console.warn("Start watching"); const cachedContents: Record = {} chokidar .watch(process.cwd() + "/bundle", { @@ -82,6 +43,10 @@ export default async function dev() { const content = fs.readFileSync(jsFile, "utf-8"); if (cachedContents[jsFile]) { if (content.indexOf(cachedContents[jsFile]) >= 0) { + const sourceMap = `${jsFile}.map` + if (fs.existsSync(sourceMap)) { + mergeMap(sourceMap); + } return; } } @@ -113,7 +78,47 @@ export default async function dev() { } }); + const tscProcess = exec("node node_modules/.bin/tsc -w -p .", { + env: process.env, + }); + const rollupProcess = exec("node node_modules/.bin/rollup -c -w", { + env: process.env, + }); + [tscProcess, rollupProcess].forEach(e => { + e.stdout?.on("data", (data) => { + console.log(data.toString()); + }); + e.stderr?.on("data", (data) => { + console.log(data.toString()); + }); + }) + console.warn("Waiting ..."); + keypress(process.stdin); + const ips = getIPAdress(); + process.stdin.on("keypress", function (ch, key) { + if (key && key.ctrl && key.name == "r") { + ips.forEach((e) => { + console.log(`IP:${e}`); + qrcode.generate(e, { small: true }); + }); + } + if (key && key.ctrl && key.name == "c") { + process.stdin.pause(); + tscProcess.kill("SIGABRT"); + rollupProcess.kill("SIGABRT"); + process.exit(0); + } + }); + process.stdin.setRawMode(true); + process.stdin.resume(); + + await delay(3000); + console.warn("Start watching"); + ips.forEach((e) => { + console.log(`IP:${e}`); + qrcode.generate(e, { small: true }); + }); }