You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
2.9 KiB

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