6
6
<Message Importance =" high" Text =" Building Service Worker Register $(ServiceWorkerRegisterFileName)" Condition =" !Exists('$(WWWRoot)$(ServiceWorkerRegisterFileName)')" />
7
7
<Message Importance =" high" Text =" Re-Building Service Worker Register $(ServiceWorkerRegisterFileName)" Condition =" Exists('$(WWWRoot)$(ServiceWorkerRegisterFileName)')" />
8
8
9
- <!-- Add ServiceWorkerRegister.js to index.html -->
10
- <PropertyGroup Label =" HomePage" >
11
- <IndexFile >$(WWWRoot)$(ServiceWorkerIndexUrl)</IndexFile >
12
- <IndexLines >$([System.IO.File]::ReadAllText($(IndexFile)))</IndexLines >
13
- </PropertyGroup >
14
-
15
- <Message Importance =" high" Text =" Adding $(ServiceWorkerRegisterFileName) to $(IndexFile)"
16
- Condition =" '$(IndexLines.Contains($(ServiceWorkerRegisterFileName)))'=='false'" />
17
- <WriteLinesToFile
18
- File =" $(IndexFile)"
19
- Overwrite =" true"
20
- Lines =" $(IndexLines.Replace('< /head> ',' < script src=" $(ServiceWorkerRegisterFileName)">< /script> %0D%0A< /head> '))"
21
- Condition =" '$(IndexLines.Contains($(ServiceWorkerRegisterFileName)))'=='false'" />
22
-
23
9
<!-- The "Templates" properties are used to define where to find templates for the service worker register -->
24
10
<PropertyGroup Label =" Templates" >
25
11
<!-- The template folder location ** probably never change ** -->
34
20
<ServiceWorkerRegisterInstallableType Condition =" '$(ServiceWorkerRegisterInstallableType)'==''" >installable-banner</ServiceWorkerRegisterInstallableType >
35
21
<!-- The file that contains template code for the service worker "update available" -->
36
22
<ServiceWorkerRegisterInstallableTemplate Condition =" '$(ServiceWorkerRegisterInstallableTemplate)' == ''" >$(ServiceWorkerRegisterTemplatePath)sw_register-$(ServiceWorkerRegisterInstallableType).template.js</ServiceWorkerRegisterInstallableTemplate >
37
- </PropertyGroup >
38
-
39
- <PropertyGroup Label =" Implementation" >
40
23
<!-- event fired by browser when the service worker has installed ** probably never change **-->
41
24
<ServiceWorkerInstalledEvent Condition =" '$(ServiceWorkerInstalledEvent)'==''" >installed</ServiceWorkerInstalledEvent >
42
25
<!-- Text to display when an update is available -->
46
29
const serviceWorkerFileName = '$(ServiceWorkerBaseURL)$(ServiceWorkerFileName)'%3B;
47
30
const swInstalledEvent = '$(ServiceWorkerInstalledEvent)'%3B;
48
31
const staticCachePrefix = '$(ServiceWorkerCacheName)-v'%3B;
49
- const updateAlertMessage = '$(ServiceWorkerUpdateAlertText)'%3B;
32
+ const updateAlertMessage = '$(ServiceWorkerUpdateAlertText)'%3B;
50
33
</ServiceWorkerRegisterConstants >
51
34
</PropertyGroup >
52
35
<ItemGroup >
53
- <ServiceWorkerRegisterTemplateLines Include =" $([System.IO.File]::ReadAllText($(ServiceWorkerRegisterTemplate)))" />
54
- <ServiceWorkerRegisterTemplateLines Include =" $([System.IO.File]::ReadAllText($(ServiceWorkerRegisterUpdateTemplate)))" />
55
- <ServiceWorkerRegisterTemplateLines Include =" $([System.IO.File]::ReadAllText($(ServiceWorkerRegisterInstallableTemplate)))" />
36
+ <!-- Read the Service Worker Register template-->
37
+ <ServiceWorkerRegisterTemplateLines
38
+ Condition =" Exists('$(ServiceWorkerRegisterTemplate)')"
39
+ Include =" $([System.IO.File]::ReadAllText($(ServiceWorkerRegisterTemplate)))" />
40
+ <!-- Read the Service Worker Update template-->
41
+ <ServiceWorkerRegisterTemplateLines
42
+ Condition =" Exists('$(ServiceWorkerRegisterUpdateTemplate)')"
43
+ Include =" $([System.IO.File]::ReadAllText($(ServiceWorkerRegisterUpdateTemplate)))" />
44
+ <!-- Read the Service Worker Installable template-->
45
+ <ServiceWorkerRegisterTemplateLines
46
+ Condition =" Exists('$(ServiceWorkerRegisterInstallableTemplate)')"
47
+ Include =" $([System.IO.File]::ReadAllText($(ServiceWorkerRegisterInstallableTemplate)))" />
56
48
</ItemGroup >
49
+ <!-- (Re)Create the ServiceWorkerRegister.js file -->
57
50
<WriteLinesToFile
51
+ Condition =" '$(ServiceWorkerRegisterConstants)@(ServiceWorkerRegisterTemplateLines)' != ''"
58
52
File =" $(WWWRoot)$(ServiceWorkerRegisterFileName)"
59
53
Overwrite =" true"
60
54
Lines =" $(ServiceWorkerRegisterConstants);@(ServiceWorkerRegisterTemplateLines);"
61
55
/>
56
+ <!-- Call the target for adding the ServiceWorkerRegister.js file to index.html -->
57
+ <CallTarget
58
+ Condition =" Exists('$(WWWRoot)$(ServiceWorkerRegisterFileName)')"
59
+ Targets =" _ServiceWorkerUpdateIndex"
60
+ />
62
61
</Target >
63
62
63
+ <Target Name =" _ServiceWorkerUpdateIndex" >
64
+ <!-- Add ServiceWorkerRegister.js to index.html -->
65
+ <PropertyGroup >
66
+ <IndexFile >$(WWWRoot)$(ServiceWorkerIndexUrl)</IndexFile >
67
+ <IndexLines >$([System.IO.File]::ReadAllText($(IndexFile)))</IndexLines >
68
+ </PropertyGroup >
69
+
70
+ <Message
71
+ Importance =" high"
72
+ Text =" Adding $(ServiceWorkerRegisterFileName) to $(IndexFile)"
73
+ Condition =" '$(IndexLines.Contains($(ServiceWorkerRegisterFileName)))'=='false'"
74
+ />
75
+ <WriteLinesToFile
76
+ File =" $(IndexFile)"
77
+ Overwrite =" true"
78
+ Lines =" $(IndexLines.Replace('< /head> ',' < script src=" $(ServiceWorkerRegisterFileName)">< /script> %0D%0A< /head> '))"
79
+ Condition =" '$(IndexLines.Contains($(ServiceWorkerRegisterFileName)))'=='false'"
80
+ />
81
+
82
+ </Target >
64
83
</Project >
0 commit comments