-
Notifications
You must be signed in to change notification settings - Fork 73
/
import fixup script.ps1
444 lines (339 loc) · 14.9 KB
/
import fixup script.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
return
cd D:\dr\gh\ews-javascript-api\src\js
$content = Get-Content ..\..\errors.txt
$lines = $content | ?{$_.contains("TS2304")}
$dupli = $content | ?{$_.contains("TS2300")}
$ts2305 = $content | ?{$_.contains("TS2305")}
$NoTS7017 = $content |?{!$_.contains("TS7017")}
#src/js/Attributes/RequiredServerVersionAttribute.ts(3,11): error TS2304: Cannot find name 'ExchangeVersion'.
$fixes = @()
$lines |%{if($_ -match '(\A(?<file>.*)\()([^'']+).* (.(?<target>.*)[^.]+)') {
$fix = "" | select FileToFix,Symbol
$fix.FileToFix = $matches.file
$fix.Symbol = $matches.target
if(!$fix.FileToFix.EndsWith(".d.ts")){
$fixes += $fix
}
}
}
#$fixes
#| ?{$_.filetofix.contains("AddressEntityCollection")}
$fixes | group filetofix | %{ ############## - use this to fix TS2304
#Write-Verbose $_.name.Replace("src/js/","") -Verbose
$filetofix = dir $_.name.Replace("src/js/","").replace("/","\") -ErrorAction SilentlyContinue
if($filetofix -eq $null){
$filetofix = dir $_.name.Replace("test/","../../test/").replace("/","\") -ErrorAction SilentlyContinue
}
if($filetofix -ne $null){
$insercontent = @()
$_.group | select -Unique -Property symbol | %{
#Write-Verbose $_.symbol -Verbose
$symfile = dir ($_.symbol + ".ts") -Recurse
if($symfile){
#Write-Verbose $uri1 -Verbose
#Write-Verbose $uri2 -Verbose
$uri1 = New-Object System.Uri -ArgumentList $filetofix.FullName
$uri2 = New-Object System.Uri -ArgumentList $symfile.FullName
$importfile = $uri1.MakeRelative($uri2).replace(".ts","")
if(!$importfile.StartsWith(".")){$importfile = "./" + $importfile}
$importstatement = "import {" + $_.symbol + "} from """ + $importfile + """;"
Write-Verbose ($filetofix.FullName + " | " + $importstatement) -Verbose
$insercontent += $importstatement
}
else
{
Write-Verbose ($filetofix.FullName + " | " + $_.symbol) -Verbose
}
}
#$_.group.count
#$insercontent
$filecontent = Get-Content $filetofix.FullName
$filecontent = $insercontent + $filecontent
$filecontent | Set-Content -Path $filetofix
#$filecontent
}
}
$fixes = @(); $NoTS7017 |%{if($_ -match '(\A(?<file>.*)\()([^'']+).* (.(?<target>.*)[^.]+)') {
$fix = "" | select FileToFix,Symbol
$fix.FileToFix = $matches.file
$fix.Symbol = $matches.target
$fixes += $fix
}
}
return;$fixes[0] | %{
#Write-Verbose $_.FileToFix.Replace("src/js/","").Replace("/","\") -Verbose
$filetofix = dir $_.FileToFix.Replace("src/js/","").replace("/","\") -ErrorAction SilentlyContinue
if($filetofix){
Write-Verbose $_.symbol -Verbose
$symfile = dir ($_.symbol + ".ts") -Recurse
if($symfile){
Write-Verbose $uri1 -Verbose
Write-Verbose $uri2 -Verbose
$uri1 = New-Object System.Uri -ArgumentList $filetofix.FullName
$uri2 = New-Object System.Uri -ArgumentList $symfile.FullName
$importfile = $uri1.MakeRelative($uri2)
$importstatement = "import " + $_.symbol + " = require(""" + $importfile + """);"
Write-Verbose $importstatement -Verbose
}
}
}
return;$ff = $fixes | group filetofix | %{ ########## checking if already fixed by using import statement search
#Write-Verbose $_.name.Replace("src/js/","") -Verbose
$filetofix = dir $_.name.Replace("src/js/","").replace("/","\") -ErrorAction SilentlyContinue
if($filetofix){
$insercontent = @()
$_.group | select -Unique -Property symbol | %{
#Write-Verbose $_.symbol -Verbose
$symfile = dir ($_.symbol + ".ts") -Recurse
if($symfile){
#Write-Verbose $uri1 -Verbose
#Write-Verbose $uri2 -Verbose
$uri1 = New-Object System.Uri -ArgumentList $filetofix.FullName
$uri2 = New-Object System.Uri -ArgumentList $symfile.FullName
$importfile = $uri1.MakeRelative($uri2).replace(".ts","")
if(!$importfile.StartsWith(".")){$importfile = "./" + $importfile}
$importstatement = "import " + $_.symbol + " = require(""" + $importfile + """);"
Write-Verbose ($filetofix.FullName + " | " + $importstatement) -Verbose
$insercontent += $importstatement
}
else
{
Write-Verbose ($filetofix.FullName + " | " + $_.symbol) -Verbose
}
}
#$_.group.count
#$insercontent
$alreadyfixed = $filetofix | Select-String -SimpleMatch $importstatement
$alreadyfixed
#$filecontent = Get-Content $filetofix.FullName
#$filecontent = $insercontent + $filecontent
#$filecontent | Set-Content -Path $filetofix
#$filecontent
}
}
$ff
return
############# fix to copy ts file
$matches = dir *.ts -Recurse | Select-String -SimpleMatch "<copyright file=" #| %{$_.FileName}
$matches | %{
$path = $_.Path;
$file = dir (Join-Path "..\..\..\ews-javascriptapi_generatedTSFiles\" $_.Filename) -ErrorAction SilentlyContinue
#if(!$file){
# #$path.Replace("D:\dr\gh\ews-javascript-api\src\js\","").Replace($_.Filename,"");
# $target = $path.Replace("D:\dr\gh\ews-javascript-api\src\js\","D:\dr\gh\ews-javascriptapi_generatedTSFiles\copied\");
# $targetpath = $target.Replace($_.Filename,"");
# $targetpath
# md $targetpath
# copy $path $target -Force
#}
#if($file)
#{
# copy $file $path -Force
#}
if(!$file){
$_.FileName
}
}
$matches1 = dir *.ts -Recurse | Select-String -SimpleMatch "<copyright file=" #| %{$_.FileName}
$files | %{
$path = $_.FullName;
$file = dir (Join-Path "..\..\..\ews-javascriptapi_generatedTSFiles\" ($_.Name.replace("SearchFilter.",""))) -ErrorAction SilentlyContinue
#if(!$file){
# #$path.Replace("D:\dr\gh\ews-javascript-api\src\js\","").Replace($_.Filename,"");
# $target = $path.Replace("D:\dr\gh\ews-javascript-api\src\js\","D:\dr\gh\ews-javascriptapi_generatedTSFiles\copied\");
# $targetpath = $target.Replace($_.Filename,"");
# $targetpath
# md $targetpath
# copy $path $target -Force
#}
if($file)
{
#Remove-Item ($file.BaseName + ".js") -Verbose
copy $file $path -Force -Verbose
}
}
###################### bulk check missing export=
$aa = dir *.ts -Recurse | Select-String -SimpleMatch "//module Microsoft.Exchange.WebServices.Data {" -Context 3,0
$aa | %{
$m = $_
$s = $m.Context.PreContext | ?{$_.contains("export")}
if(!$s){
$m.Filename
}
}
return
"pattern to detect modulename -"
if("var EwsUtilities = require(`"./EwsUtilities`");" -match '\(\".\/((?<module>.*)\")' ){$Matches}
regex for module line
if("var EwsUtilities = require(`"./EwsUtilities`");" -match '.*(var).*(require).*\(\".\/(?<moduleName>.*)\"\);' ){$Matches}
if("var EwsUtilities = require(`"../asda/dasdada/dasda/ServiceObjectInfo`");" -match '.*(var).*(require).*\(.*\/(?<moduleName>.*)\"\);' ){$Matches} # refined
$f = dir *.js -Recurse
$ews = $f | Select-String -Pattern '.*(var).*(require).*\(\".\/(?<moduleName>.*)\"\);'
$util = dir ewsutilities.js -Recurse | Select-String -Pattern '.*(var).*(require).*\(.*\/(?<moduleName>.*)\"\);'
$util | %{
$moduleName = $_.Matches | %{$_.Groups["moduleName"]}
Write-Verbose $moduleName -Verbose
}
cd D:\dr\gh\ews-javascript-api\build\output\node\src\
[Collections.Generic.List[String]]$looping = @()
[Collections.Generic.List[String]]$done = @()
function subm ($f, $indent = 0, $x = $f){
$indention = "`t" * $indent
$match = dir ($f + ".js") -Recurse | Select-String -Pattern '.*(var).*(require).*\(.*\/(?<moduleName>.*)\"\);'
if($match)
{
$moduleNames = $match | %{$_.Matches | %{$_.Groups["moduleName"].Value}}
$moduleNames | ?{!$global:done.Contains($_)} | %{
if($_ -like $x){
Write-Warning "$indention file $f - chained to $_"
Write-Warning "$indention found loop - $($f<#$match.Filename | select -Unique#>) "
#$global:looping.Contains($f)
if(!$global:looping.Contains($f)){$global:looping.Add($f)}
}
elseif(!$global:looping.contains($_)){
$global:looping;
Write-Verbose "$indention file $f - chained to $_" -Verbose
$indent++
if($_ -ne $x){$global:done.Add($_)}
subm $_ $indent $x
$indent--
}
else{
Write-Verbose "$indention skipped $f" -Verbose
}
}
}
}
$looping.Clear()
$done.Clear()
subm "AttachmentsPropertyDefinition" 0
$moduleName = $util | %{$_.Matches | %{$_.Groups["moduleName"].Value.ToString()}}
Write-Verbose $moduleName -Verbose
d:
cd\
cd .\dr\gh\ews-javascript-api
cd .\src\js
$ts = dir *.ts -Exclude *.d.ts -Recurse
$ts.Count
dir *.ts | measure
dir *.ts -Recurse | measure
$ts | %{$_.name}
$ts | %{$_.fullname}
$ts | %{$_.fullname.replace(".ts",".js")}
$ts | %{$_.fullname.replace(".ts",".js") | Test-Path}
$ts | %{$_.fullname.replace(".ts",".js") | Test-Path} | ?{!$_}
$ts | %{$_.fullname.replace(".ts",".js") | del -Confirm}
$ts | %{$_.fullname.replace(".ts",".js") | del}
script to fix throw not implemented error ro something traceable.
return;
$fs = dir *.ts -Recurse | Select-String -pattern "{ throw new Error(`"Not implemented.`");" -SimpleMatch | %{$_.path} | select -Unique
foreach($f in $fs){
$c = Get-Content $f
$fn = ([System.IO.FileInfo]$f).Name
$fp = $f.Replace("\src\","\test\src\")
$path = ([System.IO.FileInfo]$fp).DirectoryName
mkdir $path -ErrorAction SilentlyContinue
if($c){
$c.Where({$_.contains("{ throw new Error(`"Not implemented.`");")}) | %{
$l = $_.replace("/","").trim();
Write-Verbose ("$fn - " + $l.Substring(0,$l.indexof("("))) -Verbose;
$c[$c.IndexOf($_)] = $_.replace("{ throw new Error(`"Not implemented.`");", "{ throw new Error(`"$fn - " + $l.Substring(0,$l.indexof("(")) + " : Not implemented.`");")
}
#$c
#$c | Set-Content $fp -Force
$c | Set-Content $f -Force
Start-Sleep -Milliseconds 200
Write-Verbose $fp -Verbose
}
}
return
# import module = require -> to -> import {module} from file
#if('import SortDirection = require("../../src/js/Enumerations/SortDirection");' -match'^import\W(?<module>\w*)\s*=.*\((?<target>.*)\).*'){$Matches;$Matches["target"].Length}
$pattern = '^import\W(?<module>\w*)\s*=.*\((?<target>.*)\).*'
$alltsFiles = dir *.ts -Recurse | Select-String -Pattern $pattern
$groups = $alltsFiles | group path
foreach($group in $groups){
$content = Get-Content $group.Name -Raw
if($content){
#$lines = $group.Group.Line | %{ if($_ -match $pattern){ "Import {$($Matches['module'])} from $($Matches['target']);" }}
foreach($grp in $group.Group){
$line = $grp.Line
$replace = "import {$($grp.Matches[0].Groups["module"].Value)} from $($grp.Matches[0].Groups["target"].Value);"
$content = $content.Replace($line,$replace)
}
}
Write-Verbose $group.Name -Verbose
$content | Set-Content -Path $group.Name -Encoding UTF8
}
return
#$filetofix = dir .\ExchangeWebService.ts
$uri1 = New-Object System.Uri -ArgumentList $filetofix.FullName
if($filetofix -ne $null){
$insercontent = @()
$allfiles = dir *.ts -Recurse;
$allfiles | ?{!$_.FullName.EndsWith(".d.ts")} | ?{!$_.BaseName.endsWith("Attribute")} | sort BaseName | %{
#Write-Verbose $_.symbol -Verbose
$symfile = $_.BaseName # dir ($_ + ".ts") -Recurse
if($symfile){
#Write-Verbose $uri1 -Verbose
#Write-Verbose $uri2 -Verbose
#$uri2 = New-Object System.Uri -ArgumentList $symfile.FullName
$importfile = $_.FullName.Replace("\","/").Replace("D:/dr/lgh/ews-javascript-api/src/js",".") # $uri1.MakeRelative($uri2).replace(".ts","")
#if(!$importfile.StartsWith(".")){$importfile = "./" + $importfile}
$importstatement = "// import {" + $symfile + "} from """ + $importfile.Replace(".ts","") + """;"
$importstatement += "`r`n// export {" + $symfile + "}"
#Write-Verbose ($filetofix.FullName + " | " + $importstatement) -Verbose
#Write-Verbose ($importstatement) -Verbose
$insercontent += $importstatement
}
else
{
Write-Verbose ($filetofix.FullName + " | " + $_.symbol) -Verbose
}
}
}
$exports = "export {"
$allfiles.BaseName | %{$exports += "`r`n// $_,"}
$exports += "`r`n};"
$moduleNames = @()
$allthrows = @()
function searchdependencyportstatus($f){
$match = dir ($f + ".ts") -Recurse | Select-String -Pattern '(import).*\".*\/(?<moduleName>.*)\"\;'
if($match)
{
$moduleNames = $match | %{$_.Matches | %{$_.Groups["moduleName"].Value}}
$moduleNames | %{
if($global:moduleNames -notcontains $_){
$global:moduleNames += $_
Write-Host $_ -ForegroundColor Red
$m2 = dir ($_ + ".ts") -Recurse | Select-String -Pattern '^\s+\w.*throw new Error.*Not implemented.*'
$global:allthrows += $m2
write-host "---------------------------------------------------" -ForegroundColor Yellow
#$list
searchdependencyportstatus $_
}
#else{"skipping $_"}
}
}
}
searchdependencyportstatus "Attachment"
function findChildClass($f){
$match = dir "*.ts" -Recurse | Select-String -Pattern '(import).*\".*\/(?<moduleName>.*)\"\;'
if($match)
{
$moduleNames = $match | %{$_.Matches | %{$_.Groups["moduleName"].Value}}
$moduleNames | %{
if($global:moduleNames -notcontains $_){
$global:moduleNames += $_
Write-Host $_ -ForegroundColor Red
$m2 = dir ($_ + ".ts") -Recurse | Select-String -Pattern '^\s+\w.*throw new Error.*Not implemented.*'
$global:allthrows += $m2
write-host "---------------------------------------------------" -ForegroundColor Yellow
#$list
searchdependencyportstatus $_
}
#else{"skipping $_"}
}
}
}
searchdependencyportstatus "Attachment"