MiniME.Compiler.Compile C# (CSharp) Méthode

Compile() public méthode

public Compile ( ) : void
Résultat void
        public void Compile()
        {
            // Automatic output filename
            if (String.IsNullOrEmpty(OutputFileName) && m_files.Count>0)
            {
                string strFileName = m_files[0].filename;

                int dotpos = strFileName.LastIndexOf('.');
                if (dotpos >= 0)
                    OutputFileName = strFileName.Substring(0, dotpos);

                OutputFileName += ".min.";

                if (MinifyKind == MinifyKind.CSS)
                    OutputFileName += "css";
                else
                    OutputFileName += "js";
            }

            string OptionsFile = OutputFileName + ".minime-options";

            if (!StdOut && CheckFileTimes && File.Exists(OutputFileName))
            {
                // Get the timestamp of the output file
                var dtOutput=System.IO.File.GetLastWriteTimeUtc(OutputFileName);

                // Compare with the timestamp of all the input files
                bool bNeedCompile=false;
                foreach (var f in m_files)
                {
                    if (System.IO.File.GetLastWriteTimeUtc(f.filename) > dtOutput)
                    {
                        bNeedCompile = true;
                        break;
                    }
                }

                // Also check timestamp of any response files used
                if (!bNeedCompile)
                {
                    foreach (var f in m_ResponseFiles)
                    {
                        if (System.IO.File.GetLastWriteTimeUtc(f)> dtOutput)
                        {
                            bNeedCompile = true;
                            break;
                        }
                    }
                }

                // Also check if any options have changed
                if (!bNeedCompile && UseOptionsFile)
                {
                    if (File.Exists(OptionsFile))
                    {
                        string oldOptions = File.ReadAllText(OptionsFile, Encoding.UTF8);

                        int splitpos = oldOptions.IndexOf("included:");

                        string included_files = "";
                        if (splitpos>=0)
                        {
                            included_files = oldOptions.Substring(splitpos + 10);
                            oldOptions = oldOptions.Substring(0, splitpos);
                        }

                        bNeedCompile = oldOptions != CaptureOptions(false);

                        if (!bNeedCompile)
                        {
                            // Check if any included files changed
                            foreach (var f in included_files.Split('\n', '\r'))
                            {
                                try
                                {
                                    if (System.IO.File.GetLastWriteTimeUtc(f) > dtOutput)
                                    {
                                        bNeedCompile = true;
                                        break;
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                    else
                    {
                        bNeedCompile = true;
                    }
                }

                if (!bNeedCompile)
                {
                    Console.WriteLine("Nothing Changed");
                    return;
                }
            }

            // Compile
            string str = CompileToString();

            // StdOut?
            if (StdOut)
            {
                Console.Write(str);
                Console.WriteLine("");
                return;
            }

            // Write
            if (OutputEncoding!=null)
            {
                System.IO.File.WriteAllText(OutputFileName, str, OutputEncoding);
            }
            else
            {
                System.IO.File.WriteAllText(OutputFileName, str);
            }

            // Save options
            if (UseOptionsFile)
            {
                if (CheckFileTimes)
                {
                    // Save options
                    File.WriteAllText(OptionsFile, CaptureOptions(true), Encoding.UTF8);
                }
                else
                {
                    // Delete an old options file
                    if (File.Exists(OptionsFile))
                        File.Delete(OptionsFile);
                }
            }
        }