Skip to content

Instantly share code, notes, and snippets.

View chriskuech's full-sized avatar

Chris Kuech chriskuech

  • Datum Source, ex MSFT
View GitHub Profile
function Invoke-AfterEach {
Param(
[scriptblock[]]$ScriptBlock,
[scriptblock]$OnTaskComplete
)
$ScriptBlock | % {
Start-Job {
Param($action, $callback)
&$action
&$callback
$modulesDir = $env:PSModulePath -split ":" | Select -First 1
Move-Item .\MyModule $modulesDir
function Assert-ArrayEquality($test, $expected) {
$test | Should -HaveCount $expected.Count
0..($test.Count - 1) | % {$test[$_] | Should -Be $expected[$_]}
}
function Assert-HashtableEquality($test, $expected) {
$test.Keys | Should -HaveCount $expected.Keys.Count
$test.Keys | % {$test[$_] | Should -Be $expected[$_]}
}
function Invoke-WithStorageAccount {
Param(
[ValidateNotNullOrEmpty()]
[scriptblock]$ScriptBlock
)
$name = ("s$(New-Guid)" -replace "-").Substring(24)
$storageAccount = New-AzStorageAccount `
-ResourceGroupName "ephemeral-storages" `
-Name $name`
Invoke-InDirectory $RepoRoot {
Invoke-InContext "Build ReactJS App" {
Invoke-InContext "Validate" {
Invoke-InContext "Lint" { yarn lint }
Invoke-InContext "Test" { yarn test }
}
Invoke-InContext "Transpile" { yarn build:ts }
Invoke-InContext "Bundle" { yarn webpack }
}
Invoke-InContext "Build Container" { docker build . }
# ContextLogger.psm1
$ContextStack = [System.Collections.Stack]::new()
function Invoke-InContext {
Param(
[ValidateNotNullOrEmpty()]
[string] $Name,
[ValidateNotNullOrEmpty()]
[scriptblock] $ScriptBlock
# invoke in repo root
Invoke-InDirectory "$PSScriptRoot/.." {
Invoke-InDirectory "./components" {
npm install
npm build
}
Invoke-InDirectory "./server" {
npm install
npm build
}
function Invoke-InDirectory {
Param(
[ValidateScript( { Test-Path $_ -PathType Container } )]
[string] $Path,
[ValidateNotNullOrEmpty()]
[scriptblock] $ScriptBlock
)
try {
Push-Location $Path
$ErrorActionPreference = "Stop"
Push-Location "./path/I/need/to/be/in"
try {
# do something here
} finally {
Pop-Location
}
# modified from https://github.com/chriskuech/functional
function recursiveEquality($a, $b) {
# recursive step for arrays
if ($a -is [array] -and $b -is [array]) {
if ($a.Count -ne $b.Count) {
return $false
}
$inequalIndexes = 0..($a.Count - 1) | ? { -not (recursiveEquality $a[$_] $b[$_]) }
return $inequalIndexes.Count -eq 0
}