예제 #1
0
 protected override bool IsEnabled()
 {
     // Don't minify Markdown
     _spansTuple = TextView.GetSelectedSpan(c => !c.IsOfType("Markdown") &&
                                            Mef.GetImport <IFileMinifier>(c) != null);
     return(_spansTuple != null);
 }
예제 #2
0
        private static void InitiateExecutors()
        {
            var compiler = WebEditor.Host.ExportProvider.GetExport <ProjectCompiler>();

            ThreadingTask.Task.Run(async() =>
            {
                Parallel.ForEach(
                    Mef.GetSupportedContentTypes <ICompilerRunnerProvider>()
                    .Where(c => WESettings.Instance.ForContentType <ICompilerInvocationSettings>(c).CompileOnBuild),
                    c => compiler.Value.CompileSolutionAsync(c).DoNotWait("compiling solution-wide " + c.DisplayName)
                    );

                await BuildMenu.UpdateBundleFiles();
            }).DoNotWait("running solution-wide compilers");

            if (WESettings.Instance.JavaScript.LintOnBuild)
            {
                LintFileInvoker.RunOnAllFilesInProjectAsync(new[] { "*.js" }, f => new JavaScriptLintReporter(new JsHintCompiler(), f))
                .DoNotWait("running solution-wide JSHint");
                LintFileInvoker.RunOnAllFilesInProjectAsync(new[] { "*.js" }, f => new JavaScriptLintReporter(new JsCodeStyleCompiler(), f))
                .DoNotWait("running solution-wide JSCS");
            }

            if (WESettings.Instance.TypeScript.LintOnBuild)
            {
                LintFileInvoker.RunOnAllFilesInProjectAsync(new[] { "*.ts" }, f => new LintReporter(new TsLintCompiler(), WESettings.Instance.TypeScript, f))
                .DoNotWait("running solution-wide TSLint");
            }

            if (WESettings.Instance.CoffeeScript.LintOnBuild)
            {
                LintFileInvoker.RunOnAllFilesInProjectAsync(new[] { "*.coffee", "*.iced" }, f => new LintReporter(new CoffeeLintCompiler(), WESettings.Instance.CoffeeScript, f))
                .DoNotWait("running solution-wide CoffeeLint");
            }
        }
예제 #3
0
        protected override bool Execute(MinifyCommandId commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (_spansTuple == null)
            {
                return(false);
            }

            var    source = _spansTuple.Item2.GetText();
            string result = Mef.GetImport <IFileMinifier>(_spansTuple.Item2.Snapshot.TextBuffer.ContentType)
                            .MinifyString(source);

            if (result == null)
            {
                return(false); // IFileMinifier already displayed an error
            }
            if (result == source)
            {
                EditorExtensionsPackage.DTE.StatusBar.Text = "The selection is already minified";
                return(false);
            }

            using (EditorExtensionsPackage.UndoContext("Minify"))
                TextView.TextBuffer.Replace(_spansTuple.Item1, result);

            return(true);
        }
예제 #4
0
            public MinifyFileCommand(IContentType contentType, MinifyCommandId id)
            {
                Mef.SatisfyImportsOnce(this);
                ContentType       = contentType;
                _sourceExtensions = FileExtensionRegistry.GetFileExtensionSet(contentType);

                Command = new OleMenuCommand((s, e) => Execute(), new CommandID(CommandGuids.guidMinifyCmdSet, (int)id));
                Command.BeforeQueryStatus += (s, e) => CheckVisible();
            }
예제 #5
0
        private void BuildEvents_OnBuildDone(vsBuildScope Scope, vsBuildAction Action)
        {
            bool success = _dte.Solution.SolutionBuild.LastBuildInfo == 0;

            if (!success)
            {
                string text = _dte.StatusBar.Text; // respect localization of "Build failed"
                Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                {
                    _dte.StatusBar.Text = text;
                }), DispatcherPriority.ApplicationIdle, null);

                return;
            }

            if (Action != vsBuildAction.vsBuildActionClean)
            {
                var compiler = WebEditor.Host.ExportProvider.GetExport <ProjectCompiler>();
                ThreadingTask.Task.Run(() =>
                {
                    Parallel.ForEach(
                        Mef.GetSupportedContentTypes <ICompilerRunnerProvider>()
                        .Where(c => WESettings.Instance.ForContentType <ICompilerInvocationSettings>(c).CompileOnBuild),
                        c => compiler.Value.CompileSolutionAsync(c).DontWait("compiling solution-wide " + c.DisplayName)
                        );
                    BuildMenu.UpdateBundleFiles();
                }).DontWait("running solution-wide compilers");

                if (WESettings.Instance.JavaScript.LintOnBuild)
                {
                    LintFileInvoker.RunOnAllFilesInProjectAsync(new[] { "*.js" }, f => new JavaScriptLintReporter(new JsHintCompiler(), f))
                    .DontWait("running solution-wide JSHint");
                    LintFileInvoker.RunOnAllFilesInProjectAsync(new[] { "*.js" }, f => new JavaScriptLintReporter(new JsCodeStyleCompiler(), f))
                    .DontWait("running solution-wide JSCS");
                }

                if (WESettings.Instance.TypeScript.LintOnBuild)
                {
                    LintFileInvoker.RunOnAllFilesInProjectAsync(new[] { "*.ts" }, f => new LintReporter(new TsLintCompiler(), WESettings.Instance.TypeScript, f))
                    .DontWait("running solution-wide TSLint");
                }

                if (WESettings.Instance.CoffeeScript.LintOnBuild)
                {
                    LintFileInvoker.RunOnAllFilesInProjectAsync(new[] { "*.coffee", "*.iced" }, f => new LintReporter(new CoffeeLintCompiler(), WESettings.Instance.CoffeeScript, f))
                    .DontWait("running solution-wide CoffeeLint");
                }
            }
            else if (Action == vsBuildAction.vsBuildActionClean)
            {
                LintReporter.Reset();
            }
        }
예제 #6
0
        private static void InitiateExecutors()
        {
            var compiler = WebEditor.Host.ExportProvider.GetExport <ProjectCompiler>();

            Task.Run(() =>
            {
                Parallel.ForEach(
                    Mef.GetSupportedContentTypes <ICompilerRunnerProvider>()
                    .Where(c => { var settings = WESettings.Instance.ForContentType <ICompilerInvocationSettings>(c); return(settings != null && settings.CompileOnBuild); }),
                    c => compiler.Value.CompileSolutionAsync(c).DoNotWait("compiling solution-wide " + c.DisplayName)
                    );
            }).DoNotWait("running solution-wide compilers");

            RunLinters();
            RunBundles();
        }
예제 #7
0
        public async static Task <CssCompilerResult> GenerateResult(string sourceFileName, string targetFileName, string mapFileName, bool isSuccess, string result, IEnumerable <CompilerError> errors)
        {
            CssCompilerResult compilerResult = new CssCompilerResult(sourceFileName, targetFileName, isSuccess, result, errors);

            if (mapFileName == null)
            {
                return(null);
            }

            var extension = Path.GetExtension(sourceFileName).TrimStart('.');

            compilerResult.SourceMap = CssSourceMap.Create(await FileHelpers.ReadAllTextRetry(targetFileName),
                                                           await FileHelpers.ReadAllTextRetry(mapFileName),
                                                           Path.GetDirectoryName(targetFileName),
                                                           Mef.GetContentType(extension));

            return(compilerResult);
        }
예제 #8
0
        private async static Threading.Task WriteMinFile(string bundleSourcePath, string extension, bool bundleChanged)
        {
            string minPath = Path.ChangeExtension(bundleSourcePath, ".min" + Path.GetExtension(bundleSourcePath));

            // If the bundle didn't change, don't re-minify, unless the user just enabled minification.
            if (!bundleChanged && File.Exists(minPath))
            {
                return;
            }

            var  fers        = WebEditor.ExportProvider.GetExport <IFileExtensionRegistryService>().Value;
            var  contentType = fers.GetContentTypeForExtension(extension);
            var  settings    = WESettings.Instance.ForContentType <IMinifierSettings>(contentType);
            var  minifier    = Mef.GetImport <IFileMinifier>(contentType);
            bool changed     = await minifier.MinifyFile(bundleSourcePath, minPath);

            if (settings.GzipMinifiedFiles && (changed || !File.Exists(minPath + ".gzip")))
            {
                FileHelpers.GzipFile(minPath);
            }
        }
예제 #9
0
파일: BuildMenu.cs 프로젝트: waodng/VSIX
        private async Task Minify()
        {
            _dte.StatusBar.Text = "Web Essentials: Minifying files...";
            var extensions = new HashSet <string>(
                Mef.GetSupportedExtensions <IFileMinifier>(),
                StringComparer.OrdinalIgnoreCase
                );

            var files = ProjectHelpers.GetAllProjects()
                        .Select(ProjectHelpers.GetRootFolder)
                        .SelectMany(p => Directory.EnumerateFiles(p, "*", SearchOption.AllDirectories))
                        .Where(f => extensions.Contains(Path.GetExtension(f)));

            await Task.WhenAll(files.AsParallel().Select(async file =>
                                                         await MinificationSaveListener.ReMinify(
                                                             FileExtensionRegistry.GetContentTypeForExtension(Path.GetExtension(file).TrimStart('.')),
                                                             file,
                                                             false
                                                             )));

            WebEssentialsPackage.DTE.StatusBar.Clear();
        }
예제 #10
0
        private void Minify()
        {
            _dte.StatusBar.Text = "Web Essentials: Minifying files...";
            var extensions = new HashSet <string>(
                Mef.GetSupportedExtensions <IFileMinifier>(),
                StringComparer.OrdinalIgnoreCase
                );

            var files = ProjectHelpers.GetAllProjects()
                        .Select(ProjectHelpers.GetRootFolder)
                        .SelectMany(p => Directory.EnumerateFiles(p, "*", SearchOption.AllDirectories))
                        .Where(f => extensions.Contains(Path.GetExtension(f)));

            // Perform expensive blocking work in parallel
            Parallel.ForEach(files, file =>
                             MinificationSaveListener.ReMinify(
                                 ContentTypeManager.GetContentType(Path.GetExtension(file).TrimStart('.')),
                                 file,
                                 false
                                 )
                             );

            EditorExtensionsPackage.DTE.StatusBar.Clear();
        }
예제 #11
0
 protected CompilingMarginBase(IMarginSettings settings, ITextDocument document)
     : base(settings, document)
 {
     Notifier = Mef.GetImport <ICompilationNotifierProvider>(Document.TextBuffer.ContentType).GetCompilationNotifier(document);
     Notifier.CompilationReady += (s, e) => UpdateMargin(e.CompilerResult);
 }
예제 #12
0
        public static CssCompilerResult GenerateResult(string sourceFileName, string targetFileName, string mapFileName, bool isSuccess, string result, string resultMap, IEnumerable <CompilerError> errors, string rtlSourceFileName, string rtlTargetFileName, string rtlMapFileName, string rtlResult, string rtlResultMap, bool hasSkipped = false)
        {
            CssCompilerResult compilerResult = new CssCompilerResult(sourceFileName, targetFileName, mapFileName, isSuccess, result, resultMap, errors, hasSkipped, rtlSourceFileName, rtlTargetFileName, rtlMapFileName, rtlResult, rtlResultMap);

            if (mapFileName == null)
            {
                return(compilerResult);
            }

            string extension = Path.GetExtension(sourceFileName).TrimStart('.');

            compilerResult.SourceMap = CssSourceMap.Create(result, resultMap, Path.GetDirectoryName(targetFileName), Mef.GetContentType(extension));

            return(compilerResult);
        }
예제 #13
0
 public BuildMenu(DTE2 dte, OleMenuCommandService mcs)
 {
     Mef.SatisfyImportsOnce(this);
     _dte = dte;
     _mcs = mcs;
 }