private async Task <CompilerResult> ProcessResult(Process process, string errorText, string sourceFileName, string targetFileName, string mapFileName) { string result = ""; bool success = false; IEnumerable <CompilerError> errors = null; try { if (process.ExitCode == 0) { if (!string.IsNullOrEmpty(targetFileName) && File.Exists(targetFileName)) { result = await FileHelpers.ReadAllTextRetry(targetFileName); } success = true; } else { errors = ParseErrors(errorText); } } catch (FileNotFoundException missingFileException) { Logger.Log(ServiceName + ": " + Path.GetFileName(targetFileName) + " compilation failed. " + missingFileException.Message); } if (success) { var renewedResult = await PostProcessResult(result, sourceFileName, targetFileName, mapFileName); if (!ReferenceEquals(result, renewedResult)) { await FileHelpers.WriteAllTextRetry(targetFileName, renewedResult); result = renewedResult; } } var compilerResult = await CompilerResultFactory.GenerateResult( sourceFileName : sourceFileName, targetFileName : targetFileName, mapFileName : mapFileName, isSuccess : success, result : result, errors : errors ) as CompilerResult; if (!success) { var firstError = compilerResult.Errors.Where(e => e != null).Select(e => e.Message).FirstOrDefault(); if (firstError != null) { Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compilation failed: " + firstError); } } return(compilerResult); }
public virtual async Task <CompilerResult> CompileAsync(string sourceFileName, string targetFileName) { bool onlyPreview = false; if (WEIgnore.TestWEIgnore(sourceFileName, this is ILintCompiler ? "linter" : "compiler", ServiceName.ToLowerInvariant())) { if (WESettings.Instance.General.ShowWEIgnoreLogs) { Logger.Log(String.Format(CultureInfo.CurrentCulture, "{0}: The file {1} is ignored by .weignore. Skipping..", ServiceName, Path.GetFileName(sourceFileName))); } if (!Previewing) { return(await CompilerResultFactory.GenerateResult(sourceFileName, targetFileName, string.Empty, false, string.Empty, string.Empty, Enumerable.Empty <CompilerError>(), true)); } onlyPreview = true; } CompilerResult response = await NodeServer.CallServiceAsync(GetPath(sourceFileName, targetFileName)); return(await ProcessResult(response, onlyPreview, sourceFileName, targetFileName)); }
// Don't try-catch this method: We need to "address" all the bugs, // which may occur as the (node.js-based) service implement changes. private async Task <CompilerResult> ProcessResult(CompilerResult result, bool onlyPreview, string sourceFileName, string targetFileName) { if (result == null) { Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compilation failed: The service failed to respond to this request\n\t\t\tPossible cause: Syntax Error!"); return(await CompilerResultFactory.GenerateResult(sourceFileName, targetFileName)); } if (!result.IsSuccess) { var firstError = result.Errors.Where(e => e != null).Select(e => e.Message).FirstOrDefault(); if (firstError != null) { Logger.Log(firstError); } return(result); } string resultString = PostProcessResult(result.Result, result.TargetFileName, result.SourceFileName); if (!onlyPreview) { // Write output file if (result.TargetFileName != null && (MinifyInPlace || !File.Exists(result.TargetFileName) || resultString != await FileHelpers.ReadAllTextRetry(result.TargetFileName))) { ProjectHelpers.CheckOutFileFromSourceControl(result.TargetFileName); await FileHelpers.WriteAllTextRetry(result.TargetFileName, resultString); if (!(this is ILintCompiler)) { ProjectHelpers.AddFileToProject(result.SourceFileName, result.TargetFileName); } } // Write map file if (GenerateSourceMap && (!File.Exists(result.MapFileName) || result.ResultMap != await FileHelpers.ReadAllTextRetry(result.MapFileName))) { ProjectHelpers.CheckOutFileFromSourceControl(result.MapFileName); await FileHelpers.WriteAllTextRetry(result.MapFileName, result.ResultMap); if (!(this is ILintCompiler)) { ProjectHelpers.AddFileToProject(result.TargetFileName, result.MapFileName); } } await RtlVariantHandler(result); } return(CompilerResult.UpdateResult(result, resultString)); }
private async Task <CompilerResult> ProcessResult(Process process, string errorText, string sourceFileName, string targetFileName, string mapFileName) { var result = await ValidateResult(process, targetFileName, errorText); var resultText = result.Result; bool success = result.IsSuccess; if (success) { var renewedResult = await PostProcessResult(resultText, sourceFileName, targetFileName, mapFileName); if (!ReferenceEquals(resultText, renewedResult)) { await FileHelpers.WriteAllTextRetry(targetFileName, renewedResult); resultText = renewedResult; } } IEnumerable <CompilerError> errors = result.Errors; var compilerResult = await CompilerResultFactory.GenerateResult( sourceFileName : sourceFileName, targetFileName : targetFileName, mapFileName : mapFileName, isSuccess : success, result : resultText, errors : errors ) as CompilerResult; if (!success) { var firstError = compilerResult.Errors.Where(e => e != null).Select(e => e.Message).FirstOrDefault(); if (firstError != null) { Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compilation failed: " + firstError); } } return(compilerResult); }
internal async Task <CompilerResult> GetCompilerResult() { return(await CompilerResultFactory.GenerateResult(SourceFileName, TargetFileName, MapFileName, Success, Content, Map, Errors, false, RtlSourceFileName, RtlTargetFileName, RtlMapFileName, RtlContent, RtlMap)); }