Skip to content

Instantly share code, notes, and snippets.

@aaronfrost
Created May 1, 2014 18:00
Show Gist options
  • Save aaronfrost/043b23ccd1316775fd2f to your computer and use it in GitHub Desktop.
Save aaronfrost/043b23ccd1316775fd2f to your computer and use it in GitHub Desktop.
//In your Gruntfile
grunt.registerTask('replaceURL', '...', require('./urlReplacer.js'));
//Then in urlReplacer.js
var fs, r, oldfile, newfile;
fs = require('fs');
r = new RegExp("some regex to match your url", 'g');
//read the the file and replace the text
oldfile = fs.readFileSync(__dirname + '/file-with-url-that-needs-to-be-replaced.js', 'utf8');
newfile = oldfile.replace(r, 'http://thenewurl.com');
//write the file back to a temp dir with the right url
fs.writeFileSync(__dirname + '/file-with-url-that-needs-to-be-replaced.js', newfile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment