Skip to content

Commit

Permalink
Merge pull request #11 from toddjordan/only-index-latest-patches
Browse files Browse the repository at this point in the history
Only index the most current patch of each minor
  • Loading branch information
toddjordan authored Jul 25, 2019
2 parents 46ad1d6 + aed24df commit 67d0d14
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
)
Expand All @@ -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
Expand Down

0 comments on commit 67d0d14

Please sign in to comment.