private void OnInputIsFile() { var content = File.ReadAllText(Input); var converted = _codeConverter.ConvertToTypeScript(content, CodeConversionOptions); var outputPath = GetOutputFilePath(Input, Output, CodeConversionOptions); CreateOrUpdateFile(outputPath, converted, PartialOverride); }
private void OnInputIsFile() { var content = File.ReadAllText(Input); var converted = _codeConverter.ConvertToTypeScript(content, CodeConversionOptions); var outputPath = GetOutputFilePath(Input, Output, FileNameConversionOptions); FileSystem.EnsureDirectoryExists(outputPath.ContainingDirectory()); File.WriteAllText(outputPath, converted); }
public void Handle() { string inputLine; while ((inputLine = _stdio.ReadLine()) != "EXIT") { Output output; try { var input = JsonConvert.DeserializeObject <Input>(inputLine, _serializerSettings); var convertedCode = _codeConverter.ConvertToTypeScript(input.Code, input.MapToCodeConversionOptions()); output = new Output { Succeeded = true, ConvertedCode = convertedCode }; } catch (Exception ex) { output = new Output { Succeeded = false, ErrorMessage = ex.Message }; } var outputLine = JsonConvert.SerializeObject(output, _serializerSettings); _stdio.WriteLine(outputLine); } }
public void Handle() { while (_stdio.ReadLine() is var inputLine && inputLine != "EXIT") { Output output; try { var input = JsonConvert.DeserializeObject <Input>(inputLine, _serializerSettings); var codeConversionOptions = input.MapToCodeConversionOptions(); var convertedCode = _codeConverter.ConvertToTypeScript(input.Code, codeConversionOptions); var convertedFileName = string.IsNullOrWhiteSpace(input.FileName) ? null : _fileNameConverter.ConvertToTypeScript(input.FileName, codeConversionOptions); output = new Output { Succeeded = true, ConvertedCode = convertedCode, ConvertedFileName = convertedFileName }; } catch (Exception ex) { output = new Output { Succeeded = false, ErrorMessage = ex.Message }; } var outputLine = JsonConvert.SerializeObject(output, _serializerSettings); _stdio.WriteLine(outputLine); } }
private void OnInputIsFile() { var exclusions = GetExclusions().TryGetValue(Input, out var set) ? set : null; if (exclusions == _ignoreFile) { return; } var content = File.ReadAllText(Input); var converted = _codeConverter.ConvertToTypeScript(content, CodeConversionOptions, name => exclusions?.Contains(name) != true); var outputPath = GetOutputFilePath(Input, Output, CodeConversionOptions); CreateOrUpdateFile(outputPath, converted, PartialOverride); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } Response.Cookies.Append( nameof(Settings), JsonConvert.SerializeObject(Settings), new CookieOptions { Expires = DateTimeOffset.MaxValue }); PreviousInputCode = InputCode; ConvertedCode = _codeConverter.ConvertToTypeScript(InputCode ?? string.Empty, Settings.MapToCodeConversionOptions()); return(RedirectToPage()); }
public void ConvertClass() { var converted = _codeConverter.ConvertToTypeScript( @"class Item { public int Id { get; set; } public string Name { get; set; } }", new CodeConversionOptions(export: true, useTabs: false, tabSize: 4)); Assert.Equal(@"export interface Item { id: number; name: string; }", converted); }