{"size": 734, "ext": "js", "max_stars_repo_path": "src/utils/type/utils/loadTypeMetaFromUrl.js", "max_stars_repo_name": "brianneisler/components", "max_stars_repo_stars_event_min_datetime": "2020-05-17T18:55:54.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-17T18:55:54.000Z", "max_issues_repo_path": "src/utils/type/utils/loadTypeMetaFromUrl.js", "max_issues_repo_name": "brianneisler/components", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/utils/type/utils/loadTypeMetaFromUrl.js", "max_forks_repo_name": "brianneisler/components", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.5833333333, "max_line_length": 74, "alphanum_fraction": 0.7929155313}
import fse from 'fs-extra'
import downloadType from './downloadType'
import anyTypeFileExistsAtPath from '../anyTypeFileExistsAtPath'
import loadTypeMetaFromPath from './loadTypeMetaFromPath'
import resolveDownloadedTypePath from './resolveDownloadedTypePath'

const loadTypeMetaFromUrl = async (url, context) => {
  const downloadedTypePath = resolveDownloadedTypePath(url)
  const isDownloaded = await anyTypeFileExistsAtPath(downloadedTypePath)

  if (!isDownloaded) {
    await fse.ensureDirAsync(downloadedTypePath)
    await downloadType(url, downloadedTypePath)
  }

  const typeMeta = await loadTypeMetaFromPath(downloadedTypePath, context)
  return {
    ...typeMeta,
    query: url
  }
}

export default loadTypeMetaFromUrl
