Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
BuZZ-T committed Nov 28, 2021
1 parent 55976b2 commit 9619a01
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ node_js:
script:
- npm run lint
- npm run build:silent
- npm run build:examples:silent
- npm run test
- npm run test:coverage:coveralls
4 changes: 2 additions & 2 deletions commons/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IConfigOptions } from '../interfaces/config.interfaces'
import type { LoggerConfig } from '../interfaces/interfaces'
import type { IChromeFullConfig, IChromeSingleConfig } from '../interfaces/interfaces'
import { ComparableVersion } from './ComparableVersion';
import type { IConfigOptions } from '../interfaces/config.interfaces'
import { ComparableVersion } from './ComparableVersion'

export const LOAD_CONFIG: LoggerConfig = {
start: 'Downloading local storage file',
Expand Down
35 changes: 21 additions & 14 deletions download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { join as pathJoin } from 'path'
/* eslint-disable-next-line import/no-namespace */
import * as unzipper from 'unzipper'
import { promisify } from 'util'
import { config } from 'yargs'

import { fetchChromeZipFile } from './api'
import { DEFAULT_FULL_CONFIG, DEFAULT_SINGLE_CONFIG } from './commons/constants'
import { NoChromiumDownloadError } from './errors'
import type { IChromeConfig } from './interfaces/interfaces'
import { progress } from './log/progress'
import { logger } from './log/spinner'
import { loadStore } from './store/loadStore'
import { isChromeSingleConfig } from './utils/typeguards'
import { getChromeDownloadUrl, loadVersions, mapVersions } from './versions'
import { IChromeFullConfig, IChromeSingleConfig } from './interfaces/interfaces'
import { DEFAULT_FULL_CONFIG, DEFAULT_SINGLE_CONFIG } from './commons/constants'

/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const Progress = require('node-fetch-progress')
Expand Down Expand Up @@ -40,23 +41,29 @@ function registerSigIntHandler(path: string): void {
})
}

function enrichAdditionalConfig(additionalConfig: Partial<IChromeConfig>): IChromeConfig {
if (isChromeSingleConfig(additionalConfig)) {
return {
...DEFAULT_SINGLE_CONFIG,
...additionalConfig,
}
} else {
return {
...DEFAULT_FULL_CONFIG,
...additionalConfig,
}
}
}

/**
*
* Downloads a chromium zip file based on the given config
* @see DEFAULT_FULL_CONFIG
* @see DEFAULT_SINGLE_CONFIG
* @param configParam
* @param additionalConfig Manually set config, which will override the settings in the default config
*/
export async function downloadChromium(configParam: Partial<IChromeConfig>): Promise<void> {
export async function downloadChromium(additionalConfig: Partial<IChromeConfig>): Promise<void> {

const config: IChromeConfig = configParam.single === null
? {
...DEFAULT_SINGLE_CONFIG,
...configParam,
} as IChromeSingleConfig
: {
...DEFAULT_FULL_CONFIG,
...configParam,
} as IChromeFullConfig
const config = enrichAdditionalConfig(additionalConfig)

const versions = await loadVersions()
const store = await loadStore()
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"build": "tsc -p tsconfig.json",
"build:silent": "npm run build -- --noEmit",
"build:examples": "cd examples/ && npm run build",
"build:examples:silent": "cd examples/ && npm run build -- --noEmit",
"release": "npm run build && npm publish",
"release-github": "npm run build && npm publish --registry=https://npm.pkg.github.com/"
},
Expand Down
6 changes: 5 additions & 1 deletion utils/typeguards.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IVersionWithDisabled, IVersion, TextFunction } from '../interfaces/interfaces'
import type { IChromeConfig, IChromeSingleConfig, IVersionWithDisabled, IVersion, TextFunction } from '../interfaces/interfaces'

export function isTextFunction(value: string | TextFunction | undefined): value is TextFunction {
return typeof value === 'function'
Expand All @@ -14,3 +14,7 @@ export function isIVersion(value: unknown): value is IVersion {
export function isIVersionWithDisabled(value: unknown): value is IVersionWithDisabled {
return isIVersion(value) && typeof (value as IVersionWithDisabled).disabled === 'boolean'
}

export function isChromeSingleConfig(value: Partial<IChromeConfig>): value is Partial<IChromeSingleConfig> {
return value.single !== null
}

0 comments on commit 9619a01

Please sign in to comment.