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
You can't move it outside because in javascript the global regex will start on the last used index. So if we didn't create new one every time, the last index will not be at zero. Alternatively we can reset the last index to zero though I find that a bit more confused