import axios from "axios" ; import cheerio from "cheerio" ; import EventType from "../../src/EventType" ; import EventSource from "../EventSource" ; import EventSources from "../EventSources" ; import EventTypeMap from "../EventTypeMap" ; import getEventSourceType from "../getEventSourceType" ; param events param lastEvents param eventSource const downloadEvents = ( events , lastEvents , eventSource ) : Promise < void > => axios . get < string > ( eventSource . javadocUrl + eventSource . allClasses ) . then ( ( response ) => { const body = response . data ; try { const $ = cheerio . load ( body ) ; $ ( "a" ) . each ( ( _ , element ) => { const a = $ ( element ) ; const href = a . prop ( "href" ) ; if ( href && href . endsWith ( "Event.html" ) ) { const name = href . substring ( 0 , href . length - 5 ) . split ( "/" ) . pop ( ) ; const source = getEventSourceType ( href ) ; if ( source ) { if ( ! eventSource . downloadSources . includes ( source ) ) return ; if ( ! events [ name + source ] ) { const lastEvent = lastEvents [ name + source ] ; let description = "" ; let deprecateDescription ; if ( lastEvent ) { description = lastEvent . description ; deprecateDescription = lastEvent . deprecateDescription ; } events [ name + source ] = { deprecateDescription : deprecateDescription || "" , description : description , link : eventSource . javadocUrl + href , name : name || "" , source : source , } ; } } else { console . error ( `${ href } に対応する EventSourceType が見つかりませんでした` ) ; } } } ) ; } catch ( e ) { console . error ( e ) ; } } ) . catch ( ( reason ) => console . error ( reason ) ) ; param lastEventMap export const downloadEventMap = async ( lastEventMap ) : Promise < EventTypeMap > => { const eventMap = { } ; await Promise . all ( Object . values ( EventSources ) . map ( ( source ) => downloadEvents ( eventMap , lastEventMap , source ) ) ) ; return eventMap ; } ;