Skip to content

Only index the most current patch of each minor #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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