-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtsg.ps1
52 lines (45 loc) · 1.26 KB
/
tsg.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
param ($assembly, $outputDir, $baseClass)
if (!$assembly)
{
Write-Host "PowerShell[.exe] .\tsg.ps1 -assembly <file> [-outputDir <directory>] [-baseClass <file>]"
}
else
{
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition;
if (!$outputDir)
{
$outputDir = '.';
}
$outputDir = [IO.Path]::GetFullPath($outputDir);
$assembly = [IO.Path]::GetFullPath($assembly);
# Ensure output directory exists
if (!(Test-Path -Path $outputDir))
{
mkdir $outputDir > $null;
}
# Generate CSDL metadata
$mg = [IO.Path]::Combine($scriptPath, '.bin\MetadataGenerator.exe');
$csdl = [IO.Path]::Combine($outputDir, 'out.json');
if (Test-Path -Path $csdl)
{
del $csdl > $null;
}
$command = '"$mg" -i "$assembly" -o "$csdl"';
iex "& $command";
if (!(Test-Path -Path $csdl))
{
Write-Host "Unexpected error: Metadata generation failed.";
}
else
{
# Generate typescript
$tsgen = [IO.Path]::Combine($scriptPath, 'tsgen.js');
$command = 'node $tsgen -camelCase -i "$csdl" -o "$outputDir"';
if ($baseClass)
{
$command += ' -b "$baseClass"';
}
iex "& $command";
Write-Host "Done";
}
}