Skip to content

Commit

Permalink
Merge pull request #9 from SQL-MisterMagoo/chucker-master
Browse files Browse the repository at this point in the history
Chucker master - local branch for PR #5
  • Loading branch information
SQL-MisterMagoo authored Dec 6, 2019
2 parents 0757890 + c092c2b commit 16f4ada
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Blazor.PWA.MSBuild.Tasks/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>1.0.1</VersionPrefix>
<VersionPrefix>1.0.2</VersionPrefix>
<VersionSuffix>beta$([System.DateTime]::Now.ToString("yyyyMMdd-HHmmss"))</VersionSuffix>
<VersionSuffix Condition="'$(Configuration)' == 'Release'"></VersionSuffix>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

<!-- Base URL for the app -->
<ManifestBaseUrl Condition="'$(ManifestBaseUrl)' == ''">/</ManifestBaseUrl>
<ManifestBaseUrl Condition="!'$(ManifestBaseUrl.StartsWith(/))'">/$(ManifestBaseUrl)</ManifestBaseUrl>
<ManifestBaseUrl Condition="!'$(ManifestBaseUrl.EndsWith(/))'">$(ManifestBaseUrl)/</ManifestBaseUrl>

<!-- Please see https://developers.google.com/web/fundamentals/web-app-manifest/#display for options -->
<ManifestDisplay Condition="'$(ManifestDisplay)' == ''">standalone</ManifestDisplay>
Expand Down Expand Up @@ -82,7 +84,7 @@
<WriteLinesToFile
File="$(IndexFile)"
Overwrite="true"
Lines="$(IndexLines.Replace('&lt;/head&gt;',' &lt;link href=&quot;/$(ManifestFileName)&quot; rel=&quot;manifest&quot;/&gt;%0D%0A&lt;/head&gt;'))"
Lines="$(IndexLines.Replace('&lt;/head&gt;',' &lt;link href=&quot;$(ManifestBaseUrl)$(ManifestFileName)&quot; rel=&quot;manifest&quot;/&gt;%0D%0A&lt;/head&gt;'))"
Condition="'$(IndexLines.Contains(rel=&quot;manifest&quot;))'=='false'"/>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<!-- Setup the declarations for the Service Worker -->
<ServiceWorkerConstants Condition="'$(ServiceWorkerConstants)' == '' AND '$(BlazorProjectType)' == 'CSB'">
const baseURL = '$(ServiceWorkerBaseURL)'%3B;
const baseURL = '$(ServiceWorkerBaseUrl)'%3B;
const indexURL = '$(ServiceWorkerBaseUrl)$(ProjectIndexPage)'%3B;
const networkFetchEvent = '$(ServiceWorkerNetworkFetchEvent)'%3B;
const swInstallEvent = '$(ServiceWorkerInstallEvent)'%3B;
Expand All @@ -61,7 +61,7 @@

<!-- Setup the declarations for the Service Worker -->
<ServiceWorkerConstants Condition="'$(ServiceWorkerConstants)' == '' AND '$(BlazorProjectType)' == 'SSB'">
const baseURL = '$(ServiceWorkerBaseURL)'%3B;
const baseURL = '$(ServiceWorkerBaseUrl)'%3B;
const indexURL = '$(ServiceWorkerBaseUrl)$(ProjectHomePage)'%3B;
const networkFetchEvent = '$(ServiceWorkerNetworkFetchEvent)'%3B;
const swInstallEvent = '$(ServiceWorkerInstallEvent)'%3B;
Expand Down Expand Up @@ -105,7 +105,7 @@
<WriteLinesToFile Condition="'$(BlazorProjectType)' == 'CSB'"
File="$(WWWRoot)$(ServiceWorkerFileName)"
Overwrite="false"
Lines="const requiredFiles = [;@(DistFiles -> '&quot;/%(RecursiveDir)%(FileName)%(Extension)&quot;'->Replace('\','/'),',%0D%0A');]%3B;" />
Lines="const requiredFiles = [;@(DistFiles -> '&quot;$(ServiceWorkerBaseUrl)%(RecursiveDir)%(FileName)%(Extension)&quot;'->Replace('\','/'),',%0D%0A');]%3B;" />
<WriteLinesToFile Condition="'$(BlazorProjectType)' == 'CSB'"
File="$(WWWRoot)$(ServiceWorkerFileName)"
Overwrite="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<ServiceWorkerBlazorInstallMethod Condition="'$(ServiceWorkerBlazorInstallMethod)'==''">PWAInstallable</ServiceWorkerBlazorInstallMethod>
<!-- Setup the declarations for the Service Worker Register -->
<ServiceWorkerRegisterConstants Condition="'$(ServiceWorkerRegisterConstants)' == ''">
const serviceWorkerFileName = '$(ServiceWorkerBaseURL)$(ServiceWorkerFileName)'%3B;
const serviceWorkerFileName = '$(ServiceWorkerBaseUrl)$(ServiceWorkerFileName)'%3B;
const swInstalledEvent = '$(ServiceWorkerInstalledEvent)'%3B;
const staticCachePrefix = '$(ServiceWorkerCacheName)-v'%3B;
const updateAlertMessage = '$(ServiceWorkerUpdateAlertText)'%3B;
Expand Down Expand Up @@ -110,7 +110,7 @@
<WriteLinesToFile
File="$(IndexFile)"
Overwrite="true"
Lines="$(IndexLines.Replace('&lt;/head&gt;',' &lt;script src=&quot;$(ServiceWorkerRegisterFileName)&quot;&gt;&lt;/script&gt;%0D%0A&lt;/head&gt;'))"
Lines="$(IndexLines.Replace('&lt;/head&gt;',' &lt;script src=&quot;$(ServiceWorkerBaseUrl)$(ServiceWorkerRegisterFileName)&quot;&gt;&lt;/script&gt;%0D%0A&lt;/head&gt;'))"
Condition="'$(IndexLines.Contains($(ServiceWorkerRegisterFileName)))'=='false'"
/>

Expand Down
2 changes: 2 additions & 0 deletions Blazor.PWA.MSBuild.Tasks/build/BlazorPWA.MSBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

<!-- The "home route" url for the application -->
<ServiceWorkerBaseUrl Condition="'$(ServiceWorkerBaseUrl)' == ''">/</ServiceWorkerBaseUrl>
<ServiceWorkerBaseUrl Condition="!'$(ServiceWorkerBaseUrl.StartsWith(/))'">/$(ServiceWorkerBaseUrl)</ServiceWorkerBaseUrl>
<ServiceWorkerBaseUrl Condition="!'$(ServiceWorkerBaseUrl.EndsWith(/))'">$(ServiceWorkerBaseUrl)/</ServiceWorkerBaseUrl>

<!-- The CSB home page served up for the base URL -->
<ProjectIndexPage Condition="'$(ProjectIndexPage)' == ''">index.html</ProjectIndexPage>
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#### 06/12/2019

- PR #5 from @chucker merged with these changes
- Bug: **Property** **`ManifestBaseUrl`** - used to specify the base Url in the manifest.json was not being used in the index `<head>` link for **manifest.json**
- Bug: **Property** **`ServiceWorkerBaseUrl`** - used to specify the base Url in the ServiceWorker was not being used in the _required files_ list.
- Bug: **Property** **`ServiceWorkerBaseUrl`** - used to specify the base Url in the ServiceWorker was not being used in the index `<head>` link for **ServiceWorker.js**
- Also @SQL-MisterMagoo
- Added code to automatically add leading and trailing slashes to **Property** **`ManifestBaseUrl`**
- Added code to automatically add leading and trailing slashes to **Property** **`ServiceWorkerBaseUrl`**

#### 11/11/2019

- Added new **Property** **`ServiceWorkerIgnoreHosts`** - used to prevent service worker installation on specific hosts e.g. localhost
Expand Down
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ I don't have a Mac, but I believe Safari does not prompt on desktop either.
Install the nuget BlazorPWA.MsBuild

#### Package Manager:
`Install-Package BlazorPWA.MSBuild -Version 1.0.1`
`Install-Package BlazorPWA.MSBuild -Version 1.0.2`

#### .NET Cli:
`dotnet add package BlazorPWA.MSBuild --version 1.0.1`
`dotnet add package BlazorPWA.MSBuild --version 1.0.2`

#### Package Reference
`<PackageReference Include="BlazorPWA.MSBuild" Version="1.0.1"/>`
`<PackageReference Include="BlazorPWA.MSBuild" Version="1.0.2"/>`

## Configuration

Expand Down Expand Up @@ -171,6 +171,40 @@ The service worker will not register itself when the `hostname` matches anything

*Note: the single quotes around each hostname are required for now*

### Handle different base Urls for different configurations

Sample csproj file for two different base Urls

``` XML
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ManifestForce>true</ManifestForce>
<ServiceWorkerForce>true</ServiceWorkerForce>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<ServiceWorkerBaseUrl>prod</ServiceWorkerBaseUrl>
<ManifestBaseUrl>prod</ManifestBaseUrl>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<ServiceWorkerBaseUrl>dev</ServiceWorkerBaseUrl>
<ManifestBaseUrl>dev</ManifestBaseUrl>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BlazorPWA.MSBuild" Version="1.0.1-beta20191206-002218">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
```
This project file use **`ManifestForce`** and **`ServiceWorkerForce`** to ensure that the **manifest.json** and **ServiceWorker.js** files are rebuilt - otherwise they would not change when you changed configuration.

## Roadmap

- [ ] At the moment, there is only one choice for caching strategy - Cache First/Network Fallback - I will add more (https://developers.google.com/web/ilt/pwa/introduction-to-progressive-web-app-architectures#caching_strategies_supported_by_sw-toolbox)
Expand Down

0 comments on commit 16f4ada

Please sign in to comment.