Skip to content

Commit a67af1e

Browse files
committed
Added generation options
1 parent ae329e2 commit a67af1e

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/Typewriter/Options.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ public enum VerbosityLevel
1010
Trace
1111
}
1212

13+
/// <summary>
14+
/// Specifies how Typewriter will processes the input metadata and what type of outputs it produces.
15+
/// </summary>
16+
public enum GenerationMode
17+
{
18+
/// <summary>
19+
/// (default) Produces the output code files by cleaning the input metadata, parsing the docs, and adding annotations before generating the output files.
20+
/// </summary>
21+
Full,
22+
/// <summary>
23+
/// Produces an output metadata file by cleaning metadata, documentation parsing, and adding doc annotations.
24+
/// </summary>
25+
Metadata,
26+
/// <summary>
27+
/// Uses the input metadata and only generates code files for the target platform. It bypasses the cleaning, doc parsing, and adding doc annotations.
28+
/// </summary>
29+
Files
30+
}
31+
1332
class Options
1433
{
1534
[Option('l', "language", Default = "CSharp", HelpText = "The target language for the generated code files. The values can be: Android, Java, ObjC, CSharp, PHP, Python, TypeScript, or GraphEndpointList")]
@@ -26,5 +45,11 @@ class Options
2645

2746
[Option('d', "docs", Default = ".", HelpText = "Path to the root of the documentation repo folder")]
2847
public string DocsRoot { get; set; }
48+
49+
[Option('g', "generationmode", Default = GenerationMode.Full, HelpText = "Specifies the generation mode. The values can be: Full, Metadata, or Files. Full generation mode produces " +
50+
"the output code files by cleaning the input metadata, parsing the documentation, and adding annotations before generating the output files. Metadata generation mode" +
51+
"produces an output metadata file by cleaning metadata, documentation parsing, and adding documentation annotations. Files generation mode produces code files from" +
52+
"an input metadata and bypasses the cleaning, documentation parsing, and adding documentation annotations.")]
53+
public GenerationMode GenerateMode { get; set; }
2954
}
3055
}

src/Typewriter/Program.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,40 @@ private static void GenerateSDK(Options options)
3131

3232
string csdlContents = MetadataResolver.GetMetadata(options.Metadata);
3333

34+
// Generate the files from the input metadata and do not preprocess.
35+
if (options.GenerateMode == GenerationMode.Files)
36+
{
37+
var files = MetadataToClientSource(csdlContents, options.Language);
38+
FileWriter.WriteAsync(files, options.Output);
39+
40+
stopwatch.Stop();
41+
Logger.Info($"Generation time: {stopwatch.Elapsed } seconds.");
42+
43+
return;
44+
}
45+
3446
// Clean up EDMX to work with the generators assumptions.
3547
string processedCsdlContents = MetadataPreprocessor.CleanMetadata(csdlContents);
3648

3749
// Inject documentation annotations into the CSDL using ApiDoctor.
3850
string csdlWithDocAnnotations = AnnotationHelper.ApplyAnnotationsToCsdl(processedCsdlContents, options).Result;
51+
52+
// Output the clean and annotated metadata.
53+
if (options.GenerateMode == GenerationMode.Metadata)
54+
{
55+
// TODO: Write the metadata to the output directory using csdlWithDocAnnotations.
56+
57+
stopwatch.Stop();
58+
Logger.Info($"Generation time: {stopwatch.Elapsed } seconds.");
59+
60+
return;
61+
}
3962

63+
// Default GenerationMode.Full.
4064
// Create code files from the CSDL with annotations for the target platform and write those files to disk.
4165
var files = MetadataToClientSource(csdlWithDocAnnotations, options.Language);
4266
FileWriter.WriteAsync(files, options.Output);
43-
67+
4468
stopwatch.Stop();
4569
Logger.Info($"Generation time: {stopwatch.Elapsed } seconds.");
4670
}

0 commit comments

Comments
 (0)