I'm working on a grunt file for work. We work locally with our files being in html and when we implement them into our CMS they need to be converted to aspx.
I'm trying to replace all instances of <script scr=""></script>
with <imod:ScriptPlaceHolder id="#nameOfFile" runat="server" type="FileInclude" url="#pathToFile"></imod:ScriptPlaceHolder>
I'm using "grunt-replace": "^0.8.0." This task is registered under default and build. I've tried using a regex to match the name, and I've been looking at the documentation for far too long. Here is what my grunt file with replace looks like:
replace: {
dist: {
options: {
patterns: [
{
match: '/script src="/g',
replacement: function() {
'asp:PlaceHolder runat="server" url="';
}
}
]
},
files: [
{expand: true, flatten: true, src: ['<%= config.dist %>/index.html'], dest: 'dist/'}
]
}
},
With some help from Matthew Kime, I was able to get this working. In my regex I had to search for 2 periods because I'm using grunt-rev to version my files. I also used the file name stripped of it's extension to name the files dynamically.
Here is the conclusion I was able to arrive at.
// replace script tags to imod placeholders
replace: {
dist: {
options: {
patterns: [
{
match: /<script src=\"(.*\/)(.+?)\.(.+?)\.js\"><\/script>/g,
replacement: '<imod:ScriptPlaceHolder id="$2$3" type="FileInclude" url="$1$2.$3.js" runat="server"></imod:ScriptPlaceHolder>'
}
]
},
files: [
{expand: true, flatten: true, src: ['<%= config.dist %>/index.html'], dest: 'dist/'}
]
}
},