Skip to content

Commit

Permalink
Add Utilities.psm1
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkyjac committed Oct 18, 2024
1 parent e9a3aa6 commit ee1786e
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
- "**.targets"
- "**.sln"
- "**/Client/**/*.json"
# Added to check if pipeline is working
- "/scripts/**/*.psm1"
- "/scripts/**/*.ps1"
- "**/ci.yml"
pull_request:
branches: [main]
paths:
Expand Down
139 changes: 139 additions & 0 deletions scripts/Utilities/Utilities.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Utilities

$scriptConfig = @{}
$scriptConfig.WorkspaceFolder = ".."
$scriptConfig.SolutionFileName = "Kentico.Xperience.Shopify.sln"
$scriptConfig.AssemblyName = "DancingGoat"

<#
.DESCRIPTION
Returns shared configuration for PowerShell scripts
#>
function Get-ScriptConfig {
return $scriptConfig
}

<#
.DESCRIPTION
Returns the main solution file path
#>
function Get-SolutionPath {
return Resolve-Path(Join-Path $($scriptConfig.WorkspaceFolder) $($scriptConfig.SolutionFileName))
}

<#
.DESCRIPTION
Returns the web application folder path from the workspace root
#>
function Get-WebProjectPath {
return Resolve-Path(Join-Path $($scriptConfig.WorkspaceFolder) "examples/DancingGoat-Shopify")
}

<#
.DESCRIPTION
Returns the admin application folder path from the workspace root
#>
<#function Get-AdminProjectPath {
return Resolve-Path(Join-Path $($scriptConfig.WorkspaceFolder) "src/Kentico.Community.Portal.Admin")
}#>

<#
.DESCRIPTION
Returns the admin client application folder path from the workspace root
#>
<#function Get-AdminClientProjectPath {
return Resolve-Path(Join-Path $($scriptConfig.WorkspaceFolder) "src/Kentico.Community.Portal.Admin/Client")
}#>

<#
.DESCRIPTION
Returns the Core project folder path from the workspace root
#>
<#function Get-CoreProjectPath {
return Resolve-Path(Join-Path $($scriptConfig.WorkspaceFolder) "src/Kentico.Community.Portal.Core")
}#>


<#
.DESCRIPTION
Gets the database connection string from the user secrets or appsettings.json file
#>
<#function Get-ConnectionString {
$projectPath = Get-WebProjectPath
# Try to get the connection string from user secrets first
Write-Host "Checking for a connection string user secrets for project: $projectPath"
$connectionString = dotnet user-secrets list --project $projectPath `
| Select-String -Pattern "ConnectionStrings:" `
| ForEach-Object { $_.Line -replace '^ConnectionStrings:CMSConnectionString \= ', '' }
if (-not [string]::IsNullOrEmpty($connectionString)) {
Write-Host 'Using ConnectionString from user-secrets'
return $connectionString
}
$appSettingFileName = $Env:ASPNETCORE_ENVIRONMENT -eq "CI" ? 'appsettings.CI.json' : 'appsettings.json'
$jsonFilePath = Join-Path $projectPath $appSettingFileName
Write-Host "Using settings from $jsonFilePath"
if (!(Test-Path $jsonFilePath)) {
throw "Could not find file $jsonFilePath"
}
$appSettingsJson = Get-Content $jsonFilePath | Out-String | ConvertFrom-Json
$connectionString = $appSettingsJson.ConnectionStrings.CMSConnectionString;
if (!$connectionString) {
throw "Connection string not found in $jsonFilePath"
}
return $connectionString;
}#>

<#
.DESCRIPTION
Ensures the expression successfully exits and throws an exception
with the failed expression if it does not.
#>
function Invoke-ExpressionWithException {
param(
[string]$expression
)

Write-Host "$expression"

Invoke-Expression -Command $expression

if ($LASTEXITCODE -ne 0) {
$errorMessage = "[ $expression ] failed`n`n"

throw $errorMessage
}
}
function Write-Status {
param(
[string]$message
)

Write-Host $message -ForegroundColor Blue
}

function Write-Notification {
param(
[string]$message
)

Write-Host $message -ForegroundColor Magenta
}

function Write-Error {
param(
[string]$message
)

Write-Host $message -ForegroundColor Red
}

0 comments on commit ee1786e

Please sign in to comment.