Skip to content

Commit 67d0d14

Browse files
authored
Merge pull request #11 from toddjordan/only-index-latest-patches
Only index the most current patch of each minor
2 parents 46ad1d6 + aed24df commit 67d0d14

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Diff for: lib/api.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require('dotenv').config()
22

33
import { readJsonSync } from 'fs-extra'
44
import { difference } from 'lodash-es'
5-
import { compare as compareSemVers } from 'semver'
5+
import { gt, compare as compareSemVers } from 'semver'
66
import downloadApiDocs from './api-docs-sync'
77
import algoliaDriver from './drivers/algolia'
88
import jsonDriver from './drivers/json'
@@ -42,9 +42,11 @@ async function processDocs(driver, project) {
4242
}
4343

4444
try {
45-
console.log(`Processing ${project} for versions: ${versionsToProcess}`)
46-
47-
await versionsToProcess
45+
// iterate versions and drop latest minor of each major in buckets
46+
// make an array of the latest minors you get
47+
let latestPatches = Object.values(versionsToProcess.reduce(addIfLatestPatch, {}));
48+
console.log(`Processing ${project} for versions: ${latestPatches}`)
49+
await latestPatches
4850
.filter(version => filterMissingRevs(version, project))
4951
.map(version => readIndexFileForVersion(version, project))
5052
// Fetch all public modules and public classes
@@ -54,7 +56,6 @@ async function processDocs(driver, project) {
5456
// Run the schema against all data stored
5557
.map(mapDataForVersion)
5658
.map(content => writeToDriver(driver, content))
57-
5859
let versions = [...prevIndexedVersions, ...versionsToProcess].sort(
5960
compareSemVers
6061
)
@@ -69,6 +70,19 @@ async function processDocs(driver, project) {
6970
}
7071
}
7172

73+
function addIfLatestPatch(latestPatches, version) {
74+
let semvers = version.split('.')
75+
let major = semvers[0];
76+
let minor = semvers[1];
77+
let minorVersion = `${major}.${minor}`;
78+
if (minorVersion in latestPatches && gt(version, latestPatches[minorVersion])) {
79+
latestPatches[minorVersion] = version;
80+
} else if (!(minorVersion in latestPatches)) {
81+
latestPatches[minorVersion] = version;
82+
}
83+
return latestPatches;
84+
}
85+
7286
function filterMissingRevs(version, libName) {
7387
const emberVersionJSONPath = `./tmp/rev-index/${libName}-${version}.json`
7488
let isIncluded = true

0 commit comments

Comments
 (0)