本文整理汇总了TypeScript中semver.valid函数的典型用法代码示例。如果您正苦于以下问题:TypeScript valid函数的具体用法?TypeScript valid怎么用?TypeScript valid使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了valid函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
return this.getVersionList().then(list => {
let chromedriverVersion: string = null;
let latest = '';
let latestVersion = '';
for (let item of list) {
// Get a semantic version
let version = item.split('/')[0];
if (semver.valid(version) == null) {
version += '.0';
if (semver.valid(version)) {
// First time: use the version found.
if (chromedriverVersion == null) {
chromedriverVersion = version;
latest = item;
latestVersion = item.split('/')[0];
} else if (semver.gt(version, chromedriverVersion)) {
// After the first time, make sure the semantic version is greater.
chromedriverVersion = version;
latest = item;
latestVersion = item.split('/')[0];
} else if (version === chromedriverVersion) {
// If the semantic version is the same, check os arch.
// For 64-bit systems, prefer the 64-bit version.
if (this.osarch === 'x64') {
if (item.includes(this.getOsTypeName() + '64')) {
latest = item;
}
}
}
}
}
}
return {url: Config.cdnUrls().chrome + latest, version: latestVersion};
});
示例2:
.sort((a, b) => {
if (!semver.valid(a) && !semver.valid(b)) {
return a.localeCompare(b);
}
if (!semver.valid(a)) {
return -1;
}
if (!semver.valid(b)) {
return 1;
}
return semver.gt(a, b, true) ? -1 : 1;
})
示例3: _isValid
protected _isValid(version: Version, modifiedWith: Version): boolean {
if (!semver.valid(version)) {
this.log(
"Generator version format doesn't follow SemVer: 1.2.3(-4|-alpha.5|-beta.6)"
);
} else if (semver.valid(modifiedWith) && semver.lt(version, modifiedWith)) {
this.log(
`Current generator version (${version}) is lower than that used last time (${modifiedWith})
Upgrade generator-wupjs before proceeding further`
);
} else {
return true;
}
return false;
}
示例4: main
async function main() {
const validTag = !!semver.valid(commitMessage);
if (!validTag) {
console.log('Not a valid version tag, not publishing');
return;
}
if (process.env.TRAVIS_OS_NAME === 'osx') {
const allReleases: GithubMeta<Release[]> = await gh.repos.getReleases({
owner: 'SanderRonde',
repo: 'media-app',
per_page: 20,
page: 0
});
const latestRelease = allReleases.data[0];
if (latestRelease.tag_name !== `v${VERSION}`) {
console.log('Latest release does not match this version, not publishing')
return;
}
await gh.repos.editRelease({
owner: 'SanderRonde',
repo: 'media-app',
id: latestRelease.id + '',
tag_name: `v${VERSION}`,
draft: false
});
console.log('Succesfully created release');
} else {
console.log('Not publishing since this is linux');
}
}
示例5: convertXmlToVersionList
export function convertXmlToVersionList(
fileName: string, matchFile: string,
versionParser: (key: string) => string | null,
semanticVersionParser: (key: string) => string): VersionList|null {
const xmlJs = readXml(fileName);
if (!xmlJs) {
return null;
}
const versionList: VersionList = {};
for (const content of xmlJs['ListBucketResult']['Contents']) {
const key = content['Key'][0] as string;
if (key.includes(matchFile)) {
const version = versionParser(key);
if (version) {
const semanticVersion = semanticVersionParser(key);
if (!semver.valid(semanticVersion)) {
continue;
}
const name = key.split('/')[1];
const size = +content['Size'][0];
if (!versionList[semanticVersion]) {
versionList[semanticVersion] = {};
}
versionList[semanticVersion][name] = {name, size, url: key, version};
}
}
}
return versionList;
}
示例6: updatePlatform
private async updatePlatform(platform: string, version: string, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise<void> {
const platformData = this.$platformsData.getPlatformData(platform, projectData);
const data = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName);
const currentVersion = data && data.version ? data.version : "0.2.0";
const installedModuleDir = temp.mkdirSync("runtime-to-update");
let newVersion = version === constants.PackageVersion.NEXT ?
await this.$packageInstallationManager.getNextVersion(platformData.frameworkPackageName) :
version || await this.$packageInstallationManager.getLatestCompatibleVersion(platformData.frameworkPackageName);
await this.$pacoteService.extractPackage(`${platformData.frameworkPackageName}@${newVersion}`, installedModuleDir);
const cachedPackageData = this.$fs.readJson(path.join(installedModuleDir, "package.json"));
newVersion = (cachedPackageData && cachedPackageData.version) || newVersion;
const canUpdate = platformData.platformProjectService.canUpdatePlatform(installedModuleDir, projectData);
if (canUpdate) {
if (!semver.valid(newVersion)) {
this.$errors.fail("The version %s is not valid. The version should consists from 3 parts separated by dot.", newVersion);
}
if (!semver.gt(currentVersion, newVersion)) {
await this.updatePlatformCore(platformData, { currentVersion, newVersion, canUpdate, platformTemplate }, projectData, config);
} else if (semver.eq(currentVersion, newVersion)) {
this.$errors.fail("Current and new version are the same.");
} else {
this.$errors.fail(`Your current version: ${currentVersion} is higher than the one you're trying to install ${newVersion}.`);
}
} else {
this.$errors.failWithoutHelp("Native Platform cannot be updated.");
}
}
示例7: fullyQualifyVersion
// We sometimes deal with 'x.y'-style version tags because the minor version doesn't
// really matter, but the semver module *requires* that we use x.y.z notation. So
// this module appends a '.0' to those versions to ensure that the semver module
// doesn't crash due to a version syntax problem.
function fullyQualifyVersion(version: string): string {
if (!valid(version)) {
return version + '.0';
}
return version;
}
示例8: appendVersion
function appendVersion(packageToInstall: string, version: string) {
const validSemver = semver.valid(version)
if (validSemver) {
packageToInstall += `@${validSemver}`
}
return packageToInstall
}
示例9: return
return (() => {
let platformData = this.$platformsData.getPlatformData(platform);
this.$projectDataService.initialize(this.$projectData.projectDir);
let data = this.$projectDataService.getValue(platformData.frameworkPackageName).wait();
let currentVersion = data && data.version ? data.version : "0.2.0";
let newVersion = version || this.$npmInstallationManager.getLatestVersion(platformData.frameworkPackageName).wait();
let cachedPackageData = this.$npmInstallationManager.addToCache(platformData.frameworkPackageName, newVersion).wait();
newVersion = (cachedPackageData && cachedPackageData.version) || newVersion;
let canUpdate = platformData.platformProjectService.canUpdatePlatform(currentVersion, newVersion).wait();
if (canUpdate) {
if (!semver.valid(newVersion)) {
this.$errors.fail("The version %s is not valid. The version should consists from 3 parts separated by dot.", newVersion);
}
if (semver.gt(currentVersion, newVersion)) { // Downgrade
let isUpdateConfirmed = this.$prompter.confirm(`You are going to downgrade to runtime v.${newVersion}. Are you sure?`, () => false).wait();
if (isUpdateConfirmed) {
this.updatePlatformCore(platformData, currentVersion, newVersion, canUpdate).wait();
}
} else if (semver.eq(currentVersion, newVersion)) {
this.$errors.fail("Current and new version are the same.");
} else {
this.updatePlatformCore(platformData, currentVersion, newVersion, canUpdate).wait();
}
} else {
this.updatePlatformCore(platformData, currentVersion, newVersion, canUpdate).wait();
}
}).future<void>()();
示例10:
validate: (version: Version): true | string => {
if (!semver.valid(version)) {
return "Version format doesn't follow SemVer: 1.2.3(-4|-alpha.5|-beta.6)";
}
return true;
}