예제 #1
0
        public static void MinifyFile(string fileName)
        {
            ThreadPool.QueueUserWorkItem((o) =>
            {
                try
                {
                    string ext = Path.GetExtension(fileName);
                    string minFile;
                    bool minFileExist = FileHelpers.HasMinFile(fileName, out minFile);

                    string mapFile;
                    bool mapFileExist = FileHelpers.HasSourceMap(minFile, out mapFile);

                    bool gzipFileExist = File.Exists(minFile + ".gz");

                    bool produceSourceMap = (minFileExist && mapFileExist) || (!minFileExist && !mapFileExist);
                    bool produceGzipFile  = (minFileExist && gzipFileExist) || (!minFileExist && !gzipFileExist);

                    MinificationResult result = FileMinifier.MinifyFile(fileName, produceGzipFile, produceSourceMap);
                    if (result == null)
                    {
                        return;
                    }

                    ErrorListService.ProcessCompilerResults(result);

                    if (!result.HasErrors && produceSourceMap && !string.IsNullOrEmpty(result.SourceMap))
                    {
                        mapFile = minFile + ".map";
                        ProjectHelpers.CheckFileOutOfSourceControl(mapFile);
                        File.WriteAllText(mapFile, result.SourceMap, new UTF8Encoding(true));

                        if (!mapFileExist)
                        {
                            ProjectHelpers.AddNestedFile(minFile, mapFile);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            });
        }
예제 #2
0
 private static void ErrorMinifyingFile(object sender, MinifyFileEventArgs e)
 {
     ErrorListService.ProcessCompilerResults(e.Result);
     BundlerMinifierPackage._dte.StatusBar.Text = $"There was a error minifying {Path.GetFileName(e.OriginalFile)}";
 }
예제 #3
0
 private static void ErrorMinifyingFile(object sender, MinifyFileEventArgs e)
 {
     ErrorListService.ProcessCompilerResults(e.Result);
     BundlerMinifierPackage._dte.StatusBar.Text = Resources.Text.ErrorMinifying.AddParams(Path.GetFileName(e.OriginalFile));
 }