0

Currently the static resources we use are part of a web project in Visual Studio. There are certain files in the project that we want locally that we don't want being deployed to production. We manage this by using the .csproj file and seeing if a file is mark as "content" or "none" etc. (If it's marked as "none" it doesn't get pulled on the deploy).

This works great however we are moving our development out of Visual Studio and into a more Javascript friendly IDE. However if we add or delete files we still need to go back to Visual Studio and update the .csproj file to ensure that production won't get out of sync and that the build won't break.

This got me thinking, as we are implementing Node/Grunt if there's a plug-in of sorts that handles kind of the same thing -- a whitelist/blacklist kind of approach that the server could look at and decide which files to pick up and which ones to leave.

I've tried googling around but I'm not having much luck in figuring out exactly how to phrase it and I'm hoping someone here has any idea on how this can be done. I'm also willing to hear any other better ways of perhaps handling this issue. That in environment agnostic.

Hanna
  • 10,315
  • 11
  • 56
  • 89
  • Hey have you found what you are looking for on this? I'm trying to solve something similar and I can't agree more that it's difficult to phrase, and searching is even a challenge as well – scniro Apr 03 '15 at 13:52
  • @salniro -- Sorry I have not found what I'm looking for on this. I am still looking for a good answer though so I've attached a bounty to this question and hopefully this will draw some attention and get us a good answer. – Hanna Apr 03 '15 at 17:35
  • Awesome! I asked a very similar question today as well so we might have a chance there as well. Not exact, but darn close. Check it out if you have time. There is a comment that refers a plugin we might find handy. Haven't found the time yet to look into it fully but at first glance it might be what we're looking for. Here is the library as was commented on my end [grunt-usemin](https://github.com/yeoman/grunt-usemin) – scniro Apr 03 '15 at 17:45

1 Answers1

4

Grunt comes with built-in file filters. You can filter anything, it's very powerful. I can't offer a specific solution without seeing your Grunt tasks, but here is an example of different exclusion patterns with the grunt-copy task:

copy: {
  dist: {
    files: [{
      expand: true,
      dot: true,
      dest: 'dist',
      src: [
        '*.{ico,png,txt}',
        'bower_components/**/*',
        'assets/images/{,*/}*.{webp}',
        'assets/fonts/**/*',
        'index.html',
        '!*.something',  // exclude all files with the extension .something
        '!.tmp/**/*'     // exclude all files recursively under .tmp directory
      ]
    }]
 }

Grunt uses node-glob so you may want to explore the documentation there to learn about different patterns.

I will also mention that there are plugins to perform string replacements on any file (eg. grunt-replace). With something like that, you can modify your .csproj file automatically to add/remove files based on your Grunt filters (or vice versa).

Please excuse the anecdote, but as a former .NET developer myself who relied on Visual Studio to handle everything for me, I was initially intimidated by the complexity and apparent frailty of Node.js processes. My message to you would be don't get intimidated, once I became comfortable I realized I had control over every aspect of the build process and was no longer at the mercy of VS. It was the most liberating moment of my career and I haven't looked back.

Terry
  • 14,099
  • 9
  • 56
  • 84
  • Nice! Thanks Terry. So if I understand this correctly you can use these patterns to match files. I haven't read over everything yet, but how does it return the list of matched files? Where does that list go? Is it in an array or is it written to a file, or is that also customizable? – Hanna Apr 08 '15 at 15:28
  • 1
    Using Terry's example of `grunt-copy`, the files included/excluded in the `src` property are copied to a destination directory (the `dest` property) name `dist`. Your build process would then take the files that are in `dist` and deploy those to your server. – M. Adam Kendall Apr 10 '15 at 03:07
  • @Johannes you should read some more about Grunt tasks in general and how they work. There are commonalities between all of them that are fundamental to Grunt. Or, if you're like me and prefer to learn from doing, setup a Gruntfile with a simple task like copy and play around with the options to see what happens. – Terry Apr 10 '15 at 19:09
  • Thanks M. Adam Kendall. And Yeah Terry, I'll need to of course just do some general learning. There are many tasks I wanted to leverage want also needed to know if we could overhaul the deploy process where I work. Sounds like this will work great. Thanks again. – Hanna Apr 12 '15 at 05:47