javascript - 如何从 Webhook 运行 Gulp

标签 javascript node.js git build gulp

在将代码推送到远程存储库后,我尝试将 Gulp 作为构建过程的一部分。我的计划是使用一个 webhook,它将在提交与 origin merge 后触发。

当 webhook 被命中时,如何触发 Gulp?我正在考虑使用一个简单的连接服务器运行 node.js,但是从那里我如何让 gulp 运行?

var connect = require('connect');
var http = require('http');

var app = connect();

var myGulp = require('./gulpfile.js');

// respond to all requests
app.use(function(req, res){
  res.end('Hello from connect.\n');
})

//create node.js http server and listen on port
http.createServer(app).listen(8888);

最佳答案

为您的 webhook 创建一条路由,并使用 gulp-chug 从您的 gulpfile 调用您的 gulp 任务

var gulp = require('gulp');
var chug = require('gulp-chug');

app.get('/webhook', function(req, res) {
  gulp.src('./gulpfile.js', { read: false})
    .pipe( chug( {
      tasks: ['default']  
    } ) );
});

关于javascript - 如何从 Webhook 运行 Gulp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33437787/

相关文章:

javascript - 是否可以在 node.js 中创建子进程,当它们的父进程退出时它们不会退出?

javascript 闭包仍然适用

javascript - 鼠标悬停时在 iframe 中显示源 html

javascript - 截至2018年支持ES6(ECMAScript 2015)

node.js - 使用 Express 进行外部获取请求

node.js - 如何使用 Node.js 内置调试​​器向上/向下移动堆栈帧

node.js - 作为 promise 对 sinch 进行 api 调用

git - 在 GitHub 上更新 fork 项目

git - sublime text 选项 "-n -w"(对于 git)总是打开我以前的标签

git - AWK - 解析 git status 命令中的第二列