Skip to content

Commit bc9db81

Browse files
committed
fix: support for multiple smartbulls
1 parent 81d77c1 commit bc9db81

1 file changed

Lines changed: 37 additions & 36 deletions

File tree

  • apps/package-manager/packages/generic/src/generateExpectations/nrk

apps/package-manager/packages/generic/src/generateExpectations/nrk/smartbull.ts

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,61 +32,62 @@ export function getSmartbullExpectedPackages(
3232
logger: LoggerInstance,
3333
expectedPackages: ExpectedPackageWrap[]
3434
): ExpectedPackageWrapMediaFile[] {
35-
let orgSmartbullExpectedPackage: ExpectedPackageWrap | undefined = undefined
35+
const orgSmartbullExpectedPackages: ExpectedPackageWrap[] = []
3636

3737
// Find the smartbull package:
3838
for (const packageWrap of expectedPackages) {
3939
if (expectedPackageIsSmartbull(packageWrap)) {
4040
// hack
41-
orgSmartbullExpectedPackage = packageWrap
41+
orgSmartbullExpectedPackages.push(packageWrap)
4242
}
4343
}
4444

4545
// Find smartbull source packages:
46-
const smartbullExpectations: ExpectedPackageWrap[] = []
46+
const smartbullExpectations: ExpectedPackageWrapMediaFile[] = []
4747
for (const packageWrap of expectedPackages) {
4848
if (expectedPackageIsSmartbullSource(packageWrap)) {
4949
// Set the smartbull priority:
5050
packageWrap.priority = PriorityMagnitude.PLAY_SOON
51-
smartbullExpectations.push(packageWrap)
51+
smartbullExpectations.push(packageWrap as ExpectedPackageWrapMediaFile)
5252
}
5353
}
5454

55-
// Handle Smartbull:
56-
const smartbulls: ExpectedPackageWrapMediaFile[] = []
57-
if (orgSmartbullExpectedPackage && smartbullExpectations.length > 0) {
58-
// Sort alphabetically on filePath:
59-
smartbullExpectations.sort((a, b) => {
60-
const expA = a.expectedPackage as ExpectedPackage.ExpectedPackageMediaFile
61-
const expB = b.expectedPackage as ExpectedPackage.ExpectedPackageMediaFile
55+
// Sort smartbulls alphabetically on filePath:
56+
smartbullExpectations.sort((a, b) => {
57+
// Lowest first:
58+
if (a.expectedPackage.content.filePath > b.expectedPackage.content.filePath) return 1
59+
if (a.expectedPackage.content.filePath < b.expectedPackage.content.filePath) return -1
6260

63-
// lowest first:
64-
if (expA.content.filePath > expB.content.filePath) return 1
65-
if (expA.content.filePath < expB.content.filePath) return -1
61+
// Lowest first: (lower is better)
62+
if (a.priority > b.priority) return 1
63+
if (a.priority < b.priority) return -1
6664

67-
return 0
68-
})
69-
// Pick the last one:
70-
const bestSmartbull = smartbullExpectations[smartbullExpectations.length - 1] as
71-
| ExpectedPackageWrapMediaFile
72-
| undefined
73-
if (bestSmartbull) {
74-
if (orgSmartbullExpectedPackage.expectedPackage.type === ExpectedPackage.PackageType.MEDIA_FILE) {
75-
const org = orgSmartbullExpectedPackage as ExpectedPackageWrapMediaFile
65+
return 0
66+
})
67+
// Pick the last one:
68+
const bestSmartbull =
69+
smartbullExpectations.length > 0 ? smartbullExpectations[smartbullExpectations.length - 1] : undefined
7670

77-
const newPackage: ExpectedPackageWrapMediaFile = {
78-
...org,
79-
expectedPackage: {
80-
...org.expectedPackage,
81-
// Take these from bestSmartbull:
82-
content: bestSmartbull.expectedPackage.content,
83-
version: {}, // Don't even use bestSmartbull.expectedPackage.version,
84-
sources: bestSmartbull.expectedPackage.sources,
85-
},
86-
}
87-
smartbulls.push(newPackage)
88-
} else logger.warn('orgSmartbullExpectation is not a MEDIA_FILE')
89-
}
71+
if (!bestSmartbull) return []
72+
73+
// Handle Smartbull:
74+
const smartbulls: ExpectedPackageWrapMediaFile[] = []
75+
for (const orgSmartbullExpectedPackage of orgSmartbullExpectedPackages) {
76+
if (orgSmartbullExpectedPackage.expectedPackage.type === ExpectedPackage.PackageType.MEDIA_FILE) {
77+
const org = orgSmartbullExpectedPackage as ExpectedPackageWrapMediaFile
78+
79+
const newPackage: ExpectedPackageWrapMediaFile = {
80+
...org,
81+
expectedPackage: {
82+
...org.expectedPackage,
83+
// Take these from bestSmartbull:
84+
content: bestSmartbull.expectedPackage.content,
85+
version: {}, // Don't even use bestSmartbull.expectedPackage.version,
86+
sources: bestSmartbull.expectedPackage.sources,
87+
},
88+
}
89+
smartbulls.push(newPackage)
90+
} else logger.warn('orgSmartbullExpectation is not a MEDIA_FILE')
9091
}
9192
return smartbulls
9293
}

0 commit comments

Comments
 (0)