예제 #1
0
        static int Main(params string[] args)
        {
            string configPath = args[0];
            string file = args.Length > 1 ? args[1] : null;
            var configs = GetConfigs(configPath, file);

            if (configs == null)
            {
                Console.WriteLine("\x1B[33mNo configurations matched");
                return 0;
            }

            Telemetry.TrackEvent("Command line");

            ConfigFileProcessor processor = new ConfigFileProcessor();
            EventHookups(processor, configPath);

            var results = processor.Process(configPath, configs);
            var errorResults = results.Where(r => r.HasErrors);

            foreach (var result in errorResults)
                foreach (var error in result.Errors)
                {
                    Console.Write("\x1B[31m" + error.Message);
                }

            return errorResults.Any() ? 1 : 0;
        }
예제 #2
0
        /// <summary>
        /// Execute the Clean Task
        /// </summary>
        public override bool Execute()
        {
            var configFile = new FileInfo(FileName);

            if (!configFile.Exists)
            {
                Log.LogWarning(configFile.FullName + " does not exist");
                return true;
            }

            Log.LogMessage(MessageImportance.High, Environment.NewLine + "WebCompiler: Begin cleaning output of " + configFile.Name);
            Telemetry.SetDeviceName("MSBuild");

            try
            {
                var processor = new ConfigFileProcessor();
                processor.DeleteOutputFiles(configFile.FullName);

                Log.LogMessage(MessageImportance.High, "WebCompiler: Done cleaning output of " + configFile.Name);

                return true;
            }
            catch (Exception ex)
            {
                Log.LogError(ex.Message);
                Telemetry.TrackException(ex);
                return false;
            }
        }
예제 #3
0
        static int Main(params string[] args)
        {
            string configPath = args[0];
            string file       = args.Length > 1 ? args[1] : null;
            var    configs    = GetConfigs(configPath, file);

            if (configs == null)
            {
                Console.WriteLine("\x1B[33mNo configurations matched");
                return(0);
            }

            Telemetry.SetDeviceName("Command line");

            ConfigFileProcessor processor = new ConfigFileProcessor();

            EventHookups(processor, configPath);

            var results      = processor.Process(configPath, configs);
            var errorResults = results.Where(r => r.HasErrors);

            foreach (var result in errorResults)
            {
                foreach (var error in result.Errors)
                {
                    Console.Write("\x1B[31m" + error.Message);
                }
            }

            return(errorResults.Any() ? 1 : 0);
        }
예제 #4
0
        /// <summary>
        /// Execute the Clean Task
        /// </summary>
        public override bool Execute()
        {
            var configFile = new FileInfo(FileName);

            if (!configFile.Exists)
            {
                Log.LogWarning(configFile.FullName + " does not exist");
                return(true);
            }

            Log.LogMessage(MessageImportance.High, Environment.NewLine + "WebCompiler: Begin cleaning output of " + configFile.Name);

            try
            {
                var processor = new ConfigFileProcessor();
                processor.DeleteOutputFiles(configFile.FullName);

                Log.LogMessage(MessageImportance.High, "WebCompiler: Done cleaning output of " + configFile.Name);

                return(true);
            }
            catch (Exception ex)
            {
                Log.LogError(ex.Message);
                return(false);
            }
        }
        /// <summary>
        /// Execute the Task
        /// </summary>
        public override bool Execute()
        {
            FileInfo configFile = new FileInfo(FileName);
            CompilerService.Initialize();

            Log.LogMessage(MessageImportance.High, Environment.NewLine + "WebCompiler: Begin compiling " + configFile.Name);

            if (!configFile.Exists)
            {
                Log.LogWarning(configFile.FullName + " does not exist");
                return true;
            }

            Telemetry.TrackEvent("MSBuild");

            ConfigFileProcessor processor = new ConfigFileProcessor();
            processor.BeforeProcess += (s, e) => { if (e.ContainsChanges) FileHelpers.RemoveReadonlyFlagFromFile(e.Config.GetAbsoluteOutputFile()); };
            processor.AfterProcess += Processor_AfterProcess;
            processor.BeforeWritingSourceMap += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            processor.AfterWritingSourceMap += Processor_AfterWritingSourceMap;

            FileMinifier.BeforeWritingMinFile += (s, e) => { if (e.ContainsChanges) FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            FileMinifier.AfterWritingMinFile += FileMinifier_AfterWritingMinFile;
            FileMinifier.BeforeWritingGzipFile += (s, e) => { if (e.ContainsChanges) FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            FileMinifier.AfterWritingGzipFile += FileMinifier_AfterWritingGzipFile;

            try
            {
                var results = processor.Process(configFile.FullName);
                bool isSuccessful = true;

                foreach (CompilerResult result in results)
                {
                    if (result.HasErrors)
                    {
                        isSuccessful = false;

                        foreach (var error in result.Errors)
                        {
                            Log.LogError("WebCompiler", "0", "", error.FileName, error.LineNumber, error.ColumnNumber, error.LineNumber, error.ColumnNumber, error.Message, null); ;
                        }
                    }
                }

                Log.LogMessage(MessageImportance.High, "WebCompiler: Done compiling " + configFile.Name);
                return isSuccessful;
            }
            catch (Exception ex)
            {
                Log.LogError(ex.Message);
                Telemetry.TrackException(ex);
                return false;
            }
        }
예제 #6
0
        /// <summary>
        /// Execute the Task
        /// </summary>
        public override bool Execute()
        {
            FileInfo configFile = new FileInfo(FileName);

            CompilerService.Initialize();

            Log.LogMessage(MessageImportance.High, Environment.NewLine + "WebCompiler: Begin compiling " + configFile.Name);

            if (!configFile.Exists)
            {
                Log.LogWarning(configFile.FullName + " does not exist");
                return(true);
            }

            ConfigFileProcessor processor = new ConfigFileProcessor();

            processor.BeforeProcess          += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.Config.GetAbsoluteOutputFile()); };
            processor.AfterProcess           += Processor_AfterProcess;
            processor.BeforeWritingSourceMap += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            processor.AfterWritingSourceMap  += Processor_AfterWritingSourceMap;

            FileMinifier.BeforeWritingMinFile  += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            FileMinifier.AfterWritingMinFile   += FileMinifier_AfterWritingMinFile;
            FileMinifier.BeforeWritingGzipFile += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            FileMinifier.AfterWritingGzipFile  += FileMinifier_AfterWritingGzipFile;

            try
            {
                var  results      = processor.Process(configFile.FullName);
                bool isSuccessful = true;

                foreach (CompilerResult result in results)
                {
                    if (result.HasErrors)
                    {
                        isSuccessful = false;

                        foreach (var error in result.Errors)
                        {
                            Log.LogError("WebCompiler", "0", "", error.FileName, error.LineNumber, error.ColumnNumber, error.LineNumber, error.ColumnNumber, error.Message, null);;
                        }
                    }
                }

                Log.LogMessage(MessageImportance.High, "WebCompiler: Done compiling " + configFile.Name);
                return(isSuccessful);
            }
            catch (Exception ex)
            {
                Log.LogError(ex.Message);
                return(false);
            }
        }
예제 #7
0
        private static void EventHookups(ConfigFileProcessor processor, string configPath)
        {
            // For console colors, see http://stackoverflow.com/questions/23975735/what-is-this-u001b9-syntax-of-choosing-what-color-text-appears-on-console

            processor.BeforeProcess += (s, e) => { Console.WriteLine($"Processing \x1B[36m{e.Config.InputFile}"); if (e.ContainsChanges) FileHelpers.RemoveReadonlyFlagFromFile(e.Config.GetAbsoluteOutputFile()); };
            processor.AfterProcess += (s, e) => { Console.WriteLine($"  \x1B[32mCompiled"); };
            processor.BeforeWritingSourceMap += (s, e) => { if (e.ContainsChanges) FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            processor.AfterWritingSourceMap += (s, e) => { Console.WriteLine($"  \x1B[32mSourcemap"); };
            processor.ConfigProcessed += (s, e) => { Console.WriteLine("\t"); };

            FileMinifier.BeforeWritingMinFile += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            FileMinifier.AfterWritingMinFile += (s, e) => { Console.WriteLine($"  \x1B[32mMinified"); };
            FileMinifier.BeforeWritingGzipFile += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            FileMinifier.AfterWritingGzipFile += (s, e) => { Console.WriteLine($"  \x1B[32mGZipped"); };
        }
예제 #8
0
        public void ShouldAppendMinOnlyOnce()
        {
            var configPath = Path.Combine(processingConfigFile, "outputfilemin.json");
            var configs = ConfigHandler.GetConfigs(configPath);
            var outputFile = configs.First().OutputFile;

            // Capture the name of the resulting (minified) file.
            string resultFile = string.Empty;
            FileMinifier.BeforeWritingMinFile += (object sender, MinifyFileEventArgs e) => { resultFile = new FileInfo(e.ResultFile).Name; };

            ConfigFileProcessor processor = new ConfigFileProcessor();
            var results = processor.Process(configPath, configs, force: true);

            Assert.AreEqual(outputFile, resultFile);
        }
예제 #9
0
        private static void EventHookups(ConfigFileProcessor processor, string configPath)
        {
            // For console colors, see http://stackoverflow.com/questions/23975735/what-is-this-u001b9-syntax-of-choosing-what-color-text-appears-on-console

            processor.BeforeProcess          += (s, e) => { Console.WriteLine($"Processing \x1B[36m{e.Config.InputFile}"); FileHelpers.RemoveReadonlyFlagFromFile(e.Config.GetAbsoluteOutputFile()); };
            processor.AfterProcess           += (s, e) => { Console.WriteLine($"  \x1B[32mCompiled"); };
            processor.BeforeWritingSourceMap += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            processor.AfterWritingSourceMap  += (s, e) => { Console.WriteLine($"  \x1B[32mSourcemap"); };
            processor.ConfigProcessed        += (s, e) => { Console.WriteLine("\t"); };

            FileMinifier.BeforeWritingMinFile  += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            FileMinifier.AfterWritingMinFile   += (s, e) => { Console.WriteLine($"  \x1B[32mMinified"); };
            FileMinifier.BeforeWritingGzipFile += (s, e) => { FileHelpers.RemoveReadonlyFlagFromFile(e.ResultFile); };
            FileMinifier.AfterWritingGzipFile  += (s, e) => { Console.WriteLine($"  \x1B[32mGZipped"); };
        }
예제 #10
0
 public void Setup()
 {
     _processor = new ConfigFileProcessor();
 }
예제 #11
0
 public void Setup()
 {
     Telemetry.Enabled = false;
     _processor = new ConfigFileProcessor();
 }