1
+ Write-Host " angularDocsRoot value is: " $angularDocsRoot ; # angularDocsRoot octo variable
2
+ $isLatest = " VariableIsLatest" ;
3
+ $tag = " VariableValue" ;
4
+ $path = $angularDocsRoot ;
5
+ $newPath = $path -replace $tagFolder , $tag # tagFolder octo variable
6
+ $angularDocsRootFolder = [System.IO.Directory ]::GetParent($angularDocsRoot );
7
+ Write-Host " newPath is:" $newPath ;
8
+
9
+ # ######Delete all other folders starting with <AngularMajor>.<Major>########
10
+ # ######Since we are going to keep the latest and greatest########
11
+ $lastDot = $tag.LastIndexOf (' .' );
12
+ $filter = $tag.Substring (0 , $lastDot );
13
+ $foldersToDel = Get-ChildItem - Path $angularDocsRootFolder - Directory - Filter $filter *
14
+ Write-Host " Folders to delete: " $foldersToDel
15
+
16
+ try {
17
+ foreach ($f in $foldersToDel ){
18
+ if ([System.IO.Directory ]::Exists($f.FullName ))
19
+ { Write-Host $f.FullName " to be deleted!"
20
+ Remove-Item $f.FullName - Recurse - Force } }
21
+ }
22
+ catch { Write-Host " Exception while deleting the old folders" }
23
+
24
+ New-Item - Path $newPath - ItemType Directory - Force
25
+ Copy-Item - Path $path \* - Destination $newPath - Recurse - Force
26
+
27
+ # ##Add metatag inside index.html files' head section
28
+ $indexFiles = Get-ChildItem - Path $newPath - File - Recurse - Filter index.html
29
+ foreach ($indexFile in $indexFiles ) {
30
+ $newText = [System.IO.File ]::ReadAllText($indexFile.FullName ).Replace(" </head>" , " <meta name=`" robots`" content=`" noindex,nofollow`" >
31
+ </head>" );
32
+ [System.IO.File ]::WriteAllText($indexFile.FullName , $newText );
33
+ }
34
+
35
+ # ###########Update the angular-docs/sass and typescript folders if isLatest flag is true###########
36
+ if ($isLatest ) {
37
+ $sassFolder = $path + " \sass" ;
38
+ $typeScriptFolder = $path + " \typescript" ;
39
+
40
+ $sassFolderToUpdate = $path + " \..\sass" ;
41
+ $typeScriptFolderToUpdate = $path + " \..\typescript" ;
42
+ Write-Host " [Latest] sassFolderToUpdate is:" $sassFolderToUpdate ;
43
+ Write-Host " [Latest] typeScriptFolderToUpdate is:" $typeScriptFolderToUpdate ;
44
+
45
+ # Delete the existing content as octopus option - delete all before deployment
46
+ try {
47
+ Remove-Item $sassFolderToUpdate \* - Recurse - Force
48
+ Remove-Item $typeScriptFolderToUpdate \* - Recurse - Force }
49
+ catch { Write-Host " Exception while deleting the $sassFolderToUpdate or $typeScriptFolderToUpdate " }
50
+
51
+ New-Item - Path $sassFolderToUpdate \latest - ItemType Directory - Force
52
+ Copy-Item - Path $sassFolder \* - Destination $sassFolderToUpdate \latest - Recurse - Force
53
+
54
+ New-Item - Path $typeScriptFolderToUpdate \latest - ItemType Directory - Force
55
+ Copy-Item - Path $typeScriptFolder \* - Destination $typeScriptFolderToUpdate \latest - Recurse - Force
56
+ }
57
+
58
+ # ##########Json file content Update###########
59
+ $filePath = $jsonFile ; # jsonFile octo variable
60
+ Write-Host " Check file exists: " ([System.IO.File ]::Exists($filePath ))
61
+ Write-Host " Check dir exists:" ([System.IO.Directory ]::Exists($angularDocsRootFolder ));
62
+
63
+ if ([System.IO.File ]::Exists($filePath ) -and [System.IO.Directory ]::Exists($angularDocsRootFolder )) {
64
+ $folders = Get-ChildItem - Path $angularDocsRootFolder - Directory - Exclude $tagFolder , " sass" , " typescript" ;
65
+ $textToUpdate = " " ;
66
+ foreach ($item in $folders ) {
67
+ $textToUpdate += ' "' + $item.Name + ' "' ;
68
+ }
69
+ $textToUpdate = " [" + $textToUpdate.Replace (" `"`" " , " `" `,`" " ) + " ]" ;
70
+ Write-Host $textToUpdate ;
71
+
72
+ $content = [System.IO.File ]::ReadAllText($filePath );
73
+ $newContent = $content -replace " \[.*\]" , $textToUpdate ;
74
+ [System.IO.File ]::WriteAllText($filePath , $newContent );
75
+ }
0 commit comments