Ant 使用 exec 目标编译 Coffee 脚本
我有一个使用一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
try =
或使用一个 arg value=... 对于命令
Coffee 可执行文件的每一部分都必须位于路径上或使用 =
EDIT
正如多米尼克指出的那样,“*”不会被扩展,所以你应该使用 apply =
参见 Ant 手动应用任务 你可以使用parallel=“true”,意味着只运行命令一次,如果可能的话,将所有文件作为参数附加到咖啡上,以加快速度。
try =
or use one arg value=... for every part of the command
coffee executable has to be on path or use =
EDIT
as Dominic pointed out, the '*' won't be expanded, so you should use 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.
实际上,您可以通过执行以下操作来实现:
其中 javascript_dir 指向您的 js 目录(目标),而 Coffeescript_dir 指向您的 Coffeescript 目录(来源)。
*当然,如果你只想就地编译,你可以省略 --output 和 javascript_dir 。
Actually, you can achieve that by doing something like:
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.