Ejemplo n.º 1
0
        public async Task MinifyFileAsync(MinifiedFile minifiedFile)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var root = Path.GetDirectoryName(Solution.GetFullName());

            var destinationFile = minifiedFile.GetFullOutputPath(root);

            if (!File.Exists(destinationFile))
            {
                InfoBar.NewMessage()
                .WithErrorImage()
                .WithText("The path ")
                .WithText(minifiedFile.OutputFile, underline: true)
                .WithText(" is not valid.")
                .Publish();

                return;
            }

            MinifyResult result = null;

            switch (minifiedFile.MinifyType)
            {
            case MinifyType.CSHtml:
                result = await CSHtmlMinifier.MinifyFileAsync(minifiedFile.GetFullSourcePath(root), destinationFile, ((CsHtmlMinifiedFile)minifiedFile).UsePreMailer);

                break;

            case MinifyType.Js:
                if (!await JsMinifier.TryMinifyFileAsync("esbuild.exe", minifiedFile.GetFullSourcePath(root), destinationFile, ((JsMinifiedFile)minifiedFile).Options))
                {
                    InfoBar.NewMessage()
                    .WithErrorImage()
                    .WithText("The file ")
                    .WithText(minifiedFile.SourceFile, underline: true)
                    .WithText(" contains invalid js.")
                    .Publish();
                }
                break;

            default:
                throw new InvalidOperationException("Please create an issue on GitHub, if this throws.");
            }

            if (result is object && !result.Success)
            {
                InfoBar.NewMessage()
                .WithErrorImage()
                .WithText("The file ")
                .WithText(minifiedFile.SourceFile, underline: true)
                .WithText(" produced warnings. ")
                .WithText(result.Message)
                .Publish();
            }
        }
Ejemplo n.º 2
0
        public void RemoveFromConfigFile(MinifiedFile file)
        {
            Config.RemoveFile(file);

            SetConfigFile(Config.FullName);
        }