feat: dynamic versionScheme import (#5393)

This commit is contained in:
Rhys Arkins 2020-02-06 13:23:24 +00:00 committed by GitHub
parent 987e0a2bfd
commit 0ec6617b6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 30 deletions

View file

@ -7,18 +7,16 @@ import {
VERSION_SCHEME_HEX, VERSION_SCHEME_HEX,
VERSION_SCHEME_HASHICORP, VERSION_SCHEME_HASHICORP,
VERSION_SCHEME_IVY, VERSION_SCHEME_IVY,
VERSION_SCHEME_LOOSE,
VERSION_SCHEME_MAVEN, VERSION_SCHEME_MAVEN,
VERSION_SCHEME_NODE, VERSION_SCHEME_NODE,
VERSION_SCHEME_NPM, VERSION_SCHEME_NPM,
VERSION_SCHEME_NUGET,
VERSION_SCHEME_PEP440, VERSION_SCHEME_PEP440,
VERSION_SCHEME_POETRY, VERSION_SCHEME_POETRY,
VERSION_SCHEME_REGEX,
VERSION_SCHEME_RUBY, VERSION_SCHEME_RUBY,
VERSION_SCHEME_SEMVER, VERSION_SCHEME_SEMVER,
VERSION_SCHEME_SWIFT, VERSION_SCHEME_SWIFT,
} from '../constants/version-schemes'; } from '../constants/version-schemes';
import { getVersionSchemeList } from '../versioning';
import { import {
PLATFORM_TYPE_AZURE, PLATFORM_TYPE_AZURE,
PLATFORM_TYPE_BITBUCKET, PLATFORM_TYPE_BITBUCKET,
@ -659,26 +657,7 @@ const options: RenovateOptions[] = [
name: 'versionScheme', name: 'versionScheme',
description: 'Version scheme to use for filtering and comparisons', description: 'Version scheme to use for filtering and comparisons',
type: 'string', type: 'string',
allowedValues: [ allowedValues: getVersionSchemeList(),
VERSION_SCHEME_CARGO,
VERSION_SCHEME_COMPOSER,
VERSION_SCHEME_DOCKER,
VERSION_SCHEME_GIT,
VERSION_SCHEME_HASHICORP,
VERSION_SCHEME_HEX,
VERSION_SCHEME_IVY,
VERSION_SCHEME_LOOSE,
VERSION_SCHEME_MAVEN,
VERSION_SCHEME_NODE,
VERSION_SCHEME_NPM,
VERSION_SCHEME_NUGET,
VERSION_SCHEME_PEP440,
VERSION_SCHEME_POETRY,
VERSION_SCHEME_REGEX,
VERSION_SCHEME_RUBY,
VERSION_SCHEME_SEMVER,
VERSION_SCHEME_SWIFT,
],
default: VERSION_SCHEME_SEMVER, default: VERSION_SCHEME_SEMVER,
cli: false, cli: false,
env: false, env: false,

View file

@ -1,5 +1,5 @@
import fs from 'fs';
import { logger } from '../logger'; import { logger } from '../logger';
import { getOptions } from '../config/definitions';
import { import {
VersioningApi, VersioningApi,
VersioningApiConstructor, VersioningApiConstructor,
@ -8,14 +8,26 @@ import {
export * from './common'; export * from './common';
const supportedSchemes = getOptions().find(
option => option.name === 'versionScheme'
).allowedValues;
const schemes: Record<string, VersioningApi | VersioningApiConstructor> = {}; const schemes: Record<string, VersioningApi | VersioningApiConstructor> = {};
for (const scheme of supportedSchemes) { const versionSchemeList: string[] = [];
export const getVersionSchemeList = (): string[] => versionSchemeList;
const versionSchemes = fs
.readdirSync(__dirname, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
.sort();
for (const scheme of versionSchemes) {
try {
schemes[scheme] = require('./' + scheme).api; // eslint-disable-line schemes[scheme] = require('./' + scheme).api; // eslint-disable-line
versionSchemeList.push(scheme);
} catch (err) /* istanbul ignore next */ {
logger.fatal({ err }, `Can not load version scheme "${scheme}".`);
process.exit(1);
}
} }
export function get(versionScheme: string): VersioningApi { export function get(versionScheme: string): VersioningApi {