本文整理汇总了TypeScript中semver.patch函数的典型用法代码示例。如果您正苦于以下问题:TypeScript patch函数的具体用法?TypeScript patch怎么用?TypeScript patch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了patch函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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";
}
}
示例2: 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;
}
示例3:
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);
comparatorResult = semver.rcompareIdentifiers(str, str);
versionsArr = semver.sort(['', new semver.SemVer('')]);
示例4: 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));
//.........这里部分代码省略.........