Private/Angular/Setup/Install-NodeModule.ps1
<############################################################################ # Run npm install if package not already present in package.json, # and import statement add to app.module.ts ############################################################################> Function Install-NodeModule([WebCsprojInfo]$webCsprojInfo, [string]$packageName, [string]$className = "", [string]$importFromFile = "", [string]$classToInsert = "") { [string]$packageJsonFile = "$($webCsprojInfo.angularDir)\package.json" [string]$packageJsonContents = Get-Content -raw $packageJsonFile if($packageJsonContents -like "*`"$($packageName)`"*") { # Already installed, do nothing } else { Write-Host "### Add npm library: $packageName" [string] $curDir = Get-Location try { Set-Location $webCsprojInfo.angularDir &{npm install --save $($packageName)} # Special case, sometimes this fails, try again, don't know why if($LastExitCode -ne 0) { &{npm install} } } finally { Set-Location $curDir } Confirm-LastExitCode if($className -ne "") { Write-Host "### Add angular include for $packageName !!!!!!!!!!!!!!!!!!!!!!! $webCsprojInfo $className $importFromFile $classToInsert" Edit-NgModuleAddImport $webCsprojInfo $className $importFromFile $classToInsert } } } |