|
1 | 1 | [CmdletBinding()] |
2 | 2 | Param( |
3 | | - [Parameter(Mandatory=$True,Position=1)] |
4 | | - [string]$vsixPackageJson, |
| 3 | + [Parameter(Mandatory = $True, Position = 1)] |
| 4 | + [string]$extensionPath, |
5 | 5 |
|
6 | | - [Parameter(Mandatory=$True,Position=2)] |
| 6 | + [Parameter(Mandatory = $True, Position = 2)] |
7 | 7 | [string]$vsixName, |
8 | 8 |
|
9 | | - [Parameter(Mandatory=$True,Position=3)] |
| 9 | + [Parameter(Mandatory = $True, Position = 3)] |
10 | 10 | [string]$vsixDisplayName, |
11 | 11 |
|
12 | | - [Parameter(Mandatory=$True,Position=4)] |
| 12 | + [Parameter(Mandatory = $True, Position = 4)] |
13 | 13 | [string]$versionNumber, |
14 | 14 |
|
15 | | - [Parameter(Mandatory=$True,Position=5)] |
16 | | - [string]$aikey |
| 15 | + [Parameter(Mandatory = $True, Position = 5)] |
| 16 | + [string]$aikey, |
| 17 | + |
| 18 | + [Parameter(Mandatory = $True, Position = 6)] |
| 19 | + [string]$commandCategory, |
| 20 | + |
| 21 | + [Parameter(Mandatory = $True, Position = 7)] |
| 22 | + [string]$wizardLaunchCommand, |
| 23 | + |
| 24 | + [Parameter(Mandatory = $True, Position = 8)] |
| 25 | + [string]$deployAppCommand |
17 | 26 | ) |
18 | 27 | function Clear-WhiteSpace ($Text) { |
19 | 28 | "$($Text -replace "(`t|`n|`r)"," " -replace "\s+"," ")".Trim() |
20 | 29 | } |
21 | 30 |
|
22 | 31 | ## SET NAME AND VERSION IN VSIX Package json |
23 | | -if($vsixName){ |
24 | | - Write-Host |
25 | | - Write-Host "Setting name and version in VSIX package json" |
| 32 | +if ($vsixName) { |
| 33 | + |
| 34 | + $vsixPackageJson = Join-Path $extensionPath "package.json" |
| 35 | + $vsixPackageNlsJson = Join-Path $extensionPath "package.nls.json" |
| 36 | + $vsixPackagei18nJson = Join-Path $extensionPath "locales/en/package.i18n.json" |
| 37 | + $vsixExtensionTsFile = Join-Path $extensionPath "src/extension.ts" |
| 38 | + |
| 39 | + # REPLACE Version, Name, DisplayName and commands IN package.json |
| 40 | + if (Test-Path($vsixPackageJson)) { |
| 41 | + |
| 42 | + Write-Host |
| 43 | + Write-Host "Setting name,version and commands in VSIX package json" |
26 | 44 |
|
27 | | - if(Test-Path($vsixPackageJson)){ |
28 | 45 | $packagejsonContent = Get-Content $vsixPackageJson | ConvertFrom-Json |
29 | 46 | $LocalIdentity = $packagejsonContent.name |
30 | 47 | $localDisplayName = $packagejsonContent.displayName |
31 | 48 | $localVersionNumber = $packagejsonContent.version |
32 | 49 | $localAiKey = $packagejsonContent.aiKey |
| 50 | + $localwizardLaunchCommand = $packagejsonContent.contributes.commands[0].command |
| 51 | + $localdeployAppCommand = $packagejsonContent.contributes.commands[1].command |
33 | 52 |
|
34 | 53 | Write-Host "Replacing $LocalIdentity by $vsixName" |
35 | 54 | Write-Host "Replacing $localDisplayName by $vsixDisplayName" |
36 | 55 | Write-Host "Replacing $localVersionNumber by $versionNumber" |
| 56 | + Write-Host "Replacing $localwizardLaunchCommand by $wizardLaunchCommand" |
| 57 | + Write-Host "Replacing $localdeployAppCommand by $deployAppCommand" |
37 | 58 |
|
38 | 59 | $content = (Get-Content -path $vsixPackageJson -Raw) |
39 | 60 |
|
40 | 61 | $content = $content -replace "$LocalIdentity" , "$vsixName" |
41 | 62 | $content = $content -replace [regex]::Escape("$localDisplayName") , "$vsixDisplayName" |
42 | 63 | $content = $content -replace "$localVersionNumber" , "$versionNumber" |
43 | 64 | $content = $content -replace "$localAiKey" , "$aikey" |
| 65 | + $content = $content -replace "$localwizardLaunchCommand" , "$wizardLaunchCommand" |
| 66 | + $content = $content -replace "$localdeployAppCommand" , "$deployAppCommand" |
44 | 67 |
|
45 | 68 | [System.IO.File]::WriteAllLines($vsixPackageJson, $content, [System.Text.UTF8Encoding]($False)) |
46 | 69 |
|
47 | | - Write-Host "$resolvedPath - Version, Name & DisplayName applied ($versionNumber, $vsixName, $vsixDisplayName)" |
| 70 | + Write-Host "$resolvedPath - Version, Name, DisplayName and commands applied ($versionNumber, $vsixName, $vsixDisplayName, $wizardLaunchCommand, $deployAppCommand)" |
48 | 71 | } |
49 | | - else{ |
| 72 | + else { |
50 | 73 | throw "No VSIX package json file found." |
51 | 74 | } |
| 75 | + |
| 76 | + # REPLACE command category IN package.nls.json |
| 77 | + if (Test-Path($vsixPackageNlsJson)) { |
| 78 | + |
| 79 | + $jsonFile = Get-Content $vsixPackageNlsJson | ConvertFrom-Json |
| 80 | + $localCommandCategory = $jsonFile.'webTemplateStudioExtension.commands.wts' |
| 81 | + Write-Host "Replacing $localCommandCategory command category by $commandCategory in package.nls.json" |
| 82 | + |
| 83 | + $content = (Get-Content -path $vsixPackageNlsJson -Raw) |
| 84 | + $content = $content -replace [regex]::Escape("$localCommandCategory") , "$commandCategory" |
| 85 | + |
| 86 | + [System.IO.File]::WriteAllLines($vsixPackageNlsJson, $content, [System.Text.UTF8Encoding]($False)) |
| 87 | + Write-Host "$resolvedPath - category applied ($commandCategory)" |
| 88 | + } |
| 89 | + else { |
| 90 | + throw "No VSIX package.nls.json file found." |
| 91 | + } |
| 92 | + |
| 93 | + # REPLACE command category IN package.i18n.json |
| 94 | + if (Test-Path($vsixPackagei18nJson)) { |
| 95 | + |
| 96 | + $jsonFile = Get-Content $vsixPackagei18nJson | ConvertFrom-Json |
| 97 | + $localCommandCategory = $jsonFile.'webTemplateStudioExtension.commands.wts' |
| 98 | + Write-Host "Replacing $localCommandCategory command category by $commandCategory in package.i18n.json" |
| 99 | + |
| 100 | + $content = (Get-Content -path $vsixPackagei18nJson -Raw) |
| 101 | + $content = $content -replace [regex]::Escape("$localCommandCategory") , "$commandCategory" |
| 102 | + |
| 103 | + [System.IO.File]::WriteAllLines($vsixPackagei18nJson, $content, [System.Text.UTF8Encoding]($False)) |
| 104 | + Write-Host "$resolvedPath - category applied ($commandCategory)" |
| 105 | + } |
| 106 | + else { |
| 107 | + throw "No VSIX package.i18n.json file found." |
| 108 | + } |
| 109 | + |
| 110 | + # REPLACE commands IN extension.ts |
| 111 | + if (Test-Path($vsixExtensionTsFile)) { |
| 112 | + |
| 113 | + $localWizardLaunchCommand = "webTemplateStudioExtension.wizardLaunch.local" |
| 114 | + $localdeployAppCommand = "webTemplateStudioExtension.deployApp.local" |
| 115 | + |
| 116 | + Write-Host |
| 117 | + Write-Host "Replacing $localWizardLaunchCommand by $wizardLaunchCommand in extension.ts" |
| 118 | + Write-Host "Replacing $localdeployAppCommand by $deployAppCommand in extension.ts" |
| 119 | + |
| 120 | + $content = (Get-Content -path $vsixExtensionTsFile -Raw) |
| 121 | + $content = $content -replace [regex]::Escape("$localWizardLaunchCommand") , "$wizardLaunchCommand" |
| 122 | + $content = $content -replace [regex]::Escape("$localdeployAppCommand") , "$deployAppCommand" |
| 123 | + |
| 124 | + [System.IO.File]::WriteAllLines($vsixExtensionTsFile, $content, [System.Text.UTF8Encoding]($False)) |
| 125 | + Write-Host "$resolvedPath - Commands applied ($localWizardLaunchCommand, $localdeployAppCommand)" |
| 126 | + } |
| 127 | + else { |
| 128 | + throw "No VSIX extension.ts file found." |
| 129 | + } |
52 | 130 | } |
53 | | -else{ |
| 131 | +else { |
54 | 132 | throw "Identity is mandatory." |
55 | 133 | } |
56 | 134 |
|
0 commit comments