コード例 #1
0
        public void WithPreprocessorFiles()
        {
            var preprocessingConfig = new PreprocessingConfig(XElement.Parse("<Preprocessing><Engines>sass</Engines></Preprocessing>"));

            var sourceDirectory   = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\AssemblerActivityTest\");
            var assemblerActivity = new AssemblerActivity(new WebGreaseContext(new WebGreaseConfiguration()));

            assemblerActivity.PreprocessingConfig = preprocessingConfig;

            assemblerActivity.Inputs.Add(new InputSpec {
                Path = Path.Combine(sourceDirectory, @"Input\Case4\Stylesheet1.scss")
            });
            assemblerActivity.Inputs.Add(new InputSpec {
                Path = Path.Combine(sourceDirectory, @"Input\Case4\Stylesheet2.css")
            });
            assemblerActivity.OutputFile = Path.Combine(sourceDirectory, @"Output\Case4\case4.css");
            assemblerActivity.Execute();

            // Assertions
            var outputFilePath = assemblerActivity.OutputFile;

            Assert.IsTrue(File.Exists(outputFilePath));
            var text = File.ReadAllText(outputFilePath);

            Assert.IsTrue(!string.IsNullOrWhiteSpace(text));
            Assert.IsTrue(text.Contains("Stylesheet1.scss  */"));
            Assert.IsTrue(text.Contains("font-size: %MetroSdk.BaseFontSize%;"));
            Assert.IsTrue(text.Contains("@media screen and (min-width: %MetroSdk.Mq.MinWidth%) and (max-width: %MetroSdk.Mq.MaxWidth%) {"));
            Assert.IsTrue(text.Contains("Stylesheet2.css  */"));
            Assert.IsTrue(text.Contains(".asome {\r\n    color: blue;\r\n}"));
        }
コード例 #2
0
        public void OnlyDirectories()
        {
            var sourceDirectory   = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\AssemblerActivityTest");
            var assemblerActivity = new AssemblerActivity(new WebGreaseContext(new WebGreaseConfiguration()));

            assemblerActivity.Inputs.Add(new InputSpec {
                Path = Path.Combine(sourceDirectory, @"Input\Case2\a")
            });
            assemblerActivity.Inputs.Add(new InputSpec {
                Path = Path.Combine(sourceDirectory, @"Input\Case2\b")
            });
            assemblerActivity.OutputFile = Path.Combine(sourceDirectory, @"Output\Case2\all.js");
            assemblerActivity.Execute();

            // Assertions
            var outputFilePath = assemblerActivity.OutputFile;

            Assert.IsTrue(File.Exists(outputFilePath));
            var text = File.ReadAllText(outputFilePath);

            Assert.IsTrue(!string.IsNullOrWhiteSpace(text));
            Assert.IsTrue(text.Contains("var name = \"script1.js\";"));
            Assert.IsTrue(text.Contains("var name = \"script2.js\";"));
            Assert.IsTrue(text.Contains("var name = \"script3.js\";"));
        }
コード例 #3
0
        public void DirectoriesWithWildCards()
        {
            var sourceDirectory   = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\AssemblerActivityTest");
            var assemblerActivity = new AssemblerActivity(new WebGreaseContext(new WebGreaseConfiguration()));

            assemblerActivity.Inputs.Add(new InputSpec {
                Path = Path.Combine(sourceDirectory, @"Input\Case3\a"), SearchPattern = "script*.js"
            });
            assemblerActivity.Inputs.Add(new InputSpec {
                Path = Path.Combine(sourceDirectory, @"Input\Case3\b"), SearchPattern = "script*.js"
            });
            assemblerActivity.Inputs.Add(new InputSpec {
                Path = Path.Combine(sourceDirectory, @"Input\Case3\d"), SearchPattern = "script*.js", SearchOption = SearchOption.TopDirectoryOnly
            });
            assemblerActivity.OutputFile = Path.Combine(sourceDirectory, @"Output\Case3\all.js");
            assemblerActivity.Execute();

            // Assertions
            var outputFilePath = assemblerActivity.OutputFile;

            Assert.IsTrue(File.Exists(outputFilePath));
            var text = File.ReadAllText(outputFilePath);

            Assert.IsTrue(!string.IsNullOrWhiteSpace(text));
            Assert.IsTrue(text.Contains("var name = \"script1.js\";"));
            Assert.IsTrue(text.Contains("var name = \"script2.js\";"));
            Assert.IsTrue(text.Contains("var name = \"script3.js\";"));
            Assert.IsFalse(text.Contains("var name = \"script4.js\";"));
            Assert.IsFalse(text.Contains("var name = \"script5.js\";"));
            Assert.IsTrue(text.Contains("var name = \"script6.js\";"));
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ymf1/webgrease
        private static void ExecuteBundling(IWebGreaseContext context)
        {
            var assembler = new AssemblerActivity(context);

            // CSS filesets should not append semicolons between files, nor use single-line comments
            assembler.AddSemicolons = false;

            foreach (var fileSet in context.Configuration.CssFileSets.Where(file => file.InputSpecs.Any() && !file.Output.IsNullOrWhitespace()))
            {
                var jsConfig = fileSet.Bundling.GetNamedConfig(context.Configuration.ConfigType);

                if (jsConfig.ShouldBundleFiles)
                {
                    // for each file set (that isn't empty of inputs)
                    // bundle the files, however this can only be done on filesets that have an output value of a file (ie: has an extension)
                    var outputfile = GetOutputFolder(fileSet.Output, context.Configuration.ConfigType);

                    if (Path.GetExtension(outputfile).IsNullOrWhitespace())
                    {
                        Console.WriteLine(ResourceStrings.InvalidBundlingOutputFile, outputfile);
                        continue;
                    }

                    assembler.OutputFile = outputfile;
                    assembler.Inputs.Clear();

                    foreach (var inputSpec in fileSet.InputSpecs)
                    {
                        assembler.Inputs.Add(inputSpec);
                    }

                    try
                    {
                        assembler.Execute();
                    }
                    catch (Exception ex)
                    {
                        HandleError(ex);
                    }
                }
            }

            // JS filesets SHOULD append semicolons between files, and use single-line comments
            assembler.AddSemicolons = true;
            foreach (var fileSet in context.Configuration.JSFileSets.Where(file => file.InputSpecs.Any() && !file.Output.IsNullOrWhitespace()))

            {
                var cssConfig = fileSet.Bundling.GetNamedConfig(context.Configuration.ConfigType);

                if (cssConfig.ShouldBundleFiles)
                {
                    // for each file set (that isn't empty of inputs)
                    // bundle the files, however this can only be done on filesets that have an output value of a file (ie: has an extension)
                    var outputfile = GetOutputFolder(fileSet.Output, context.Configuration.DestinationDirectory);

                    if (Path.GetExtension(outputfile).IsNullOrWhitespace())
                    {
                        Console.WriteLine(ResourceStrings.InvalidBundlingOutputFile, outputfile);
                        continue;
                    }

                    assembler.OutputFile = outputfile;
                    assembler.Inputs.Clear();
                    foreach (var inputSpec in fileSet.InputSpecs)
                    {
                        assembler.Inputs.Add(inputSpec);
                    }

                    try
                    {
                        assembler.Execute();
                    }
                    catch (Exception ex)
                    {
                        HandleError(ex);
                    }
                }
            }
        }