@@ -651,70 +651,68 @@ function cleanup() {
651651 if ( browserProc ) browserProc . kill ( ) ;
652652}
653653
654- ( async function ( ) {
655- try {
656- process . on ( "SIGINT" , ( ) => {
657- cleanup ( ) ;
658- process . exit ( 0 ) ;
659- } ) ;
660- process . on ( "SIGTERM" , ( ) => {
661- cleanup ( ) ;
662- process . exit ( 0 ) ;
663- } ) ;
664- process . on ( "exit" , cleanup ) ;
665-
666- const rootURLObj = new URL ( "http://localhost:8080" ) ;
667- const rootURL = rootURLObj . origin + rootURLObj . pathname ;
668- let pageQueue = [ rootURL ] ;
669- const seenURLs = new Set ( ) ;
670- if ( rootURL . endsWith ( "/" ) ) seenURLs . add ( rootURL + "index.html" ) ;
671- baseDir = "./out" ;
672- assetDir = path . join ( baseDir , "/assets" ) ;
673- // wait browser
674- await new Promise ( ( resolve ) => setTimeout ( resolve , 1500 ) ) ;
675-
676- //setup dir
677- if ( fs . existsSync ( baseDir ) ) {
678- fs . rmSync ( baseDir , { recursive : true , force : true } ) ;
679- }
680- for ( const mimeType of MIME ) {
681- fs . mkdirSync ( path . join ( assetDir , mimeType ) , { recursive : true } ) ;
682- }
654+ try {
655+ process . on ( "SIGINT" , ( ) => {
656+ cleanup ( ) ;
657+ process . exit ( 0 ) ;
658+ } ) ;
659+ process . on ( "SIGTERM" , ( ) => {
660+ cleanup ( ) ;
661+ process . exit ( 0 ) ;
662+ } ) ;
663+ process . on ( "exit" , cleanup ) ;
664+
665+ const rootURLObj = new URL ( "http://localhost:8080" ) ;
666+ const rootURL = rootURLObj . origin + rootURLObj . pathname ;
667+ let pageQueue = [ rootURL ] ;
668+ const seenURLs = new Set ( ) ;
669+ if ( rootURL . endsWith ( "/" ) ) seenURLs . add ( rootURL + "index.html" ) ;
670+ baseDir = "./out" ;
671+ assetDir = path . join ( baseDir , "/assets" ) ;
672+ // wait browser
673+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1500 ) ) ;
674+
675+ //setup dir
676+ if ( fs . existsSync ( baseDir ) ) {
677+ fs . rmSync ( baseDir , { recursive : true , force : true } ) ;
678+ }
679+ for ( const mimeType of MIME ) {
680+ fs . mkdirSync ( path . join ( assetDir , mimeType ) , { recursive : true } ) ;
681+ }
683682
684- while ( pageQueue . length !== 0 ) {
685- const url = pageQueue . shift ( ) ;
683+ while ( pageQueue . length !== 0 ) {
684+ const url = pageQueue . shift ( ) ;
686685
687- const links = await crawl ( url ) ;
688- seenURLs . add ( url ) ;
686+ const links = await crawl ( url ) ;
687+ seenURLs . add ( url ) ;
689688
690- const newLinks = links . filter ( ( link ) => {
691- if ( ! seenURLs . has ( link ) ) {
692- if ( link . endsWith ( "/" ) ) seenURLs . add ( link + "index.html" ) ;
693- seenURLs . add ( link ) ;
694- return true ;
695- }
696- } ) ;
697- pageQueue = pageQueue . concat ( newLinks ) ;
698- //console.log("concat:", newLinks);
699- console . log ( pageQueue ) ;
700- console . log ( pageQueue . length ) ;
701- }
689+ const newLinks = links . filter ( ( link ) => {
690+ if ( ! seenURLs . has ( link ) ) {
691+ if ( link . endsWith ( "/" ) ) seenURLs . add ( link + "index.html" ) ;
692+ seenURLs . add ( link ) ;
693+ return true ;
694+ }
695+ } ) ;
696+ pageQueue = pageQueue . concat ( newLinks ) ;
697+ //console.log("concat:", newLinks);
698+ console . log ( pageQueue ) ;
699+ console . log ( pageQueue . length ) ;
700+ }
702701
703- const fontCSSPath = path . join ( baseDir , "fonts.css" ) ;
704- console . log ( `Writing ${ fontCSSPath } ` ) ;
705- fs . writeFileSync ( fontCSSPath , [ ...fontCSSSet ] . join ( "\n" ) , "utf-8" ) ;
706- console . log ( "visited" , [ ...seenURLs ] ) ;
702+ const fontCSSPath = path . join ( baseDir , "fonts.css" ) ;
703+ console . log ( `Writing ${ fontCSSPath } ` ) ;
704+ fs . writeFileSync ( fontCSSPath , [ ...fontCSSSet ] . join ( "\n" ) , "utf-8" ) ;
705+ console . log ( "visited" , [ ...seenURLs ] ) ;
707706
708- // cleanup empty dir
709- for ( const mimeType of MIME ) {
710- const dirPath = path . join ( assetDir , mimeType ) ;
711- if ( fs . existsSync ( dirPath ) && fs . readdirSync ( dirPath ) . length === 0 ) {
712- fs . rmdirSync ( dirPath ) ;
713- }
707+ // cleanup empty dir
708+ for ( const mimeType of MIME ) {
709+ const dirPath = path . join ( assetDir , mimeType ) ;
710+ if ( fs . existsSync ( dirPath ) && fs . readdirSync ( dirPath ) . length === 0 ) {
711+ fs . rmdirSync ( dirPath ) ;
714712 }
715- } catch ( err ) {
716- console . error ( err ) ;
717- } finally {
718- process . exit ( 0 ) ;
719713 }
720- } ) ( ) ;
714+ } catch ( err ) {
715+ console . error ( err ) ;
716+ } finally {
717+ process . exit ( 0 ) ;
718+ }
0 commit comments