public DartService(ICollection <Type> customTypes, Type type, List <MethodInfo> methods, List <EventInfo> events, string package, Func <MethodInfo, string> getMethodId) { Type = new DartType(customTypes, type, package); Methods = new List <DartMethod>(); Events = new List <DartEvent>(); foreach (MethodInfo method in methods) { Type r = DotNetTools.WrapReturnIntoFakeClass(type, method); Type p = DotNetTools.WrapParamsIntoFakeClass(type, method); Type[] tmp = { r, p }; DartType returnType = new DartType(customTypes.Concat(tmp).ToList(), r, package); DartType paramType = new DartType(customTypes.Concat(tmp).ToList(), p, package); Methods.Add(new DartMethod(customTypes, method, returnType, paramType, package, getMethodId)); } foreach (EventInfo @event in events) { Type args = @event.GetPlatformEventArgs(); DartType dartArgs = new DartType(customTypes, args, package); Events.Add(new DartEvent(customTypes, @event, dartArgs, package)); } }
public static int Main(string[] args) => BuildRunner.Execute(args, build => { var codegen = "fsdgenfsd"; var dotNetTools = new DotNetTools(Path.Combine("tools", "bin")).AddSource(Path.Combine("tools", "bin")); var dotNetBuildSettings = new DotNetBuildSettings { NuGetApiKey = Environment.GetEnvironmentVariable("NUGET_API_KEY"), DocsSettings = new DotNetDocsSettings { GitLogin = new GitLoginInfo("FacilityApiBot", Environment.GetEnvironmentVariable("BUILD_BOT_PASSWORD") ?? ""), GitAuthor = new GitAuthorInfo("FacilityApiBot", "*****@*****.**"), GitBranchName = Environment.GetEnvironmentVariable("APPVEYOR_REPO_BRANCH"), SourceCodeUrl = "https://github.com/FacilityApi/Facility/tree/master/src", ProjectHasDocs = name => !name.StartsWith("fsdgen", StringComparison.Ordinal), }, DotNetTools = dotNetTools, SourceLinkSettings = new SourceLinkSettings { ShouldTestPackage = name => !name.StartsWith("fsdgen", StringComparison.Ordinal), }, }; build.AddDotNetTargets(dotNetBuildSettings); build.Target("codegen") .DependsOn("build") .Describe("Generates code from the FSD") .Does(() => codeGen(verify: false)); build.Target("verify-codegen") .DependsOn("build") .Describe("Ensures the generated code is up-to-date") .Does(() => codeGen(verify: true)); build.Target("test") .DependsOn("verify-codegen"); void codeGen(bool verify) { string configuration = dotNetBuildSettings.BuildOptions.ConfigurationOption.Value; string versionSuffix = $"cg{DateTime.UtcNow:yyyyMMddHHmmss}"; RunDotNet("pack", Path.Combine("src", codegen, $"{codegen}.csproj"), "-c", configuration, "--no-build", "--output", Path.GetFullPath(Path.Combine("tools", "bin")), "--version-suffix", versionSuffix); string packagePath = FindFiles($"tools/bin/{codegen}.*-{versionSuffix}.nupkg").Single(); string packageVersion = Regex.Match(packagePath, @"[/\\][^/\\]*\.([0-9]+\.[0-9]+\.[0-9]+(-.+)?)\.nupkg$").Groups[1].Value; string toolPath = dotNetTools.GetToolPath($"{codegen}/{packageVersion}"); string verifyOption = verify ? "--verify" : null; RunApp(toolPath, "example/ExampleApi.fsd", "example/output", "--newline", "lf", verifyOption); RunApp(toolPath, "example/ExampleApi.fsd.md", "example/output", "--newline", "lf", "--verify"); RunApp(toolPath, "example/ExampleApi.fsd", "example/output/ExampleApi-nowidgets.fsd", "--excludeTag", "widgets", "--newline", "lf", verifyOption); RunApp(toolPath, "example/ExampleApi.fsd.md", "example/output/ExampleApi-nowidgets.fsd", "--excludeTag", "widgets", "--newline", "lf", "--verify"); } });