Skip to content

Commit 77c8a4c

Browse files
author
Junhui Tong
committed
seperate launch_local
1 parent 03e480f commit 77c8a4c

File tree

4 files changed

+54
-8
lines changed

4 files changed

+54
-8
lines changed

Diff for: backend/api_impl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function launchScript() {
1212
Deno.statSync(scriptFile)
1313
} catch (_e) {
1414
scriptFile = Deno.env.get('TEMP') + '\\excel.js'
15-
const content = staticAssets['./excel.js']
15+
const content = staticAssets['excel.js']
1616
Deno.writeTextFileSync(scriptFile, content)
1717
}
1818
const cmd = new Deno.Command('cscript.exe', {

Diff for: build.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
const htmlContent = Deno.readTextFileSync('./frontend/dist/index.html')
55
const jsContent = Deno.readTextFileSync('./frontend/dist/assets/index.js')
66

7-
// replace content within <!--SCRIPT-START--> and <!--SCRIPT-END--> to jsContent
8-
const newHtmlContent = htmlContent.replace(/<!--SCRIPT-START-->[\s\S]*<!--SCRIPT-END-->/, `<!--SCRIPT-START-->\n<script type="module">\n${jsContent}\n</script>\n<!--SCRIPT-END-->`)
7+
// replace this line:
8+
// <script type="module" crossorigin src="/assets/index.js"></script>
9+
// to jsContent
10+
const newHtmlContent = htmlContent.replace(
11+
/<script type="module" crossorigin src="\/assets\/index.js"><\/script>/,
12+
`<script type="module"> ${jsContent} </script>`)
913

1014
const wshScriptContent = Deno.readTextFileSync('./excel.js')
1115

@@ -16,3 +20,5 @@ const staticAssets = {
1620
}
1721

1822
Deno.writeTextFileSync('./static_assets.json', JSON.stringify(staticAssets, null, 2))
23+
24+
console.log(newHtmlContent)

Diff for: launch.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
// wait for frontend exit, then terminate backend
33
import { apiImpl } from "./backend/api_impl.ts";
44
import { startDenoWebApp } from "./dwa/dwa_service.ts";
5-
import * as vite from 'npm:vite'
65

76
startDenoWebApp('./frontend', 8080, apiImpl);
87

9-
const frontend = await vite.createServer()
10-
frontend.listen(5173)
11-
128
//await new Promise(r => setTimeout(r, 1000))
139
// launch chrome with Default proflie
1410
const cmd3 = new Deno.Command(`C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe`, {
15-
args: ['--app=http://localhost:5173', '--new-window', '--profile-directory=Default'],
11+
args: ['--app=http://localhost:8080', '--new-window', '--profile-directory=Default'],
1612
})
1713

1814
const browser = cmd3.spawn()

Diff for: launch_local.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// launch backend and frontend
2+
// wait for frontend exit, then terminate backend
3+
import { apiImpl } from "./backend/api_impl.ts";
4+
import { startDenoWebApp } from "./dwa/dwa_service.ts";
5+
import * as vite from 'npm:vite'
6+
7+
startDenoWebApp('./frontend', 8080, apiImpl);
8+
9+
const frontend = await vite.createServer()
10+
frontend.listen(5173)
11+
12+
//await new Promise(r => setTimeout(r, 1000))
13+
// launch chrome with Default proflie
14+
const cmd3 = new Deno.Command(`C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe`, {
15+
args: ['--app=http://localhost:5173', '--new-window', '--profile-directory=Default'],
16+
})
17+
18+
const browser = cmd3.spawn()
19+
console.log('browser started, pid:', browser.pid)
20+
21+
Deno.addSignalListener("SIGINT", () => {
22+
console.log('SIGINT received')
23+
Exit()
24+
})
25+
26+
// stop frontend if backend is closed
27+
28+
function Exit() {
29+
const close = (p: Deno.ChildProcess) => {
30+
try {
31+
p.kill()
32+
} catch (e) {
33+
console.log(e.message)
34+
}
35+
}
36+
console.log('exiting app')
37+
// console.log('closing frontend')
38+
// close(frontend)
39+
console.log('closing browser')
40+
close(browser)
41+
Deno.exit()
42+
}
43+
44+

0 commit comments

Comments
 (0)