Gruntjs grunt与ant的集成

Gruntjs grunt与ant的集成,gruntjs,Gruntjs,有没有关于grunt与ant集成的好教程?我们当前的构建使用ant,因为我们是一家Java商店。然而,前端开始成为一级公民,我们正在研究使用node和grunt进行前端构建。我需要集成前端构建和ant构建。我需要知道如何规范所有自定义任务以及内置grunt任务的退出代码,并在ant调用grunt任务时将控制台输出限制为这些预定义代码。任何帮助都将不胜感激。Grunt可以调用命令行,因此您可以轻松地在Grunt中创建多个任务,这些任务除了通过shell执行ant任务外什么都不做 grunt she

有没有关于grunt与ant集成的好教程?我们当前的构建使用ant,因为我们是一家Java商店。然而,前端开始成为一级公民,我们正在研究使用node和grunt进行前端构建。我需要集成前端构建和ant构建。我需要知道如何规范所有自定义任务以及内置grunt任务的退出代码,并在ant调用grunt任务时将控制台输出限制为这些预定义代码。任何帮助都将不胜感激。

Grunt可以调用命令行,因此您可以轻松地在Grunt中创建多个任务,这些任务除了通过shell执行ant任务外什么都不做

grunt shell
库使得从grunt任务执行外部命令特别容易:

但是,由于您讨论的是自定义退出代码,您可能必须编写自己的自定义grunt任务,该任务执行shell命令,然后查看响应代码(可能使用
grunt.helpers.spawn
helper):

我的建议?如果可能的话,最好与ant彻底决裂,并将其完全用于JavaScript相关项目

Grunt的插件库越来越多,也越来越有用。如果你不能复制你的ant构建文件并创建一个100%的javascript解决方案,我会感到惊讶。

你可能会使用它,其中包括一个npm模块*1)

然后,您只需要自定义目标,如:

…

<target
    name="-mm:compile:main~hooked"
   extensionOf="-compile:main~hook"
    depends="
        -my-compile-npm-hook
    " 
>

<target
    name="-my-compile-npm-hook"
>
    <echo>install local grunt-cli</echo>
    <antcall target="npm:install">
        <param name="in.npm.package.name" value="grunt-cli" />
    </antcall>
</target>

…
…
安装本地grunt cli

对于当前的node.js版本,您可以使用以下宏:

<macrodef name="exec-node">
    <attribute name="module" description="The name of the NodeJS module to execute"/>
    <attribute name="failonerror" default="true" description="Fail if the exit code is not 0"/>
    <element name="args" implicit="yes" description="Argument to pass to the exec task"/>
    <sequential>
        <exec executable="cmd.exe" failonerror="@{failonerror}" osfamily="winnt">
            <arg line="/c  @{module}" />
            <args/>

            <!-- Windows cmd output workaround: http://stackoverflow.com/a/10359327/227349 -->
            <!-- Forces node's stderror and stdout to a temporary file -->
            <arg line=" &gt; _tempfile.out 2&lt;&amp;1"/>

            <!-- If command exits with an error, then output the temporary file        -->
            <!-- to stdout delete the temporary file and finally exit with error level 1  -->
            <!-- so that the apply task can catch the error if @failonerror="true"        -->
            <arg line=" || (type _tempfile.out &amp; del _tempfile.out &amp; exit /b 1)"/>

            <!-- Otherwise, just type the temporary file and delete it-->
            <arg line=" &amp; type _tempfile.out &amp; del _tempfile.out &amp;"/>
        </exec>
        <exec executable="@{module}" failonerror="@{failonerror}" osfamily="unix">
            <args/>
        </exec>
    </sequential>
</macrodef>

您可以调用任何命令:例如:

<target name="jshint">
    <exec-node module="grunt">
        <arg value="jshint" />
    </exec-node>
</target>


工作起来很有魅力:还可以确保stderr也被打印出来,这是打电话给grunt时的一个常见问题。

我也在一家Java商店,这很难销售。虽然前端对我们来说也越来越重要,但我们不太可能将JS作为服务器端代码的构建语言。更现实的方法似乎是通过自定义ant任务调用grunt。另一方面,我没看到有人这么做。。。