Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
BuZZ-T committed Nov 29, 2021
1 parent 55976b2 commit 8bd3cc9
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 23 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
5 changes: 3 additions & 2 deletions config/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import type { MaybeMockedDeep } from 'ts-jest/dist/utils/testing'
import { mocked } from 'ts-jest/utils'

import { ComparableVersion } from '../commons/ComparableVersion'
import { DEFAULT_CONFIG_OPTIONS } from '../commons/constants'
import type { IChromeConfigWrapper, IStoreConfigWrapper, IExportConfigWrapper } from '../interfaces/interfaces'
import type { OS } from '../interfaces/os.interfaces'
import { Spinner, logger } from '../log/spinner'
import { createChromeFullConfig, createChromeOptions, createImportConfig, createExportConfig } from '../test.utils'
import { DEFAULT_OPTIONS, readConfig } from './config'
import { readConfig } from './config'

/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const program = require('commander')
Expand Down Expand Up @@ -109,7 +110,7 @@ describe('config', () => {

it('should set increase on fail', () => {
programMock.opts.mockReturnValue({
...DEFAULT_OPTIONS,
...DEFAULT_CONFIG_OPTIONS,
increaseOnFail: true,
})

Expand Down
2 changes: 1 addition & 1 deletion config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 20 additions & 14 deletions download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -40,23 +40,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
3 changes: 2 additions & 1 deletion examples/example-download-all-params.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { downloadChromium } from 'rusted-chromium'
import { ComparableVersion } from '../commons/ComparableVersion';

import { ComparableVersion } from '../commons/ComparableVersion'

downloadChromium({
arch: 'x64',
Expand Down
1 change: 1 addition & 0 deletions examples/example-download-single.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { downloadChromium } from 'rusted-chromium'

import { ComparableVersion } from '../commons/ComparableVersion'

downloadChromium({
Expand Down
2 changes: 1 addition & 1 deletion examples/example-export.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exportStore } from 'rusted-chromium';
import { exportStore } from 'rusted-chromium'

exportStore({
quiet: false,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
},
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 8bd3cc9

Please sign in to comment.