Skip to content

Commit fcd1d39

Browse files
committed
improvements to powershell script
1 parent 99c1908 commit fcd1d39

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.DS_Store
3-
package
3+
package
4+
LambdaFunction.zip

package.ps1

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1-
Write-Output "Packaging Lambda app"
2-
Remove-Item -Recurse -Force .\package
3-
New-Item .\package -type directory -f
4-
New-Item .\package\temp -type directory -f
1+
Write-Output "Packaging Lambda app"
2+
if (Test-Path .\package) {
3+
Remove-Item .\package -Recurse -Force
4+
}
5+
6+
7+
New-Item .\package -type directory -f | Out-Null
8+
New-Item .\package\temp -type directory -f | Out-Null
9+
Write-Output "Copying dependencies..."
510
Copy-Item .\backup.js .\package\temp\
611
Copy-Item .\diff.js .\package\temp\
712
Copy-Item .\s3-backfill.js .\package\temp\
813
Copy-Item .\s3-snapshot.js .\package\temp\
9-
Copy-Item .\node_modules\ .\package\temp\ -recurse
10-
11-
$environmentFile = Read-Host -Prompt 'Enter the name of the config file you would like to add to your deployment (e.g. dcx.env)'
14+
robocopy .\node_modules\ .\package\temp\ /E | Out-Null
15+
Write-Output "Dependencies sorted"
1216

13-
$currentdir = $PSScriptRoot
14-
15-
New-Item .\package\temp\index.js -type file -f
17+
$environmentFile = Read-Host -Prompt 'Enter the name of the config file you would like to add to your deployment (e.g. Forms-dc4.env)'
1618

19+
Write-Output "Generating output..."
20+
New-Item .\package\temp\index.js -type file -f | Out-Null
1721
get-content .\config\$environmentFile,".\index.js" | set-content ".\package\temp\index.js"
22+
Write-Output "Output generated"
1823

19-
$packageName = "LambdaFunction"
24+
Add-Type -assembly "system.io.compression.filesystem"
25+
$currentPath = (Get-Item -Path ".\" -Verbose).FullName
26+
$sourcePath = $currentPath + "\package\temp"
27+
$outputFile = $currentPath + "\LambdaFunction.zip"
2028

21-
$destination = $currentdir + "\package\" + $packageName + ".zip"
29+
if (Test-Path $outputFile) {
30+
Remove-Item $outputFile -Force
31+
}
2232

23-
Add-Type -assembly "system.io.compression.filesystem"
24-
[io.compression.zipfile]::CreateFromDirectory($currentdir + "\package\temp", $destination)
33+
[io.compression.zipfile]::CreateFromDirectory($sourcePath, $outputFile)
2534

26-
Write-Output "lambda app ready to be uploaded. Located at: " $destination
35+
Write-Output "λ function ready to be uploaded at: $($outputFile)"

0 commit comments

Comments
 (0)