getdave / grunt-deployments

MYSQL database deployments using GruntJS
MIT License
72 stars 34 forks source link

Support for windows platform #42

Open wizioo opened 10 years ago

wizioo commented 10 years ago

As you askes me, here's my version working on windows. I was a little surprised by the develop branch having a totally different structure from master where I originally changed the code. I have 2 points I'd want you to see:

I hope my contribution is useful and usable for you (and others).

However, thank you for this fantastic grunt plugin!

getdave commented 10 years ago

@wizioo thanks for this pull request. It is very much appreciated. I will review just as soon as I can.

nickbouton commented 10 years ago

@wizioo @getdave Can you confirm that this properly replaces on Win7? I'm still having trouble - it's only replacing the first instance of the URL from what I'm seeing.

getdave commented 10 years ago

@nickbouton I can't confirm this I'm afraid as I don't have a windows machine. Sorry about that. Maybe @wizioo can help you there?

Just so you're both aware my plan for ongoing development to counter this issue would be to provide a option in the grunt task config which allows the user to supply their own search/replace mechanism. This would allow Windows users to create and test their own search/replace without me needing to buy and test on the windows machine.

I also feel such an approach would be the most extendible. Any thoughts?

wizioo commented 10 years ago

@nickbouton You're right... sed command only replace the 1st instance of the url. We have to find another solution. Any idea for the "find and replace" on windows machines?

PS: Sorry for not having answered before, I didn't have time.

nickbouton commented 10 years ago

@wizioo Maybe using powershell instead? Not sure offhand.

http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir http://stackoverflow.com/questions/20077763/execute-powershell-script-from-grunt

Might be some way of getting it to work via shell.sed() as well. Not sure why it's only replacing one instance other than missing some parameters in addition to -i. The -r switch allows usage of extended regular expression syntax (on Windows at least). Maybe that's needed?

wizioo commented 10 years ago

@nickbouton I think I've got it! shell.sed() hasn't "global" option. I had a look on powershell but it was too restrictive. But I finally just used js own search and replace functions. It would work on any OS. I only had to read an write the file, and Grunt know how to do this.

Just use it in db_replace instead of sed command:

var reg= new RegExp(search,"g");               //Create a global regexp w/ search string 
var myFile=grunt.file.read(output_file);        //Get file as a string
var result = myFile.replace(reg, replace);    //Replace search string by replace string
grunt.file.write(output_file, result);                //Write in file

I'll do a pull request w/ this feature as soon as possible.

wizioo commented 10 years ago

Hi there, I've tested and it seems to work on windows. No reason that it doesn't on other platform. It would be better to have this grunt plugin to be universal by default rather than having to configure your gruntfile w/ different options according to your platform.

@nickbouton Can you test it and confirm ?

@getdave I hope it will be included on your next release. Thanks for the work already done.

nickbouton commented 10 years ago

Thanks for your work on this, @wizioo. I will test it out this evening and get back to you.

getdave commented 10 years ago

Guys if this is just to do with relying on the use of sed to control search and replace then you might like to look at this branch

https://github.com/getdave/grunt-deployments/tree/feature/advanced-search-replace

More here