我正在尝试自动更新新 Node 模块,但是,npm update 似乎不想在 grunt 中正确运行,同时也使用新版本更新 package.json 文件。无论 package.json 文件中指定了什么版本,我都想执行此操作。
到目前为止我发现的是 Node 模块:npm-check-updates ( https://www.npmjs.com/package/npm-check-updates )
问题是我无法让它与 npm-shell 或 npm-exec 等其他模块一起使用。
我尝试过直接使用 npm update -D,但也失败了。
我想问是否可以做到。
这是我使用的:
grunt.registerTask('update', 'Update npm modules', function() {
var exec = require('child_process').exec;
var cb = this.async();
exec('npm update -D', {}, function(err, stdout) {
console.log(stdout);
cb();
});
});
最佳答案
如果我是正确的,您是否正在尝试更新 package.json 文件中的所有 npm 包?我建议使用这个包。
安装软件包。
npm install grunt-auto-install --save-dev
将其添加到您的繁重任务中。
grunt.loadNpmTasks('grunt-auto-install');
然后将配置添加到 gruntfile.js
grunt.initConfig({
auto_install: {
local: {},
subdir: {
options: {
cwd: 'subdir',
stdout: true,
stderr: true,
failOnError: true,
npm: '--production'
}
}
},
});
引用资料如下:
https://www.npmjs.com/package/grunt-auto-install
更新软件包后 使用 grunt 任务自动更新您的 devDependency 和依赖项。 安装 npm 模块以更新开发依赖项对象中的包。
npm install --save-dev grunt-dev-update
将其添加到您的繁重任务中。
grunt.loadNpmTasks('grunt-dev-update');
将您的配置添加到 gruntfile 中。
devUpdate: {
main: {
options: {
//task options go here
}
}
}
关于node.js - 从 grunt 中更新 NPM 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31819978/