public static async Task <bool> CompileFileAsync(string filePath, OutputPaneWrapper outputPane, string workingDir = null) { if (!TypeScriptHelpers.IsTypeScriptFile(filePath) || !Path.IsPathRooted(filePath)) { throw new ArgumentException($"{nameof(filePath)} has to be a rooted '.ts' or '.tsx' file."); } return(await CompileAsync($"\"{filePath}\"", workingDir ?? Path.GetDirectoryName(filePath), new CompileRedirector(outputPane))); }
public static async Task <bool> CompileProjectAsync(string filePath, OutputPaneWrapper outputPane) { if (!TypeScriptHelpers.IsTsJsConfigJsonFile(filePath) || !Path.IsPathRooted(filePath)) { throw new ArgumentException($"{nameof(filePath)} has to be a rooted 'tsconfig.json' file."); } return(await CompileAsync($"-p \"{filePath}\"", workingDir : Path.GetDirectoryName(filePath), redirector : new CompileRedirector(outputPane))); }
public static async Task <TsConfigJson> CreateAsync(string fullPathToFile) { if (!TypeScriptHelpers.IsTsJsConfigJsonFile(fullPathToFile)) { throw new ArgumentException("Expected full path to 'tsconfig.json' file.", nameof(fullPathToFile)); } if (File.Exists(fullPathToFile)) { var retryInterval = 500; // populate _source with retries for recoverable errors. for (var attempts = 5; attempts >= 0; attempts--) { try { using (var fin = new FileStream(fullPathToFile, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var reader = new StreamReader(fin)) { object source = null; var text = await reader.ReadToEndAsync(); try { // JsonConvert and JObject.Parse exhibit slightly different behavior, // so fall back to JObject.Parse if JsonConvert does not properly deserialize // the object. source = JsonConvert.DeserializeObject(text); } catch (ArgumentException) { source = JObject.Parse(text); } return(source == null ? null : new TsConfigJson(fullPathToFile, source)); } } catch (Exception exc) when(attempts > 0 && (exc is IOException || exc is UnauthorizedAccessException)) { // only retry on IO related exceptions } Thread.Sleep(retryInterval); retryInterval *= 2; // exponential backoff } } return(null); }