Skip to content

Commit 57b83e8

Browse files
committed
Add targets to package to download govuk-frontend NPM package
1 parent 125adb9 commit 57b83e8

File tree

6 files changed

+158
-8
lines changed

6 files changed

+158
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,5 @@ ASALocalRun/
333333
lib
334334

335335
.DS_Store
336+
337+
src/GovUk.Frontend.AspNetCore/govuk-frontend-version.txt
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<RestoreGovUkFrontendNpmPackage Condition="'$(RestoreGovUkFrontendNpmPackage)' == ''">false</RestoreGovUkFrontendNpmPackage>
5+
<GovUkFrontendNpmPackageLocation Condition="'$(GovUkFrontendNpmPackageLocation)' == ''">govuk-frontend</GovUkFrontendNpmPackageLocation>
6+
<CopyGovUkFrontendAssetsToWebRoot Condition="'$(CopyGovUkFrontendAssetsToWebRoot)' == ''">true</CopyGovUkFrontendAssetsToWebRoot>
7+
</PropertyGroup>
8+
</Project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<BuildDependsOn>
5+
RestoreGovUkFrontendNpmPackage;
6+
$(BuildDependsOn)
7+
</BuildDependsOn>
8+
9+
<CopyAllFilesToSingleFolderForPackageDependsOn>
10+
RestoreGovUkFrontendNpmPackage;
11+
$(CopyAllFilesToSingleFolderForPackageDependsOn)
12+
</CopyAllFilesToSingleFolderForPackageDependsOn>
13+
14+
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
15+
RestoreGovUkFrontendNpmPackage;
16+
$(CopyAllFilesToSingleFolderForMsdeployDependsOn)
17+
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
18+
19+
<CopyFilesToOutputDirectory>
20+
RestoreGovUkFrontendNpmPackage;
21+
$(CopyFilesToOutputDirectory)
22+
</CopyFilesToOutputDirectory>
23+
</PropertyGroup>
24+
25+
<UsingTask
26+
TaskName="GovUk.Frontend.AspNetCore.Build.DownloadNpmPackage"
27+
AssemblyFile="$(MSBuildThisFileDirectory)..\tools\net8.0\any\GovUk.Frontend.AspNetCore.Build.dll" />
28+
29+
<Target Name="RestoreGovUkFrontendNpmPackage" Condition="'$(RestoreGovUkFrontendNpmPackage)' == 'true'">
30+
<GetGovUkFrontendVersion DllPath="$(MSBuildThisFileDirectory)..\lib\net8.0\GovUk.Frontend.AspNetCore.dll">
31+
<Output TaskParameter="Version" PropertyName="GovUkFrontendVersion" />
32+
</GetGovUkFrontendVersion>
33+
34+
<GovUk.Frontend.AspNetCore.Build.DownloadNpmPackage
35+
Package="govuk-frontend"
36+
Version="$(GovUkFrontendVersion)xx"
37+
PackageBaseDirectory="/dist/govuk"
38+
DestinationDirectory="$(GovUkFrontendNpmPackageLocation)" />
39+
40+
<ItemGroup>
41+
<_AssetFiles Include="$(GovUkFrontendNpmPackageLocation)/assets/**/*" />
42+
</ItemGroup>
43+
44+
<Copy
45+
SourceFiles="@(_AssetFiles)"
46+
DestinationFolder="wwwroot\assets\%(RecursiveDir)"
47+
SkipUnchangedFiles="true"
48+
Condition="'$(CopyGovUkFrontendAssetsToWebRoot)' == 'true'" />
49+
50+
<ItemGroup>
51+
<Content Remove="$(GovUkFrontendNpmPackageLocation)\**\*" />
52+
<None Include="$(GovUkFrontendNpmPackageLocation)\**\*" />
53+
</ItemGroup>
54+
</Target>
55+
</Project>

src/GovUk.Frontend.AspNetCore/GovUk.Frontend.AspNetCore.csproj

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Razor" InitialTargets="InstallGovUkFrontendPackage">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor" InitialTargets="InstallGovUkFrontendPackage;WriteGovUkFrontendVersionFile">
22

33
<PropertyGroup>
44
<TargetFrameworks>net8.0</TargetFrameworks>
@@ -26,7 +26,8 @@
2626
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2727
</PropertyGroup>
2828

29-
<UsingTask TaskName="GovUk.Frontend.AspNetCore.Build.DownloadNpmPackage"
29+
<UsingTask
30+
TaskName="GovUk.Frontend.AspNetCore.Build.DownloadNpmPackage"
3031
AssemblyFile="../GovUk.Frontend.AspNetCore.Build/bin/net8.0/GovUk.Frontend.AspNetCore.Build.dll" />
3132

3233
<Target Name="InstallGovUkFrontendPackage" Condition="!Exists('$(GovUkFrontendLibrary)')">
@@ -35,18 +36,30 @@
3536
<GovUk.Frontend.AspNetCore.Build.DownloadNpmPackage
3637
Package="govuk-frontend"
3738
Version="$(GovUkFrontendVersion)"
38-
PackageBaseDirectory="/dist/govuk"
39+
PackageBaseDirectory="dist\govuk"
3940
DestinationDirectory="$(GovUkFrontendLibrary)" />
4041
</Target>
4142

43+
<Target Name="WriteGovUkFrontendVersionFile">
44+
<ItemGroup>
45+
<_VersionFileLines Include="$(GovUkFrontendVersion)" />
46+
</ItemGroup>
47+
48+
<WriteLinesToFile File="govuk-frontend-version.txt" Lines="@(_VersionFileLines)" Overwrite="true" />
49+
50+
<ItemGroup>
51+
<Content Include="govuk-frontend-version.txt" Pack="true" PackagePath="\" />
52+
</ItemGroup>
53+
</Target>
54+
4255
<Target Name="CopyXmlDocToDocsProject" AfterTargets="Build">
4356
<ItemGroup>
4457
<_XmlDocFile Include="$(OutputPath)GovUk.Frontend.AspNetCore.xml" />
4558
</ItemGroup>
4659

4760
<Copy
4861
SourceFiles="@(_XmlDocFile)"
49-
DestinationFolder="$(RepoRoot)/src/GovUk.Frontend.AspNetCore.Docs"
62+
DestinationFolder="$(RepoRoot)\src\GovUk.Frontend.AspNetCore.Docs"
5063
Condition="Exists('%(_XmlDocFile.Identity)')"/>
5164
</Target>
5265

@@ -91,12 +104,12 @@
91104
</_CompiledAssets>
92105

93106
<EmbeddedResource Include="$(GovUkFrontendLibrary)assets\**\*">
94-
<Link>Content/Assets/%(RecursiveDir)%(Filename)%(Extension)</Link>
95-
<LogicalName>Content/Assets/%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
107+
<Link>Content\Assets\%(RecursiveDir)%(Filename)%(Extension)</Link>
108+
<LogicalName>Content\Assets\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
96109
</EmbeddedResource>
97110
<EmbeddedResource Include="@(_CompiledAssets)">
98-
<Link>Content/Compiled/%(LinkedName)</Link>
99-
<LogicalName>Content/Compiled/%(LinkedName)</LogicalName>
111+
<Link>Content\Compiled\%(LinkedName)</Link>
112+
<LogicalName>Content\Compiled\%(LinkedName)</LogicalName>
100113
</EmbeddedResource>
101114
</ItemGroup>
102115

@@ -109,4 +122,9 @@
109122
<None Include="icon.png" Pack="true" PackagePath="\" />
110123
</ItemGroup>
111124

125+
<ItemGroup>
126+
<Content Include="GovUk.Frontend.AspNetCore.props" Pack="true" PackFolder="build" />
127+
<Content Include="GovUk.Frontend.AspNetCore.targets" Pack="true" PackFolder="build" />
128+
</ItemGroup>
129+
112130
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<RestoreGovUkFrontendNpmPackage Condition="'$(RestoreGovUkFrontendNpmPackage)' == ''">false</RestoreGovUkFrontendNpmPackage>
5+
<GovUkFrontendNpmPackageLocation Condition="'$(GovUkFrontendNpmPackageLocation)' == ''">govuk-frontend</GovUkFrontendNpmPackageLocation>
6+
<CopyGovUkFrontendAssetsToWebRoot Condition="'$(CopyGovUkFrontendAssetsToWebRoot)' == ''">true</CopyGovUkFrontendAssetsToWebRoot>
7+
</PropertyGroup>
8+
</Project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<BuildDependsOn>
5+
RestoreGovUkFrontendNpmPackage;
6+
$(BuildDependsOn)
7+
</BuildDependsOn>
8+
9+
<CopyAllFilesToSingleFolderForPackageDependsOn>
10+
RestoreGovUkFrontendNpmPackage;
11+
$(CopyAllFilesToSingleFolderForPackageDependsOn)
12+
</CopyAllFilesToSingleFolderForPackageDependsOn>
13+
14+
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
15+
RestoreGovUkFrontendNpmPackage;
16+
$(CopyAllFilesToSingleFolderForMsdeployDependsOn)
17+
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
18+
19+
<CopyFilesToOutputDirectory>
20+
RestoreGovUkFrontendNpmPackage;
21+
$(CopyFilesToOutputDirectory)
22+
</CopyFilesToOutputDirectory>
23+
</PropertyGroup>
24+
25+
<UsingTask
26+
TaskName="GovUk.Frontend.AspNetCore.Build.DownloadNpmPackage"
27+
AssemblyFile="$(MSBuildThisFileDirectory)..\tools\net8.0\any\GovUk.Frontend.AspNetCore.Build.dll" />
28+
29+
<Target Name="RestoreGovUkFrontendNpmPackage" Condition="'$(RestoreGovUkFrontendNpmPackage)' == 'true'">
30+
<ReadLinesFromFile File="$(MSBuildThisFileDirectory)..\govuk-frontend-version.txt">
31+
<Output TaskParameter="Lines" ItemName="_GovUkFrontendVersionFileLines" />
32+
</ReadLinesFromFile>
33+
34+
<PropertyGroup>
35+
<GovUkFrontendVersion>@(_GovUkFrontendVersionFileLines)</GovUkFrontendVersion>
36+
</PropertyGroup>
37+
38+
<GovUk.Frontend.AspNetCore.Build.DownloadNpmPackage
39+
Package="govuk-frontend"
40+
Version="$(GovUkFrontendVersion)"
41+
PackageBaseDirectory="/dist/govuk"
42+
DestinationDirectory="$(GovUkFrontendNpmPackageLocation)" />
43+
44+
<ItemGroup>
45+
<_AssetFiles Include="$(GovUkFrontendNpmPackageLocation)\assets\**\*" />
46+
</ItemGroup>
47+
48+
<Copy
49+
SourceFiles="@(_AssetFiles)"
50+
DestinationFolder="wwwroot\assets\%(RecursiveDir)"
51+
SkipUnchangedFiles="true"
52+
Condition="'$(CopyGovUkFrontendAssetsToWebRoot)' == 'true'" />
53+
54+
<ItemGroup>
55+
<Content Remove="$(GovUkFrontendNpmPackageLocation)\**\*" />
56+
<None Include="$(GovUkFrontendNpmPackageLocation)\**\*" />
57+
</ItemGroup>
58+
</Target>
59+
</Project>

0 commit comments

Comments
 (0)