Skip to content

Commit

Permalink
Merge pull request #66 from Sitecore/develop
Browse files Browse the repository at this point in the history
Merging develop 9.0.2.3 to master
  • Loading branch information
scottmulligan authored Oct 18, 2018
2 parents ad372cc + fd6786e commit 7abab7a
Show file tree
Hide file tree
Showing 25 changed files with 1,058 additions and 5,489 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ lib/Support/*
*.dll
*sc-internal*
publishTemp/

tools/*
!tools/packages.config
cake-config.user.json
116 changes: 116 additions & 0 deletions CakeScripts/helper-methods.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System.Text.RegularExpressions;

/*===============================================
================= HELPER METHODS ================
===============================================*/

public class Configuration
{
private MSBuildToolVersion _msBuildToolVersion;

public string WebsiteRoot {get;set;}
public string InstanceUrl {get;set;}
public string SolutionName {get;set;}
public string ProjectFolder {get;set;}
public string BuildConfiguration {get;set;}
public bool RunCleanBuilds {get;set;}
public string MessageStatisticsApiKey {get;set;}
public string BuildToolVersions
{
set
{
if(!Enum.TryParse(value, out this._msBuildToolVersion))
{
this._msBuildToolVersion = MSBuildToolVersion.Default;
}
}
}

public string SourceFolder => $"{ProjectFolder}\\src";
public string FoundationSrcFolder => $"{SourceFolder}\\Foundation";
public string FeatureSrcFolder => $"{SourceFolder}\\Feature";
public string ProjectSrcFolder => $"{SourceFolder}\\Project";

public string SolutionFile => $"{ProjectFolder}\\{SolutionName}";
public MSBuildToolVersion MSBuildToolVersion => this._msBuildToolVersion;
public string BuildTargets => this.RunCleanBuilds ? "Clean;Build" : "Build";
public string SitecoreLibrariesPath => $"{WebsiteRoot}\\bin";
public string SitecoreLibModuleCommerce => $"{ProjectFolder}\\lib\\Modules\\Commerce";
}

public void PublishProjects(string rootFolder, string websiteRoot)
{
var projects = GetFiles($"{rootFolder}\\**\\website\\*.csproj");

foreach (var project in projects)
{
MSBuild(project, cfg => InitializeMSBuildSettings(cfg)
.WithTarget(configuration.BuildTargets)
.WithProperty("DeployOnBuild", "true")
.WithProperty("DeployDefaultTarget", "WebPublish")
.WithProperty("WebPublishMethod", "FileSystem")
.WithProperty("DeleteExistingFiles", "false")
.WithProperty("publishUrl", websiteRoot)
.WithProperty("BuildProjectReferences", "false"));
}
}

public FilePathCollection GetTransformFiles(string rootFolder)
{
Func<IFileSystemInfo, bool> exclude_obj_bin_folder = fileSystemInfo => !fileSystemInfo.Path.FullPath.Contains("/obj/") && !fileSystemInfo.Path.FullPath.Contains("/bin/");

var xdtFiles = GetFiles($"{rootFolder}/**/*.xdt", exclude_obj_bin_folder);

return xdtFiles;
}

public void Transform(string rootFolder) {
var xdtFiles = GetTransformFiles(rootFolder);

foreach (var file in xdtFiles)
{
Information($"Applying configuration transform:{file.FullPath}");
var fileToTransform = Regex.Replace(file.FullPath, ".+website/(.+)/*.xdt", "$1");
var sourceTransform = $"{configuration.WebsiteRoot}\\{fileToTransform}";
if (FileExists(sourceTransform))
{
XdtTransformConfig(sourceTransform // Source File
, file.FullPath // Tranforms file (*.xdt)
, sourceTransform); // Target File
}

}
}

public void RebuildIndex(string indexName)
{
cakeConsole.WriteLine($"Rebuild {indexName}");
var url = $"{configuration.InstanceUrl}utilities/indexrebuild.aspx?index={indexName}";
string responseBody = HttpGet(url);
}

public MSBuildSettings InitializeMSBuildSettings(MSBuildSettings settings)
{
settings.SetConfiguration(configuration.BuildConfiguration)
.SetVerbosity(Verbosity.Minimal)
.SetMSBuildPlatform(MSBuildPlatform.Automatic)
.SetPlatformTarget(PlatformTarget.MSIL)
.UseToolVersion(configuration.MSBuildToolVersion)
.WithRestore();
return settings;
}

public void CreateFolderIfNotExist(string folderPath)
{
if (!DirectoryExists(folderPath))
{
CreateDirectory(folderPath);
}
}

public void WriteError(string errorMessage)
{
cakeConsole.ForegroundColor = ConsoleColor.Red;
cakeConsole.WriteError(errorMessage);
cakeConsole.ResetColor();
}
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ The code, samples and/or solutions provided in this repository are for example p

# Getting Started

**This guide assumes you've cloned and deployed Sitecore.HabitatHome.Content. See the README.md file in the [Sitecore.HabitatHome.Content](https://github.com/sitecore/sitecore.habitathome.content) repository.**
**This guide assumes you've cloned and deployed Sitecore.HabitatHome.Platform. See the README.md file in the [Sitecore.HabitatHome.Platform](https://github.com/sitecore/sitecore.habitathome.platform) repository.**

## Prerequisites

### Sitecore Version

Prior to attempting the demo installation, ensure you have a working **Sitecore XC 9.0.1** instance. Detailed installation instructions can be found at [doc.sitecore.com](http://commercesdn.sitecore.net/SitecoreXC_9.0/Installation-Guide/Sitecore-XC-9.0_Installation_Guide(On-Prem).pdf).
Prior to attempting the demo installation, ensure you have a working **Sitecore XC 9.0.2** instance. Detailed installation instructions can be found at [doc.sitecore.com](http://commercesdn.sitecore.net/SitecoreXC_9.0/Installation-Guide/9.0.2/SitecoreXC-9.0_Installation_Guide(On-Prem).pdf).

You do not need to install the Storefront Theme

Expand All @@ -34,15 +34,12 @@ You do not need to install the Storefront Theme

## Custom Install - before you start

If you do **not want to use the default settings**, you need to adjust the appropriate values in the following files:
If you do **not want to use the default settings**, you need to adjust the appropriate values in the `/cake-config.json` file.

* `/gulp-config.js`
* `/publishsettings.targets`
* `src\Project\HabitatHome\website\App_Config\Include\Project\z.HabitatHome.Commerce.WebSite.DevSettings.config`

Note: If you've already deployed the HabitatHome Content demo, and you wish to run the HabitatHome Commerce demo in a new instance by customizing these sttings,
you would need to also customize the settings in the HabitatHome Content demo and deploy it to the new instance **before** deploying HabitatHome Commerce.
See README.md in Sitecore.HabitatHome.Content for custom settings.
Note: If you've already deployed the HabitatHome Platform demo, and you wish to run the HabitatHome Commerce demo in a new instance by customizing these sttings,
you would need to also customize the settings in the HabitatHome Platform demo and deploy it to the new instance **before** deploying HabitatHome Commerce.
See README.md in Sitecore.HabitatHome.Platform for custom settings.

## Installation
**All installation instructions assume using PowerShell 5.1 in administrative mode.**
Expand All @@ -54,23 +51,25 @@ Clone the Sitecore.HabitatHome.Commerce repository locally - default settings as
`git clone [email protected]:Sitecore/Sitecore.HabitatHome.Commerce.git`

### 2 Deploy Solution
Note: If you have not yet done so, deploy the base HabitatHome.Content solution. See README.md in Sitecore.HabitatHome.Content
You can run the `quick-deploy` gulp task from the root of the HabitatHome.Content solution for a quicker deploy that excludes post deploy actions or Unicorn synchronization.
Note: If you have not yet done so, deploy the base HabitatHome.Platform solution. See README.md in Sitecore.HabitatHome.Platform
You can run the `Quick-Deploy` gulp task from the root of the HabitatHome.Platform solution for a quicker deploy that excludes post deploy actions or Unicorn synchronization.

To deploy the HabitatHome.Commerce solution, from the root of the solution
To deploy the **HabitatHome.Commerce** solution, from the root of the solution

`npm install`
`node_modules\.bin\gulp initial`
> gulp **initial** only needs to be executed successfully during the initial deployment. Subsequent deployments can be made by running the default gulp task (gulp with no parameters).
`.\build.ps1 -Target Initial`

_Notes:_

- Build target **Initial** only needs to be executed successfully during the initial deployment. Subsequent deployments can be made by running the **Default** Cake build target: `.\build.ps1` (without target specification).

### 3 Deploy Engine

The next step will deploy Habitat Home's custom Commerce Engine with its relevant plugin and load the catalog, inventory and promotions.

_Notes:_
* If you want to use your own engine suffix rather than `habitat`, you need to update it in `deploy-commerce-engine.ps1`
* If you want to use your own databases rather than `habitat_Global`, you need to update it in `\src\Project\HabitatHome\engine\wwwroot\bootstrap\Global.json`
* If you want to use your own databases rather than `habitat_SharedEnvironments`, you need to update it in `\src\Project\HabitatHome\engine\wwwroot\data\Environments\Plugin.SQL.PolicySet-1.0.0.json`
* If you want to use your own engine suffix rather than `habitathome`, you need to update it in `deploy-commerce-engine.ps1`
* If you want to use your own databases rather than `habitathome_Global`, you need to update it in `\src\Project\HabitatHome\engine\wwwroot\bootstrap\Global.json`
* If you want to use your own databases rather than `habitathome_SharedEnvironments`, you need to update it in `\src\Project\HabitatHome\engine\wwwroot\data\Environments\Plugin.SQL.PolicySet-1.0.0.json`
The script is provided as an example and should be reviewed to understand its behavior prior to its execution. In summary, the script:

- Compiles and publishes the engine to a temporary location (default .\publishTemp)
Expand All @@ -86,9 +85,9 @@ The script is provided as an example and should be reviewed to understand its be

Assuming you have the default installation settings:

deploy-commerce-engine.ps1 -Bootstrap -Initialize
`.\deploy-commerce-engine.ps1 -Bootstrap -Initialize`

> if you have made any changes to your settings, review the deploy-engine-commerce.ps1 script and override / modify the parameters as required.
> if you have made any changes to your settings, review the `deploy-engine-commerce.ps1` script and override / modify the parameters as required.

# Contribute or Issues
Expand Down
184 changes: 184 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#addin "Cake.XdtTransform"
#addin "Cake.Powershell"
#addin "Cake.Http"
#addin "Cake.Json"
#addin "Newtonsoft.Json"

#load "local:?path=CakeScripts/helper-methods.cake"


var target = Argument<string>("Target", "Default");
var configuration = new Configuration();
var cakeConsole = new CakeConsole();

var unicornSyncScript = $"./scripts/Unicorn/Sync.ps1";

var configJsonFile = "cake-config.json";

/*===============================================
================ MAIN TASKS =====================
===============================================*/

Setup(context =>
{
cakeConsole.ForegroundColor = ConsoleColor.Yellow;

var configFile = new FilePath(configJsonFile);
configuration = DeserializeJsonFromFile<Configuration>(configFile);
});

Task("Default")
.WithCriteria(configuration != null)
.IsDependentOn("Clean")
.IsDependentOn("Copy-Sitecore-Lib")
.IsDependentOn("Publish-Website-Projects")
.IsDependentOn("Apply-Xml-Transform")
.IsDependentOn("Modify-Unicorn-Source-Folder")
.IsDependentOn("Publish-Transforms")
.IsDependentOn("Sync-Unicorn")
.IsDependentOn("Deploy-EXM-Campaigns");

Task("Quick-Deploy")
.WithCriteria(configuration != null)
.IsDependentOn("Clean")
.IsDependentOn("Copy-Sitecore-Lib")
.IsDependentOn("Publish-Website-Projects")
.IsDependentOn("Apply-Xml-Transform")
.IsDependentOn("Modify-Unicorn-Source-Folder")
.IsDependentOn("Publish-Transforms");

Task("Initial")
.WithCriteria(configuration != null)
.IsDependentOn("Clean")
.IsDependentOn("Copy-Sitecore-Lib")
.IsDependentOn("Publish-Website-Projects")
.IsDependentOn("Apply-Xml-Transform")
.IsDependentOn("Modify-Unicorn-Source-Folder")
.IsDependentOn("Publish-Transforms")
.IsDependentOn("Sync-Unicorn")
.IsDependentOn("Deploy-EXM-Campaigns")
.IsDependentOn("Rebuild-Core-Index")
.IsDependentOn("Rebuild-Master-Index")
.IsDependentOn("Rebuild-Web-Index");


/*===============================================
================= SUB TASKS =====================
===============================================*/

Task("Clean").Does(() => {
CleanDirectories($"{configuration.SourceFolder}/**/obj");
CleanDirectories($"{configuration.SourceFolder}/**/bin");
});

Task("Copy-Sitecore-Lib").Does(() => {
cakeConsole.WriteLine("Copying Sitecore Commerce XA Libraries");
var commerceLibraries = GetFiles($"{configuration.SitecoreLibrariesPath}\\**\\Sitecore.Commerce.XA.*").Select(x => x.FullPath).ToList();
CreateFolderIfNotExist(configuration.SitecoreLibModuleCommerce);
CopyFiles(commerceLibraries, configuration.SitecoreLibModuleCommerce, preserveFolderStructure: true);
});

Task("Publish-Website-Projects")
.IsDependentOn("Build-Solution")
.IsDependentOn("Publish-Foundation-Projects")
.IsDependentOn("Publish-Feature-Projects")
.IsDependentOn("Publish-Project-Projects");


Task("Build-Solution").Does(() => {
MSBuild(configuration.SolutionFile, cfg => InitializeMSBuildSettings(cfg));
});

Task("Publish-Foundation-Projects").Does(() => {
PublishProjects(configuration.FoundationSrcFolder, configuration.WebsiteRoot);
});

Task("Publish-Feature-Projects").Does(() => {
PublishProjects(configuration.FeatureSrcFolder, configuration.WebsiteRoot);
});

Task("Publish-Project-Projects").Does(() => {
PublishProjects(configuration.ProjectSrcFolder, configuration.WebsiteRoot);
});

Task("Apply-Xml-Transform").Does(() => {
var layers = new string[] { configuration.FoundationSrcFolder, configuration.FeatureSrcFolder, configuration.ProjectSrcFolder};

foreach(var layer in layers)
{
Transform(layer);
}
});

Task("Publish-Transforms").Does(() => {
var destination = $@"{configuration.WebsiteRoot}\temp\transforms";

CreateFolderIfNotExist(destination);

try
{
var xdtFolder = $"{configuration.SourceFolder}\\**\\website";
var xdtFiles = GetTransformFiles(xdtFolder).Select(x => x.FullPath).ToList();
CopyFiles(xdtFiles, destination, preserveFolderStructure: true);
}
catch (System.Exception ex)
{
WriteError(ex.Message);
}
});

Task("Modify-Unicorn-Source-Folder").Does(() => {
var zzzDevSettingsFile = File($"{configuration.WebsiteRoot}/App_config/Include/Project/z.HabitatHome.Commerce.Website.DevSettings.config");

var rootXPath = "configuration/sitecore/sc.variable[@name='{0}']/@value";
var sourceFolderXPath = string.Format(rootXPath, "commerce.sourceFolder");
var directoryPath = MakeAbsolute(new DirectoryPath(configuration.SourceFolder)).FullPath;

var xmlSetting = new XmlPokeSettings {
Namespaces = new Dictionary<string, string> {
{"patch", @"http://www.sitecore.net/xmlconfig/"}
}
};
XmlPoke(zzzDevSettingsFile, sourceFolderXPath, directoryPath, xmlSetting);
});

Task("Sync-Unicorn").Does(() => {
var unicornUrl = configuration.InstanceUrl + "unicorn.aspx";
Information("Sync Unicorn items from url: " + unicornUrl);

var authenticationFile = new FilePath($"{configuration.WebsiteRoot}/App_config/Include/Unicorn.SharedSecret.config");
var xPath = "/configuration/sitecore/unicorn/authenticationProvider/SharedSecret";

string sharedSecret = XmlPeek(authenticationFile, xPath);


StartPowershellFile(unicornSyncScript, new PowershellSettings()
.SetFormatOutput()
.SetLogOutput()
.WithArguments(args => {
args.Append("secret", sharedSecret)
.Append("url", unicornUrl);
}));
});

Task("Deploy-EXM-Campaigns").Does(() => {
var url = $"{configuration.InstanceUrl}utilities/deployemailcampaigns.aspx?apiKey={configuration.MessageStatisticsApiKey}";
string responseBody = HttpGet(url);

Information(responseBody);
});

Task("Rebuild-Core-Index").Does(() => {
RebuildIndex("sitecore_core_index");
});

Task("Rebuild-Master-Index").Does(() => {
RebuildIndex("sitecore_master_index");
});

Task("Rebuild-Web-Index").Does(() => {
RebuildIndex("sitecore_web_index");
});


RunTarget(target);
Loading

0 comments on commit 7abab7a

Please sign in to comment.