public static ExporterConsoleParameters ExtractParametersFromArgs(string[] args) { var t = typeof(ExporterConsoleParameters); var instance = new ExporterConsoleParameters(); foreach (var s in args) { var trimmed = s.TrimStart('-'); var kv = trimmed.Split('='); if (kv.Length != 2) { Console.WriteLine("Unrecognized parameter: {0}", s); continue; } var key = kv[0].Trim(); var value = kv[1].Trim().Trim('"'); var prop = t.GetProperty(key); if (prop == null) { Console.WriteLine("Unrecognized parameter: {0}", key); continue; } if (prop.PropertyType == typeof(bool)) { bool parsedValue = Boolean.Parse(value); prop.SetValue(instance, parsedValue); continue; } if (prop.PropertyType == typeof(string)) { prop.SetValue(instance, value); continue; } if (prop.PropertyType == typeof(string[])) { var parsedValue = value.Split(';'); prop.SetValue(instance, parsedValue); continue; } Console.WriteLine("Cannot parse parameter for source property {0}", key); } try { instance.Validate(); } catch (Exception ex) { Console.WriteLine("Parameters validation error: {0}", ex.Message); PrintHelp(); return(null); } return(instance); }
/// <summary> /// Usage: rtcli.exe Assembly.dll [Assembly2.dll Assembly3.dll ... etc] file.ts /// </summary> /// <param name="args"></param> public static void Main(string[] args) { Console.WriteLine("Reinforced.Typings CLI generator (c) 2015 by Pavel B. Novikov"); if (args.Length == 0) { PrintHelp(); return; } try { _parameters = ExtractParametersFromArgs(args); if (_parameters == null) { Console.WriteLine("No valid parameters found. Exiting."); Environment.Exit(0); } var settings = InstantiateExportSettings(); ResolveFluentMethod(settings); TsExporter exporter = new TsExporter(settings); exporter.Export(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Environment.Exit(1); } Console.WriteLine("Reinforced.Typings generation finished with total {0} assemblies loaded", _totalLoadedAssemblies); Console.WriteLine("Please build CompileTypeScript task to update javascript sources"); }
public static ExporterConsoleParameters FromFile(TextReader tr) { ExporterConsoleParameters result = new ExporterConsoleParameters(); result.TargetFile = tr.ReadLine(); result.ReferencesTmpFilePath = tr.ReadLine(); result.TargetDirectory = tr.ReadLine(); result.Hierarchy = bool.Parse(tr.ReadLine()); result.DocumentationFilePath = tr.ReadLine(); result.ConfigurationMethod = tr.ReadLine(); result.SourceAssemblies = new string[int.Parse(tr.ReadLine())]; for (int i = 0; i < result.SourceAssemblies.Length; i++) { result.SourceAssemblies[i] = tr.ReadLine(); } var lc = tr.ReadLine(); if (lc != null) { var regexCount = int.Parse(lc); for (int i = 0; i < regexCount; i++) { result.AssemblyRegex.Add(new AssemblyRegex() { Pattern = tr.ReadLine(), Replace = tr.ReadLine() }); } } return(result); }
/// <summary> /// Usage: rtcli.exe Assembly.dll [Assembly2.dll Assembly3.dll ... etc] file.ts /// </summary> /// <param name="args"></param> public static void Main(string[] args) { Console.WriteLine("Reinforced.Typings CLI generator (c) 2015-2018 by Pavel B. Novikov"); ExporterConsoleParameters parameters = null; if (args.Length == 0) { PrintHelp(); return; } try { if (string.Compare(args[0], "profile", #if NETCORE StringComparison.CurrentCultureIgnoreCase #else StringComparison.InvariantCultureIgnoreCase #endif ) == 0) { if (!File.Exists(args[1])) { Console.WriteLine("Cannot find profile {0}, exiting", args[1]); return; } parameters = ExtractParametersFromFile(args[1]); } else { parameters = ExtractParametersFromArgs(args); } if (parameters == null) { Console.WriteLine("No valid parameters found. Exiting."); return; } _suppressedWarnings = ParseSuppressedWarnings(parameters.SuppressedWarnings); var settings = InstantiateExportContext(parameters); ResolveFluentMethod(settings, parameters); TsExporter exporter = new TsExporter(settings); exporter.Export(); _assemblyManager.TurnOffAdditionalResolvation(); foreach (var rtWarning in settings.Warnings) { var msg = VisualStudioFriendlyErrorMessage.Create(rtWarning); Console.WriteLine(msg.ToString()); } ReleaseReferencesTempFile(parameters); }
/// <summary> /// Usage: rtcli.exe Assembly.dll [Assembly2.dll Assembly3.dll ... etc] file.ts /// </summary> /// <param name="args"></param> public static void Main(string[] args) { Console.WriteLine("Reinforced.Typings CLI generator (c) 2015 by Pavel B. Novikov"); if (args.Length == 0) { PrintHelp(); return; } try { _parameters = ExtractParametersFromArgs(args); if (_parameters == null) { Console.WriteLine("No valid parameters found. Exiting."); Environment.Exit(0); } _referencesFilePath = _parameters.ReferencesTmpFilePath; var settings = InstantiateExportContext(); ResolveFluentMethod(settings); TsExporter exporter = new TsExporter(settings); exporter.Export(); foreach (var rtWarning in settings.Warnings) { var msg = VisualStudioFriendlyErrorMessage.Create(rtWarning); Console.WriteLine(msg.ToString()); } } catch (RtException rtException) { var error = VisualStudioFriendlyErrorMessage.Create(rtException); Console.WriteLine(error.ToString()); Console.WriteLine(rtException.StackTrace); ReleaseReferencesTempFile(); Environment.Exit(1); } catch (Exception ex) { BuildError(ex.Message); Console.WriteLine(ex.StackTrace); //ReleaseReferencesTempFile(); Environment.Exit(1); } ReleaseReferencesTempFile(); Console.WriteLine("Reinforced.Typings generation finished with total {0} assemblies loaded", _totalLoadedAssemblies); Console.WriteLine("Please build CompileTypeScript task to update javascript sources"); }
public static ExporterConsoleParameters FromFile(TextReader tr) { ExporterConsoleParameters result = new ExporterConsoleParameters(); result.TargetFile = tr.ReadLine(); result.ReferencesTmpFilePath = tr.ReadLine(); result.TargetDirectory = tr.ReadLine(); result.Hierarchy = bool.Parse(tr.ReadLine()); result.DocumentationFilePath = tr.ReadLine(); result.ConfigurationMethod = tr.ReadLine(); result.SourceAssemblies = new string[int.Parse(tr.ReadLine())]; for (int i = 0; i < result.SourceAssemblies.Length; i++) { result.SourceAssemblies[i] = tr.ReadLine(); } return(result); }
/// <summary> /// Usage: rtcli.exe Assembly.dll [Assembly2.dll Assembly3.dll ... etc] file.ts /// </summary> /// <param name="args"></param> public static void Main(string[] args) { Console.WriteLine("Reinforced.Typings CLI generator (c) 2015 by Pavel B. Novikov"); if (args.Length == 0) { PrintHelp(); return; } try { _parameters = ExtractParametersFromArgs(args); if (_parameters == null) { Console.WriteLine("No valid parameters found. Exiting."); Environment.Exit(0); } var settings = InstantiateExportContext(); ResolveFluentMethod(settings); TsExporter exporter = new TsExporter(settings); exporter.Export(); foreach (var rtWarning in settings.Warnings) { var msg = VisualStudioFriendlyErrorMessage.Create(rtWarning); Console.WriteLine(msg.ToString()); } } catch (RtException rtException) { var error = VisualStudioFriendlyErrorMessage.Create(rtException); Console.WriteLine(error.ToString()); Console.WriteLine(rtException.StackTrace); Environment.Exit(1); } catch (Exception ex) { BuildError(ex.Message); Console.WriteLine(ex.StackTrace); Environment.Exit(1); } Console.WriteLine("Reinforced.Typings generation finished with total {0} assemblies loaded", _totalLoadedAssemblies); Console.WriteLine("Please build CompileTypeScript task to update javascript sources"); }
public static ExporterConsoleParameters ExtractParametersFromArgs(string[] args) { var t = typeof(ExporterConsoleParameters); var instance = new ExporterConsoleParameters(); foreach (var s in args) { var trimmed = s.TrimStart('-'); var kv = trimmed.Split('='); if (kv.Length != 2) { Console.WriteLine("Unrecognized parameter: {0}", s); continue; } var key = kv[0].Trim(); var value = kv[1].Trim().Trim('"'); var prop = t.GetProperty(key); if (prop == null) { Console.WriteLine("Unrecognized parameter: {0}", key); continue; } if (prop.PropertyType == typeof(bool)) { bool parsedValue = Boolean.Parse(value); prop.SetValue(instance, parsedValue); continue; } if (prop.PropertyType == typeof(string)) { prop.SetValue(instance, value); continue; } if (prop.PropertyType == typeof(string[])) { var parsedValue = value.Split(';'); prop.SetValue(instance, parsedValue); continue; } Console.WriteLine("Cannot parse parameter for source property {0}", key); } try { instance.Validate(); } catch (Exception ex) { Console.WriteLine("Parameters validation error: {0}", ex.Message); PrintHelp(); return null; } return instance; }
protected override string GenerateCommandLineCommands() { ExporterConsoleParameters consoleParams = new ExporterConsoleParameters() { ExportPureTypings = ExportPureTypings, WriteWarningComment = WriteWarningComment, Hierarchy = Hierarchical, TargetDirectory = FixTargetPath(TargetDirectory), TargetFile = FixTargetPath(TargetFile), References = ExtractReferences(), SourceAssemblies = ExtractSourceAssemblies(), RootNamespace = RootNamespace, CamelCaseForProperties = CamelCaseForProperties, CamelCaseForMethods = CamelCaseForMethods, DocumentationFilePath = DocumentationFilePath.EndsWith(".xml",StringComparison.InvariantCultureIgnoreCase)?DocumentationFilePath:String.Empty, GenerateDocumentation = GenerateDocumentation, ConfigurationMethod = ConfigurationMethod }; return consoleParams.ExportConsoleParameters(); }