Skip to content

Commit

Permalink
add debug: boolean to all API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
BuZZ-T committed May 4, 2022
1 parent 0369cee commit a69f3fa
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions commons/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const DEFAULT_FULL_CONFIG: IChromeFullConfig = {
single: null,
inverse: false,
quiet: false,
debug: false,
}

export const DEFAULT_SINGLE_CONFIG: IChromeSingleConfig = {
Expand All @@ -49,4 +50,5 @@ export const DEFAULT_SINGLE_CONFIG: IChromeSingleConfig = {
downloadFolder: null,
single: new ComparableVersion(10, 0, 0, 0),
quiet: false,
debug: false,
}
10 changes: 5 additions & 5 deletions config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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 { DebugMode, logger } from '../log/logger'
import { logger } from '../log/logger'
/* eslint-disable-next-line import/no-namespace */
import * as packageJson from '../package.json'
import { mapOS } from '../utils'
Expand Down Expand Up @@ -46,10 +46,6 @@ export function readConfig(args: string[], platform: NodeJS.Platform): ConfigWra

const os = mapOS(options.os || platform)

if(options.debug) {
logger.setDebugMode(DebugMode.DEBUG)
}

if (!options.os && options.arch) {
logger.warn('Setting "--arch" has no effect, when "--os" is not set!')
}
Expand All @@ -66,6 +62,7 @@ export function readConfig(args: string[], platform: NodeJS.Platform): ConfigWra
config: {
url: options.importStore,
quiet: options.quiet,
debug: options.debug,
},
}
}
Expand All @@ -76,6 +73,7 @@ export function readConfig(args: string[], platform: NodeJS.Platform): ConfigWra
config: {
path: typeof options.exportStore === 'string' ? options.exportStore : undefined,
quiet: options.quiet,
debug: options.debug,
}
}
}
Expand All @@ -90,6 +88,7 @@ export function readConfig(args: string[], platform: NodeJS.Platform): ConfigWra
downloadFolder: options.folder || null,
single: new ComparableVersion(options.single),
quiet: options.quiet,
debug: options.debug,
}

return {
Expand Down Expand Up @@ -117,6 +116,7 @@ export function readConfig(args: string[], platform: NodeJS.Platform): ConfigWra
single: null,
inverse: options.inverse,
quiet: options.quiet,
debug: options.debug,
},
}
}
5 changes: 4 additions & 1 deletion download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DEFAULT_FULL_CONFIG, DEFAULT_SINGLE_CONFIG } from './commons/constants'
import { DOWNLOAD_ZIP, EXTRACT_ZIP } from './commons/loggerTexts'
import { NoChromiumDownloadError } from './errors'
import type { DownloadReportEntry, IChromeConfig } from './interfaces/interfaces'
import { logger } from './log/logger'
import { DebugMode, logger } from './log/logger'
import { progress } from './log/progress'
import { spinner } from './log/spinner'
import { loadStore } from './store/loadStore'
Expand Down Expand Up @@ -78,6 +78,9 @@ async function extractZip(downloadPath: string) {
* @param additionalConfig Manually set config, which will override the settings in the default config
*/
async function downloadForConfig(config: IChromeConfig): Promise<DownloadReportEntry[]> {
if(config.debug) {
logger.setDebugMode(DebugMode.DEBUG)
}

const versions = await loadVersions()
const store = await loadStore()
Expand Down
4 changes: 4 additions & 0 deletions interfaces/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface IChromeFullConfig {
single: null
inverse: boolean
quiet: boolean
debug: boolean
}

export interface IChromeSingleConfig {
Expand All @@ -48,16 +49,19 @@ export interface IChromeSingleConfig {
download: boolean
downloadFolder: string | null
quiet: boolean
debug: boolean
}

export interface IStoreConfig {
url: string
quiet: boolean
debug: boolean
}

export interface IExportConfig {
path?: string
quiet: boolean
debug: boolean
}

export type ConfigWrapper = IStoreConfigWrapper | IChromeConfigWrapper | IExportConfigWrapper
Expand Down
5 changes: 5 additions & 0 deletions store/exportStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import { join } from 'path'
import { LOCAL_STORE_FILE } from '../commons/constants'
import { NoLocalstoreError } from '../errors'
import type { IExportConfig } from '../interfaces/interfaces'
import { DebugMode, logger } from '../log/logger'

export function exportStore(config: IExportConfig, stdio: NodeJS.WriteStream): void {
if(config.debug) {
logger.setDebugMode(DebugMode.DEBUG)
}

const filePath = config.path ?? join(__dirname, '..', LOCAL_STORE_FILE)
if (!existsSync(filePath)) {
throw new NoLocalstoreError(config.path)
Expand Down
5 changes: 5 additions & 0 deletions store/importStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { promisify } from 'util'
import { LOCAL_STORE_FILE } from '../commons/constants'
import type { IStoreConfig } from '../interfaces/interfaces'
import type { StoreSize } from '../interfaces/store.interfaces'
import { DebugMode, logger } from '../log/logger'
import { downloadStore } from './downloadStore'
import { readStoreFile } from './readStore'
import type { Store } from './Store'
Expand All @@ -15,6 +16,10 @@ const readFilePromise = promisify(readFile)
const localStoreFilePath = join(__dirname, '..', LOCAL_STORE_FILE)

export async function importAndMergeLocalstore(config: IStoreConfig): Promise<StoreSize> {
if(config.debug) {
logger.setDebugMode(DebugMode.DEBUG)
}

const isURL = config.url.startsWith('http://') || config.url.startsWith('https://')

const store = isURL
Expand Down

0 comments on commit a69f3fa

Please sign in to comment.