Private/Angular/Setup/Edit-AngularAddBootstrap.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<############################################################################
 # Install npm libraries to support bootstrap
 # Update index.html and styles.css for bootstrap support.
 ############################################################################>

Function Edit-AngularAddBootstrap([WebCsprojInfo]$webCsprojInfo) 
{
    [string] $curDir = Get-Location
    try {
        Set-Location $webCsprojInfo.angularDir
        Write-Host "### Install bootstrap"
        &{npm install --save bootstrap@4.0.0-alpha.6}
        Confirm-LastExitCode

        Write-Host "### Install angular bootstrap"
        &{npm install --save @ng-bootstrap/ng-bootstrap}
        Confirm-LastExitCode
    } finally {
        Set-Location $curDir
    }

    Write-Host "### Add bootstrap to app.module.ts"
    Edit-NgModuleAddImport $webCsprojInfo "NgbModule" "@ng-bootstrap/ng-bootstrap" "NgbModule.forRoot()"

    Write-Host "### Add link to bootstrap css to Angular's styles.css"
    [string]$stylesCssFile = "$($webCsprojInfo.angularDir)/src/styles.css"
    # Check to see if text already exists
    $contents = Get-Content $stylesCssFile
    $containsWord = $contents | %{$_ -match "bootstrap.min.css"}
    If($containsWord -contains $false)
    {
        Add-Content $stylesCssFile "@import '../node_modules/bootstrap/dist/css/bootstrap.min.css';" 
    }

    Write-Host "### Updating index.html for bootstrap support"
    [string]$indexHtmlFileName = "$($webCsprojInfo.angularDir)\src\index.html"
    New-NgIndexHtmlToString "$($solnInfo.nickName)" | Out-FileUtf8NoBom $indexHtmlFileName
}