diff --git a/.travis.yml b/.travis.yml index 079b0a7..3755d1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ node_js: script: - npm run lint - - npm run build:silent + - npm run build + - npm run init:examples + - npm run build:examples:silent - npm run test - npm run test:coverage:coveralls diff --git a/commons/constants.ts b/commons/constants.ts index df3322c..546ed26 100644 --- a/commons/constants.ts +++ b/commons/constants.ts @@ -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', diff --git a/config/config.ts b/config/config.ts index 95c9364..bbf4842 100644 --- a/config/config.ts +++ b/config/config.ts @@ -3,13 +3,13 @@ import * as program from 'commander' import { ComparableVersion } from '../commons/ComparableVersion' +import { DEFAULT_CONFIG_OPTIONS } from '../commons/constants' import type { IConfigOptions } from '../interfaces/config.interfaces' import type { ConfigWrapper, IChromeSingleConfig } from '../interfaces/interfaces' import { logger } from '../log/spinner' /* eslint-disable-next-line import/no-namespace */ import * as packageJson from '../package.json' import { mapOS } from '../utils' -import { DEFAULT_CONFIG_OPTIONS } from '../commons/constants'; /** * Checks the arguments passed to the programm and returns them diff --git a/download.ts b/download.ts index 5b0d77e..81cc9fe 100644 --- a/download.ts +++ b/download.ts @@ -5,14 +5,14 @@ import * as unzipper from 'unzipper' import { promisify } from 'util' 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') @@ -40,23 +40,29 @@ function registerSigIntHandler(path: string): void { }) } +function enrichAdditionalConfig(additionalConfig: Partial): 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): Promise { +export async function downloadChromium(additionalConfig: Partial): Promise { - 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() diff --git a/examples/example-download-all-params.ts b/examples/example-download-all-params.ts index d1a4980..da297c4 100644 --- a/examples/example-download-all-params.ts +++ b/examples/example-download-all-params.ts @@ -1,5 +1,6 @@ import { downloadChromium } from 'rusted-chromium' -import { ComparableVersion } from '../commons/ComparableVersion'; + +import { ComparableVersion } from '../commons/ComparableVersion' downloadChromium({ arch: 'x64', diff --git a/examples/example-download-single.ts b/examples/example-download-single.ts index b10bbcd..8941eab 100644 --- a/examples/example-download-single.ts +++ b/examples/example-download-single.ts @@ -1,4 +1,5 @@ import { downloadChromium } from 'rusted-chromium' + import { ComparableVersion } from '../commons/ComparableVersion' downloadChromium({ diff --git a/examples/example-export.ts b/examples/example-export.ts index 1eab3e9..d5265e0 100644 --- a/examples/example-export.ts +++ b/examples/example-export.ts @@ -1,4 +1,4 @@ -import { exportStore } from 'rusted-chromium'; +import { exportStore } from 'rusted-chromium' exportStore({ quiet: false, diff --git a/package.json b/package.json index 0d8bccf..66c8295 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,12 @@ "test:coverage": "jest --coverage", "test:coverage:coveralls": "jest --coverage --coverageReporters=text-lcov | coveralls", "test:debug": "node --inspect --inspect-brk node_modules/.bin/jest --runInBand", + "init:examples": "cd examples/ && npm install", "prebuild": "npm run clean", "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/" }, diff --git a/utils/typeguards.ts b/utils/typeguards.ts index 5dbdeab..ed566fc 100644 --- a/utils/typeguards.ts +++ b/utils/typeguards.ts @@ -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' @@ -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): value is Partial { + return value.single !== null +}