-
Notifications
You must be signed in to change notification settings - Fork 35
/
Drop2Export.ps1
102 lines (84 loc) · 3.32 KB
/
Drop2Export.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
97
98
99
100
101
102
#Copy solution files (managed\unmanaged) from drop folder to the export folder.
#distribute solutions to sub folders (and rename them) by the SolutionMappings.json file in the exports folder
#skip sampledata and anchor files
#root folder of the repo by which the drop and export folder are defined
param (
[string]$repoPath
)
function Write-Error{
param(
[string]$Description,
[string]$filename
)
Write-Output "$Description in $filename $PSItem"
EXIT 1
}
function Copy-File{
param(
[string]$filePath
)
try{
$exportSolutionName = [System.IO.Path]::GetFileName($filePath)
$exportSolutionName = [System.IO.Path]::GetFileNameWithoutExtension($exportSolutionName)
$isManaged = $exportSolutionName.Contains("_managed")
$exportProjectName = $exportSolutionName.replace("_managed","")
#skip anchor and sampledata solutions as they dont hold entities and display names
if($exportProjectName.EndsWith('Anchor') -eq $false -and $exportProjectName.EndsWith('SampleData') -eq $false){
if($projectsArr.ContainsKey($exportProjectName)){
$exportFolder = $exportPath +'\' + $exportProjectName
if(![System.IO.Directory]::Exists($exportFolder)){
New-Item -Path $exportPath -Name $exportProjectName -ItemType "directory" | Out-Null
}
$zipSolution = $projectsArr[$exportProjectName]
if($isManaged){
$zipSolution += "_managed"
}
$zipSolution += '.zip'
Copy-Item $filePath -Destination ($exportFolder + '\' + $zipSolution) -Force
Write-Output "Copying to $exportFolder\$zipSolution"
}else{
Write-Output "Project $exportProjectName does not exist in SolutionMappings.json file "
}
}
}catch{
Write-Error "Could not copy $filePath"
}
}
#---------------------------------------------------------
if(!$repoPath){
$repoPath = $PSScriptRoot
}
$dropPath = $repoPath + '\drop\Debug\AnyCPU\Solutions'
$exportPath = $repoPath + '\exports\solutions'
$solutionMappings = $exportPath + '\solutionMappings.json'
if (![System.IO.Directory]::Exists($dropPath)){
Write-Error "Solutions do not exist in $dropPath"
}
if (![System.IO.Directory]::Exists($exportPath)){
Write-Error "Exports folder does not exist in $exportPath"
}
#read the solutionmapping.json file to create hashable of all projects and solution
$solutionContent = Get-content -Raw -path $solutionMappings
$solutions = ConvertFrom-Json -InputObject $solutionContent
$projectsArr = @{}
$projectName = 'ProjectName'
$solutionName = 'SolutionName'
foreach($solution in $solutions.SolutionMappings){
$projectName = $solution.ProjectName
$solutionName = $solution.SolutionName
$projectsArr[$projectName] = $solutionName
}
#iterate through all zip files under the droppath folder and copy relevant files to export folder
try{
if ([System.IO.Directory]::Exists($dropPath)){
$filesArr = [System.IO.Directory]::GetFiles($dropPath, "*.zip", 1)
ForEach($file in $filesArr){
if([System.IO.Path]::GetExtension($file) -eq '.zip'){
Copy-File $file.Trim()
}
}
}
}
catch{
Write-Error "Error reading file" $exportPath
}