Refactor ref files path

This is an initial re-factoring of pre-process files by moving preProcessFile from preCompile.ts into services.ts and use new scanner to perform the tasks. Couple more clean-up and re-factoring are still needed as indicated in TODO comments and they will be added soon
We can't move this out because it is a global regex and when you reuse it, the last index will not be at zero so it will produce wrong result. Alternatively we can set the last index to zero but I think this way is more clear