-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.ps1
84 lines (67 loc) · 2.71 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Define vars
$googleUpdateUrl = "https://clients2.google.com/service/update2/crx"
$edgeUpdateUrl = "https://edge.microsoft.com/extensionwebstorebase/v1/crx"
# Define the source folder path and output zip file names
$srcFolderPath = "src"
$manifestPath = Join-Path $srcFolderPath "manifest.json"
$destFolderPath = "dist"
$chromeFolder = Join-Path $destFolderPath "chrome"
$edgeFolder = Join-Path $destFolderPath "edge"
$chromeZip = Join-Path $destFolderPath "chrome.zip"
$edgeZip = Join-Path $destFolderPath "edge.zip"
# Function to create folder if it doesn't exist and clear it if it does
function Ensure-Folder {
param (
[string]$folderPath
)
if (-not (Test-Path $folderPath)) {
New-Item -ItemType Directory -Path $folderPath | Out-Null
Write-Output "Folder created: $folderPath"
} else {
Remove-Item -Path (Join-Path $folderPath '*') -Recurse -Force
Write-Output "Folder cleared: $folderPath"
}
}
# Function to create a zip file
function Create-ZipFile {
param (
[string]$sourceFolder,
[string]$zipFileName
)
# Create the zip file
Compress-Archive -Path $sourceFolder -DestinationPath $zipFileName -Force
Write-Output "Zip file created: $zipFileName"
}
# Ensure dist folder and its subfolders exist and are empty
Write-Output "Creating necessary folders and clearing existing content..."
Ensure-Folder -folderPath $destFolderPath
Ensure-Folder -folderPath $chromeFolder
Ensure-Folder -folderPath $edgeFolder
# Read the original manifest
$manifest = Get-Content -Raw -Path $manifestPath | ConvertFrom-Json
# Function to update the manifest and create a zip file
function Update-ManifestAndZip {
param (
[string]$updateUrl,
[string]$zipFileName,
[string]$destFolder
)
# Update the update_url in the manifest
$manifest.update_url = $updateUrl
# Write the updated manifest back to the file, prettified
$manifest | ConvertTo-Json -Depth 4 | Set-Content -Path $manifestPath
# Copy files to the destination folder
Copy-Item -Path (Join-Path $srcFolderPath '*') -Destination $destFolder -Recurse -Force
# Create the zip file
Create-ZipFile -sourceFolder $destFolder -zipFileName $zipFileName
}
# Update for Chrome
Update-ManifestAndZip -updateUrl $googleUpdateUrl -zipFileName $chromeZip -destFolder $chromeFolder
# Update for Edge
Update-ManifestAndZip -updateUrl $edgeUpdateUrl -zipFileName $edgeZip -destFolder $edgeFolder
# Restore the original manifest
$manifest.update_url = $googleUpdateUrl
$manifest | ConvertTo-Json -Depth 4 | Set-Content -Path $manifestPath
Write-Output "Manifest restored to original update URL."
Write-Output ""
Write-Output "Test extension by reloading extension in browser."