1
1
// This code is Deno only
2
2
3
+ import { assert } from "@std/assert/assert" ;
3
4
import { exists } from "@std/fs/exists" ;
4
5
import * as ESBuild from "esbuild" ;
5
6
import { OPTIONS } from "./config.ts" ;
@@ -9,11 +10,12 @@ const BUILD_OPTIONS: ESBuild.BuildOptions = {
9
10
minify : false ,
10
11
define : { LIVE_RELOAD : "true" } ,
11
12
} ;
12
- if ( import . meta. main ) {
13
- if ( ! await exists ( new URL ( "../dictionary/dictionary.ts" , import . meta. url ) ) ) {
14
- const Dictionary = await import ( "../dictionary/build.ts" ) ;
15
- await Dictionary . build ( ) ;
16
- }
13
+ async function watchMain ( ) : Promise < void > {
14
+ const context = await ESBuild . context ( BUILD_OPTIONS ) ;
15
+ await context . watch ( ) ;
16
+ await context . serve ( { servedir : "./dist/" } ) ;
17
+ }
18
+ async function watchDictionary ( ) : Promise < never > {
17
19
const command = new Deno . Command ( Deno . execPath ( ) , {
18
20
args : [
19
21
"run" ,
@@ -32,9 +34,14 @@ if (import.meta.main) {
32
34
stdin : "null" ,
33
35
} ) ;
34
36
const process = command . spawn ( ) ;
35
- const context = await ESBuild . context ( BUILD_OPTIONS ) ;
36
- await context . watch ( ) ;
37
- await context . serve ( { servedir : "./dist/" } ) ;
38
37
const status = await process . status ;
38
+ assert ( ! status . success ) ;
39
39
Deno . exit ( status . code ) ;
40
40
}
41
+ if ( import . meta. main ) {
42
+ if ( ! await exists ( new URL ( "../dictionary/dictionary.ts" , import . meta. url ) ) ) {
43
+ const Dictionary = await import ( "../dictionary/build.ts" ) ;
44
+ await Dictionary . build ( ) ;
45
+ }
46
+ await Promise . all ( [ watchDictionary ( ) , watchMain ( ) ] ) ;
47
+ }
0 commit comments