Use different module templates for feature and foundation projects when using add-helixmodule.ps1

The add-helixmodule.ps

In my first Sitecore Helix project I got introduced to a PowerShell script add-helixmodule.ps1
This script has a few commands that you can call from the console inside Visual Studio:
  • Add-Feature
  • Add-Foundation
  • Add-Project
This script saves us a lot of time creating new feature and foundation projects in Visual Studio. It creates a project inside Visual Studio based on a "template".
The creator of this PowerShell script is Marc Duiker, for more info you can read about it in his blog post here.

Why have two different templates

After creating several feature and foundation projects, I wanted to extend the template to have more references and files in the feature projects. I did not want to add all of these changes when creating foundation projects.

The solution

I solved this by creating two module template folders. One for Foundations and another for Features.
In the Feature module template I added references to the foundation projects and added the files I wanted to be created when calling the Add-Feature command.
In the Foundation module template I removed the files we usually don't need there, and tried to make it as slim as possible.

Changes needed to make the commands use correct template folders

In the JSON file we have the following line:
"moduleTemplatePath": "C:\\yyy\\xxx\\module-template",

I created two new paths in the configuration:
"moduleFoundationTemplatePath": "C:\\yyy\\xxx\\module-template-foundation",
"moduleFeatureTemplatePath": "C:\\yyy\\xxx\\module-template-feature",

Changes to add-helixmodule.ps:
I changed the script so it would pick up the correct template paths. When using Add-Feature we would be using the moduleFeatureTemplatePath. When using Add-Foundation we would be using the ModuleFoundationPath.


Additional notes

If you end up with files and references you don’t use you should not add them, the templates are there to help you create the files and references that you need instead of adding them manually.
We did update the feature template with more items during the development, introducing Glass Mapper and more.
We made minimal changes to the initial foundation template.
We could also introduce a third module template folder for the Add-Project.

Comments

Ole said…
Added changes needed to have a different node module folder to the Add-project command.
Remember to add moduleProjectTemplatePath to the add-helix-module-configuration.json file.

Popular posts from this blog

Step by step guide to add Glass Mapper to Helix solution

Using interfaces with Glass Mapper

Adding dynamic image source for multi-site solutions with $site$ token and setting dynamic datasource location for components