Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dynamic versionScheme import #5393

Merged
merged 1 commit into from Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 2 additions & 23 deletions lib/config/definitions.ts
Expand Up @@ -7,18 +7,16 @@ import {
VERSION_SCHEME_HEX,
VERSION_SCHEME_HASHICORP,
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,
} from '../constants/version-schemes';
import { getVersionSchemeList } from '../versioning';
import {
PLATFORM_TYPE_AZURE,
PLATFORM_TYPE_BITBUCKET,
Expand Down Expand Up @@ -659,26 +657,7 @@ const options: RenovateOptions[] = [
name: 'versionScheme',
description: 'Version scheme to use for filtering and comparisons',
type: 'string',
allowedValues: [
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,
],
allowedValues: getVersionSchemeList(),
default: VERSION_SCHEME_SEMVER,
cli: false,
env: false,
Expand Down
26 changes: 19 additions & 7 deletions lib/versioning/index.ts
@@ -1,5 +1,5 @@
import fs from 'fs';
import { logger } from '../logger';
import { getOptions } from '../config/definitions';
import {
VersioningApi,
VersioningApiConstructor,
Expand All @@ -8,14 +8,26 @@ import {

export * from './common';

const supportedSchemes = getOptions().find(
option => option.name === 'versionScheme'
).allowedValues;

const schemes: Record<string, VersioningApi | VersioningApiConstructor> = {};

for (const scheme of supportedSchemes) {
schemes[scheme] = require('./' + scheme).api; // eslint-disable-line
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
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 {
Expand Down