【问题标题】:How do I get error codes (Windows) out of the NPM version of JSHint, for CI?对于 CI,如何从 JSHint 的 NPM 版本中获取错误代码 (Windows)?
【发布时间】:2013-10-16 18:39:31
【问题描述】:

我们刚刚在 Windows 中升级到 NPM 版本的 JSHint,我们的 CI 不会再因 JSHint 失败而失败。这感觉像是一个愚蠢的问题,但我想不通。

我们正在运行 NAnt 和 CCNet。当我们尝试从 NAnt 中运行 jshint.cmd 时,它会说路径错误。我无法在脚本中对路径进行硬编码,因为每个开发站(和 CI 服务器)都将 NPM 和 JSHint 安装在不同的位置(“C:\Users\me\AppData\Roaming\npm”)。

所以我们编写了一个 NAnt 调用的批处理文件,它调用 jshint.cmd。它现在运行 JSHint,但不会给出错误代码或正确失败。看起来我们的批处理文件的末尾在 jshint.cmd 失败后没有运行,并且看起来没有为 NAnt 设置要检查的错误级别。我也尝试在 NAnt 中检查 resultproperty,但没有成功。

这里有一些文件:

JSHint.build

<target name="JSHint">
    <exec program="runjshint.cmd" basedir="${jshint.dir}" workingdir="${jshint.dir}">
        <arg value="${scripts.dir}" />
    </exec>
</target>

runjshint.cmd

    jshint --reporter=reporter.js %1
    REM Everything past here isn't run.

NAnt 输出

             [exec] C:\work\ThirdParty\jshint>jshint --reporter=reporter.js ..\..\src\Scripts
             [exec]
             [exec]
             [exec] jshint failed:
             [exec]
             [exec] ..\..\src\Scripts\app\ViewModels\FakeViewModel.js: line 62, col 31, 'FakeVariable' is not defined.
             [exec] ..\..\src\Scripts\app\ViewModels\FakeViewModel.js: line 78, col 33, 'FakeVariable' is not defined.
             [exec]
             [exec] 2 errors

        BUILD SUCCEEDED

请注意,即使 JSHint 失败,构建也会成功。

【问题讨论】:

标签: windows node.js batch-file nant jshint


【解决方案1】:

我在 SO 上的另一篇帖子中找到了答案:https://stackoverflow.com/a/10359327/227349

<!--Next arg: forces node's stderror and stdout to a temporary file-->
<arg line=" &gt; _tempfile.out 2&lt;&amp;1"/>

<!--Next arg: 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)"/>

<!--Next arg: Otherwise, just type the temporary file and delete it-->
<arg line=" &amp; type _tempfile.out &amp; del _tempfile.out &amp;"/>

【讨论】:

猜你喜欢
  • 2018-02-04
  • 2019-03-01
  • 2020-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
相关资源
最近更新 更多