Private/Angular/Service/New-NgCrudService.ps1
<############################################################################ ############################################################################> Function New-NgCrudServicePrivate([WebCsprojInfo]$webCsprojInfo, $entity, [bool]$create, [bool]$read, [bool]$update, [bool]$delete, [bool]$list, [bool]$filter) { # If all switches unspecified (false), then they are all true # (Syntax explained in http://peterreavy.com/tech/2014/04/30/Map,-reduce-and-filter-in-PowerShell.html) if( -not ( ($create, $read, $update, $delete, $list, $filter) | % { [bool]$tempBool = $false } { $tempBool = $tempBool -or $_ } { $tempBool }) ) { $create = $true $read = $true $update = $true $delete = $true $list = $true $filter = $true } $entityCapital = (ConvertTo-CapitalCamelCase $entity) $entityLowerCamel = (ConvertTo-LowerCamelCase $entity) $entityLowerKebab = (ConvertTo-KebabCase $entity) [string]$verbList = "" if($create -eq $true) { $verbList += '"create",' } if($read -eq $true) { $verbList += '"get",' } if($update -eq $true) { $verbList += '"update",' } if($delete -eq $true) { $verbList += '"delete",' } if($list -eq $true) { $verbList += '"list",' } if($filter -eq $true) { $verbList += '"filter",' } #remove final comma $verbList = $verbList -replace ".$" [string]$result = New-NgCrudServiceTsToString $entity $verbList # Save output to desired folder [string]$angularServiceFileName = "$($webCsprojInfo.angularServiceDir)\$($entityLowerKebab).service.ts" Write-Output "### Create service for $entity to $angularServiceFileName for $verbList" $result | Out-FileUtf8NoBom $angularServiceFileName # Add import to app.module Write-Output "### Add service $($entityCapital)Service to app.module.shared.ts" Edit-NgModuleAddService $webCsprojInfo "$($entityCapital)Service" "./service/$($entityLowerKebab).service" } |