forked from michaelneu/webxcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
54 lines (43 loc) · 1.49 KB
/
build.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
. .\variables.ps1
. .\constants.ps1
. .\log.ps1
$missing = [Reflection.Missing]::Value
$excel = New-Object -ComObject Excel.Application
$book = $excel.Workbooks.Add($missing)
Function CleanupExportedCode($lines)
{
While ($lines[0] -and ($lines[0].StartsWith("VERSION") -or $lines[0].StartsWith("BEGIN") -or $lines[0].StartsWith(" ") -or $lines[0].StartsWith("END")))
{
$ignore = $lines.RemoveAt(0)
}
}
Function AddScriptToBook($book, $file)
{
$extension = $file.Extension.ToLower()
$lines = [System.Collections.ArrayList][IO.File]::ReadAllLines($file.FullName)
CleanupExportedCode $lines
$code = [String]::Join("`r`n", $lines.ToArray())
$tmp = New-TemporaryFile
[IO.File]::WriteAllLines($tmp.FullName, $code)
$moduleType = $COMPONENT_TYPE_MODULE
If ($extension -eq ".cls")
{
$moduleType = $COMPONENT_TYPE_CLASS
}
$module = $book.VBProject.VBComponents.Add($moduleType)
$module.Name = [IO.Path]::GetFileNameWithoutExtension($file.FullName)
$module.CodeModule.AddFromFile($tmp.FullName)
Remove-Item $tmp.FullName -Force
}
$files = gci src *.* -rec | where { ! $_.PSIsContainer }
LogInfo "Found $($files.Count) modules"
ForEach ($file in $files)
{
AddScriptToBook $book $file
}
MkDir -Force $BUILD_DIRECTORY > $null
$excel.DisplayAlerts = $false
$book.SaveAs($FILENAME, $XL_FILE_FORMAT_MACRO_ENABLED)
$excel.DisplayAlerts = $true
$excel.Quit()
LogInfo "Document created"