Skip to content

Commit 3f6566b

Browse files
darrelmillerMIchaelMainer
authored andcommitted
Typewriter.exe is born - added new command line exe for SDK generation (#143)
* Standalone generator EXE * Fixed nupkg description * Made new Initialize parameter optional * Fixed logging, parameters and template locations * Integrated the useful parts of vipr - captured the useful projects and added to this project. * Updated to Typewrite name and namespace * Updates to Typewriter processing * Enhancement: use Description as a backup to LongDescription * Added scripts for the basic self serve workflow.
1 parent 66dd5c4 commit 3f6566b

File tree

20 files changed

+623
-61
lines changed

20 files changed

+623
-61
lines changed

Generate.ps1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
param([String]$metadata='https://graph.microsoft.com/v1.0/$metadata')
2+
3+
$ErrorActionPreference = "Stop"
4+
5+
# pull docs
6+
git clone --depth 1 https://github.com/microsoftgraph/microsoft-graph-docs.git docs
7+
8+
# Get metadata
9+
Invoke-WebRequest $metadata -outfile metadata.xml
10+
11+
# apidoctor the $metadata
12+
apidoc publish-edmx --path 'docs\api-reference\v1.0' --source metadata.xml --output finalmetadata --skip-generation
13+
14+
# Generate new Types from metadata
15+
typewriter -v Info -l CSharp -m 'finalmetadata/metadata.xml' -o generated
16+
17+
# Based on Language pull repo
18+
git clone --depth 1 https://github.com/microsoftgraph/msgraph-sdk-dotnet.git source
19+
20+
# Create branch
21+
set-location source
22+
git checkout -b metadata-2018-09-14
23+
24+
# delete generated files
25+
remove-item -Recurse .\source\src\Microsoft.Graph\Models\Generated\
26+
remove-item -Recurse .\source\src\Microsoft.Graph\Requests\Generated\
27+
28+
# copy generated files
29+
move-item .\generated\com\microsoft\graph\model .\source\src\Microsoft.Graph\Models\Generated\
30+
move-item .\generated\com\microsoft\graph\requests .\source\src\Microsoft.Graph\Requests\Generated\
31+
32+
# commit and push branch

Package.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
msbuild Typewriter.sln /p:Configuration=Release /m
2+
choco pack Typewriter.nuspec -version %1
3+
choco upgrade Typewriter -s .

Templates/CSharp/Model/EntityType.cs.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace <#=entity.Namespace.GetNamespaceName()#>
8686

8787
/// <summary>
8888
/// Gets or sets <#=property.Name.SplitCamelCase().ToLower()#>.
89-
<# if (property.LongDescription != null) {
89+
<# if (property.LongDescription != null || property.Description != null) {
9090
#>
9191
/// <#=property.GetSanitizedLongDescription()#>
9292
<# } #>

Typewriter.nuspec

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package >
3+
<metadata>
4+
<id>Typewriter</id>
5+
<version>$version$</version>
6+
<authors>Microsoft</authors>
7+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
8+
<description>Tool for generating types for the Microsoft Graph SDK</description>
9+
<releaseNotes></releaseNotes>
10+
<copyright>� Microsoft Corporation. All rights reserved.</copyright>
11+
<licenseUrl>http://msdn.microsoft.com/en-US/cc300389</licenseUrl>
12+
<frameworkAssemblies>
13+
<frameworkAssembly assemblyName="System" targetFramework="net45" />
14+
</frameworkAssemblies>
15+
</metadata>
16+
<files>
17+
<file src="src\Typewriter\bin\Release\Typewriter.exe" target="tools" />
18+
<file src="src\Typewriter\bin\Release\*.dll" target="tools" />
19+
<file src="src\Typewriter\bin\Release\.config\*" target="tools\.config" />
20+
<file src="Templates\**\*.*" target="tools\templates" />
21+
</files>
22+
</package>

Typewriter.sln

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27004.2005
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{6ACF6CEE-A594-4DFE-9286-C7154E91738B}"
7+
ProjectSection(SolutionItems) = preProject
8+
.nuget\NuGet.Config = .nuget\NuGet.Config
9+
.nuget\NuGet.exe = .nuget\NuGet.exe
10+
.nuget\NuGet.targets = .nuget\NuGet.targets
11+
EndProjectSection
12+
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphODataTemplateWriter", "src\GraphODataTemplateWriter\GraphODataTemplateWriter.csproj", "{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}"
14+
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Templates", "Templates\Templates.csproj", "{5F526973-F69E-4C26-B8AD-612590A17A9E}"
16+
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphODataTemplateWriter.Test", "GraphODataTemplateWriter.Test\GraphODataTemplateWriter.Test.csproj", "{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}"
18+
ProjectSection(ProjectDependencies) = postProject
19+
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE} = {E6B5202F-4F66-428A-AB92-0AAA11BA81DE}
20+
{5F526973-F69E-4C26-B8AD-612590A17A9E} = {5F526973-F69E-4C26-B8AD-612590A17A9E}
21+
EndProjectSection
22+
EndProject
23+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Typewriter", "src\Typewriter\Typewriter.csproj", "{CA08F5D7-AA00-462E-BE5E-E4F54C257FA5}"
24+
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vipr.Core", "submodules\vipr\src\Core\Vipr.Core\Vipr.Core.csproj", "{04C24936-006A-4FD8-A872-EE55588C1CBE}"
26+
EndProject
27+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vipr.Reader.OData.v4", "submodules\vipr\src\Readers\Vipr.Reader.OData.v4\Vipr.Reader.OData.v4.csproj", "{6D8D8008-0A34-490F-8B38-21D9C8BF25C0}"
28+
EndProject
29+
Global
30+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
31+
Debug|Any CPU = Debug|Any CPU
32+
Release|Any CPU = Release|Any CPU
33+
EndGlobalSection
34+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
35+
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
38+
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Release|Any CPU.Build.0 = Release|Any CPU
39+
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Release|Any CPU.ActiveCfg = Debug|Any CPU
44+
{2256EC8D-FD7E-4A49-B616-70755AFC9F6C}.Release|Any CPU.Build.0 = Debug|Any CPU
45+
{CA08F5D7-AA00-462E-BE5E-E4F54C257FA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{CA08F5D7-AA00-462E-BE5E-E4F54C257FA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{CA08F5D7-AA00-462E-BE5E-E4F54C257FA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{CA08F5D7-AA00-462E-BE5E-E4F54C257FA5}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{04C24936-006A-4FD8-A872-EE55588C1CBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{04C24936-006A-4FD8-A872-EE55588C1CBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{04C24936-006A-4FD8-A872-EE55588C1CBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{04C24936-006A-4FD8-A872-EE55588C1CBE}.Release|Any CPU.Build.0 = Release|Any CPU
53+
{6D8D8008-0A34-490F-8B38-21D9C8BF25C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54+
{6D8D8008-0A34-490F-8B38-21D9C8BF25C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
55+
{6D8D8008-0A34-490F-8B38-21D9C8BF25C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{6D8D8008-0A34-490F-8B38-21D9C8BF25C0}.Release|Any CPU.Build.0 = Release|Any CPU
57+
EndGlobalSection
58+
GlobalSection(SolutionProperties) = preSolution
59+
HideSolutionNode = FALSE
60+
EndGlobalSection
61+
GlobalSection(ExtensibilityGlobals) = postSolution
62+
SolutionGuid = {C61920F8-6272-4B08-8A79-3E2B6EDD0C60}
63+
EndGlobalSection
64+
EndGlobal

src/GraphODataTemplateWriter/CodeHelpers/CSharp/TypeHelperCSharp.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,11 @@ public static string GetToLowerFirstCharName(this OdcmProperty property)
213213

214214
public static string GetSanitizedLongDescription(this OdcmProperty property)
215215
{
216-
if (property.LongDescription != null)
216+
var description = property.LongDescription ?? property.Description;
217+
218+
if (description != null)
217219
{
218-
return property.LongDescription.Replace("<", "&lt;").Replace(">", "&gt;").Replace("&", "&amp;");
220+
return description.Replace("<", "&lt;").Replace(">", "&gt;").Replace("&", "&amp;");
219221
}
220222
return null;
221223
}

src/GraphODataTemplateWriter/GraphODataTemplateWriter.csproj

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
<Reference Include="Microsoft.CSharp" />
5050
<Reference Include="System.Data" />
5151
<Reference Include="System.Xml" />
52-
<Reference Include="Vipr.Core">
53-
<SpecificVersion>False</SpecificVersion>
54-
<HintPath>..\..\submodules\vipr\src\Core\Vipr.Core\bin\$(Configuration)\Vipr.Core.dll</HintPath>
55-
</Reference>
5652
</ItemGroup>
5753
<ItemGroup>
5854
<Compile Include="CodeHelpers\Android\CodeWriterAndroid.cs" />
@@ -133,9 +129,6 @@
133129
<None Include=".config\TemplateWriterSettings.json">
134130
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
135131
</None>
136-
<Content Include="NLog.config">
137-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
138-
</Content>
139132
<None Include="NLog.xsd">
140133
<SubType>Designer</SubType>
141134
</None>
@@ -144,7 +137,12 @@
144137
<ItemGroup>
145138
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
146139
</ItemGroup>
147-
<ItemGroup />
140+
<ItemGroup>
141+
<ProjectReference Include="..\..\submodules\vipr\src\Core\Vipr.Core\Vipr.Core.csproj">
142+
<Project>{04c24936-006a-4fd8-a872-ee55588c1cbe}</Project>
143+
<Name>Vipr.Core</Name>
144+
</ProjectReference>
145+
</ItemGroup>
148146
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
149147
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
150148
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

src/GraphODataTemplateWriter/NLog.config

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/GraphODataTemplateWriter/Settings/ConfigurationService.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,27 @@ public static class ConfigurationService
1111
{
1212
private static IConfigurationProvider _configurationProvider;
1313
private static TemplateWriterSettings templateWriterSettings = null;
14-
15-
public static void Initialize(IConfigurationProvider configurationProvider)
14+
private static string targetLanguage = null;
15+
public static void Initialize(IConfigurationProvider configurationProvider, string targetLanguage = null)
1616
{
1717
_configurationProvider = configurationProvider;
18+
if (!String.IsNullOrEmpty(targetLanguage))
19+
{
20+
ConfigurationService.targetLanguage = targetLanguage;
21+
}
1822
}
1923

2024
private static TemplateWriterSettings LoadSettingsForLanguage()
2125
{
2226
TemplateWriterSettings mainTWS = _configurationProvider.GetConfiguration<TemplateWriterSettings>();
2327

24-
TemplateWriterSettings.mainSettingsObject = mainTWS;
28+
if (targetLanguage != null)
29+
{
30+
mainTWS.TargetLanguage = targetLanguage;
31+
}
2532

33+
TemplateWriterSettings.mainSettingsObject = mainTWS;
34+
2635
//First dynamically create a new class that holds settings for the target language
2736
//We store a reference on the default constructor to the mainTWS and then copy
2837
//all properties on it.

src/GraphODataTemplateWriter/TemplateProcessor/TemplateInfoProvider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Microsoft.Graph.ODataTemplateWriter.TemplateProcessor
77
using System.IO;
88
using System.Linq;
99
using Microsoft.Graph.ODataTemplateWriter.TemplateProcessor.Enums;
10+
using NLog;
1011

1112
/// <summary>
1213
/// Configures and creates the ITemplateInfo from the json config file.
@@ -19,6 +20,7 @@ class TemplateInfoProvider : ITemplateInfoProvider
1920
private readonly FileNameCasing defaultCasing;
2021
private readonly SubProcessor defaultSubProcessor;
2122
private readonly Template defaultTemplate;
23+
private static Logger logger = LogManager.GetCurrentClassLogger();
2224

2325
/// <summary>
2426
/// Creates a TemplateInfoProvider
@@ -43,9 +45,12 @@ public TemplateInfoProvider(IList<Dictionary<string,string>> mapping,
4345

4446
public IEnumerable<ITemplateInfo> Templates()
4547
{
48+
logger.Debug($"Processing {this.mapping.Count()} mappings.");
49+
4650
var templates = this.ReadTemplateFiles();
4751
foreach (var templateInfo in this.mapping)
4852
{
53+
//logger.Trace($"Loading template: {templateInfo.}");
4954
string templateName = null;
5055
if (templateInfo.TryGetValue("Template", out templateName) && templates.ContainsKey(templateName))
5156
{
@@ -64,6 +69,8 @@ public IEnumerable<ITemplateInfo> Templates()
6469
private Dictionary<string, IList<string>> ReadTemplateFiles()
6570
{
6671
var templates = new Dictionary<string, IList<string>>();
72+
logger.Debug($"Loading templates from {this.templatesDirectory}");
73+
6774
foreach (string path in (Directory.EnumerateFiles(this.templatesDirectory, "*.*.tt", SearchOption.AllDirectories)))
6875
{
6976
// Remove the .tt and then remove the file type extension

0 commit comments

Comments
 (0)