{"size": 843, "ext": "js", "max_stars_repo_path": "download/download.js", "max_stars_repo_name": "AndreasMadsen/wasm-dom", "max_stars_repo_stars_event_min_datetime": "2017-03-01T01:34:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-30T10:16:14.000Z", "max_issues_repo_path": "download/download.js", "max_issues_repo_name": "AndreasMadsen/wasm-dom", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "download/download.js", "max_forks_repo_name": "AndreasMadsen/wasm-dom", "max_forks_repo_forks_event_min_datetime": "2021-07-18T17:49:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-18T17:49:30.000Z"}
{"max_stars_count": 16, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 24.0857142857, "max_line_length": 64, "alphanum_fraction": 0.6204033215}
'use strict';

const fs = require('fs');
const path = require('path');
const async = require('async');
const request = require('request');
const webIDL2 = require('webidl2');
const endpoint = require('endpoint');
const WebIDLExtract = require('webidl-extract');

const sources = JSON.parse(fs.readFileSync(
  path.resolve(__dirname, 'webidl-sources.json'), 'utf8'
));

async.eachSeries(sources, function ({name, href}, done) {
  request(href)
    .pipe(new WebIDLExtract())
    .pipe(endpoint(function (err, webidl) {
      if (err) return done(err);

      const webIDLJSON = JSON.stringify(
        webIDL2.parse(webidl.toString()),
        null, 2
      );

      fs.writeFile(
        path.resolve(__dirname, '..', 'webidl', `${name}.json`),
        webIDLJSON,
        done
      );
    }));
}, function (err) {
  if (err) throw err;
});
