63 lines
1.5 KiB
PowerShell
63 lines
1.5 KiB
PowerShell
param(
|
|
[switch]$UsePm2,
|
|
[string]$Pm2Name = "lolympus-tournament-support"
|
|
)
|
|
|
|
if (-not $env:NODE_ENV) {
|
|
$env:NODE_ENV = "dev"
|
|
}
|
|
|
|
$MainScript = Join-Path $PSScriptRoot "dist/main.js"
|
|
|
|
if ($isMacOS -or $isLinux) {
|
|
$env:MachineEnvFile = "$env:HOME/source/global-env-vars.txt"
|
|
} elseif ($isWindows) {
|
|
$env:MachineEnvFile = "$env:USERPROFILE/source/global-env-vars.txt"
|
|
}
|
|
|
|
function Set-EnvFromFile {
|
|
param([string]$Path)
|
|
|
|
if (-not (Test-Path $Path)) {
|
|
throw "File not found: $Path"
|
|
}
|
|
|
|
foreach ($line in Get-Content $Path) {
|
|
if ([string]::IsNullOrWhiteSpace($line)) { continue }
|
|
if ($line -match '^\s*#') { continue }
|
|
|
|
if ($line -match '^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$') {
|
|
$key = $matches[1]
|
|
$value = $matches[2].Trim()
|
|
|
|
if (
|
|
($value.StartsWith('"') -and $value.EndsWith('"')) -or
|
|
($value.StartsWith("'") -and $value.EndsWith("'"))
|
|
) {
|
|
$value = $value.Substring(1, $value.Length - 2)
|
|
}
|
|
|
|
[System.Environment]::SetEnvironmentVariable($key, $value)
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Test-Path $env:MachineEnvFile) {
|
|
Set-EnvFromFile $env:MachineEnvFile
|
|
}
|
|
|
|
if (-not $env:INFISICAL_CLIENT_ID) {
|
|
Write-Error "INFISICAL_CLIENT_ID is not set."
|
|
exit 1
|
|
}
|
|
|
|
if (-not $env:INFISICAL_CLIENT_SECRET) {
|
|
Write-Error "INFISICAL_CLIENT_SECRET is not set."
|
|
exit 1
|
|
}
|
|
|
|
if ($UsePm2) {
|
|
pm2 start $MainScript --name $Pm2Name --update-env
|
|
} else {
|
|
node $MainScript
|
|
} |