outaTiME / grunt-replace

Replace text patterns with applause.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trying to replace string with a question mark "?" in it

cthorne66 opened this issue · comments

I've tried all the regex expressions I could find so far, but with no luck. I'm evaluating the following string inside of a css file with import statements for other stylesheets

@import url('../lib/bootstrap.2.3.1/css/bootstrap.min.css?@@buildDate');

I'm trying to replace "?@@buildDate" with an empty string. I could quite simply replace the "@@buildDate" alone, but it's the question mark that is preventing concatenation of css files. (i've also logged a ticket with that lib)

Here are some of the variations I've tried

options: {
patterns: [{
match: '/?@@buildDate/g',
replacement: ''
}]

}

Also
match: '/?@@buildDate/g' (single escape, with jshint doesn't like)
match: '/?@@buildDate/g', (double escape)

To no avail. Any suggestions?

Thank you
Chris

Hi pal,

do you try ...

options: {
  patterns: [
    {
      match: 'buildDate',
      replacement: ''
    }
  ]
}

it might be work ... remember by default grunt-replace uses @@ prefix for matching string ...

please tell me if it works ...

thks !

mmm, the following script must be work ...

options: {
  patterns: [
    {
      match: /\?@@buildDate/g,
      replacement: ''
    }
  ]
}

but ... mmm ... if doesn't work ... probably you are doing something wrong ... processing css and resolving import before grunt-replace execution or bad file definition in grunt-replace task ...

some feedback will be right ^^

Yeah, so the reason for the url args is for cache busing in test env. Unfortunately, the css minifier will not concatenate files for QA as usual if the @import url has a "?" in it, so I'm trying to work around it by removing this string "?@@buildDate" (including the question mark).

I fully expect I am doing something wrong :-)

I've also tried

options: {
patterns: [{
match: '?@@buildDate',
replacement: ''
}],
usePrefix: false
}

and

options: {
patterns: [{
match: '?@@buildDate',
replacement: ''
}],
usePrefix: ''
}

mmmm, you can share your gruntfile ?? i need to see the execution flow ...

mmm for any reason grunt-replace not found expression matching ...

when i use the below, i get this error (which I never see in any other variation):
Warning: Error while processing "./buildTarget/css/bluestyles.css" file. Use --force to continue.

options: {
patterns: [{
match: '?@@buildDate',
replacement: ''
}],
usePrefix: false
}

My grunt file is quite large and for my employer, so I'm not able to share it, but I'm executing the below by itself to test it with "grunt replace:removeBuildStamp"

replace: {
    addBuildStamp: {
        options: {
            patterns: [{
                match: 'buildDate',
                replacement: 'rel=' + '<%= new Date().getTime() %>'
            }]
        },
        files: [{
            expand: true,
            src: ['<%= BUILD_PATH %>' + 'css/*.css']
        }]
    },
    removeBuildStamp: {
        options: {
            patterns: [{
                match: /\?@@buildDate/g,
                replacement: ''
            }]

        },
        files: [{
            expand: true,
            src: ['<%= BUILD_PATH %>' + 'css/*.css']
        }]
    }
}

Thank you for looking

formatted better

replace: {
    addBuildStamp: {
        options: {
            patterns: [{
                match: 'buildDate',
                replacement: 'rel=' + '<%= new Date().getTime() %>'
            }]
        },
        files: [{
            expand: true,
            src: ['<%= BUILD_PATH %>' + 'css/*.css']
        }]
    },
    removeBuildStamp: {
        options: {
            patterns: [{
                match: /\?@@buildDate/g,
                replacement: ''
            }]

        },
        files: [{
            expand: true,
            src: ['<%= BUILD_PATH %>' + 'css/*.css']
        }]
    }
}

mmm ... something wired ... how execute the replace action ?

you have two actions ... addBuildStamp and removeBuildStamp ... the first (addBuildStamp) replaces @@buildDate with rel=' + '<%= new Date().getTime() %> ... and the second (removeBuildStamp) probably doesn't match expression cos the first make the replacement ... it could be possible ??

both actions are working over the same resources ...

I'm not executing both at the same time, that would have made sense though. before building for a QA deployment, i execute the "replace:removeBuildStamp" task explicitly

perhaps you could try to reproduce by finding this string in a file

@import url('../lib/bootstrap.2.3.1/css/bootstrap.min.css?@@buildDate');

and replacing it with

@import url('../lib/bootstrap.2.3.1/css/bootstrap.min.css');

mmmm ... so wired ... i not really understand the execution scenario ... one more time probably the replacement issues comes with bad execution flows ...

the only way to help you ... is if you give me an test scenario ... gruntfile ... css ... and execution flows ... can you ?

you can build a small set of rules o make a fork with related test case ... it will be better ...

ok, i will do that. Thank you!

Love this lib!

I deleted all my node_modules, and forced an update. It seems to be doing exactly what I want it to now.

Thank you

cooooongrats !!!

awesome ... thks for using grunt-replace ^^

👍