import { writeFile } from 'fs' ; const sitemapGenerator = require ( 'sitemap-generator' ) ; export const sitemap = ( host ) => new Promise < string > ( ( resolve , reject ) => { const generator = new sitemapGenerator ( host ) ; generator . crawler . addFetchCondition ( ( parsedUrl ) => { return ! parsedUrl . url . includes ( 'sitemap.xml' ) ; } ) ; generator . on ( 'done' , ( sitemaps ) => { if ( sitemaps && sitemaps [ 0 ] ) { writeFile ( 'dist/sitemap.xml' , sitemaps [ 0 ] , ( ) => { console . log ( 'Generated sitemap.xml' ) ; return resolve ( sitemaps [ 0 ] ) ; } ) ; } else { return reject ( 'Failed to generate sitemap.xml' ) ; } } ) ; generator . on ( 'clienterror' , ( err ) => { return reject ( err ) ; } ) ; console . log ( `starting sitemap crawler on ${ host }` ) ; generator . start ( ) ; } ) ;