private static void AddFilesToProject(CompilerOptions options) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); ProjectItem item = VsHelpers.DTE.Solution.FindProjectItem(options.InputFilePath); if (item?.ContainingProject != null) { if (options.OutputFilePath == Path.ChangeExtension(options.InputFilePath, ".css")) { VsHelpers.AddNestedFile(options.InputFilePath, options.OutputFilePath); } else { VsHelpers.AddFileToProject(item.ContainingProject, options.OutputFilePath); } string mapFilePath = Path.ChangeExtension(options.OutputFilePath, ".css.map"); if (File.Exists(mapFilePath)) { VsHelpers.AddNestedFile(options.OutputFilePath, mapFilePath); } } }
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); }
private static void AddFilesToProject(CompilerOptions options) { ProjectItem item = VsHelpers.DTE.Solution.FindProjectItem(options.InputFilePath); if (item?.ContainingProject != null) { if (options.OutputFilePath == Path.ChangeExtension(options.InputFilePath, ".css")) { VsHelpers.AddNestedFile(options.InputFilePath, options.OutputFilePath); } else { VsHelpers.AddFileToProject(item.ContainingProject, options.OutputFilePath); } string mapFilePath = Path.ChangeExtension(options.OutputFilePath, ".css.map"); if (File.Exists(mapFilePath)) { VsHelpers.AddNestedFile(options.OutputFilePath, mapFilePath); } } }