使用映射器 Phing UpToDateTask?
有人可以给我一个如何使用 Phing 的 UpToDateTask
的示例吗? 映射器?我无法弄清楚,并且在网上找不到任何示例。
这就是我想要实现的目标。我有一堆 SCSS 文件 使用 ExecTask 和 Ruby 的 SASS 解析器转换为 CSS。但是,我只 如果任何源文件发生更改,想要重新生成 CSS 文件。
源 SCSS 文件位于 app/assets/css
中,编译后的文件为 放置在 app/webroot/css
中。如何使用 UpToDateTask
来测试是否有 app/assets/css
中的文件比中的任何文件新 app/webroot/css
?
请注意,SASS 编译没有一对一的文件名映射到 CSS 文件。最终可能会有十几个 SCSS 文件 编译成3-4个CSS文件。我知道我可以简单地将这些 CSS 文件硬编码到我的 build.xml
中,但我想创建一个更通用、可重用的构建目标。
提前致谢!
Can someone give me an example of how to use Phing's UpToDateTask
with a
mapper? I can't figure it out and I can't find any examples on the net.
Here's what I am trying to achieve. I have a bunch of SCSS files that I
convert to CSS using the ExecTask
and Ruby's SASS parser. But, I only
want to regenerate the CSS files if any of the source files have changed.
The source SCSS files are in app/assets/css
and the compiled files are
placed in app/webroot/css
. How can I use the UpToDateTask
to test if any
of the files in app/assets/css
are newer than any of the files inapp/webroot/css
?
Note that the SASS comilation does not have a 1-to-1 filename mapping to
CSS files. There could be a dozen SCSS files that in the end get
compiled into 3-4 CSS files. I know I could simply hard-code those CSS files into my build.xml
but I would like to create a more generic, re-usable build target.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您事先知道将存在哪些结果文件,则可以使用身份映射器来检查每个源文件是否比单个结果文件新。对每个结果文件执行此操作,您就会知道是否有更改。
If you know in advance which result files will exist, you can use an identity mapper to check if each of the source files are newer than a single result file. Do that for each result file, and you'll know if there have been changes.
我通过反复试验自己解决了这个问题。我上面描述的场景(测试源目录中的任何文件是否比目标目录中的任何文件更新)无法在
uptodate
任务中使用映射器来实现。uptodate
任务只是迭代fileset
,使用mapper
转换任何文件名,然后将该文件与原始文件进行比较。目前我使用的文件集包括所有不以下划线开头的文件(SASS 包含)和一个简单的映射器,该映射器仅将
*.scss
映射到*.css
。它有效,但并不完美。当只有一个包含文件发生更改(以下划线开头的文件)时,Phing 将不会检测到任何更改并跳过重建 CSS 资源。I figured it out for myself using trial and error. The scenario I described above (testing if any file in a source directory is newer than any file in a destination directory) cannot be achieved using a mapper in the
uptodate
task. Theuptodate
task simply iterates over thefileset
, converts any filename using themapper
and then compares that file with the original file.For the time being I am using a fileset that includes all files that do not start with an underscore (which are SASS includes) and a simple mapper that just globs
*.scss
to*.css
. It works, but it's not perfect. When only one of the include files changes (those starting with an underscore) then Phing will not detect any changes and skip rebuilding the CSS assets.