private static void ValidateJsFileSet(JSFileSet fileSet, string[] locales, JsMinificationConfig retailConfig, JsMinificationConfig debugConfig)
        {
            // if the debug config is null, there should only be the retail config
            Assert.IsTrue(fileSet.Minification.Count == (debugConfig == null ? 1 : 2));
            ValidateListIsSame(fileSet.Locales, locales);

            var retail = fileSet.Minification["Retail"];

            Assert.IsNotNull(retail);

            JsMinificationConfig debug;

            if (!fileSet.Minification.TryGetValue("Debug", out debug))
            {
                debug = null;
            }

            if (debugConfig != null)
            {
                Assert.IsNotNull(debug);
            }
            else
            {
                Assert.IsNull(debug);
            }
        }
Example #2
0
        private static void ProcessJsFileSet(MinifyJSActivity jsCruncher, JSFileSet fileSet, string configType, string baseOutputPath)
        {
            var jsConfig = fileSet.Minification.GetNamedConfig(configType);

            if (jsConfig.ShouldMinify)
            {
                foreach (var file in fileSet.InputSpecs.SelectMany(inputSpec => GetFiles(inputSpec.Path, inputSpec.SearchPattern, inputSpec.SearchOption)))
                {
                    // execute minification on each file in the set.

                    // configure settings.
                    jsCruncher.ShouldMinify = jsConfig.ShouldMinify;

                    // if we specified some globals to ignore, format them on the command line with the
                    // other minification arguments
                    if (!string.IsNullOrWhiteSpace(jsConfig.GlobalsToIgnore))
                    {
                        jsCruncher.MinifyArgs = Strings.GlobalsToIgnoreArg + jsConfig.GlobalsToIgnore + ' ' + jsConfig.MinificationArugments;
                    }
                    else
                    {
                        jsCruncher.MinifyArgs = jsConfig.MinificationArugments;
                    }

                    jsCruncher.ShouldAnalyze = false; // we are minimizing, not validating

                    jsCruncher.SourceFile = file;
                    var outputPath = GetOutputFolder(fileSet.Output, baseOutputPath);
                    jsCruncher.DestinationFile = GetOutputFilename(file, outputPath, true);

                    try
                    {
                        // execute
                        jsCruncher.Execute();
                    }
                    catch (Exception ex)
                    {
                        HandleError(ex, file);
                    }
                }
            }
        }
Example #3
0
        /// <summary>Creates the input spec objects based on input and output paths.</summary>
        /// <param name="wgConfig">Config object to use.</param>
        /// <param name="inputPath">Input path from the command parameters</param>
        /// <param name="outputPath">output path from the command parameters</param>
        private static void AddInputSpecs(WebGreaseConfiguration wgConfig, string inputPath, string outputPath)
        {
            if (inputPath.IsNullOrWhitespace() && outputPath.IsNullOrWhitespace())
            {
                // no paths need to be overriden.
                return;
            }

            string outputPathExtension = Path.GetExtension(outputPath);
            string inputPathExtension  = Path.GetExtension(inputPath);

            bool createCssInput = false;
            bool createJsInput  = false;

            // Set the file filter to the extension of the output path (if it's a file)
            if (!outputPathExtension.IsNullOrWhitespace())
            {
                // if the output path is a file we only process css OR js files into it.
                if (outputPathExtension.EndsWith(Strings.Css, StringComparison.OrdinalIgnoreCase))
                {
                    createCssInput = true;
                }
                else
                {
                    createJsInput = true;
                }
            }
            else if (!inputPathExtension.IsNullOrWhitespace())
            {
                // if the input path is not a folder, only set one of the file sets for processing
                if (inputPathExtension.EndsWith(Strings.Css, StringComparison.OrdinalIgnoreCase))
                {
                    createCssInput = true;
                }
                else
                {
                    createJsInput = true;
                }
            }
            else
            {
                // if both the intput and  output path are not a file, assume they are a folder process both JS and CSS files found within.
                createCssInput = true;
                createJsInput  = true;
            }

            var cssFileSet = new CssFileSet();
            var jsFileSet  = new JSFileSet();

            // set or update input specs
            if (createCssInput)
            {
                cssFileSet.InputSpecs.Add(GetInputSpec(inputPath, Strings.CssFilter));
            }

            if (createJsInput)
            {
                if (jsFileSet.InputSpecs.Any())
                {
                    jsFileSet.InputSpecs.Clear();
                }

                jsFileSet.InputSpecs.Add(GetInputSpec(inputPath, Strings.JsFilter));
            }

            // set output spec
            jsFileSet.Output  = outputPath;
            cssFileSet.Output = outputPath;

            wgConfig.JSFileSets.Add(jsFileSet);
            wgConfig.CssFileSets.Add(cssFileSet);
        }