@@ -10,6 +10,23 @@ import { Dictionary } from "./type.ts";
1010const SOURCE = new URL ( "./dictionary" , import . meta. url ) ;
1111const DESTINATION = new URL ( "./dictionary.ts" , import . meta. url ) ;
1212
13+ export async function buildWithDictionary (
14+ dictionary : Dictionary ,
15+ ) : Promise < void > {
16+ const json = JSON . stringify (
17+ Object . fromEntries ( dictionary ) ,
18+ undefined ,
19+ 2 ,
20+ ) ;
21+ const code = `\
22+ // This code is autogenerated
23+
24+ import { Dictionary } from "./type.ts";
25+
26+ export const dictionary: Dictionary = new Map(Object.entries(${ json } ));
27+ ` ;
28+ await Deno . writeTextFile ( DESTINATION , code ) ;
29+ }
1330export async function build ( ) : Promise < boolean > {
1431 console . log ( "Building dictionary..." ) ;
1532 const start = performance . now ( ) ;
@@ -24,19 +41,7 @@ export async function build(): Promise<boolean> {
2441 displayError ( text , result . errors ) ;
2542 return false ;
2643 }
27- const json = JSON . stringify (
28- Object . fromEntries ( dictionary ) ,
29- undefined ,
30- 2 ,
31- ) ;
32- const code = `\
33- // This code is autogenerated
34-
35- import { Dictionary } from "./type.ts";
36-
37- export const dictionary: Dictionary = new Map(Object.entries(${ json } ));
38- ` ;
39- await Deno . writeTextFile ( DESTINATION , code ) ;
44+ await buildWithDictionary ( dictionary ) ;
4045 const end = performance . now ( ) ;
4146 const total = Math . floor ( end - start ) ;
4247 const parsing = Math . floor ( endDictionary - startDictionary ) ;
0 commit comments