Skip to content

Commit

Permalink
Updated build scripts
Browse files Browse the repository at this point in the history
Removed WebMarkupMin - it is over-zealous with its minification.
Specifically caused issues with AngularJs directive params that conflict
with HTML boolean attributes, e.g. `<umb-checkmark checked>`.

Powershell script updated to generate the Umbraco package format.

NuGet format is still being developed.
  • Loading branch information
leekelleher committed Nov 15, 2019
1 parent 0b0bc08 commit 40d5cdd
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ artifacts/
build/assets/
src/packages/*/**
/tools/*.exe
/build/__umb/*
/build/__nuget/*
23 changes: 9 additions & 14 deletions build/build-assets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ param(
Write-Host $ConfigurationName;

if ($ConfigurationName -eq 'Debug') {
Write-Host $SolutionDir;
Write-Host $TargetDir;
Write-Host $ProjectName;
Write-Host $ProjectDir;
Write-Host $TargetDevWebsite;
Write-Host $SolutionDir;
Write-Host $TargetDir;
Write-Host $ProjectName;
Write-Host $ProjectDir;
Write-Host $TargetDevWebsite;
}

$targetFolder = "${SolutionDir}..\build\assets";
Expand All @@ -34,17 +34,12 @@ $pluginFolder = "${targetFolder}\App_Plugins\Contentment\";
if (!(Test-Path -Path $pluginFolder)) {New-Item -Path $pluginFolder -Type Directory;}
Copy-Item -Path "${ProjectDir}Web\UI\App_Plugins\Contentment\*" -Force -Recurse -Destination "${pluginFolder}";

# Load WebMarkupMin (for minification)
[Reflection.Assembly]::LoadFile("${SolutionDir}..\tools\lib\AdvancedStringBuilder.dll");
[Reflection.Assembly]::LoadFile("${SolutionDir}..\tools\lib\WebMarkupMin.Core.dll");
$htmlMinifier = [WebMarkupMin.Core.HtmlMinifier]::new();

# HTML - Copy and Minify (or just remove comments)
$htmlFiles = Get-ChildItem -Path "${ProjectDir}DataEditors" -Recurse -Force -Include *.html;
foreach($htmlFile in $htmlFiles){
$contents = Get-Content -Path $htmlFile.FullName;
$minifiedHtml = $htmlMinifier.Minify($contents).MinifiedContent;
Set-Content -Path "${pluginFolder}\editors\$($htmlFile.Name)" -Value $minifiedHtml;
$contents = Get-Content -Path $htmlFile.FullName;
$minifiedHtml = [Regex]::Replace($contents, "^<!--.*?-->", "");
Set-Content -Path "${pluginFolder}\editors\$($htmlFile.Name)" -Value $minifiedHtml;
}

# CSS - Bundle & Minify
Expand All @@ -59,5 +54,5 @@ Get-Content -Path "${ProjectDir}DataEditors\**\*.js" | Set-Content -Path $target

# In debug mode, copy the assets over to the local dev website
if ($ConfigurationName -eq 'Debug' -AND -NOT($TargetDevWebsite -eq '')) {
Copy-Item -Path "${targetFolder}\*" -Force -Recurse -Destination $TargetDevWebsite;
Copy-Item -Path "${targetFolder}\*" -Force -Recurse -Destination $TargetDevWebsite;
}
72 changes: 60 additions & 12 deletions build/build-pkgs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,33 @@ Function parseSemVer($version) {
};
}

# Set various variables / paths

# Set various variables / folder paths

$projectNamespace = 'Umbraco.Community.Contentment';
$packageName = 'Contentment';
$packageUrl = 'https://github.com/leekelleher/umbraco-contentment';
$licenseName = 'Mozilla Public License Version 2.0';
$licenseUrl = 'https://mozilla.org/MPL/2.0/';
$authorName = 'Lee Kelleher';
$authorUrl = 'https://leekelleher.com/';
$minUmbracoVersion = parseSemVer('8.2.0');

$rootFolder = (Get-Item($MyInvocation.MyCommand.Path)).Directory.Parent.FullName;
$buildFolder = Join-Path -Path $rootFolder -ChildPath 'build';
$assetsFolder = Join-Path -Path $buildFolder -ChildPath 'assets';
$srcFolder = Join-Path -Path $rootFolder -ChildPath 'src';

$rootPath = (Get-Item($MyInvocation.MyCommand.Path)).Directory.Parent.FullName;
$buildPath = Join-Path -Path $rootPath -ChildPath 'build';
$assetsPath = Join-Path -Path $buildPath -ChildPath 'assets';
$srcPath = Join-Path -Path $rootPath -ChildPath 'src';

# Get some package metadata - name, description, links, etc.

$version = Get-Content -Path "${rootPath}\VERSION";
$version = Get-Content -Path "${rootFolder}\VERSION";
$semver = parseSemVer($version);


# Update the assembly version number

Set-Content -Path "${srcPath}\Umbraco.Community.Contentment\Properties\VersionInfo.cs" -Value @"
Set-Content -Path "${srcFolder}\${projectNamespace}\Properties\VersionInfo.cs" -Value @"
using System.Reflection;
[assembly: AssemblyVersion("$($semver.Major).$($semver.Minor)")]
Expand All @@ -51,7 +61,7 @@ using System.Reflection;
# Build the VS project

# Ensure NuGet.exe
$nuget_exe = "${rootPath}\tools\nuget.exe";
$nuget_exe = "${rootFolder}\tools\nuget.exe";
If (-NOT(Test-Path -Path $nuget_exe)) {
Write-Host "Retrieving nuget.exe...";
Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $nuget_exe;
Expand All @@ -66,23 +76,61 @@ if (-NOT(Test-Path $msbuild_exe)) {
}

Write-Host 'Restoring NuGet packages...';
& $nuget_exe restore "${srcPath}\${projectNamespace}.sln";
& $nuget_exe restore "${srcFolder}\${projectNamespace}.sln";

Write-Host 'Compiling Visual Studio solution.';
& $msbuild_exe "${srcPath}\${projectNamespace}.sln" /p:Configuration=Release
& $msbuild_exe "${srcFolder}\${projectNamespace}.sln" /p:Configuration=Release
if (-NOT $?) {
throw 'The MSBuild process returned an error code.';
}


# Populate the Umbraco package manifest

$umbFolder = Join-Path -Path $buildFolder -ChildPath '__umb';
if (!(Test-Path -Path $umbFolder)) {New-Item -Path $umbFolder -Type Directory;}

$umbracoManifest = Join-Path -Path $buildFolder -ChildPath 'manifest-umbraco.xml';
$umbracoPackageXml = [xml](Get-Content $umbracoManifest);
$umbracoPackageXml.umbPackage.info.package.version = "$($semver.Major).$($semver.Minor).$($semver.Patch)";
$umbracoPackageXml.umbPackage.info.package.name = $packageName;
$umbracoPackageXml.umbPackage.info.package.license.set_InnerText($licenseName);
$umbracoPackageXml.umbPackage.info.package.license.url = $licenseUrl;
$umbracoPackageXml.umbPackage.info.package.url = $packageUrl;
$umbracoPackageXml.umbPackage.info.package.requirements.major = "$($minUmbracoVersion.Major)";
$umbracoPackageXml.umbPackage.info.package.requirements.minor = "$($minUmbracoVersion.Minor)";
$umbracoPackageXml.umbPackage.info.package.requirements.patch = "$($minUmbracoVersion.Patch)";
$umbracoPackageXml.umbPackage.info.author.name = $authorName;
$umbracoPackageXml.umbPackage.info.author.website = $authorUrl;

$filesXml = $umbracoPackageXml.CreateElement('files');

$assetFiles = Get-ChildItem -Path $assetsFolder -File -Recurse;
foreach($assetFile in $assetFiles){

$umbracoPackageManifest = Join-Path -Path $buildPath -ChildPath 'manifest-umbraco.xml';
$hash = Get-FileHash -Path $assetFile.FullName -Algorithm MD5;
$guid = $hash.Hash.ToLower() + $assetFile.Extension;
$orgPath = "~" + $assetFile.Directory.FullName.Replace($assetsFolder, "").Replace("\", "/");

$fileXml = $umbracoPackageXml.CreateElement("file");
$fileXml.set_InnerXML("<guid>${guid}</guid><orgPath>${orgPath}</orgPath><orgName>$($assetFile.Name)</orgName>");
$filesXml.AppendChild($fileXml);

Copy-Item -Path $assetFile.FullName -Destination "${umbFolder}\${guid}";
}

$umbracoPackageXml.umbPackage.ReplaceChild($filesXml, $umbracoPackageXml.SelectSingleNode("/umbPackage/files")) | Out-Null;
$umbracoPackageXml.Save("${umbFolder}\package.xml");

$artifactsFolder = Join-Path -Path $rootFolder -ChildPath 'artifacts';
if (!(Test-Path -Path $artifactsFolder)) {New-Item -Path $artifactsFolder -Type Directory;}
Compress-Archive -Path "${umbFolder}\*" -DestinationPath "${artifactsFolder}\Contentment_$($semver.VersionString).zip" -Force;


# Populate the NuGet package manifest

$nugetPackageManifest = Join-Path -Path $buildPath -ChildPath 'manifest-nuget.xml';

$nugetPackageManifest = Join-Path -Path $buildFolder -ChildPath 'manifest-nuget.xml';


# Anything else?
40 changes: 20 additions & 20 deletions build/manifest-nuget.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id></id>
<version>0.0.0</version>
<title></title>
<authors></authors>
<owners></owners>
<projectUrl></projectUrl>
<iconUrl></iconUrl>
<requireLicenseAcceptance></requireLicenseAcceptance>
<description></description>
<summary></summary>
<copyright></copyright>
<licenseUrl></licenseUrl>
<language></language>
<tags></tags>
<dependencies>
<dependency id="UmbracoCms.Core" version="0.0.0" />
<dependency id="UmbracoCms.Web" version="0.0.0" />
</dependencies>
</metadata>
<metadata>
<id></id>
<version>0.0.0</version>
<title></title>
<authors></authors>
<owners></owners>
<projectUrl></projectUrl>
<iconUrl></iconUrl>
<requireLicenseAcceptance></requireLicenseAcceptance>
<description></description>
<summary></summary>
<copyright></copyright>
<licenseUrl></licenseUrl>
<language></language>
<tags></tags>
<dependencies>
<dependency id="UmbracoCms.Core" version="0.0.0" />
<dependency id="UmbracoCms.Web" version="0.0.0" />
</dependencies>
</metadata>
</package>
56 changes: 28 additions & 28 deletions build/manifest-umbraco.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<umbPackage>
<info>
<package>
<name></name>
<version>0.0.0</version>
<license url=""></license>
<url></url>
<requirements type="strict">
<major>0</major>
<minor>0</minor>
<patch>0</patch>
</requirements>
</package>
<author>
<name></name>
<website></website>
</author>
<readme><![CDATA[]]></readme>
</info>
<info>
<package>
<name></name>
<version>0.0.0</version>
<license url=""></license>
<url></url>
<requirements type="strict">
<major>0</major>
<minor>0</minor>
<patch>0</patch>
</requirements>
</package>
<author>
<name></name>
<website></website>
</author>
<readme><![CDATA[]]></readme>
</info>

<DocumentTypes />
<Templates />
<Stylesheets />
<Macros />
<DictionaryItems />
<Languages />
<DataTypes />
<DocumentTypes />
<Templates />
<Stylesheets />
<Macros />
<DictionaryItems />
<Languages />
<DataTypes />

<Actions />
<Actions />

<control />
<control />

<files />
<files />

</umbPackage>
2 changes: 2 additions & 0 deletions src/Umbraco.Community.Contentment.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{5297EC84
ProjectSection(SolutionItems) = preProject
..\build\build-assets.ps1 = ..\build\build-assets.ps1
..\build\build-pkgs.ps1 = ..\build\build-pkgs.ps1
..\build\manifest-nuget.xml = ..\build\manifest-nuget.xml
..\build\manifest-umbraco.xml = ..\build\manifest-umbraco.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHub", "GitHub", "{49BDDD3C-6B40-4BE9-BD7E-10C85E55A59F}"
Expand Down
Binary file removed tools/lib/AdvancedStringBuilder.dll
Binary file not shown.
Binary file removed tools/lib/WebMarkupMin.Core.dll
Binary file not shown.

0 comments on commit 40d5cdd

Please sign in to comment.