forked from microsoft/ApplicationInsights-Go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateschema.ps1
92 lines (68 loc) · 2.35 KB
/
generateschema.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
<#
.SYNOPSIS
Generate data contracts for Application Insights Go SDK from bond schema.
.DESCRIPTION
This is a convenience tool for generating the AI data contracts from the latest
bond schema. It requires BondSchemaGenerator.exe in order to operate. It also
requires the latest bond schema, but will check it out from github if it is not
present in the current directory.
.PARAMETER BondSchemaGenerator
The full path to BondSchemaGenerator.exe
.PARAMETER SchemasDir
The path to the directory that contains all of the input .bond files.
.LINK https://github.com/microsoft/ApplicationInsights-Home
#>
[cmdletbinding()]
Param(
[Parameter(Mandatory=$true)]
[string] $BondSchemaGenerator,
[string] $SchemasDir
)
function RunBondSchemaGenerator
{
[cmdletbinding()]
Param(
[string] $Language,
[string[]] $Files,
[string] $Layout,
[string[]] $Omissions
)
$args = @("-v")
$args += @("-o", ".")
$args += @("-e", $Language)
$args += @("-t", $Layout)
foreach ($file in $Files) {
$args += @("-i", $file)
}
foreach ($omission in $Omissions) {
$args += @("--omit", $omission)
}
& "$BondSchemaGenerator" $args 2>&1
}
$origpath = Get-Location
try {
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
cd $dir
if (-not (Test-Path $BondSchemaGenerator -PathType Leaf)) {
Write-Host "Could not find BondSchemaGenerator at $BondSchemaGenerator"
Write-Host "Please specify the full path"
Exit 1
}
if (-not $schemasDir) {
$schemasDir = ".\ApplicationInsights-Home\EndpointSpecs\Schemas\Bond"
# Check locally.
if (-not (Test-Path .\ApplicationInsights-Home -PathType Container)) {
# Clone into it!
git clone https://github.com/microsoft/ApplicationInsights-Home.git
}
}
$files = Get-ChildItem $schemasDir | % { "$schemasDir\$_" }
$omissions = @("Microsoft.Telemetry.Domain", "Microsoft.Telemetry.Base", "AI.AjaxCallData", "AI.PageViewPerfData")
RunBondSchemaGenerator -Files $files -Language GoBondTemplateLanguage -Layout GoTemplateLayout -Omissions $omissions
RunBondSchemaGenerator -Files $files -Language GoContextTagsLanguage -Layout GoTemplateLayout -Omissions $omissions
cd appinsights\contracts
go fmt
} finally {
cd $origpath
}