Ant 使用 exec 目标编译 Coffee 脚本

发布于 2024-11-19 15:14:12 字数 1791 浏览 2 评论 0原文

我有一个使用一些 Coffee Script 的 Ant 项目。我希望 Ant 编译所有的咖啡,而不是使用另一个构建步骤来编译它。我想要使​​用的咖啡命令行脚本,它将所有咖啡文件编译为同义的 js 文件(site.coffee 编译为 site.js,app.coffee 编译为 app.js):

coffee -c ./js/*.coffee

我创建了一个我认为会运行的 Ant 任务相同的命令,但收到错误:

<target name="compilecoffee" description="Compiles coffeescript files">
    <exec executable="coffee">
        <arg value="-c ${env.WORKSPACE}js/*.coffee" />
    </exec>
</target>

现在,当我运行 antcompilecoffee -Denv.WORKSPACE=./ 时,我从 Coffee 中收到以下错误:

Buildfile: /Users/dave/Workspace/ColdFusion/Mura-Themes/e123-1/build.xml

compilecoffee:
     [exec] 
     [exec] node.js:116
     [exec]         throw e; // process.nextTick error, or 'error' event on first tick
     [exec]         ^
     [exec] Error: unrecognized option: -c ./js/3_site.coffee
     [exec]     at OptionParser.parse (/Users/dave/local/lib/node/.npm/coffee-script/1.1.1/package/lib/optparse.js:34:17)
     [exec]     at /Users/dave/local/lib/node/.npm/coffee-script/1.1.1/package/lib/command.js:245:29
     [exec]     at Object.run (/Users/dave/local/lib/node/.npm/coffee-script/1.1.1/package/lib/command.js:24:5)
     [exec]     at Object.<anonymous> (/Users/dave/local/lib/node/.npm/coffee-script/1.1.1/package/bin/coffee:7:27)
     [exec]     at Module._compile (module.js:373:26)
     [exec]     at Object..js (module.js:379:10)
     [exec]     at Module.load (module.js:305:31)
     [exec]     at Function._load (module.js:271:10)
     [exec]     at Array.<anonymous> (module.js:392:10)
     [exec]     at EventEmitter._tickCallback (node.js:108:26)
     [exec] Result: 1

如果我运行,我想到的是咖啡直接在命令行等效(coffee -c ./js/*.coffee)我没有收到任何错误,一切都按预期进行。我使用 exec 目标错误吗?

I have an Ant project that uses a bit of Coffee Script. I would like Ant to compile all of the coffee instead of having another build step to compile it. The coffee command line script that I want to use, that compiles all coffee files into synonomous js files (site.coffee compiles to site.js, app.coffee compiles to app.js):

coffee -c ./js/*.coffee

I created an Ant task that I assumed would run the same command, but am getting an error:

<target name="compilecoffee" description="Compiles coffeescript files">
    <exec executable="coffee">
        <arg value="-c ${env.WORKSPACE}js/*.coffee" />
    </exec>
</target>

Now when I run ant compilecoffee -Denv.WORKSPACE=./ I get the following error from Coffee:

Buildfile: /Users/dave/Workspace/ColdFusion/Mura-Themes/e123-1/build.xml

compilecoffee:
     [exec] 
     [exec] node.js:116
     [exec]         throw e; // process.nextTick error, or 'error' event on first tick
     [exec]         ^
     [exec] Error: unrecognized option: -c ./js/3_site.coffee
     [exec]     at OptionParser.parse (/Users/dave/local/lib/node/.npm/coffee-script/1.1.1/package/lib/optparse.js:34:17)
     [exec]     at /Users/dave/local/lib/node/.npm/coffee-script/1.1.1/package/lib/command.js:245:29
     [exec]     at Object.run (/Users/dave/local/lib/node/.npm/coffee-script/1.1.1/package/lib/command.js:24:5)
     [exec]     at Object.<anonymous> (/Users/dave/local/lib/node/.npm/coffee-script/1.1.1/package/bin/coffee:7:27)
     [exec]     at Module._compile (module.js:373:26)
     [exec]     at Object..js (module.js:379:10)
     [exec]     at Module.load (module.js:305:31)
     [exec]     at Function._load (module.js:271:10)
     [exec]     at Array.<anonymous> (module.js:392:10)
     [exec]     at EventEmitter._tickCallback (node.js:108:26)
     [exec] Result: 1

If I run, what I thought was, the coffee equivelant directly at the command line (coffee -c ./js/*.coffee) I get no errors and everything works as expected. Am I using the exec target wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑红尘 2024-11-26 15:14:13

try =

<arg line="-c ${env.WORKSPACE}js/*.coffee" />

或使用一个 arg value=... 对于命令

<target name="compilecoffee" description="Compiles coffeescript files">
 <exec executable="coffee">
  <arg value="-c"/>
  <arg value="${env.WORKSPACE}js/*.coffee" />
 </exec>
</target>

Coffee 可执行文件的每一部分都必须位于路径上或使用 =

<exec executable="full/path/to/coffee">

EDIT

正如多米尼克指出的那样,“*”不会被扩展,所以你应该使用 apply =

 <apply executable="coffee">
  <arg value="-c"/>
  <fileset dir="${env.WORKSPACE}js" includes="**/*.js"/>
 </apply>

参见 Ant 手动应用任务 你可以使用parallel=“true”,意味着只运行命令一次,如果可能的话,将所有文件作为参数附加到咖啡上,以加快速度。

try =

<arg line="-c ${env.WORKSPACE}js/*.coffee" />

or use one arg value=... for every part of the command

<target name="compilecoffee" description="Compiles coffeescript files">
 <exec executable="coffee">
  <arg value="-c"/>
  <arg value="${env.WORKSPACE}js/*.coffee" />
 </exec>
</target>

coffee executable has to be on path or use =

<exec executable="full/path/to/coffee">

EDIT

as Dominic pointed out, the '*' won't be expanded, so you should use apply =

 <apply executable="coffee">
  <arg value="-c"/>
  <fileset dir="${env.WORKSPACE}js" includes="**/*.js"/>
 </apply>

see Ant Manual apply task f.e. you may use parallel="true", means run the command only once, appending all files as arguments, if possible with coffee, to speed it up.

雄赳赳气昂昂 2024-11-26 15:14:13

实际上,您可以通过执行以下操作来实现:

<target name="compile-coffee" description="Compiles coffeescript into the javascript dir">
  <exec executable="coffee">
    <arg value="-c" />
    <arg value="--output" />
    <arg value="${javascript_dir}" />
    <arg value="${cofeescript_dir}" />
  </exec>
</target>

其中 javascript_dir 指向您的 js 目录(目标),而 Coffeescript_dir 指向您的 Coffeescript 目录(来源)。

*当然,如果你只想就地编译,你可以省略 --output 和 javascript_dir 。

Actually, you can achieve that by doing something like:

<target name="compile-coffee" description="Compiles coffeescript into the javascript dir">
  <exec executable="coffee">
    <arg value="-c" />
    <arg value="--output" />
    <arg value="${javascript_dir}" />
    <arg value="${cofeescript_dir}" />
  </exec>
</target>

where javascript_dir points to your js directory (destination) and coffeescript_dir points to your coffeescript dir (origin).

*of course you can omit --output and javascript_dir if you just want to compile in place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文