This repository has been archived by the owner on Jan 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Build.ps1
95 lines (79 loc) · 2.82 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
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
# Build.ps1
#
# Collects VBEX files into an office add-in file
#
# Copywrite (C) 2015 Philip Wales
#
Param(
[String]$buildPath,
[System.Array]$sourceFiles,
[System.Array]$references
)
$scriptRoot = if ($PSVersionTable.PSVersion.Major -ge 3) {
$PSScriptRoot
} else {
Split-Path $MyInvocation.MyCommand.Path -Parent
}
$display = (Join-Path $scriptRoot "Build-Display.ps1")
function Build {
$fileExt = [System.IO.Path]::GetExtension($buildPath)
$officeCOM = switch -wildcard ($fileExt.ToLower()) {
".xl*" {New-Object -ComObject Excel.Application; break}
#".ac*" {New-Object -ComObject Acces.Application; break}
default {throw "$fileName is not a supported office file."}
}
Write-Host "Will Build $buildPath"
dosEOLFolder $sourceFiles
$srcAddin = (BuildExcelAddin $officeCOM $sourceFiles $references $buildPath)
$officeCOM.Quit()
}
function BuildExcelAddin($officeCOM,
[System.Array] $moduleFiles,
[System.Array] $references,
[String] $outputPath) {
$newFile = $officeCOM.Workbooks.Add()
$prj = $newFile.VBProject
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($outputPath)
BuildVBProject $prj $projectName $moduleFiles $references
Write-Host "Saving Addin as $outputPath" -ForeGround Green
$newFile.SaveAs($outputPath, 55)
return $newFile
}
function BuildAccessAddin($officeCOM, [System.Array] $moduleFiles,
[System.Array] $references, [String] $outputPath) {
$newDB = $officeCOM.DBEngine.CreateDatabase($outputPath)
$prj = $officeCOM.VBE.VBProjects(1)
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($outputPath)
BuildVBProject $prj $projectName $moduleFiles $references
return $newDB
}
function BuildVBProject($prj, [String] $name, [System.Array] $moduleFiles,
[System.Array] $references) {
$prj.Name = $name
& "$display" 1 "Building VBProject $name`:"
$moduleCount = $moduleFiles.length
& "$display" 2 "Importing $moduleCount Modules:"
ForEach($moduleFile in $modulefiles) {
& "$display" 3 "$moduleFile"
$prj.VBComponents.Import($moduleFile)
}
$refCount = $references.length
Write-Host "==> " -ForeGround Green -noNewLine
Write-Host "Linking $refCount References:"
ForEach($reference in $references) {
& "$display" 3 "$reference"
$prj.References.AddFromFile( $reference )
}
}
function dosEOLFolder([System.Array] $textFiles) {
$count = $textFiles.length
Write-Host "Converting $count files to CRLF"
$textFiles | ForEach-Object { dosEOL $_ }
}
function dosEOL([String] $textFile) {
$tempOut = "$textFile-CRLF"
Get-Content $textFile | Set-Content $tempOut
Remove-Item $textFile
Move-Item $tempOut $textFile
}
Build #entry point