将多个Coffeescript文件合并到一个文件中? (多个子目录) [英] Join multiple Coffeescript files into one file? (Multiple subdirectories)

查看:149
本文介绍了将多个Coffeescript文件合并到一个文件中? (多个子目录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆.coffee文件,我需要加入到一个文件。

I've got a bunch of .coffee files that I need to join into one file.

我有一个文件夹设置像rails应用程序:

I have folders set up like a rails app:

/src/controller/log_controller.coffee
/src/model/log.coffee
/src/views/logs/new.coffee

Coffeescript有一个命令,可以将多个coffeescripts加入到一个文件中,但它只是似乎工作与一个目录。例如,这工作正常:

Coffeescript has a command that lets you join multiple coffeescripts into one file, but it only seems to work with one directory. For example this works fine:

coffee --output app/controllers.js --join --compile src/controllers/*.coffee

但我需要能够包含一些子目录命令:

But I need to be able to include a bunch of subdirectories kind of like this non-working command:

coffee --output app/all.js --join --compile src/*/*.coffee

有办法吗?有没有UNIXy的方式传递所有的文件在子目录列表?

Is there a way to do this? Is there a UNIXy way to pass in a list of all the files in the subdirectories?

我在OSX使用终端。

它们都必须加入到一个文件中,因为否则每个单独的文件被编译,用这个包装:

They all have to be joined in one file because otherwise each separate file gets compiled & wrapped with this:

(function() { }).call(this);

这突破了某些函数调用的范围。

Which breaks the scope of some function calls.

推荐答案

您可以编写一个shell脚本或Rake任务来将它们组合在一起,然后编译。像:

You could write a shell script or Rake task to combine them together first, then compile. Something like:

查找。 -type f -name'* .coffee'-print0 | xargs-0cat> output.coffee

然后编译 output.coffee

根据需要调整路径。还要确保 output.coffee 文件不在您使用 find 搜索的同一路径中,否则您将进入无限循环。

Adjust the paths to your needs. Also make sure that the output.coffee file is not in the same path you're searching with find or you will get into an infinite loop.

http://man.cx/find |
http://www.rubyrake.org/tutorial/index.html

此外,您可能对Stackoverflow上有关搜索目录的其他帖子感兴趣:

Additionally you may be interested in these other posts on Stackoverflow concerning searching across directories:

  • How do you use cat recursively?
  • Bash script to find a file in directory tree and append it to another file
  • Unix script to find all folders in the directory

这篇关于将多个Coffeescript文件合并到一个文件中? (多个子目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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