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([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 $packageName library" [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 " Edit-NgModuleAddService $webCsprojInfo $className $importFromFile $classToInsert } } } |