rikulo/stream — pull request #24 by izaera (2013-04-18 07:35:58+00:00)
Title: Allow RSP compiler receive a FilenameMapper function to map output files to directories other than the default one used by the compiler

This eases project layout when merging client and server code and also allows finer control over where files are output by the compiler.

Let's see if it looks better like this :-). I attach my reply to the previous pull request below because it was sent without format and is unreadable:

<<<<<<<
Done everything until 2.3 + number 4. Will issue pull request tomorrow.

Comments about:

> 3) _createFileDirectoryIfNecessary seems to be redundant since compileFile will do it

Not really. _locate does it, but I added _createFileDirectoryIfNecessary in the other branch of the if. I will try and refactor both branches to create the directory in compileFile.

>5) _mapFileName shall be removed. In other words, _convertToProjectPath and _convertRspSourceExtension shall be done in FilenameMapper, if any. RSP compile doesn't need to know anything about it.

I tried it, but decided to change it back to my current spec for 3 reasons:

1) _convertToProjectPath is necessary because in the full build the given path is absolute, while in "changed" build the path is relative. I can also refactor both calls to pass only relative paths to compileFile but still it would be good to call _convertToProjectPath as safe net. Perhaps it could be optimized to avoid consuming time when the path is, in fact, relative.
2) It is better to use paths relative to project dir to avoid mistakes in the FilenameMapper closure which can end placing compiled files in outer directories of file system.
3) It is better to remap the ".rsp.whatever" extension to ".rsp.dart" inside the compiler to avoid mistakes in FilenameMapper. If you forget to remap the .whatever to .dart the editor enters into an infinite loop as it tries to recompile compiled files again. If you think it it doesn't make sense to put an extension different to .dart as the compiler generates dart code, so, why bothering the user when we can do it in the framework?

Since I can't merge only the last submit, please try to do (there could be a better way for doing it, but I'm not sure):

1) delete the fork (at github)
2) fork again
3) clone to your local drive
4) copy the last modification to it.
5) Pull a request again

The filename mapper is a good spec. Here is a few suggestions:

1) It shall be named as FilenameMapper (to be consistent with dart:io's Path.filename)

2) Please follow my coding style:
2.1) Use if (xxx) {; not if( xxx )
2.2) Add a space after comma (,)
2.3) Add a space before and after an operator, such as foo == null

3) _createFileDirectoryIfNecessary seems to be redundant since compileFile will do it

4) The name argument shall be FilenameMapper filenameMapper (consistency is important)
5) _mapFileName shall be removed. In other words, _convertToProjectPath and _convertRspSourceExtension shall be done in FilenameMapper, if any. RSP compile doesn't need to know anything about it.
>>>>>>>>>>