public override string Transform(string fullFileName, string text, EnvDTE.ProjectItem projectItem) { var tags = regexScripts.Matches(text).Cast <Match>().Reverse(); foreach (var match in tags) { var tagName = match.Groups[1].Value; var attrs = match.Groups[2].Value; var code = match.Groups[3].Value; if (tagName.Is("script")) { code = JsEngine.Minify(fullFileName, code, projectItem, Xml.MinifyType.Unspecified, string.Empty); } else if (tagName.Is("style")) { int i = attrs.IndexOf("text/less", StringComparison.InvariantCultureIgnoreCase); if (i > -1) { attrs = attrs.Substring(0, i) + "text/css" + attrs.Substring(i + "text/less".Length); code = code.Replace("@@import", "@import"); // Razor views need the @ symbol to be escaped :/ code = LessEngine.TransformToCss(fullFileName, code, projectItem); code = code.Replace("@import", "@@import"); // Now we have to re-escape it } code = CssEngine.Minify(fullFileName, code, projectItem, Xml.MinifyType.Unspecified); } text = text.Substring(0, match.Index) + '<' + tagName + attrs + '>' + code + "</" + tagName + '>' + text.Substring(match.Index + match.Length); } return(text); }
public override void Process(Manager.VSProjectItemManager manager, string fullFileName, EnvDTE.ProjectItem projectItem, string baseFileName, string outputText) { base.Process(manager, fullFileName, projectItem, baseFileName, outputText); var mode = this.GetMinifyType(fullFileName); string mini = CssEngine.Minify(fullFileName, outputText, projectItem, mode); manager.AddFileByFileName(baseFileName + this.Settings.OutputExtensionCSS, mini); }
public override void Run(string fullFileName, ProjectItem projectItem) { var fileGroups = this.LoadConfigFileGroups(fullFileName); string directory = Path.GetDirectoryName(fullFileName); var productionFileText = new StringBuilder(); using (var manager = new Manager.VSProjectItemManager(this.Chirp != null ? this.Chirp.App : null, projectItem)) { foreach (var fileGroup in fileGroups) { productionFileText.Clear(); bool isJS = this.IsJsFile(fileGroup.GetName); bool isCSS = this.IsCssFile(fileGroup.GetName); string fullPath = directory + @"\" + fileGroup.Name; if (!string.IsNullOrEmpty(fileGroup.Path)) { fullPath = fileGroup.Path; } string fullPathMin = Utilities.GetBaseFileName(fullPath) + (isJS ? this.Settings.OutputExtensionJS : this.Settings.OutputExtensionCSS); if (TaskList.Instance != null) { TaskList.Instance.Remove(fullPath); TaskList.Instance.Remove(fullPathMin); } if (ImageSprite.IsImage(fileGroup.GetName)) { var img = ImageSprite.Build(fileGroup, fullPath); manager.AddFileByFileName(fullPath, img); continue; } foreach (var file in fileGroup.Files) { var path = file.Path; string code = file.GetCode(); string customArg = file.CustomArgument; if (((this.IsLessFile(path) || file.Engine == EngineType.Less) || this.IsSassFile(path) || this.IsCoffeeScriptFile(path) || file.Minify == true) && TaskList.Instance != null) { TaskList.Instance.Remove(path); } if (fileGroup.Debug) { var debugCode = "\r\n/* Chirpy Minify: {Minify}, MinifyWith: {MinifyWith}, File: {FilePath} */\r\n{Code}" .F(new { Minify = file.Minify.GetValueOrDefault(), FilePath = path, Code = isJS ? UglifyEngine.Beautify(code) : code, MinifyWith = file.MinifyWith.ToString() }); productionFileText.AppendLine(debugCode); } if (this.IsLessFile(path) || file.Engine == EngineType.Less) { code = LessEngine.TransformToCss(path, code, projectItem); } else if (this.IsCoffeeScriptFile(path)) { code = CoffeeScriptEngine.TransformToJs(path, code, projectItem); } else if (this.IsSassFile(path)) { code = SassEngine.TransformToCss(path, code, projectItem); } if (file.Minify == true) { if (this.IsCssFile(path)) { code = CssEngine.Minify(path, code, projectItem, file.MinifyWith); } else if (this.IsJsFile(path)) { code = JsEngine.Minify(path, code, projectItem, file.MinifyWith, customArg); } } productionFileText.AppendLine(code); } string output = productionFileText.ToString(); output = Utilities.ProcessText(output, fileGroup.Find, fileGroup.Replace); if (fileGroup.Minify == FileGroupXml.MinifyActions.True) { output = isJS ? JsEngine.Minify(fullPath, output, projectItem, fileGroup.MinifyWith) : CssEngine.Minify(fullPath, output, projectItem, fileGroup.MinifyWith); } //manager.AddFileByFileName(Utilities.GetBaseFileName(fullPath) + (isJS ? ".js" : isCSS ? ".css" : System.IO.Path.GetExtension(fullPath)), output); manager.AddFileByFileName(fullPath, output); if (fileGroup.Minify == FileGroupXml.MinifyActions.Both) { if (TaskList.Instance != null) { TaskList.Instance.Remove(fullPathMin); } output = isJS ? JsEngine.Minify(fullPath, output, projectItem, fileGroup.MinifyWith) : CssEngine.Minify(fullPath, output, projectItem, fileGroup.MinifyWith); manager.AddFileByFileName(fullPathMin, output); } } if (projectItem != null) { this.ReloadFileDependencies(projectItem); } } }