Skip to content

Commit

Permalink
Add report to downloadChromium
Browse files Browse the repository at this point in the history
  • Loading branch information
BuZZ-T committed Apr 16, 2022
1 parent 4458288 commit 969930a
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 38 deletions.
10 changes: 6 additions & 4 deletions download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fetchChromeZipFile } from './api'
import { DEFAULT_FULL_CONFIG, DEFAULT_SINGLE_CONFIG } from './commons/constants'
import { DOWNLOAD_ZIP, EXTRACT_ZIP } from './commons/loggerTexts'
import { NoChromiumDownloadError } from './errors'
import type { IChromeConfig } from './interfaces/interfaces'
import type { DownloadReportEntry, IChromeConfig } from './interfaces/interfaces'
import { logger } from './log/logger'
import { progress } from './log/progress'
import { spinner } from './log/spinner'
Expand Down Expand Up @@ -77,14 +77,14 @@ async function extractZip(downloadPath: string) {
* @see DEFAULT_SINGLE_CONFIG
* @param additionalConfig Manually set config, which will override the settings in the default config
*/
async function downloadForConfig(config: IChromeConfig): Promise<void> {
async function downloadForConfig(config: IChromeConfig): Promise<DownloadReportEntry[]> {

const versions = await loadVersions()
const store = await loadStore()

const mappedVersions = mapVersions(versions, config, store)

const { chromeUrl, selectedVersion, filenameOS } = await getChromeDownloadUrl(config, mappedVersions)
const { chromeUrl, filenameOS, report, selectedVersion } = await getChromeDownloadUrl(config, mappedVersions)

if (chromeUrl && selectedVersion && config.download) {
const filename = `chrome-${filenameOS}-${config.arch}-${selectedVersion.value}`
Expand Down Expand Up @@ -128,7 +128,7 @@ async function downloadForConfig(config: IChromeConfig): Promise<void> {
if (config.autoUnzip) {
await extractZip(downloadPath)
}
resolve()
resolve(report)
})

zipFileResponse.body.on('error', () => {
Expand All @@ -140,6 +140,8 @@ async function downloadForConfig(config: IChromeConfig): Promise<void> {
if (!chromeUrl && config.download && config.single) {
throw new NoChromiumDownloadError()
}

return report
}

/**
Expand Down
12 changes: 11 additions & 1 deletion interfaces/function.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import type { MappedVersion } from '../commons/MappedVersion'
import type { Nullable } from './interfaces'
import type { DownloadReportEntry, IChromeFullConfig, Nullable } from './interfaces'
import { OSSetting } from './os.interfaces'

export interface ContinueFetchingChromeUrlReturn {
chromeUrl: Nullable<string>
report: DownloadReportEntry[]
selectedVersion: Nullable<MappedVersion>
}

export interface GetChromeDownloadUrlReturn {
chromeUrl: Nullable<string>
selectedVersion: Nullable<MappedVersion>
filenameOS: string
report: DownloadReportEntry[]
}

export interface ContinueFetchingChromeUrlParams {
config: IChromeFullConfig
mappedVersions: MappedVersion[]
osSetting: OSSetting
version: Nullable<MappedVersion>
}
7 changes: 7 additions & 0 deletions interfaces/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ComparableVersion } from '../commons/ComparableVersion'
import { MappedVersion } from '../commons/MappedVersion'
import type { OS } from './os.interfaces'
import type { Arch } from './store.interfaces'

Expand Down Expand Up @@ -126,3 +127,9 @@ export interface IVersionWithDisabled extends IVersion {
}

export type Nullable<T> = T | undefined | null

export interface DownloadReportEntry {
binaryExists: boolean
download: boolean
version: Nullable<MappedVersion>
}
1 change: 1 addition & 0 deletions test/test.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const createGetChromeDownloadUrlReturn = (settings?: Partial<GetChromeDow
chromeUrl: 'chromeUrl',
selectedVersion: new MappedVersion(10, 0, 0, 0, false),
filenameOS: 'filenameOS',
report: [],
...settings,
})

Expand Down

0 comments on commit 969930a

Please sign in to comment.