Skip to content

Commit 4177acf

Browse files
committed
Corrected file copy script
1 parent f2a0bf9 commit 4177acf

File tree

2 files changed

+158
-18
lines changed

2 files changed

+158
-18
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
Param(
4+
$ModulesToGenerate = @(),
5+
[string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot ".\config\ModulesMapping.jsonc")
6+
)
7+
function Get-GraphMapping {
8+
$graphMapping = @{}
9+
$graphMapping.Add("v1.0", "graph-powershell-1.0")
10+
$graphMapping.Add("beta", "graph-powershell-beta")
11+
return $graphMapping
12+
}
13+
14+
function Remove-Invalid-NextLine {
15+
Param(
16+
$ModulesToGenerate = @()
17+
)
18+
19+
$ModulePrefix = "Microsoft.Graph"
20+
$GraphMapping = Get-GraphMapping
21+
$GraphMapping.Keys | ForEach-Object {
22+
$graphProfile = $_
23+
Get-FilesByProfile -GraphProfile $graphProfile -GraphProfilePath $GraphMapping[$graphProfile] -ModulePrefix $ModulePrefix -ModulesToGenerate $ModulesToGenerate
24+
}
25+
26+
}
27+
function Get-FilesByProfile{
28+
Param(
29+
[ValidateSet("beta", "v1.0")]
30+
[string] $GraphProfile = "v1.0",
31+
[ValidateNotNullOrEmpty()]
32+
[string] $GraphProfilePath = "graph-powershell-1.0",
33+
[ValidateNotNullOrEmpty()]
34+
[string] $ModulePrefix = "Microsoft.Graph",
35+
[ValidateNotNullOrEmpty()]
36+
$ModulesToGenerate = @()
37+
)
38+
39+
$ModulesToGenerate | ForEach-Object {
40+
$ModuleName = $_
41+
Get-Files -GraphProfile $GraphProfile -GraphProfilePath $GraphProfilePath -Module $ModuleName -ModulePrefix $ModulePrefix
42+
}
43+
44+
}
45+
function Get-Files{
46+
param(
47+
[ValidateSet("beta", "v1.0")]
48+
[string] $GraphProfile = "v1.0",
49+
[ValidateNotNullOrEmpty()]
50+
[string] $GraphProfilePath = "graph-powershell-1.0",
51+
[ValidateNotNullOrEmpty()]
52+
[string] $Module = "Users",
53+
[ValidateNotNullOrEmpty()]
54+
[string] $ModulePrefix = "Microsoft.Graph"
55+
)
56+
if($GraphProfile -eq "beta"){
57+
$ModulePrefix = "Microsoft.Graph.Beta"
58+
}
59+
$moduleImportName = "$ModulePrefix.$ModuleName"
60+
$moduleDocsPath = Join-Path $PSScriptRoot "$GraphProfilePath\$moduleImportName"
61+
Update-Files -ModuleDocsPath $moduleDocsPath -GraphProfile $GraphProfile -ModuleName $ModuleName
62+
}
63+
64+
if (-not (Test-Path $ModuleMappingConfigPath)) {
65+
Write-Error "Module mapping file not be found: $ModuleMappingConfigPath."
66+
}
67+
if ($ModulesToGenerate.Count -eq 0) {
68+
[HashTable] $ModuleMapping = Get-Content $ModuleMappingConfigPath | ConvertFrom-Json -AsHashTable
69+
$ModulesToGenerate = $ModuleMapping.Keys
70+
}
71+
function Update-Files{
72+
param (
73+
[ValidateNotNullOrEmpty()]
74+
[string] $ModuleDocsPath,
75+
[ValidateSet("beta", "v1.0")]
76+
[string] $GraphProfile = "v1.0",
77+
[ValidateNotNullOrEmpty()]
78+
[string] $ModuleName = "Users"
79+
)
80+
try{
81+
foreach($filePath in Get-ChildItem $ModuleDocsPath){
82+
Refine_File -FilePath $filePath -GraphProfile $GraphProfile -ModuleName $ModuleName
83+
#Special-Escape -FilePath $FilePath -GraphProfile $GraphProfile -ModuleName $ModuleName
84+
#Start-Sleep -Seconds 5
85+
}
86+
}catch{
87+
Write-Host "`nError Message: " $_.Exception.Message
88+
Write-Host "`nError in Line: " $_.InvocationInfo.Line
89+
Write-Host "`nError in Line Number: "$_.InvocationInfo.ScriptLineNumber
90+
Write-Host "`nError Item Name: "$_.Exception.ItemName
91+
}
92+
}
93+
function Refine_File{
94+
param (
95+
[ValidateNotNullOrEmpty()]
96+
[string] $FilePath,
97+
[ValidateSet("beta", "v1.0")]
98+
[string] $GraphProfile = "v1.0",
99+
[ValidateNotNullOrEmpty()]
100+
[string] $ModuleName = "Users"
101+
)
102+
$tempFilePath = "$env:TEMP\$($FilePath | Split-Path -Leaf)"
103+
104+
$replace = ""
105+
try{
106+
$text = Get-Content -Path $FilePath
107+
Write-Host $FilePath
108+
foreach($content in $text){
109+
if($content -match "\\n"){
110+
$text = $text -replace "\\n", $replace
111+
}
112+
}
113+
$text > $tempFilePath
114+
Remove-Item -Path $FilePath
115+
Move-Item -Path $tempFilePath -Destination $FilePath
116+
}catch{
117+
Write-Host "`nError Message: " $_.Exception.Message
118+
Write-Host "`nError in Line: " $_.InvocationInfo.Line
119+
Write-Host "`nError in Line Number: "$_.InvocationInfo.ScriptLineNumber
120+
Write-Host "`nError Item Name: "$_.Exception.ItemName
121+
}
122+
}
123+
124+
125+
# Set-Location microsoftgraph-docs-powershell
126+
# $date = Get-Date -Format "dd-MM-yyyy"
127+
# $proposedBranch = "weekly_v2_docs_update_$date"
128+
# $exists = git branch -l $proposedBranch
129+
# if ([string]::IsNullOrEmpty($exists)) {
130+
# git checkout -b $proposedBranch
131+
# }else{
132+
# Write-Host "Branch already exists"
133+
# $currentBranch = git rev-parse --abbrev-ref HEAD
134+
# if($currentBranch -ne $proposedBranch){
135+
# git checkout $proposedBranch
136+
# }
137+
# git checkout $proposedBranch
138+
# }
139+
Remove-Invalid-NextLine -ModulesToGenerate $ModulesToGenerate
140+
#cd microsoftgraph-docs-powershell
141+
Write-Host -ForegroundColor Green "-------------Done-------------"

scripts/FileCopy.ps1

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the MIT License.
33
Param(
44
$ModulesToGenerate = @(),
5-
[string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot "../microsoftgraph/config/ModulesMapping.jsonc"),
5+
[string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot "../../msgraph-sdk-powershell/config/ModulesMapping.jsonc"),
66
[string] $SDKDocsPath = (Join-Path $PSScriptRoot "../../msgraph-sdk-powershell/src"),
77
[string] $WorkLoadDocsPath = (Join-Path $PSScriptRoot "../microsoftgraph")
88
)
@@ -63,7 +63,7 @@ function Copy-Files{
6363
[ValidateNotNullOrEmpty()]
6464
[string] $GraphProfilePath = "graph-powershell-1.0",
6565
[ValidateNotNullOrEmpty()]
66-
[string] $ModuleName = "Users",
66+
[string] $Module = "Users",
6767
[ValidateNotNullOrEmpty()]
6868
[string] $ModulePrefix = "Microsoft.Graph",
6969
[ValidateNotNullOrEmpty()]
@@ -93,34 +93,33 @@ function Copy-Files{
9393
Write-Host -ForegroundColor DarkYellow "Copying v1 markdown files to " $destination
9494
Get-ChildItem $DocPath -Recurse -File | ForEach-Object {
9595
Write-Host "File $_"
96-
Write-Host "Destination $destination"
97-
#Copy-Item $_ -Destination $destination
96+
Copy-Item $_ -Destination $destination
9897
}
9998
}
10099
}
101100
}
102101

103102

104103

105-
# Set-Location microsoftgraph-docs-powershell
106-
# $date = Get-Date -Format "dd-MM-yyyy"
107-
# $proposedBranch = "weekly_v2_docs_update_$date"
108-
# $exists = git branch -l $proposedBranch
109-
# if ([string]::IsNullOrEmpty($exists)) {
110-
# git checkout -b $proposedBranch
111-
# }else{
112-
# Write-Host "Branch already exists"
113-
# git checkout $proposedBranch
114-
# }
115-
# if (-not (Test-Path $ModuleMappingConfigPath)) {
116-
# Write-Error "Module mapping file not be found: $ModuleMappingConfigPath."
117-
# }
104+
Set-Location microsoftgraph-docs-powershell
105+
$date = Get-Date -Format "dd-MM-yyyy"
106+
$proposedBranch = "weekly_v2_docs_update_$date"
107+
$exists = git branch -l $proposedBranch
108+
if ([string]::IsNullOrEmpty($exists)) {
109+
git checkout -b $proposedBranch
110+
}else{
111+
Write-Host "Branch already exists"
112+
git checkout $proposedBranch
113+
}
114+
if (-not (Test-Path $ModuleMappingConfigPath)) {
115+
Write-Error "Module mapping file not be found: $ModuleMappingConfigPath."
116+
}
118117
if ($ModulesToGenerate.Count -eq 0) {
119118
[HashTable] $ModuleMapping = Get-Content $ModuleMappingConfigPath | ConvertFrom-Json -AsHashTable
120119
$ModulesToGenerate = $ModuleMapping.Keys
121120
}
122121

123-
# Set-Location ..\microsoftgraph-docs-powershell
122+
Set-Location ..\microsoftgraph-docs-powershell
124123
Write-Host -ForegroundColor Green "-------------finished checking out to today's branch-------------"
125124
Start-Copy -ModulesToGenerate $ModulesToGenerate
126125
Write-Host -ForegroundColor Green "-------------Done-------------"

0 commit comments

Comments
 (0)