如何通过浏览器登录按钮来运行Grunt Build任务? [英] How to run Grunt Build task by cliking on button through browser?

查看:147
本文介绍了如何通过浏览器登录按钮来运行Grunt Build任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过grunt完成了一个构建过程,并且它可以在命令提示符下正常工作。现在我有一个应用程序,我想通过单击生成按钮来运行此任务。



那么有没有什么办法可以通过编写任何js或php脚本来从浏览器中运行grunt任务?



如果需要进一步澄清,请告诉我。
Thanks。

解决方案

我看到两个选择:


  1. 服务器端脚本 - 例如启动您的任务的PHP,Python等。

  2. 使用本地库的浏览器插件(从Google Chrome扩展程序启动外部应用程序?)。

当然,选项一更容易。你甚至不需要一个完整的webstack,如果你只是想运行它没有参数或任何东西。



Python可以很简​​单:

 导入套接字
导入子过程

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM);
s.bind(('0.0.0.0',17777))
s.listen()

而真:
连接,client_address = soc.accept( );
connection.send('HTTP / 1.1 200 OK \r\\\
\r\\\
')
subprocess.call(['grunt','..'])
connection.close()

然后简单地点击它,就像< a href =host:17777> run< / a> 或者XHR。

更多奇特的东西,比如状态报告,等等,你需要更复杂的东西。如果您已经有了一个基于PHP的堆栈,您可以简单地执行如下操作:

 <?php 
回声`咕噜...`;
?>

这当然会等待咕噜声完成。所以你可以看看PHP的 pcntl 之类的。



另一个想法是,如果您使用的是 supervisord ramona ,它们具有基于Web的控制面板,向它们发送请求,以便它们可以启动一个咕噜的进程。



所以上面这个应该足够用于一个小用例,而不是那么灵活。对于更强大,可扩展和认真的外观,请看 芹菜 和其他任务队列。你可以使用 flask

祝您好运。


I have made one build process through grunt and it works fine from command prompt. Now I have a application from where i want to run this task by clicking build button.

So is there any way i can rung grunt task from browser by writing any js or php script?

If any further clarification needed do let me know. Thanks.

解决方案

I see two options:

  1. Server-side script - like PHP, Python, etc. that launches your task.
  2. A browser plugin that uses native libraries (Start an external application from a Google Chrome Extension?).

Option one is, of course, much easier. And you don't even need a full webstack if you just want to run it without arguments or anything.

Python can be as simple as:

import socket
import subprocess

s = socket.socket( socket.AF_INET, socket.SOCK_STREAM );
s.bind( ( '0.0.0.0', 17777 ) )
s.listen()

while True:
    connection, client_address = soc.accept();
    connection.send( 'HTTP/1.1 200 OK\r\n\r\n' )
    subprocess.call( ['grunt', '..'] )
    connection.close()

Then simply hit it, like <a href="host:17777">run</a> or an XHR.

For more exotic things, like status reporting, arguments, etc. you'll need something more complex. If you already have a PHP-based stack up, you can simply do something like:

<?php
    echo `grunt ...`;
?>

This will, of course wait for grunt to finish. So you may look into PHP's pcntl and the like.

Another idea, if you're using something like supervisord or ramona, which have web-based control panels, is to send requests to them so that they can start a grunt process.

So the above should suffice for a tiny use-case, not so flexible. For something more robust, extensible and serious look into celery and other task queues. You can get a quite powerful command and control center using flask for example, along with a task queue. Building one in PHP shouldn't be substantially difficult either.

Good luck.

这篇关于如何通过浏览器登录按钮来运行Grunt Build任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆