public static void MinifyFile(string lessFileName, string source) { if (WESettings.GetBoolean(WESettings.Keys.LessMinify)) { string content = MinifyFileMenu.MinifyString(".css", source); string minFile = MarginBase.GetCompiledFileName(lessFileName, ".min.css", WESettings.GetBoolean(WESettings.Keys.LessCompileToFolder)); //lessFileName.Replace(".less", ".min.css"); string old = File.ReadAllText(minFile); if (old != content) { bool fileExist = File.Exists(minFile); bool useBom = WESettings.GetBoolean(WESettings.Keys.UseBom); ProjectHelpers.CheckOutFileFromSourceControl(minFile); using (StreamWriter writer = new StreamWriter(minFile, false, new UTF8Encoding(useBom))) { writer.Write(content); } if (!fileExist) { MarginBase.AddFileToProject(lessFileName, minFile); } } } }
private static bool CanCompile(string fileName) { if (EditorExtensionsPackage.DTE.Solution.FindProjectItem(fileName) == null) { return(false); } if (Path.GetFileName(fileName).StartsWith("_")) { return(false); } string minFile = MarginBase.GetCompiledFileName(fileName, ".min.css", WESettings.GetBoolean(WESettings.Keys.LessCompileToFolder)); if (File.Exists(minFile) && WESettings.GetBoolean(WESettings.Keys.LessMinify)) { return(true); } string cssFile = MarginBase.GetCompiledFileName(fileName, ".css", WESettings.GetBoolean(WESettings.Keys.LessCompileToFolder)); if (!File.Exists(cssFile)) { return(false); } return(true); }
private static bool CanCompile(string fileName) { if (EditorExtensionsPackage.DTE.Solution.FindProjectItem(fileName) == null) { return(false); } if (Path.GetFileName(fileName).StartsWith("_")) { return(false); } if (MadsKristensen.EditorExtensions.WEIgnore.TestWEIgnore(fileName, "compiler", "less")) { Logger.Log(String.Format(CultureInfo.CurrentCulture, "LESS: The file {0} is ignored by .weignore. Skipping..", Path.GetFileName(fileName))); return(false); } string minFile = MarginBase.GetCompiledFileName(fileName, ".min.css", WESettings.GetBoolean(WESettings.Keys.LessCompileToFolder)); if (File.Exists(minFile) && WESettings.GetBoolean(WESettings.Keys.LessMinify)) { return(true); } string cssFile = MarginBase.GetCompiledFileName(fileName, ".css", WESettings.GetBoolean(WESettings.Keys.LessCompileToFolder)); if (!File.Exists(cssFile)) { return(false); } return(true); }
private static void Completed(CompilerResult result) { if (result.IsSuccess) { string cssFileName = MarginBase.GetCompiledFileName(result.FileName, ".css", WESettings.GetBoolean(WESettings.Keys.LessCompileToFolder));// result.FileName.Replace(".less", ".css"); if (File.Exists(cssFileName)) { string old = File.ReadAllText(cssFileName); if (old != result.Result) { ProjectHelpers.CheckOutFileFromSourceControl(cssFileName); try { bool useBom = WESettings.GetBoolean(WESettings.Keys.UseBom); using (StreamWriter writer = new StreamWriter(cssFileName, false, new UTF8Encoding(useBom))) { writer.Write(result.Result); } } catch (Exception ex) { Logger.Log(ex); } } } MinifyFile(result.FileName, result.Result); } else if (result.Error != null && !string.IsNullOrEmpty(result.Error.Message)) { Logger.Log(result.Error.Message); } else { Logger.Log("Error compiling LESS file: " + result.FileName); } }