private static async Tasks.Task <bool> CompileSingleFileAsync(CompilerOptions options) { try { VsHelpers.CheckFileOutOfSourceControl(options.OutputFilePath); if (options.SourceMap) { VsHelpers.CheckFileOutOfSourceControl(options.OutputFilePath + ".map"); } CompilerResult result = await NodeProcess.ExecuteProcess(options); Logger.Log($"{result.Arguments}"); if (result.HasError) { Logger.Log(result.Error); VsHelpers.WriteStatus($"Error compiling LESS file. See Output Window for details"); } else { AddFilesToProject(options); Minify(options); } return(true); } catch (Exception ex) { Logger.Log(ex); VsHelpers.WriteStatus($"Error compiling LESS file. See Output Window for details"); return(false); } }
public static void Minify(CompilerOptions options) { if (!options.Minify || !File.Exists(options.OutputFilePath)) { return; } string cssContent = File.ReadAllText(options.OutputFilePath); var settings = new CssSettings { ColorNames = CssColor.Strict, CommentMode = CssComment.Important }; NUglify.UglifyResult result = Uglify.Css(cssContent, settings); if (result.HasErrors) { return; } string minFilePath = Path.ChangeExtension(options.OutputFilePath, ".min.css"); VsHelpers.CheckFileOutOfSourceControl(minFilePath); File.WriteAllText(minFilePath, result.Code, new UTF8Encoding(true)); VsHelpers.AddNestedFile(options.OutputFilePath, minFilePath); }