forked from VsVim/VsVim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Count-Lines.ps1
85 lines (72 loc) · 2.21 KB
/
Count-Lines.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
$script:scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$sourceDirs = "VimCore","VimWpf","VsVim"
$testDirs = "VimUnitTestUtils","VimCoreTest","VimWpfTest","VsVimTest"
function countFSharp() {
param ([string]$fileName = $(throw "Need a file name"))
$lines = gc $fileName |
?{ $_.Trim() -ne "" } |
?{ -not ($_ -match "^\s*//") }
$lines.Count
}
function countCSharp() {
param ([string]$fileName = $(throw "Need a file name"))
$lines = gc $fileName |
?{ $_.Trim() -ne "" } |
?{ -not ($_ -match "^\s*//") }
$lines.Count
}
pushd $scriptPath
$fsSourceFileCount = 0
$fsTestFileCount = 0
$fsSourceLines = 0
$fsTestLines = 0
$csSourceFileCount = 0
$csTestFileCount = 0
$csSourceLines = 0
$csTestLines = 0
function countFile() {
param ( [string]$fileName = $(throw "Need a file name"),
[bool]$isTest )
$ext = [IO.Path]::GetExtension($fileName)
if ( ".cs" -eq $ext ) {
$lines = countCSharp $fileName
if ( $isTest ) {
$script:csTestFileCount++
$script:csTestLines += $lines
} else {
$script:csSourceFileCount++
$script:csSourceLines += $lines
}
} else {
$lines = countFSharp $fileName
if ( $isTest ) {
$script:fsTestFileCount++
$script:fsTestLines += $lines
} else {
$script:fsSourceFileCount++
$script:fsSourceLines += $lines
}
}
}
foreach ( $dir in $sourceDirs ) {
foreach ( $file in gci $dir -re -in *.cs,*.fs,*.fsi ) {
countFile $file $false
}
}
foreach ( $dir in $testDirs ) {
foreach ( $file in gci $dir -re -in *.cs,*.fs,*.fsi ) {
countFile $file $true
}
}
write-host "F# Stats"
write-host " Source Files $fsSourceFileCount"
write-host " Source Lines $fsSourceLines"
write-host " Test Files $fsTestFileCount"
write-host " Test Lines $fsTestLines"
write-host ""
write-host "C# Stats"
write-host " Source Files $csSourceFileCount"
write-host " Source Lines $csSourceLines"
write-host " Test Files $csTestFileCount"
write-host " Test Lines $csTestLines"
popd