Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/packages/Modernizr.2.6.2/Tools/common.ps1 @ 9793

Last change on this file since 9793 was 9604, checked in by pfleck, 11 years ago

#2063:
Set up basic webpage layout based on WebApplication branch.
Added Asp.Net MVC packages and some helper packages.
Implemented login.

File size: 2.9 KB
RevLine 
[9604]1function 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
34function 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
68try {
69    $scriptsFolderProjectItem = $project.ProjectItems.Item("Scripts")
70    $projectScriptsFolderPath = $scriptsFolderProjectItem.FileNames(1)
71}
72catch {
73    # No Scripts folder
74    Write-Host "No scripts folder found"
75}
Note: See TracBrowser for help on using the repository browser.