PSEC - Powershell Enhanced Capability
Version 1.2.1

Task Execute for: Generate Deploy Zip

Properties

Implemented Functions

getTaskDesc Function Meta


    function getTaskDesc([Task]$task) {
      [string]$desc        = @"
Generate PSEC-v$ deployment files.
"@
      return $desc;
    }

primeContextTask Function Meta



    # ---------- 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)")
    }

params Function Meta



    # ---------- 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
      }

options Function Meta



      # ---------- 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
      }

copyAllBut func-copyAllBut



      # ---------- 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")
        }
    }

asTarg func-asTarg


    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
    }

isStale func-isStale



    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
    }

pruneTarget func-pruneTarget



    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
          }
        }
      }
    }

zipSrpUtil func-zipSrpUtil



    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")
    }

zipTargDir func-zipTargDir



    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")

    }

zipWSB func-zipWSB



    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")

    }

copyOne func-copyOne



    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")
    }

runScript Function Meta




    # 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";

      }

PSEC - Powershell Enhanced Capability
1.2.1

Copyright © 2018-2021, 2022, Rexcel System Inc.

 

 

 

 

 

X