pre.ps1

$filePath = ({ }.File)
$fileName = $MyInvocation.MyCommand.Name

$srcPath = ( $filePath -replace ($fileName, 'src'))

$filesArr = [System.IO.Directory]::EnumerateFiles($srcPath) 

# *************** enable DEBUG mode to track errors in SRC folder ***************
$global:genFuncDEBUGMode = $false
# disabled DEBUG: faster loading modules, but errors in src files are not tracked,
# since you dot source a script block, not file
# enabled DEBUG: slower loading modules, but error lines corresponds to a file
# *********************************************************************************

$acc =''
$acc += "`n# ***** The file is autogenerated. Do not modify! (Modify src/*.ps1 files instead) *****`n`n"

foreach ($file in $filesArr) {
    if ($file -like "*generatedCommonFuncs*") { continue }
    $acc += [System.IO.File]::ReadAllText($file) 
}


$global:commonFilePath = ($srcPath + '/generatedCommonFuncs.ps1')
$global:sbContent = [scriptblock]::Create($acc)    

if ($genFuncDEBUGMode) {
    Set-Content $global:commonFilePath $acc 
}

function global:commonLib{
    if ($global:genFuncDEBUGMode) {
        return $global:commonFilePath 
    }else{
        return $global:sbContent
    }
}