Skip to content

Commit

Permalink
Updated the line count script
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpar committed Aug 27, 2014
1 parent 13b7adf commit bc7549f
Showing 1 changed file with 31 additions and 51 deletions.
82 changes: 31 additions & 51 deletions Scripts/Count-Lines.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$sourceDirs = "VimCore","VimWpf","VsVim"
$testDirs = "VimUnitTestUtils","VimCoreTest","VimWpfTest","VsVimTest"

function countFSharp() {
function count-fsharp() {
param ([string]$fileName = $(throw "Need a file name"))

$lines = gc $fileName |
Expand All @@ -12,7 +12,7 @@ function countFSharp() {
$lines.Count
}

function countCSharp() {
function count-csharp() {
param ([string]$fileName = $(throw "Need a file name"))

$lines = gc $fileName |
Expand All @@ -21,66 +21,46 @@ function countCSharp() {
$lines.Count
}

pushd $rootPath

$fsSourceFileCount = 0
$fsTestFileCount = 0
$fsSourceLines = 0
$fsTestLines = 0
$csSourceFileCount = 0
$csTestFileCount = 0
$csSourceLines = 0
$csTestLines = 0

function countFile() {
function count-file() {
param ( [string]$fileName = $(throw "Need a file name"),
[bool]$isTest )
$data)

$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
}
$data.Lines += count-csharp $fileName
$data.Language = "C#"
}
}

foreach ( $dir in $sourceDirs ) {
foreach ( $file in gci $dir -re -in *.cs,*.fs,*.fsi ) {
countFile $file $false
else {
$data.Lines += count-fsharp $fileName
$data.Language = "F#"
}
$data.Files++
}

foreach ( $dir in $testDirs ) {
foreach ( $file in gci $dir -re -in *.cs,*.fs,*.fsi ) {
countFile $file $true
function count-dirs() {
param( [string]$path = $(throw "Need a path"),
[bool]$isTest)

foreach ($dirName in gci $path | ?{ $_.PSIsContainer }) {
$dirPath = join-path $path $dirName
$data = @{ Name = $dirName; Language = ""; Lines = 0; Files = 0 };
write-host "$dir"
foreach ($file in gci $dirPath -re -in *.cs,*.fs,*.fsi) {
count-file $file $data
}

write-output $data
}
}

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 ""
$all = @()
$all += count-dirs (join-path . "Src") $false
$all += count-dirs (join-path . "Test") $true

write-host "C# Stats"
write-host " Source Files $csSourceFileCount"
write-host " Source Lines $csSourceLines"
write-host " Test Files $csTestFileCount"
write-host " Test Lines $csTestLines"
foreach ($data in $all) {
write-host $data.Name
write-host " Source Files: $($data.Files)"
write-host " Source Lines: $($data.Lines)"
}

popd

0 comments on commit bc7549f

Please sign in to comment.