本文整理汇总了TypeScript中semver.major函数的典型用法代码示例。如果您正苦于以下问题:TypeScript major函数的具体用法?TypeScript major怎么用?TypeScript major使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了major函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: gnomeTerminalVersion
gnomeTerminalVersion((version: string) => {
logHelper.logStepStarted('gnome-terminal');
if (version === undefined || !semver.valid(version)) {
logHelper.logSubStepFail('gnome-terminal doesn\'t seem to be installed');
return;
}
if (semver.major(version) === 3 && semver.minor(version) >= 8 || semver.major(version) > 3) {
execAndReportSync('applying profile theme (Gnome 3.8+)', path.join(__dirname, '../../data/gnome-terminal/profile-theme-3.8.sh'));
} else {
execAndReportSync('applying profile theme', path.join(__dirname, 'profile-theme.sh'));
}
});
示例2: ngOnInit
ngOnInit() {
let version = this.installation.version;
let currentVersion = this.installation.currentVersion;
let versionMatch = /^(([0-9]+\.){2}[0-9]+)/.exec(version);
if (versionMatch) {
version = versionMatch[1];
} else {
this.status = "outdated";
return null;
}
let major = semver.major(version);
let minor = semver.minor(version);
let patch = semver.patch(version);
let currentMajor = semver.major(currentVersion);
let currentMinor = semver.minor(currentVersion);
let currentPatch = semver.patch(currentVersion);
if (
semver.satisfies(
`${major}.${minor}.${patch}`,
`>=${currentMajor}.${currentMinor}.${currentPatch}`
)
) {
this.status = "up-to-date";
} else if (
semver.satisfies(
`${major}.${minor}.${patch}`,
`>=${currentMajor}.${currentMinor}.x`
)
) {
this.status = "same-minor";
} else {
this.status = "outdated";
}
}
示例3: getLatestCompatibleVersion
public async getLatestCompatibleVersion(packageName: string, referenceVersion?: string): Promise<string> {
referenceVersion = referenceVersion || this.$staticConfig.version;
const isPreReleaseVersion = semver.prerelease(referenceVersion) !== null;
// if the user has some v.v.v-prerelease-xx.xx pre-release version, include pre-release versions in the search query.
const compatibleVersionRange = isPreReleaseVersion
? `~${referenceVersion}`
: `~${semver.major(referenceVersion)}.${semver.minor(referenceVersion)}.0`;
const latestVersion = await this.getLatestVersion(packageName);
if (semver.satisfies(latestVersion, compatibleVersionRange)) {
return latestVersion;
}
const data = await this.$npm.view(packageName, { "versions": true });
const maxSatisfying = semver.maxSatisfying(data, compatibleVersionRange);
return maxSatisfying || latestVersion;
}
示例4: useCpythonVersion
async function useCpythonVersion(parameters: Readonly<TaskParameters>, platform: Platform): Promise<void> {
const desugaredVersionSpec = desugarDevVersion(parameters.versionSpec);
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
task.debug(`Semantic version spec of ${parameters.versionSpec} is ${semanticVersionSpec}`);
const installDir: string | null = tool.findLocalTool('Python', semanticVersionSpec, parameters.architecture);
if (!installDir) {
// Fail and list available versions
const x86Versions = tool.findLocalToolVersions('Python', 'x86')
.map(s => `${s} (x86)`)
.join(os.EOL);
const x64Versions = tool.findLocalToolVersions('Python', 'x64')
.map(s => `${s} (x64)`)
.join(os.EOL);
throw new Error([
task.loc('VersionNotFound', parameters.versionSpec, parameters.architecture),
task.loc('ListAvailableVersions', task.getVariable('Agent.ToolsDirectory')),
x86Versions,
x64Versions,
task.loc('ToolNotFoundMicrosoftHosted', 'Python', 'https://aka.ms/hosted-agent-software'),
task.loc('ToolNotFoundSelfHosted', 'Python', 'https://go.microsoft.com/fwlink/?linkid=871498')
].join(os.EOL));
}
task.setVariable('pythonLocation', installDir);
if (parameters.addToPath) {
toolUtil.prependPathSafe(installDir);
toolUtil.prependPathSafe(binDir(installDir, platform))
if (platform === Platform.Windows) {
// Add --user directory
// `installDir` from tool cache should look like $AGENT_TOOLSDIRECTORY/Python/<semantic version>/x64/
// So if `findLocalTool` succeeded above, we must have a conformant `installDir`
const version = path.basename(path.dirname(installDir));
const major = semver.major(version);
const minor = semver.minor(version);
const userScriptsDir = path.join(process.env['APPDATA'], 'Python', `Python${major}${minor}`, 'Scripts');
toolUtil.prependPathSafe(userScriptsDir);
}
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
}
}
示例5: getSemanticVersion
export function getSemanticVersion() {
const options = minimist(process.argv.slice(2), {});
let version = options.version;
if (!version) {
version = "0.0.0";
console.log("No version argument provided, fallback to default version: " + version);
} else {
console.log("Found version: " + version);
}
if (!semver.valid(version)) {
throw new Error("Package: invalid semver version: " + version);
}
let patch = semver.patch(version);
if (!options.noversiontransform) {
patch *= 1000;
const prerelease = semver.prerelease(version);
if (prerelease) {
patch += parseInt(prerelease[1], 10);
} else {
patch += 999;
}
}
const result = {
major: semver.major(version),
minor: semver.minor(version),
patch,
getVersionString() {
return this.major.toString() + "." + this.minor.toString() + "." + this.patch.toString();
},
};
console.log("Extension Version: " + result.getVersionString());
return result;
}
示例6: usePythonVersion
export async function usePythonVersion(parameters: Readonly<TaskParameters>, platform: Platform): Promise<void> {
// Python's prelease versions look like `3.7.0b2`.
// This is the one part of Python versioning that does not look like semantic versioning, which specifies `3.7.0-b2`.
// If the version spec contains prerelease versions, we need to convert them to the semantic version equivalent
const semanticVersionSpec = pythonVersionToSemantic(parameters.versionSpec);
task.debug(`Semantic version spec of ${parameters.versionSpec} is ${semanticVersionSpec}`);
const installDir: string | null = tool.findLocalTool('Python', semanticVersionSpec, parameters.architecture);
if (!installDir) {
// Fail and list available versions
const x86Versions = tool.findLocalToolVersions('Python', 'x86')
.map(s => `${s} (x86)`)
.join(os.EOL);
const x64Versions = tool.findLocalToolVersions('Python', 'x64')
.map(s => `${s} (x64)`)
.join(os.EOL);
throw new Error([
task.loc('VersionNotFound', parameters.versionSpec),
task.loc('ListAvailableVersions'),
x86Versions,
x64Versions
].join(os.EOL));
}
task.setVariable('pythonLocation', installDir);
if (parameters.addToPath) {
toolUtil.prependPathSafe(installDir);
// Make sure Python's "bin" directories are in PATH.
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
// This is where pip is, along with anything that pip installs.
// There is a seperate directory for `pip install --user`.
//
// For reference, these directories are as follows:
// macOS / Linux:
// <sys.prefix>/bin (by default /usr/local/bin, but not on hosted agents -- see the `else`)
// (--user) ~/.local/bin
// Windows:
// <Python installation dir>\Scripts
// (--user) %APPDATA%\Python\PythonXY\Scripts
// See https://docs.python.org/3/library/sysconfig.html
if (platform === Platform.Windows) {
// On Windows, these directories do not get added to PATH, so we will add them ourselves.
const scriptsDir = path.join(installDir, 'Scripts');
toolUtil.prependPathSafe(scriptsDir);
// Add --user directory
// `installDir` from tool cache should look like $AGENT_TOOLSDIRECTORY/Python/<semantic version>/x64/
// So if `findLocalTool` succeeded above, we must have a conformant `installDir`
const version = path.basename(path.dirname(installDir));
const major = semver.major(version);
const minor = semver.minor(version);
const userScriptsDir = path.join(process.env['APPDATA'], 'Python', `Python${major}${minor}`, 'Scripts');
toolUtil.prependPathSafe(userScriptsDir);
} else {
// On Linux and macOS, tools cache should be set up so that each Python version has its own "bin" directory.
// We do this so that the tool cache can just be dropped on an agent with minimal installation (no copying to /usr/local).
// This allows us side-by-side the same minor version of Python with different patch versions or architectures (since Python uses /usr/local/lib/python3.6, etc.).
toolUtil.prependPathSafe(path.join(installDir, 'bin'));
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
}
}
}
示例7:
sem = semver.parse(str);
strn = semver.valid(str);
strn = semver.clean(str);
strn = semver.valid(str, loose);
strn = semver.clean(str, loose);
strn = semver.inc(str, "major", loose);
strn = semver.inc(str, "premajor", loose);
strn = semver.inc(str, "minor", loose);
strn = semver.inc(str, "preminor", loose);
strn = semver.inc(str, "patch", loose);
strn = semver.inc(str, "prepatch", loose);
strn = semver.inc(str, "prerelease", loose);
strn = semver.inc(str, "prerelease", loose, "alpha");
num = semver.major(str, loose);
num = semver.minor(str, loose);
num = semver.patch(str, loose);
strArr = semver.prerelease(str, loose);
// Comparison
bool = semver.gt(v1, v2, loose);
bool = semver.gte(v1, v2, loose);
bool = semver.lt(v1, v2, loose);
bool = semver.lte(v1, v2, loose);
bool = semver.eq(v1, v2, loose);
bool = semver.neq(v1, v2, loose);
bool = semver.cmp(v1, op, v2, loose);
comparatorResult = semver.compare(v1, v2, loose);
comparatorResult = semver.rcompare(v1, v2, loose);
comparatorResult = semver.compareIdentifiers(str, str);
示例8: require
/* tslint:disable:no-var-requires */
import * as fs from 'fs';
import * as path from 'path';
import { mergeDeepRight } from 'ramda';
import * as semver from 'semver';
const config = require('../app.json');
const {
version,
versionCode,
dependencies: { expo }
} = require('../package.json');
const isDev = process.argv[2] === 'development';
const expoVersion = expo.replace('^', '');
const sdkVersion = `${semver.major(expoVersion)}.0.0`;
const travisConfig = mergeDeepRight(config, {
expo: {
name: `${config.expo.name}${isDev ? ' Nightly' : ''}`,
slug: `${config.expo.slug}${isDev ? '-development' : ''}`,
sdkVersion,
version,
packagerOpts: {
nonPersistent: true
},
ios: {
buildNumber: version.split('-')[0]
},
android: {
versionCode
示例9: wizard
export default async function wizard(pwd: string, name: string) {
let its = validateName(name);
if (!its.validForNewPackages) {
let errors = (its.errors || []).concat(its.warnings || []);
throw new Error("Sorry, " + errors.join(" and ") + ".");
}
// check for a scoped name
let scoped = name.match(/@([^\/]+)\/(.*)/);
let [, scope, local] = scoped ? (scoped as [string, string, string]) : [, null, name];
console.log("This utility will walk you through creating the " + style.project(name) + " Neon project.");
console.log("It only covers the most common items, and tries to guess sensible defaults.");
console.log();
console.log("Press ^C at any time to quit.");
let root = path.resolve(pwd, local);
let guess = await guessAuthor();
let answers = await prompt([
{
type: 'input',
name: 'version',
message: "version",
default: "0.1.0",
validate: function (input) {
if (semver.valid(input)) {
return true;
}
return "Invalid version: " + input;
}
},
{ type: 'input', name: 'description', message: "description" },
{ type: 'input', name: 'node', message: "node entry point", default: "lib/index.js" },
{ type: 'input', name: 'git', message: "git repository" },
{ type: 'input', name: 'author', message: "author", default: guess.name },
{ type: 'input', name: 'email', message: "email", default: guess.email },
{
type: 'input',
name: 'license',
message: "license",
default: "MIT",
validate: function (input) {
let its = validateLicense(input);
if (its.validForNewPackages) {
return true;
}
let errors = its.warnings || [];
return "Sorry, " + errors.join(" and ") + ".";
}
}
]);
answers.name = {
npm: {
full: name,
scope: scope,
local: local
},
cargo: {
external: local,
internal: local.replace(/-/g, "_")
}
};
answers.description = escapeQuotes(answers.description);
answers.git = encodeURI(answers.git);
answers.author = escapeQuotes(answers.author);
let ctx = {
project: answers,
"neon-cli": {
major: semver.major(NEON_CLI_VERSION),
minor: semver.minor(NEON_CLI_VERSION),
patch: semver.patch(NEON_CLI_VERSION)
}
};
let lib = path.resolve(root, path.dirname(answers.node));
let native_ = path.resolve(root, 'native');
let src = path.resolve(native_, 'src');
await mkdirs(lib);
await mkdirs(src);
await writeFile(path.resolve(root, '.gitignore'), (await GITIGNORE_TEMPLATE)(ctx), { flag: 'wx' });
await writeFile(path.resolve(root, 'package.json'), (await NPM_TEMPLATE)(ctx), { flag: 'wx' });
await writeFile(path.resolve(native_, 'Cargo.toml'), (await CARGO_TEMPLATE)(ctx), { flag: 'wx' });
await writeFile(path.resolve(root, 'README.md'), (await README_TEMPLATE)(ctx), { flag: 'wx' });
await writeFile(path.resolve(root, answers.node), (await INDEXJS_TEMPLATE)(ctx), { flag: 'wx' });
await writeFile(path.resolve(src, 'lib.rs'), (await LIBRS_TEMPLATE)(ctx), { flag: 'wx' });
await writeFile(path.resolve(native_, 'build.rs'), (await BUILDRS_TEMPLATE)(ctx), { flag: 'wx' });
let relativeRoot = path.relative(pwd, root);
let relativeNode = path.relative(pwd, path.resolve(root, answers.node));
let relativeRust = path.relative(pwd, path.resolve(src, 'lib.rs'));
console.log();
console.log("Woo-hoo! Your Neon project has been created in: " + style.path(relativeRoot));
console.log();
console.log("The main Node entry point is at: " + style.path(relativeNode));
//.........这里部分代码省略.........
示例10: major
(match): match is RegExpExecArray =>
match !== null && major(match[1]) === majorVersion,