11// This code is Deno only
22
3+ import { assert } from "@std/assert/assert" ;
34import { exists } from "@std/fs/exists" ;
45import * as ESBuild from "esbuild" ;
56import { OPTIONS } from "./config.ts" ;
@@ -9,11 +10,12 @@ const BUILD_OPTIONS: ESBuild.BuildOptions = {
910 minify : false ,
1011 define : { LIVE_RELOAD : "true" } ,
1112} ;
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 > {
1719 const command = new Deno . Command ( Deno . execPath ( ) , {
1820 args : [
1921 "run" ,
@@ -32,9 +34,14 @@ if (import.meta.main) {
3234 stdin : "null" ,
3335 } ) ;
3436 const process = command . spawn ( ) ;
35- const context = await ESBuild . context ( BUILD_OPTIONS ) ;
36- await context . watch ( ) ;
37- await context . serve ( { servedir : "./dist/" } ) ;
3837 const status = await process . status ;
38+ assert ( ! status . success ) ;
3939 Deno . exit ( status . code ) ;
4040}
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