将 gulp 文件中的 npm 更新、bower prune、bower 更新自动化为 gulp 任务

automate npm update,bower prune, bower update inside gulpfile as gulp tasks

我想通过以下任务 (gulp.task) 自动执行我的 gulp 文件。

  1. npm 更新
  2. 鲍尔 p运行e
  3. 凉亭更新

每次有人更改 package.json 和 bower.json 时,我只是 运行 gulp 并且包得到 installed/updated/deleted 而不必 运行这些命令通过终端。

您可以使用 gulp-install 之类的插件来执行此操作...或者您可以像下面这样自己编写任务

var gulp = require('gulp');
var bower = require('bower');

gulp.task('bower', function(cb){
  bower.commands.install([], {save: true}, {})
    .on('end', function(installed){
      cb(); // notify gulp that this task is finished
    });
});

还有另一种更简单的方法(认为这不在 gulp 文件中)

在您的 package.json 脚本部分添加 update 命令

"scripts": {
    "update": "npm install && npm prune && bower install && bower prune",
    "first-run": "npm install -g gulp bower && npm run update"
},

然后从命令行执行:

 npm run update

您还可以创建如上所示 first-run 和 运行 之类的命令

npm run first-run

我想做这三件事:update/install/prune 为 npm 和 bower,所以我最终为此创建了一个工具:updatejs.

喜欢的话请告诉我:)