Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | 4x 4x 4x 4x 6x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4x 4x 10x 2x 2x 2x 4x 2x 2x | import { ComparableVersion } from '../commons/ComparableVersion'
import { ALL_FALSE_SINGLE_CONFIG } from '../commons/constants'
import type { DownloadReportEntry, IChromeSingleConfig } from '../interfaces/interfaces'
import type { OS } from '../interfaces/os.interfaces'
import type { Arch } from '../interfaces/store.interfaces'
import { downloadChromium } from './download'
// https://stackoverflow.com/questions/56933109/pick-one-key-value-pair-from-type
type PickOne<T> = { [P in keyof T]: Record<P, T[P]> & Partial<Record<Exclude<keyof T, P>, undefined>> }[keyof T]
export abstract class FluentDownloadSingle<T> {
protected config: IChromeSingleConfig
constructor(config?: IChromeSingleConfig) {
this.config = {
...ALL_FALSE_SINGLE_CONFIG,
...config
}
}
protected addToConfig(pConfig: PickOne<IChromeSingleConfig>): T {
this.config = {
...this.config,
...pConfig,
}
return this.self()
}
protected abstract self(): T
public arch(arch: Arch): T {
this.config.arch = arch
return this.self()
}
public autoUnzip(): T {
this.config.autoUnzip = true
return this.self()
}
public debug(): T {
this.config.debug = true
return this.self()
}
public download(): T {
this.config.download = true
return this.self()
}
public downloadFolder(downloadFolder: string): T {
this.config.downloadFolder = downloadFolder
return this.self()
}
public os(os: OS): T {
this.config.os = os
return this.self()
}
public quiet(): T {
this.config.quiet = true
return this.self()
}
public store(): T {
this.config.store = true
return this.self()
}
}
export class FluentDownloadSingleIncomplete extends FluentDownloadSingle<FluentDownloadSingleIncomplete> {
public constructor() {
super()
}
protected self(): FluentDownloadSingleIncomplete {
return this
}
public single(comparableVersion: ComparableVersion | string): FluentDownloadSingleComplete {
const single = typeof comparableVersion === 'string'
? new ComparableVersion(comparableVersion)
: comparableVersion
this.addToConfig({ single })
return new FluentDownloadSingleComplete(this.config)
}
}
export class FluentDownloadSingleComplete extends FluentDownloadSingle<FluentDownloadSingleComplete> {
public constructor(config: IChromeSingleConfig) {
super(config)
}
protected self(): FluentDownloadSingleComplete {
return this
}
public start(): Promise<DownloadReportEntry[]> {
return downloadChromium(this.config)
}
}
|