Name:gen-deploy
Type:script
Source:gen-deploy-def.psm1
function getTaskDesc([Task]$task) {
[string]$desc = @"
Generate PSEC-v$ deployment files.
"@
return $desc;
}
# ---------- prime the script when initially loaded. As a convenience the brief file is parsed and passed in.
# the existance of this methiod signals this is a context task. The method is called when the
# task is initally loaded.
#
#
function primeContextTask([Task]$task, [hashtable]$brief) {
hlogBoth("Running primeContextTask $($task.name) $($tfs.globMap.devpGlobs.lev1) $($tfs.globMap.devpGlobs.lev2) $($tfs.globMap.devpGlobs.lev3) $($tfs.globMap.devpGlobs.verstr)")
}
# ---------- define task parameters
<#
The $htOpts parms has the processed options. It can be modified or used to do
other changes to the setup.
function params {
param([Object]$task,[hashtable]$htOpts)
$tfs = $task.tfs;
$htOpts.brief = "$($task.statlocn)"
return $htOpts
}
# ---------- define task options
function options {
param([Object]$task)
$opts = @();
$tfs = $task.tfs;
hlogBoth("fetch.options $($tfs.globMap.devpGlobs.verstr)")
$opts += @{type='check'; parm="bWsbZip"; label='Wsb Zip'; place='Create WSB Zip (slow)'}
return ,$opts
}
# ---------- the actual script
function copyAllBut([hashTable]$status,[string]$srcDir,[string]$trgDir,[string]$allButRegex) {
$butRegex = '[.]bak$'
if ("" -ne "$allButRegex") {$butRegex = "$allButRegex"}
hlogBoth("copyAllBut $srcDir TO $targDir except $butRegex");
$status.copied += "copy $srcDir to $trgDir`r";
Get-ChildItem -path "$srcDir" -recurse -file |
where-object {-not ($_.Name -match "$butRegex") } |
foreach-object {
$targName = (asTarg $_.FullName $srcDir $trgDir)
##hlogBoth("copyITEM $($_.FullName) TO $targName");
(Copy-Item -path $_.FullName -Destination $targName -Force);
##[void](out-host -inputObject " copied $targName")
}
}
function asTarg([string]$item,[string]$srcDir,[string]$trgDir) {
$fileName = (& Split-Path -Path $item -leaf)
$srcNode = ""
$srcPath = (& Split-Path -Path $item -parent)
$targDir = $trgDir;
if ($srcPath.length-1 -gt $srcDir.length) {
$srcNode = "$($srcPath.substring($srcDir.length + 1))/"
$targDir = "$trgDir/$($srcNode.substring(0,$srcNode.length - 1))";
}
$targ = "$trgDir/$($srcNode)$fileName"
#hlogBoth(" asTarg $item $fileName $srcDir $trgDir $srcNode $targ");
if (-not(test-path "$targDir")) {
hlogBoth(" createDir $targDir");
$null = (New-Item -ItemType Directory -Force -Path "$targDir")
}
return ,$targ
}
function isStale([string]$src,[string]$targ) {
#hlog("testing $src $targ")
<#
if (test-path $targ) {
$srcItem = get-ChildItem $src
$targItem = get-ChildItem $targ
if ($srcItem.lastWriteTime -gt $targItem.lastWriteTime) {return $true}
return $false;
} else {
return $true;
}
return $true; #always stale
}
function pruneTarget([string]$targ) {
$count = 0;
if (test-path $targ) {
$count = (Get-ChildItem -path "$targ" | Measure-Object).count
}
hilite -yellow "prune target $targ count $count of obsolete files"
if ($count -gt 0) {
$files = [system.object[]](Get-ChildItem -recurse -path "$targ") #force a list even if 1 object
$dirs = @()
forEach($file in $files.getEnumerator()) {
#hlog("$($file.fullName)")
if ($file -is [System.IO.DirectoryInfo]) {
$dirs += $file
} else {
remove-item -path $file.fullName
##hilite -magenta "removed $($file.fullName)";
}
}
# do dirs last in reverse order
if ($dirs.length -gt 0) {
$i = $dirs.length - 1
while($I -ge 0) {
$file = $dirs[$i]
remove-item -path $file.fullName -force
hilite -magenta "removed DIR $($file.fullName)";
$i -= 1
}
}
}
}
function zipSrpUtil([string]$targDir) {
$zipper = "C:\c-pgms\7-Zip\7z.exe"
$zipName = "srp-util-demo.jar";
$savePWD = $pwd
[void](. set-location $targDir)
hlogBoth("zipSrpUtil.2 $targDir $PWD")
$STR = (& "$zipper" a -bb0 -r -tzip $zipName "$($env:PSEC_V4_UTILS)\srp-util\java-gen-prod\production\srp-util\*.*")
hlogBoth($STR)
[void](. set-location "$savePWD")
}
function zipTargDir([string]$targDir,[string]$wsbDir) {
hlogBoth("zipping $targDir")
$zipper = "C:\c-pgms\7-Zip\7z.exe"
$savePWD = $pwd
$zipName = "psec-installer-v4.zip";
$exeName = "psec-installer-v4.exe";
[void](. set-location "$targDir")
if (test-path $zipName) {
remove-item $zipName
}
if (test-path $exeName) {
remove-item $exeName
}
[void](& "$zipper" a -r -tzip $zipName -sdel *.*)
hlogBoth("zipping $zipName created")
[void](& D:\pgms\winzip-self-extract-4.0\wzipse32.exe "$zipName" "@H:\psec-v4\flows\psec-devp\tasks\gen-deploy\installer\winzip-self-extract-options.txt")
$e = (test-path $exeName)
hlogBoth("zipping $exeName created from $zipName $e before")
[void](. Start-Sleep -Seconds 10)
$e = (test-path $exeName)
hlogBoth("zipping $exeName created from $zipName $e after") #suspect delay here because of virus detector
[void](& copyOne $targDir\$exeName $wsbDir\$exeName);
[void](. set-location "$savePWD")
}
function zipWSB([string]$wsbDir) {
hlogBoth("zipping $wsbDir")
$zipper = "C:\c-pgms\7-Zip\7z.exe"
$savePWD = $pwd
$zipName = "psec-v4-wsb-installer.zip";
[void](. set-location "d:\1")
if (test-path $zipName) {
remove-item $zipName
}
[void](& "$zipper" a -r -tzip $zipName "$($wsbDir)\*.*")
hlogBoth("zipping $zipName created in $PWD")
[void](. set-location "$savePWD")
}
function copyOne([string]$src,[string]$dest) { #To syncronize
hlogBoth("CopyOne $src to $dest")
$logStr = (. Copy-Item -path $src -destination $dest -Force -Verbose);
hlogBoth("CopyOne $logStr")
}
# TODO - fix issue when running more than once
function runScript([Task]$task, [hashtable]$parms, [hashtable]$status) {
$tfs = $task.tfs;
$targDir = "$($env:PSEC_V4_DEPLOY_DIR)"
$status.copied = @()
$wsbDir = "c:\psec-sandbox"
if (notExists $parms "bWsbZip") {
if ("$targDir" -eq "") {
$status.sCondCode = "FAIL";
$status.sReason = "PSEC_V4_DEPLOY_DIR env vbl not defined"
} else {
##$null = (& zipSrpUtil $targDir)
$null = (& pruneTarget $targDir)
hlogBoth("Running script $($task.name) $targDir $($task.execLocn)")
$null = (& copyAllBut $status "$($task.execLocn)/installer" "$targDir" $null);
$null = (& copyAllBut $status "$($env:PSEC_V4_EXEC_DIR)/pandoc" "$targDir/psec-bin/pandoc" $null);
$null = (& copyAllBut $status "$($env:PSEC_V4_EXEC_DIR)/res" "$targDir/psec-bin/res" $null);
$null = (& copyAllBut $status "$($env:PSEC_V4_EXEC_DIR)/scr" "$targDir/psec-bin/scr" $null);
$null = (& copyAllBut $status "$($env:PSEC_V4_EXEC_DIR)/src" "$targDir/psec-bin/src" $null);
$null = (& copyAllBut $status "$($env:PSEC_V4_EXEC_DIR)/scr" "$targDir/psec-bin/scr" $null);
$null = (& copyAllBut $status "$($env:PSEC_V4_EXEC_DIR)/temp" "$targDir/psec-bin/temp" '[.](html|md)$');
$null = (& copyAllBut $status "$($env:PSEC_V4_UTILS)/srp-util/lib" "$targDir/psec-bin/java-lib" $null);
$null = (& zipSrpUtil "$targDir/psec-bin/java-lib")
$null = (& copyAllBut $status "$($env:PSEC_V4_FLOWS)/psec-devp/tasks/gen-docs/out-htm" "$targDir/docs" $null);
$null = (& copyAllBut $status "$($env:PSEC_V4_FLOWS)/psec-hello" "$targDir/cust-flow/psec-hello" '(-dyn[.]json)$');
$null = (& copyAllBut $status "$($env:PSEC_V4_FLOWS)/psec-demo" "$targDir/psec-flow/psec-demo" '(-dyn[.]json)$');
$null = (& copyAllBut $status "$($env:PSEC_V4_LIB_DIR)/run-generic-script" "$targDir/psec-lib/run-generic-script" $null);
$null = (& copyAllBut $status "$($env:PSEC_V4_LIB_DIR)/gen-app-icons" "$targDir/psec-lib/gen-app-icons" $null);
}
$null = (& zipTargDir $targDir "$($wsbDir)\sand-install")
} else {
# this takes a long time
$null = (& zipWSB $wsbDir)
}
return "deployed to $targDir";
}
Copyright © 2018-2021, 2022, Rexcel System Inc.