1 | function AddOrUpdate-Reference($scriptsFolderProjectItem, $fileNamePattern, $newFileName) {
|
---|
2 | try {
|
---|
3 | $referencesFileProjectItem = $scriptsFolderProjectItem.ProjectItems.Item("_references.js")
|
---|
4 | }
|
---|
5 | catch {
|
---|
6 | # _references.js file not found
|
---|
7 | return
|
---|
8 | }
|
---|
9 |
|
---|
10 | if ($referencesFileProjectItem -eq $null) {
|
---|
11 | # _references.js file not found
|
---|
12 | return
|
---|
13 | }
|
---|
14 |
|
---|
15 | $referencesFilePath = $referencesFileProjectItem.FileNames(1)
|
---|
16 | $referencesTempFilePath = Join-Path $env:TEMP "_references.tmp.js"
|
---|
17 |
|
---|
18 | if ((Select-String $referencesFilePath -pattern $fileNamePattern).Length -eq 0) {
|
---|
19 | # File has no existing matching reference line
|
---|
20 | # Add the full reference line to the beginning of the file
|
---|
21 | "/// <reference path=""$newFileName"" />" | Add-Content $referencesTempFilePath -Encoding UTF8
|
---|
22 | Get-Content $referencesFilePath | Add-Content $referencesTempFilePath
|
---|
23 | }
|
---|
24 | else {
|
---|
25 | # Loop through file and replace old file name with new file name
|
---|
26 | Get-Content $referencesFilePath | ForEach-Object { $_ -replace $fileNamePattern, $newFileName } > $referencesTempFilePath
|
---|
27 | }
|
---|
28 |
|
---|
29 | # Copy over the new _references.js file
|
---|
30 | Copy-Item $referencesTempFilePath $referencesFilePath -Force
|
---|
31 | Remove-Item $referencesTempFilePath -Force
|
---|
32 | }
|
---|
33 |
|
---|
34 | function Remove-Reference($scriptsFolderProjectItem, $fileNamePattern) {
|
---|
35 | try {
|
---|
36 | $referencesFileProjectItem = $scriptsFolderProjectItem.ProjectItems.Item("_references.js")
|
---|
37 | }
|
---|
38 | catch {
|
---|
39 | # _references.js file not found
|
---|
40 | return
|
---|
41 | }
|
---|
42 |
|
---|
43 | if ($referencesFileProjectItem -eq $null) {
|
---|
44 | return
|
---|
45 | }
|
---|
46 |
|
---|
47 | $referencesFilePath = $referencesFileProjectItem.FileNames(1)
|
---|
48 | $referencesTempFilePath = Join-Path $env:TEMP "_references.tmp.js"
|
---|
49 |
|
---|
50 | if ((Select-String $referencesFilePath -pattern $fileNamePattern).Length -eq 1) {
|
---|
51 | # Delete the line referencing the file
|
---|
52 | Get-Content $referencesFilePath | ForEach-Object { if (-not ($_ -match $fileNamePattern)) { $_ } } > $referencesTempFilePath
|
---|
53 |
|
---|
54 | # Copy over the new _references.js file
|
---|
55 | Copy-Item $referencesTempFilePath $referencesFilePath -Force
|
---|
56 | Remove-Item $referencesTempFilePath -Force
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | # Extract the version number from the file in the package's content\scripts folder
|
---|
61 | $packageScriptsFolder = Join-Path $installPath Content\Scripts
|
---|
62 | $modernizrFileName = Join-Path $packageScriptsFolder "modernizr-*.js" | Get-ChildItem -Exclude "*.min.js","*-vsdoc.js" | Split-Path -Leaf
|
---|
63 | $modernizrFileNameRegEx = "modernizr-((?:\d+\.)?(?:\d+\.)?(?:\d+\.)?(?:\d+)).js"
|
---|
64 | $modernizrFileName -match $modernizrFileNameRegEx
|
---|
65 | $ver = $matches[1]
|
---|
66 |
|
---|
67 | # Get the project item for the scripts folder
|
---|
68 | try {
|
---|
69 | $scriptsFolderProjectItem = $project.ProjectItems.Item("Scripts")
|
---|
70 | $projectScriptsFolderPath = $scriptsFolderProjectItem.FileNames(1)
|
---|
71 | }
|
---|
72 | catch {
|
---|
73 | # No Scripts folder
|
---|
74 | Write-Host "No scripts folder found"
|
---|
75 | } |
---|