Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify global init (#6452)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
- Loading branch information
Showing
2 changed files
with
65 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os from 'os'; | ||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import { RenovateConfig } from '../../config/common'; | ||
import { logger } from '../../logger'; | ||
import { initPlatform } from '../../platform'; | ||
import * as globalCache from '../../util/cache/global'; | ||
import { setEmojiConfig } from '../../util/emoji'; | ||
import * as limits from './limits'; | ||
|
||
async function setDirectories(input: RenovateConfig): Promise<RenovateConfig> { | ||
const config: RenovateConfig = { ...input }; | ||
process.env.TMPDIR = process.env.RENOVATE_TMPDIR || os.tmpdir(); | ||
if (config.baseDir) { | ||
logger.debug('Using configured baseDir: ' + config.baseDir); | ||
} else { | ||
config.baseDir = path.join(process.env.TMPDIR, 'renovate'); | ||
logger.debug('Using baseDir: ' + config.baseDir); | ||
} | ||
await fs.ensureDir(config.baseDir); | ||
if (config.cacheDir) { | ||
logger.debug('Using configured cacheDir: ' + config.cacheDir); | ||
} else { | ||
config.cacheDir = path.join(config.baseDir, 'cache'); | ||
logger.debug('Using cacheDir: ' + config.cacheDir); | ||
} | ||
await fs.ensureDir(config.cacheDir); | ||
return config; | ||
} | ||
|
||
export async function globalInitialize( | ||
config_: RenovateConfig | ||
): Promise<RenovateConfig> { | ||
let config = config_; | ||
config = await initPlatform(config); | ||
config = await setDirectories(config); | ||
globalCache.init(config); | ||
limits.init(config); | ||
setEmojiConfig(config); | ||
return config; | ||
} | ||
|
||
export function globalFinalize(config: RenovateConfig): void { | ||
globalCache.cleanup(config); | ||
} |