api.ts 2.2 KB
Newer Older
M
Matt Bierner 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import * as semver from 'semver';
7 8
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
M
Matt Bierner 已提交
9 10

export default class API {
M
Matt Bierner 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
	private static fromSimpleString(value: string): API {
		return new API(value, value);
	}

	public static readonly defaultVersion = API.fromSimpleString('1.0.0');
	public static readonly v203 = API.fromSimpleString('2.0.3');
	public static readonly v206 = API.fromSimpleString('2.0.6');
	public static readonly v208 = API.fromSimpleString('2.0.8');
	public static readonly v213 = API.fromSimpleString('2.1.3');
	public static readonly v220 = API.fromSimpleString('2.2.0');
	public static readonly v222 = API.fromSimpleString('2.2.2');
	public static readonly v230 = API.fromSimpleString('2.3.0');
	public static readonly v234 = API.fromSimpleString('2.3.4');
	public static readonly v240 = API.fromSimpleString('2.4.0');
	public static readonly v250 = API.fromSimpleString('2.5.0');
	public static readonly v260 = API.fromSimpleString('2.6.0');
	public static readonly v262 = API.fromSimpleString('2.6.2');
	public static readonly v270 = API.fromSimpleString('2.7.0');
	public static readonly v280 = API.fromSimpleString('2.8.0');
	public static readonly v290 = API.fromSimpleString('2.9.0');
	public static readonly v291 = API.fromSimpleString('2.9.1');

M
Matt Bierner 已提交
33

34 35 36 37 38
	public static fromVersionString(versionString: string): API {
		let version = semver.valid(versionString);
		if (!version) {
			return new API(localize('invalidVersion', 'invalid version'), '1.0.0');
		}
M
Matt Bierner 已提交
39

40
		// Cut off any prerelease tag since we sometimes consume those on purpose.
41 42 43
		const index = versionString.indexOf('-');
		if (index >= 0) {
			version = version.substr(0, index);
M
Matt Bierner 已提交
44
		}
45
		return new API(versionString, version);
M
Matt Bierner 已提交
46 47
	}

48 49 50 51 52
	private constructor(
		public readonly versionString: string,
		private readonly version: string
	) { }

M
Matt Bierner 已提交
53 54
	public gte(other: API): boolean {
		return semver.gte(this.version, other.version);
55
	}
M
Matt Bierner 已提交
56
}