-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateYXI.ps1
96 lines (80 loc) · 3.23 KB
/
CreateYXI.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
85
86
87
88
89
90
91
92
93
94
95
96
param($folder, [string]$version = "1.0.0", [string[]]$folders, [string]$imagePath = "")
$ErrorActionPreference = "Stop"
$dom = $env:userdomain
$usr = $env:username
$fullName = ([adsi]"WinNT://$dom/$usr,user").fullname
if (Test-Path $folder) {
$folder = Resolve-Path $folder
$name = Split-Path $folder -Leaf
$parent = Split-Path $folder -Parent
} else {
$name = $folder
$parent = Get-Location
}
if (Test-Path $imagePath) {
$imagePath = Resolve-Path $imagePath
}
Write-Host "Creating $name version $version... ($parent)"
$temp = $([System.IO.Path]::GetTempFileName())
Remove-Item $temp
New-Item $temp -type directory | Out-Null
push-location $temp
$configSourceFile = "$folder\${name}Config.xml"
if (Test-Path $configSourceFile) {
$folders += $folder
Write-Host "Including $folder"
} else {
$configSourceFile = "$folder.xml"
}
$configFile = Join-Path "$temp" "Config.xml"
Set-Content $configFile -Value '<?xml version="1.0"?>'
Add-Content $configFile -Value '<AlteryxJavaScriptPlugin>'
Add-Content $configFile -Value ' <Properties>'
Add-Content $configFile -Value ' <MetaInfo>'
Add-Content $configFile -Value " <Name>$name</Name>"
if (Test-Path $configSourceFile) {
$config = Get-Content $configSourceFile
$category = @(@($config -split "\n") -match '.*CategoryName.*')[0] -replace ".*<CategoryName>(.*)</CategoryName>.*",'$1'
Add-Content $configFile -Value " <CategoryName>$category</CategoryName>"
$description = @(@($config -split "\n") -match '.*Description.*')[0] -replace ".*<Description>(.*)</Description>.*",'$1'
Add-Content $configFile -Value " <Description>$description</Description>"
}
Add-Content $configFile -Value " <ToolVersion>$version</ToolVersion>"
Add-Content $configFile -Value " <Author>$fullName</Author>"
Add-Content $configFile -Value " <Icon>$name.png</Icon>"
Add-Content $configFile -Value ' </MetaInfo>'
Add-Content $configFile -Value ' </Properties>'
Add-Content $configFile -Value '</AlteryxJavaScriptPlugin>'
if (Test-Path $imagePath) {
Write-Host "Copying $imagePath"
Copy-Item -Destination "$temp\$name.png" -Path "$imagePath"
}
else {
if (Test-Path "$folder\$name.png") {
Write-Host "Copying $folder\$name.png"
Copy-Item -Destination "$temp" -Path "$folder\$name.png"
} else {
if (Test-Path "$folder.png") {
Write-Host "Copying $folder.png"
Copy-Item -Destination "$temp" -Path "$folder.png"
}
}
}
foreach ($sourceFolder in $folders) {
if (!(Test-Path $sourceFolder)) {
$sourceFolder = Join-Path $parent $sourceFolder
}
Write-Host "Copying $sourceFolder"
$leaf = Split-Path $sourceFolder -Leaf
New-Item $leaf -type directory | Out-Null
Get-ChildItem $sourceFolder -Exclude '*.ts', '*.map', 'node_modules', '*.bak', 'yarn.lock', 'package.json', 'ts*.json', '*Install.ps1' | Copy-Item -Destination "$temp\$leaf" -Recurse
}
Compress-Archive -Path "$temp\*" -DestinationPath "$temp\$name.zip" -Verbose -Update
$target = "$parent\${name}_$version.yxi"
if (Test-Path $target) {
Remove-Item $target
}
Move-Item "$temp\$name.zip" $target
Pop-Location
Remove-Item $temp -Recurse -Force
Write-Host "Created $target"