Ok cool, so this is what I did and it seems to work.
(readers, don't hesitate to let me know what can be done better)
# Run script: Powershell.exe -File build.ps1
# Get arguments
# Ref: https://stackoverflow.com/questions/2157554/how-to-handle-command-line-arguments-in-powershell
# Ref: https://stackoverflow.com/questions/15120597/passing-multiple-values-to-a-single-powershell-script-parameter
# Comparison Operators
# Ref: http://www.tomsitpro.com/articles/powershell-comparison-operators-conditional-logic,2-850.html
param (
# [string]$deploy = "integration",
# [string]$password = $( Read-Host "Input password, please" ),
[Parameter(Mandatory=$true)][string]$action = "none",
[Parameter(Mandatory=$false)][string]$env = ""
)
# Print instructions
function instruction {
Write-Output "<action> <env>"
Write-Output ""
Write-Output "-action, int-test, acceptance-test or deploy"
Write-Output ""
Write-Output "-env, [string]"
}
# Handle inputs
Try {
if ($action -eq "int-test") {
cmd /c 'npm install'
cmd /c 'npm run integration-test'
}
elseif ($action -eq "acceptance-test") {
cmd /c 'npm install'
cmd /c 'npm run acceptance-test'
}
elseif (($action -eq "deploy") -and ($env -eq "")){
cmd /c 'npm install'
$pathToServerless = (Get-Item -Path ".\").FullName + "\node_modules\.bin\serverless.cmd deploy"
cmd /c $pathToServerless
}
elseif (($action -eq "deploy") -and ($env -ne "")){
cmd /c 'npm install'
$pathToServerless = (Get-Item -Path ".\").FullName + "\node_modules\.bin\serverless.cmd deploy -s $env"
cmd /c $pathToServerless
}
else {
instruction
exit
}
} catch {
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Output "Execution failed for $FailedItem. The error message was $ErrorMessage"
Break
}
|