如何使用 npm.commands.version 以编程方式提升 package.json 版本
How to use npm.commands.version to bump the package.json version programatically
我希望我的项目的 package.json 版本在我每次 运行 我的项目时都能提升,为此我将 npm 包作为本地节点模块安装到我的项目中但是以下不起作用:
var npm = require('npm');
npm.load(function (e, n) {
n.commands.version("patch", function (error) {
// 'error' here equals an error message as shown below
console.log(error);
});
});
错误信息
"npm version [ | major | minor | patch | prerelease | preminor | premajor ](run in package dir)'npm -v' or 'npm --version' to print npm version (2.4.1)'npm view version' to view a package's published version'npm ls' to inspect current package/dependency versions"
知道缺少什么以及如何让它发挥作用吗?
谢谢!
顺便说一句,我不使用 g运行t,目前也不打算使用,所以 g运行t-bump 不是一个选项。
好吧,当我阅读文档时,我看到 "Like all other commands, this function takes a string array as its first parameter",这意味着您需要 ["patch"]
,而您有 "patch"
:
var npm = require('npm');
npm.load(function (e, n) {
n.commands.version(["patch"], function (error) {
// 'error' here equals an error message as shown below
console.log(error);
});
});
这对我来说很好。
我希望我的项目的 package.json 版本在我每次 运行 我的项目时都能提升,为此我将 npm 包作为本地节点模块安装到我的项目中但是以下不起作用:
var npm = require('npm');
npm.load(function (e, n) {
n.commands.version("patch", function (error) {
// 'error' here equals an error message as shown below
console.log(error);
});
});
错误信息 "npm version [ | major | minor | patch | prerelease | preminor | premajor ](run in package dir)'npm -v' or 'npm --version' to print npm version (2.4.1)'npm view version' to view a package's published version'npm ls' to inspect current package/dependency versions"
知道缺少什么以及如何让它发挥作用吗?
谢谢!
顺便说一句,我不使用 g运行t,目前也不打算使用,所以 g运行t-bump 不是一个选项。
好吧,当我阅读文档时,我看到 "Like all other commands, this function takes a string array as its first parameter",这意味着您需要 ["patch"]
,而您有 "patch"
:
var npm = require('npm');
npm.load(function (e, n) {
n.commands.version(["patch"], function (error) {
// 'error' here equals an error message as shown below
console.log(error);
});
});
这对我来说很好。