@@ -8,12 +8,12 @@ const WATCH = [
88 "./dictionary/misc.ts" ,
99 "./dictionary/parser.ts" ,
1010 "./dictionary/type.ts" ,
11- "./telo-misikeke/linku-data .json" ,
12- "./telo-misikeke /Parser.js" ,
13- "./telo-misikeke /rules.js" ,
14- "./telo-misikeke/telo-misikeke .js" ,
11+ "./telo_misikeke/linku_data .json" ,
12+ "./telo_misikeke /Parser.js" ,
13+ "./telo_misikeke /rules.js" ,
14+ "./telo_misikeke/telo_misikeke .js" ,
1515 "./src/" ,
16- "./project-data .json" ,
16+ "./project_data .json" ,
1717] ;
1818const DICTIONARY = / d i c t i o n a r y [ / \\ ] [ ^ / \\ ] + $ / ;
1919
@@ -25,24 +25,30 @@ function buildOptions(minify: boolean): ESBuild.BuildOptions {
2525 bundle : true ,
2626 minify,
2727 sourcemap : "linked" ,
28+ target : [ `es${ new Date ( ) . getFullYear ( ) - 3 } ` ] ,
2829 plugins : [ ...denoPlugins ( ) ] ,
2930 } ;
3031}
31- async function buildAll ( options : {
32- minify : boolean ;
33- buildDictionary : boolean ;
34- checkDictionary ?: boolean ;
35- } ) : Promise < void > {
32+ async function buildAll (
33+ options : Readonly < {
34+ minify : boolean ;
35+ buildDictionary : boolean ;
36+ checkDictionary ?: boolean ;
37+ } > ,
38+ ) : Promise < void > {
3639 const { minify, buildDictionary, checkDictionary } = options ;
3740 try {
3841 if ( buildDictionary ) {
3942 const Dictionary = await import ( "./dictionary/build.ts" ) ;
4043 await Dictionary . build ( checkDictionary ?? true ) ;
4144 }
45+ // deno-lint-ignore no-console
4246 console . log ( "Building main.js..." ) ;
4347 await ESBuild . build ( buildOptions ( minify ) ) ;
48+ // deno-lint-ignore no-console
4449 console . log ( "Building done!" ) ;
4550 } catch ( error ) {
51+ // deno-lint-ignore no-console
4652 console . error ( error ) ;
4753 }
4854}
@@ -53,33 +59,29 @@ if (import.meta.main) {
5359 break ;
5460 }
5561 case "watch" : {
62+ // deno-lint-ignore no-console
5663 console . log ( "Press ctrl+c to exit." ) ;
5764 const watcher = Deno . watchFs ( WATCH ) ;
5865 let task = Promise . resolve ( ) ;
59- try {
60- await buildAll ( { minify : false , buildDictionary : true } ) ;
61- let dictionaryChanged = false ;
62- const buildDebounced = debounce ( ( buildDictionary : boolean ) => {
63- task = task . then ( async ( ) => {
64- await buildAll ( {
65- minify : true ,
66- buildDictionary,
67- checkDictionary : false ,
68- } ) ;
69- dictionaryChanged = false ;
66+ await buildAll ( { minify : false , buildDictionary : true } ) ;
67+ let dictionaryChanged = false ;
68+ const buildDebounced = debounce ( ( buildDictionary : boolean ) => {
69+ task = task . then ( async ( ) => {
70+ await buildAll ( {
71+ minify : false ,
72+ buildDictionary,
73+ checkDictionary : false ,
7074 } ) ;
71- } , 500 ) ;
72- for await ( const event of watcher ) {
73- if ( event . paths . some ( ( path ) => DICTIONARY . test ( path ) ) ) {
74- dictionaryChanged = true ;
75- }
76- buildDebounced ( dictionaryChanged ) ;
75+ dictionaryChanged = false ;
76+ } ) ;
77+ } , 500 ) ;
78+ for await ( const event of watcher ) {
79+ if ( event . paths . some ( ( path ) => DICTIONARY . test ( path ) ) ) {
80+ dictionaryChanged = true ;
7781 }
78- throw new Error ( "unreachable" ) ;
79- } finally {
80- watcher . close ( ) ;
81- await task ;
82+ buildDebounced ( dictionaryChanged ) ;
8283 }
84+ throw new Error ( "unreachable" ) ;
8385 }
8486 default :
8587 throw new Error ( `unrecognized build option: ${ Deno . args [ 0 ] } ` ) ;
0 commit comments