This is what I need:
I have log statements in my javascript files, they look like this:
log.d("some log message here")
I want to dynamically add fine name and line number to these during the copy task. Ok, so adding the file name is probably easy enough, but how to I get access to line number? Strangely I could not find any information on how to do this.
The filter() method of Copy task just passing the actual line, it would be nice if it was passing 2 arguments - line and line number.
Here is the template of my task. I added comments of what I need to achieve.
I know I can get name of file from fileCopyDetails using fileCpyDetails.getSourceName() but I am stuck on how to replace the lines that start with log.d() with a new log.d statement that has line number I am really hoping someone can help me here.
task addLineNumbers(type: Copy) {
into 'build/deploy'
from 'source'
eachFile { fileCopyDetails ->
// Here I need to add line number to log.d("message")
// to become log.d("[$fileName::$line] + $message")
// for example, if original line in userdetails.js file was log.d("something logged here")
// replace with log.d("[userdetails.js::43] something logged here")
}
}