“Helix is a set of overall design principles and conventions for Sitecore development. Habitat is a real Sitecore project implemented on the Sitecore Experience Platform using Helix.” – Please ingrain this in your brain. It helps to download the source for Habitat as a reference, because you are going to need it and need it you shall!
You can download Habitat from: https://github.com/sitecore/habitat
You could read more about Helix here: http://helix.sitecore.net/
I did not choose Helix, Helix chose me. Based on conversations with Helix folks, it was apparent that Sitecore will push its partners and customers to get behind Helix. Although I am not sure when everyone or the majority will be on board with this. I was thrown into a project where they were trying to implement Helix but unfortunately it fell short in a few areas.
This was very apparent when I tried to get Gulp working.
One of the biggest issues is that devs fallback on others cleaning up their mess. In this case they fell back on TDS cleaning it up. TDS did a great job of packaging up the code and content, config transforms, etc. Since the code is packaged in an update package, custom post installation steps were needed to push them to the web root.
You can use the Multi-Project Package Bundling to easily package up Helix projects. Unfortunately this also meant that Helix principles were not followed to the T.
Earlier this month, HedgeHog posted FxCop rules for Sitecore Helix which should help a lot (http://www.hhog.com/blog/sitecore-helix-fxcop-rules/). At the end of the day it truly comes down to what technologies you want to use for your development & deployments.
FOLDER STRUCTURE, FOLDER STRUCTURE, FOLDER STRUCTURE is key. You enforce that, and you got some Structure 😉 and are part way into implementing a Helix solution.
Do not get me wrong, I am not a Helix expert nor am I a TDS expert. I learn as I go but this time I had no choice. I do not like to depending on third party technology for deployment. I like to streamline it as much as possible.
In this struggle/journey, I had to tackle the following:
- VSTS – Visual Studio Team Services with a Git repo – https://www.visualstudio.com/team-services/git/
- OctoPack – Create Nuget packages from your builds – http://docs.octopusdeploy.com/display/OD/Using+OctoPack
- Gulp – Gulpjs is a task/build runner – http://gulpjs.com/
- Octopus Deploy – Octopus is a deployment automation tool – https://octopus.com/
Now, bare in mind that I have not used any of the above except VSTS for source control before this. I hope to document in detail what you need to do to get this working. If you are one of the fruits who knows all of some of these technologies, don’t hate yo!, share..
I have been using VSTS for a while for only source control and nothing else. When I tried to set it up for builds, I was pleasantly surprised as to how easy it was. We will come to this later.
Now as for Gulp, I knew what it could be used for but had no clue how to use it or even how to get started. In order to get Gulp working, we needed Node.js running as well. In Visual Studio 2015, Node.js and Gulp are automatically installed so I did not have to do much.
Next, I looked at the Habitat source and copied the gulpfile.js, package.json and gulp-config.js files to the same location as the solution file. Deployments are specific to your company or team and cater to your individual needs. My script probably wont suffice for you but all I am trying to do here is to give you an example. Once I copied the three files, I included them in my solution.
- gulp-config.js contains configuration strings with paths etc – Optional
- gulpfile.js contains all the tasks you might end up using. Default task is executed if no startup task is specified.
- package.json file contains the references to all the plugins which are installed and could be used by your gulpfile.js
Once that is done, open the Task Runner Explorer by going to View > Other Windows > Task Runner Explorer in your Visual Studio solution.
This will open the Task Runner Explorer window. This window is your best friend for Gulp tasks. You can run any and all tasks in your Gulpfile.js file.
Even though the gulpfile.js from the Habitat solution has a bunch of code, you might need to add/modify part of it. At first I played around with the tasks and found that the solution folder structure was not right. Please refer to http://helix.sitecore.net/principles/file-structure/index.html
In my case, the default scripts did not suffice as I was using TDS for item deployment and not Unicorn. Gulp is very well documented and so all you need to do is google what you are looking for.
Most likely you will be asked to install Gulp plugins or end up on http://gulpjs.com/plugins/ .
When you encounter commands such as these npm install –save gulp-uglifycss , all you need to do is to open a command window or a windows PowerShell window and navigate to the location of the gulpfile.js. You would run the npm command at that location. By running the Node.js command, it will install the plugin and make an entry in the package.json file.
Once that is complete you would need to modify your gulpfile.js to add a required statement like the one shown below:
var concat = require(‘gulp-concat’);
var uglify = require(‘gulp-uglify’);
var zip = require(‘gulp-zip’);
var minimist = require(‘minimist’);
This would give you access to using a specific plugin in Gulp. From here on, its tweaking tasks, calling one task from the other and getting Gulp to do what you need it to do, all the while running it from the Task Runner window to make sure its working the way you need it to.
Here is my default task:
Once you have your Gulp task running and you are happy with it, we need to deal with automated builds. We will tackle VSTS and OctoPack in the next blog entry.
I encourage you to discuss Helix/Habitat based conversations in the Sitecore Slack Helix-Habitat channel – https://sitecorechat.slack.com .
If you have any questions or concerns, please get in touch with me. (@akshaysura13 on twitter or on Slack).
2 thoughts on “Finally, with one great big Gulp, I conquered Sitecore Helix!”
Great explanation, Thanks for sharing!
Hi This is nice. You minimized the gulp task and that’s good when we start the project. It would have been more useful if you had added step by step instructions. I have one question. Do we need to use gulp mandatory when we go for helix based projects? I came across one post where they are just using some batch file to publish files from VS to IIS website directory. Have you implemented any of your projects with this? If possible, could you share one article?