4
4
[string ]$SourceDir = " src"
5
5
)
6
6
7
+ # Start the main timer
8
+ $mainTimer = [System.Diagnostics.Stopwatch ]::StartNew()
9
+ $stepTimer = [System.Diagnostics.Stopwatch ]::StartNew()
10
+
7
11
# Import utility functions
8
12
$scriptPath = Split-Path - Parent $MyInvocation.MyCommand.Path
9
13
. " $scriptPath /scripts/utils/Minimize.ps1" # To get better screenshots we need to minimize the "Administrator" CMD window
10
14
. " $scriptPath /scripts/utils/TimedMessage.ps1"
11
15
. " $scriptPath /scripts/utils/Invoke.ps1" # Function to invoke a script with a timeout
12
16
. " $scriptPath /scripts/utils/Screenshot.ps1"
17
+ . " $scriptPath /scripts/utils/Path.ps1"
13
18
14
- # Start the main timer
15
- $mainTimer = [System.Diagnostics.Stopwatch ]::StartNew()
16
- $stepTimer = [System.Diagnostics.Stopwatch ]::StartNew()
17
19
18
20
Write-TimedMessage " Current directory: $ ( pwd) " - StartNewStep
19
- Write-Host " Using source directory: $SourceDir "
20
- $SourceDir = Normalize- Path $SourceDir
21
- Write-TimedMessage " Normalized source directory: $SourceDir "
21
+ $srcDir = NormalizeDirPath $SourceDir
22
+ Write-Host " Using source directory: $srcDir "
23
+ $srcDir = GetAbsPath - path $srcDir - basePath (GetDirName $PSScriptRoot )
24
+ Write-TimedMessage " Normalized source abs directory: $srcDir "
22
25
23
26
# Read name of the folders under the specified source directory into an array
24
- $folders = Get-ChildItem - Path " $PSScriptRoot / $SourceDir " - Directory | Select-Object - ExpandProperty Name
25
- Write-TimedMessage " Folders in ${SourceDir } : $folders " - StartNewStep
27
+ $folders = Get-ChildItem - Path " $srcDir " - Directory | Select-Object - ExpandProperty Name
28
+ Write-TimedMessage " Folders in ${srcDir } : $folders " - StartNewStep
26
29
27
30
# Check if the folders array is empty
28
31
if ($folders.Count -eq 0 ) {
29
- Write-TimedMessage " No folders found in ${SourceDir } . Exiting script." - StartNewStep
32
+ Write-TimedMessage " No folders found in ${srcDir } . Exiting script." - StartNewStep
30
33
exit 1
31
34
}
32
35
@@ -50,15 +53,15 @@ function Get-OfficeApp {
50
53
# Create a list of Office applications that are needed based on the file extensions of the folders
51
54
Write-TimedMessage " Identifying required Office applications" - StartNewStep
52
55
foreach ($folder in $folders ) {
53
- $FileExtension = $folder.Substring ( $folder .LastIndexOf ( ' . ' ) + 1 )
54
- $app = Get-OfficeApp - FileExtension $FileExtension
56
+ $fileExtension = GetFileExtension $folder
57
+ $app = Get-OfficeApp - FileExtension $fileExtension
55
58
56
59
if ($app ) {
57
60
if ($officeApps -notcontains $app ) {
58
61
$officeApps += $app
59
62
}
60
63
} else {
61
- Write-TimedMessage " Unknown file extension: $FileExtension . Skipping..."
64
+ Write-TimedMessage " Unknown file extension: $fileExtension . Skipping..."
62
65
continue
63
66
}
64
67
}
@@ -87,36 +90,36 @@ Write-TimedMessage "Window minimized"
87
90
88
91
foreach ($folder in $folders ) {
89
92
Write-TimedMessage " Processing folder: $folder " - StartNewStep
90
- $FileExtension = $folder.Substring ($folder.LastIndexOf (' .' ) + 1 )
91
- $app = Get-OfficeApp - FileExtension $FileExtension
93
+ $fileExtension = $folder.Substring ($folder.LastIndexOf (' .' ) + 1 )
94
+ $app = Get-OfficeApp - FileExtension $fileExtension
92
95
93
96
$ext = " "
94
97
if ($app -ne " Access" ) {
95
98
$ext = " zip"
96
99
Write-TimedMessage " Creating Zip file and renaming to Office document target" - StartNewStep
97
- . " $PSScriptRoot /scripts/Zip-It.ps1" " ${SourceDir }${folder} "
100
+ . " $PSScriptRoot /scripts/Zip-It.ps1" " ${srcDir }${folder} "
98
101
Write-TimedMessage " Zip file created"
99
102
}
100
103
else {
101
104
$ext = " accdb"
102
105
Write-TimedMessage " Copying folder and content to Skeleton folder" - StartNewStep
103
- Copy-Item - Path " ${SourceDir }${folder} /DBSource" - Destination " ${SourceDir }${folder} /Skeleton" - Recurse - Force
106
+ Copy-Item - Path " ${srcDir }${folder} /DBSource" - Destination " ${srcDir }${folder} /Skeleton" - Recurse - Force
104
107
Write-TimedMessage " Folder copied"
105
108
}
106
109
107
110
Write-TimedMessage " Copying and renaming file to correct name" - StartNewStep
108
- . " $PSScriptRoot /scripts/Rename-It.ps1" " ${SourceDir }${folder} " " $ext "
111
+ . " $PSScriptRoot /scripts/Rename-It.ps1" " ${srcDir }${folder} " " $ext "
109
112
Write-TimedMessage " File renamed"
110
113
111
114
Write-TimedMessage " Importing VBA code into Office document" - StartNewStep
112
115
# Replace the direct Build-VBA call with the timeout version
113
116
$buildVbaScriptPath = " $PSScriptRoot /scripts/Build-VBA.ps1"
114
- $success = Invoke-ScriptWithTimeout - ScriptPath $buildVbaScriptPath - Arguments @ (" ${SourceDir }${folder} " , " $app " ) - TimeoutSeconds 30
117
+ $success = Invoke-ScriptWithTimeout - ScriptPath $buildVbaScriptPath - Arguments @ (" ${srcDir }${folder} " , " $app " ) - TimeoutSeconds 30
115
118
116
119
if (-not $success ) {
117
120
Write-TimedMessage " 🔴 Build-VBA.ps1 execution timed out or failed for ${folder} . Continuing with next file..."
118
121
119
- $screenshotDir = ${SourceDir } + " screenshots/"
122
+ $screenshotDir = ${srcDir } + " screenshots/"
120
123
if (-not (Test-Path $screenshotDir )) {
121
124
New-Item - ItemType Directory - Path $screenshotDir - Force | Out-Null
122
125
Write-Host " Created screenshot directory: $screenshotDir "
0 commit comments