import * as fs from "fs" ; import fetch from "node-fetch" ; import { JSDOM } from "jsdom" ; interface Page { summary : string ; } const knownBadDescriptions = [ "CustomEvent" , "IDBTransaction" , "RTCDtmfSender" , "SVGMatrix" , ] ; fetchInterfaceDescriptions ( ) ; async function fetchInterfaceDescriptions ( ) { const webIdl = require ( "../inputfiles/browser.webidl.preprocessed.json" ) ; const interfaceNames = Object . keys ( webIdl . interfaces . interface ) . sort ( ) ; const descriptions = { } ; await interfaceNames . reduce ( async ( previousRequest , name ) => { await previousRequest ; const response = await fetch ( `https://developer.mozilla.org/en-US/docs/Web/API/${ name }$json` ) ; if ( response . ok ) { const page = await response . json ( ) ; addDescription ( name , page ) ; } else if ( response . status !== 404 ) { throw new Error ( `Failed to fetch ${ name }: ${ response . statusText }` ) ; } } , Promise . resolve ( ) ) ; function addDescription ( name , page ) { if ( page . summary && ! knownBadDescriptions . includes ( name ) ) { const fragment = JSDOM . fragment ( page . summary ) ; descriptions [ name ] = fragment . textContent ! ; } } fs . writeFileSync ( "inputfiles/mdn/apiDescriptions.json" , JSON . stringify ( descriptions , null , 2 ) ) ; }