diff --git a/lib/api.js b/lib/api.js index edfe7c4..274dbcb 100644 --- a/lib/api.js +++ b/lib/api.js @@ -2,7 +2,7 @@ require('dotenv').config() import { readJsonSync } from 'fs-extra' import { difference } from 'lodash-es' -import { compare as compareSemVers } from 'semver' +import { gt, compare as compareSemVers } from 'semver' import downloadApiDocs from './api-docs-sync' import algoliaDriver from './drivers/algolia' import jsonDriver from './drivers/json' @@ -42,9 +42,11 @@ async function processDocs(driver, project) { } try { - console.log(`Processing ${project} for versions: ${versionsToProcess}`) - - await versionsToProcess + // iterate versions and drop latest minor of each major in buckets + // make an array of the latest minors you get + let latestPatches = Object.values(versionsToProcess.reduce(addIfLatestPatch, {})); + console.log(`Processing ${project} for versions: ${latestPatches}`) + await latestPatches .filter(version => filterMissingRevs(version, project)) .map(version => readIndexFileForVersion(version, project)) // Fetch all public modules and public classes @@ -54,7 +56,6 @@ async function processDocs(driver, project) { // Run the schema against all data stored .map(mapDataForVersion) .map(content => writeToDriver(driver, content)) - let versions = [...prevIndexedVersions, ...versionsToProcess].sort( compareSemVers ) @@ -69,6 +70,19 @@ async function processDocs(driver, project) { } } +function addIfLatestPatch(latestPatches, version) { + let semvers = version.split('.') + let major = semvers[0]; + let minor = semvers[1]; + let minorVersion = `${major}.${minor}`; + if (minorVersion in latestPatches && gt(version, latestPatches[minorVersion])) { + latestPatches[minorVersion] = version; + } else if (!(minorVersion in latestPatches)) { + latestPatches[minorVersion] = version; + } + return latestPatches; +} + function filterMissingRevs(version, libName) { const emberVersionJSONPath = `./tmp/rev-index/${libName}-${version}.json` let isIncluded = true