-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetNovaProjectInfoContext.ps1
More file actions
47 lines (39 loc) · 1.88 KB
/
Copy pathGetNovaProjectInfoContext.ps1
File metadata and controls
47 lines (39 loc) · 1.88 KB
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
39
40
41
42
43
44
45
46
47
function Get-NovaProjectInfoContext {
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Path
)
$projectRoot = Resolve-NovaProjectInfoRootPath -Path $Path
$projectJson = [System.IO.Path]::Join($projectRoot, 'project.json')
Assert-NovaProjectJsonPresence -ProjectRoot $projectRoot -ProjectJson $projectJson
return [pscustomobject]@{
ProjectRoot = $projectRoot
ProjectJson = $projectJson
JsonData = Read-ProjectJsonData -ProjectJsonPath $projectJson
}
}
function Resolve-NovaProjectInfoRootPath {
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Path
)
try {
$resolvedPath = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path
} catch {
Stop-NovaOperation -Message "Project path not found: $Path. Run Get-NovaProjectInfo from a Nova project root or pass -Path to an existing project folder." -ErrorId 'Nova.Environment.ProjectPathNotFound' -Category ObjectNotFound -TargetObject $Path
}
if (-not (Test-Path -LiteralPath $resolvedPath -PathType Container)) {
Stop-NovaOperation -Message "Project path must be a folder: $resolvedPath. Pass -Path to the project root that contains project.json." -ErrorId 'Nova.Environment.ProjectPathNotDirectory' -Category InvalidArgument -TargetObject $resolvedPath
}
return $resolvedPath
}
function Assert-NovaProjectJsonPresence {
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$ProjectRoot,
[Parameter(Mandatory)][string]$ProjectJson
)
if (-not (Test-Path -LiteralPath $ProjectJson -PathType Leaf)) {
Stop-NovaOperation -Message "project.json not found in project root: $ProjectRoot. Run Get-NovaProjectInfo from a folder that contains project.json or pass -Path to that folder." -ErrorId 'Nova.Environment.ProjectJsonNotFound' -Category ObjectNotFound -TargetObject $ProjectJson
}
}