예제 #1
0
        public static void Minify(string file, string minFile)
        {
            if (file.EndsWith(".min.css"))
            {
                return;
            }

            try
            {
                string content = MinifyFileMenu.MinifyString(".css", File.ReadAllText(file));

                ProjectHelpers.CheckOutFileFromSourceControl(minFile);
                using (StreamWriter writer = new StreamWriter(minFile, false, new UTF8Encoding(true)))
                {
                    writer.Write(content);
                }

                if (WESettings.GetBoolean(WESettings.Keys.CssEnableGzipping))
                {
                    GzipFile(file, minFile, content);
                }
            }
            catch
            {
                Logger.Log("Error minifying: " + file);
            }
        }
예제 #2
0
        //private void BuildTypeScript()
        //{
        //    foreach (Project project in _dte.Solution.Projects)
        //    {
        //        new TypeScriptMargin().CompileProjectFiles(project);
        //    }
        //}

        private void Minify()
        {
            _dte.StatusBar.Text = "Web Essentials: Minifying files...";
            var files = GetFiles();

            foreach (string path in files)
            {
                string extension = Path.GetExtension(path);
                string minPath   = MinifyFileMenu.GetMinFileName(path, extension);

                if (!path.EndsWith(".min" + extension, StringComparison.Ordinal) && File.Exists(minPath) && _dte.Solution.FindProjectItem(path) != null)
                {
                    if (extension.Equals(".js", StringComparison.OrdinalIgnoreCase))
                    {
                        JavaScriptSaveListener.Minify(path, minPath, false);
                    }
                    else
                    {
                        CssSaveListener.Minify(path, minPath);
                    }
                }
            }

            _dte.StatusBar.Text = "Web Essentials: Files minified";
        }
예제 #3
0
        private static void WriteMinFile(string filePath, string bundlePath, string content, string extension)
        {
            string minPath = bundlePath.Replace(Path.GetExtension(bundlePath), ".min" + Path.GetExtension(bundlePath));

            if (extension.Equals(".js", StringComparison.OrdinalIgnoreCase))
            {
                JavaScriptSaveListener.Minify(bundlePath, minPath, true);
                MarginBase.AddFileToProject(filePath, minPath);

                if (WESettings.GetBoolean(WESettings.Keys.GenerateJavaScriptSourceMaps))
                {
                    MarginBase.AddFileToProject(filePath, minPath + ".map");
                }

                MarginBase.AddFileToProject(filePath, minPath + ".gzip");
            }
            else if (extension.Equals(".css", StringComparison.OrdinalIgnoreCase))
            {
                string minContent = MinifyFileMenu.MinifyString(extension, content);

                ProjectHelpers.CheckOutFileFromSourceControl(minPath);

                using (StreamWriter writer = new StreamWriter(minPath, false, new UTF8Encoding(true)))
                {
                    writer.Write(minContent);
                }
                MarginBase.AddFileToProject(filePath, minPath);

                CssSaveListener.GzipFile(filePath, minPath, minContent);
            }
        }
예제 #4
0
        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);

                    ProjectHelpers.CheckOutFileFromSourceControl(minFile);
                    using (StreamWriter writer = new StreamWriter(minFile, false, new UTF8Encoding(true)))
                    {
                        writer.Write(content);
                    }

                    if (!fileExist)
                    {
                        MarginBase.AddFileToProject(lessFileName, minFile);
                    }
                }
            }
        }
예제 #5
0
        void menuCommand_BeforeQueryStatus(object sender, System.EventArgs e)
        {
            OleMenuCommand menuCommand = sender as OleMenuCommand;

            var raw = MinifyFileMenu.GetSelectedFilePaths(_dte);

            files = raw.Where(f => !JsHintRunner.ShouldIgnore(f)).ToList();

            menuCommand.Enabled = files.Count > 0;
        }
예제 #6
0
        protected override void Initialize()
        {
            base.Initialize();
            Instance = this;
            JsDocComments.Register();

            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                HandleMenuVisibility(mcs);

                TransformMenu transform = new TransformMenu(DTE, mcs);
                transform.SetupCommands();

                DiffMenu diffMenu = new DiffMenu(DTE, mcs);
                diffMenu.SetupCommands();

                MinifyFileMenu minifyMenu = new MinifyFileMenu(DTE, mcs);
                minifyMenu.SetupCommands();

                BundleFilesMenu bundleMenu = new BundleFilesMenu(DTE, mcs);
                bundleMenu.SetupCommands();

                JsHintMenu jsHintMenu = new JsHintMenu(DTE, mcs);
                jsHintMenu.SetupCommands();

                ProjectSettingsMenu projectSettingsMenu = new ProjectSettingsMenu(DTE, mcs);
                projectSettingsMenu.SetupCommands();

                SolutionColorsMenu solutionColorsMenu = new SolutionColorsMenu(DTE, mcs);
                solutionColorsMenu.SetupCommands();

                BuildMenu buildMenu = new BuildMenu(DTE, mcs);
                buildMenu.SetupCommands();

                MarkdownStylesheetMenu markdownMenu = new MarkdownStylesheetMenu(DTE, mcs);
                markdownMenu.SetupCommands();
            }

            // Hook up event handlers
            Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
            {
                DTE.Events.BuildEvents.OnBuildDone     += BuildEvents_OnBuildDone;
                DTE.Events.SolutionEvents.Opened       += delegate { Settings.UpdateCache(); Settings.UpdateStatusBar("applied"); };
                DTE.Events.SolutionEvents.AfterClosing += delegate { DTE.StatusBar.Clear(); };
            }), DispatcherPriority.ApplicationIdle, null);
        }
        protected override bool Execute(uint commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (TextView != null)
            {
                _dte.UndoContext.Open("Minify");

                string content   = TextView.Selection.SelectedSpans[0].GetText();
                string extension = Path.GetExtension(_dte.ActiveDocument.FullName).ToLowerInvariant();
                string result    = MinifyFileMenu.MinifyString(extension, content);

                TextView.TextBuffer.Replace(TextView.Selection.SelectedSpans[0].Span, result);

                _dte.UndoContext.Close();
            }

            return(true);
        }
예제 #8
0
        public override void MinifyFile(string fileName, string source)
        {
            if (WESettings.GetBoolean(WESettings.Keys.LessMinify) && !Path.GetFileName(fileName).StartsWith("_"))
            {
                string content   = MinifyFileMenu.MinifyString(".css", source);
                string minFile   = GetCompiledFileName(fileName, ".min.css", UseCompiledFolder);// fileName.Replace(".less", ".min.css");
                bool   fileExist = File.Exists(minFile);

                ProjectHelpers.CheckOutFileFromSourceControl(minFile);
                using (StreamWriter writer = new StreamWriter(minFile, false, new UTF8Encoding(true)))
                {
                    writer.Write(content);
                }

                if (!fileExist)
                {
                    AddFileToProject(Document.FilePath, minFile);
                }
            }
        }
예제 #9
0
        public override void MinifyFile(string fileName, string source)
        {
            if (WESettings.GetBoolean(WESettings.Keys.CoffeeScriptMinify))
            {
                string content   = MinifyFileMenu.MinifyString(".js", source);
                string minFile   = GetCompiledFileName(fileName, ".min.js", UseCompiledFolder);//fileName.Replace(".coffee", ".min.js");
                bool   fileExist = File.Exists(minFile);

                ProjectHelpers.CheckOutFileFromSourceControl(minFile);
                using (StreamWriter writer = new StreamWriter(minFile, false, new UTF8Encoding(true)))
                {
                    writer.Write(content);
                }

                if (!fileExist)
                {
                    AddFileToProject(fileName, minFile);
                }
            }
        }
예제 #10
0
        public static void Minify(string file, string minFile)
        {
            if (file.EndsWith(".min.css"))
            {
                return;
            }

            try
            {
                string content = MinifyFileMenu.MinifyString(".css", File.ReadAllText(file));
                //Minifier minifier = new Minifier();
                //string content = minifier.MinifyStyleSheet(File.ReadAllText(file));

                ProjectHelpers.CheckOutFileFromSourceControl(minFile);
                using (StreamWriter writer = new StreamWriter(minFile, false, new UTF8Encoding(true)))
                {
                    writer.Write(content);
                }
            }
            catch
            {
                Logger.Log("Error minifying: " + file);
            }
        }
예제 #11
0
        protected async override void Initialize()
        {
            base.Initialize();

            Instance = this;

            await NodeServer.Up();

            SettingsStore.Load();
            JavaScriptIntellisense.Register();

            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                TransformMenu           transform           = new TransformMenu(DTE, mcs);
                DiffMenu                diffMenu            = new DiffMenu(mcs);
                MinifyFileMenu          minifyMenu          = new MinifyFileMenu(mcs);
                BundleFilesMenu         bundleMenu          = new BundleFilesMenu(DTE, mcs);
                JsHintMenu              jsHintMenu          = new JsHintMenu(DTE, mcs);
                TsLintMenu              tsLintMenu          = new TsLintMenu(DTE, mcs);
                HubsT4Menu              hubsT4Menu          = new HubsT4Menu(DTE, mcs);
                CoffeeLintMenu          coffeeLintMenu      = new CoffeeLintMenu(DTE, mcs);
                JsCodeStyle             jsCodeStyleMenu     = new JsCodeStyle(DTE, mcs);
                RtlCssMenu              rtlCssMenu          = new RtlCssMenu(DTE, mcs);
                CsonMenu                cson                = new CsonMenu(mcs);
                ProjectSettingsMenu     projectSettingsMenu = new ProjectSettingsMenu(DTE, mcs);
                SolutionColorsMenu      solutionColorsMenu  = new SolutionColorsMenu(mcs);
                BuildMenu               buildMenu           = new BuildMenu(DTE, mcs);
                MarkdownMenu            markdownMenu        = new MarkdownMenu(DTE, mcs);
                HandlebarsMenu          handlebarsMenu      = new HandlebarsMenu(DTE, mcs);
                AddIntellisenseFileMenu intellisenseFile    = new AddIntellisenseFileMenu(DTE, mcs);
                UnusedCssMenu           unusedCssMenu       = new UnusedCssMenu(mcs);
                PixelPushingMenu        pixelPushingMenu    = new PixelPushingMenu(mcs);
                ReferenceJsMenu         referenceJsMenu     = new ReferenceJsMenu(mcs);
                CompressImageMenu       compressImageMenu   = new CompressImageMenu(mcs);
                SpriteImageMenu         spriteImageMenu     = new SpriteImageMenu(DTE, mcs);
                UnminifyMenu            unMinifyMenu        = new UnminifyMenu(mcs);
                //ChainCompilationMenu chainCompilationMenu = new ChainCompilationMenu(DTE, mcs);

                HandleMenuVisibility(mcs);
                referenceJsMenu.SetupCommands();
                pixelPushingMenu.SetupCommands();
                unusedCssMenu.SetupCommands();
                intellisenseFile.SetupCommands();
                markdownMenu.SetupCommands();
                handlebarsMenu.SetupCommands();
                buildMenu.SetupCommands();
                solutionColorsMenu.SetupCommands();
                projectSettingsMenu.SetupCommands();
                jsHintMenu.SetupCommands();
                tsLintMenu.SetupCommands();
                hubsT4Menu.SetupCommands();
                coffeeLintMenu.SetupCommands();
                jsCodeStyleMenu.SetupCommands();
                rtlCssMenu.SetupCommands();
                cson.SetupCommands();
                bundleMenu.SetupCommands();
                minifyMenu.SetupCommands();
                diffMenu.SetupCommands();
                transform.SetupCommands();
                compressImageMenu.SetupCommands();
                spriteImageMenu.SetupCommands();
                unMinifyMenu.SetupCommands();
                //chainCompilationMenu.SetupCommands();
            }

            IconRegistration.RegisterIcons();

            // Hook up event handlers
            await Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
            {
                DTE.Events.BuildEvents.OnBuildDone += BuildEvents_OnBuildDone;
                DTE.Events.SolutionEvents.Opened += delegate { SettingsStore.Load(); ShowTopMenu(); };
                DTE.Events.SolutionEvents.AfterClosing += delegate { DTE.StatusBar.Clear(); ShowTopMenu(); };
            }), DispatcherPriority.ApplicationIdle, null);
        }