Exemple #1
0
 static void DeleteFile(string fileName)
 {
     if (File.Exists(fileName))
     {
         FileHelpers.RemoveReadonlyFlagFromFile(fileName);
         File.Delete(fileName);
     }
 }
        /// <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);
            }
        }
Exemple #3
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"); };
        }