Esempio n. 1
0
 public void Build()
 {
     _BuildSucceeded = 0;
     _BuildFailed    = 0;
     _BuildSkipped   = 0;
     try
     {
         // Синхронизира файловете DefinitelyTyped
         SynchDefinitelyTyped(_TypingsPath, _WorkspacePath);
     }
     catch (Exception ex)
     {
         _BuildFailed += 1;
         Console.WriteLine(ex.Message);
     }
     try
     {
         // Компилира проекта
         HCompilerConfig compilerConfig = new HCompilerConfig()
         {
             ProjectName   = "",
             WorkspacePath = _WorkspacePath,
             OutputPath    = _OutputPath
         };
         BuildProject(compilerConfig);
     }
     catch (Exception ex)
     {
         _BuildFailed += 1;
         Console.WriteLine(ex.Message);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Компилира файл
        /// </summary>
        private void BuildFileHTML(string sourceFile, string outputFile, HCompilerConfig compilerConfig)
        {
            // Зарежда страницата
            string sourceCode = "";

            using (TextReader reader = File.OpenText(sourceFile))
            {
                sourceCode = reader.ReadToEnd();
                reader.Close();
            }
            // Взема параметрите от кода
            string viewTitle  = null;
            string viewLayout = null;

            sourceCode = ExtractParameter(sourceCode, "@Title", out viewTitle);
            sourceCode = ExtractParameter(sourceCode, "@Layout", out viewLayout);
            // Валедира параметрите
            // ViewTitle
            if (viewTitle == null)
            {
                viewTitle = compilerConfig.ViewTitle;
            }
            // LayoutPath
            if (!String.IsNullOrWhiteSpace(viewLayout))
            {
                viewLayout = Path.Combine(compilerConfig.WorkspacePath, viewLayout);
            }
            else
            {
                viewLayout = compilerConfig.LayoutPath;
            }
            // Зарежда MasterPage, ако съществува
            if (!String.IsNullOrWhiteSpace(viewLayout) && File.Exists(viewLayout))
            {
                string layoutCode = "";
                using (TextReader reader = File.OpenText(viewLayout))
                {
                    layoutCode = reader.ReadToEnd();
                    reader.Close();
                }
                sourceCode = layoutCode.Replace("@RenderBody()", sourceCode);
            }
            // Добавя заглавие
            sourceCode = sourceCode.Replace("@View.Title", viewTitle);

            // Записва обработената страница
            using (StreamWriter writer = File.CreateText(outputFile))
            {
                writer.Write(sourceCode);
                writer.Flush();
                writer.Close();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Компилира файловете от директория
        /// </summary>
        private void BuildDirectoryFiles(HCompilerConfig compilerConfig)
        {
            string[] srcFilels = Directory.GetFiles(compilerConfig.WorkspacePath);

            foreach (string srcFile in srcFilels)
            {
                string nameFile    = Path.GetFileName(srcFile);
                string nameFileUni = nameFile.ToLower();
                if ((nameFileUni.StartsWith("_")) || (nameFileUni == "hydra.config.json"))
                {
                    _BuildSkipped += 1;
                }
                else if (nameFileUni.EndsWith(".html") || nameFileUni.EndsWith(".htm"))
                {
                    PrintBuildLine(compilerConfig.ProjectName, nameFile);

                    string outFile = Path.Combine(compilerConfig.OutputPath, nameFile);
                    BuildFileHTML(srcFile, outFile, compilerConfig);
                    _BuildSucceeded += 1;
                }
                else if (nameFileUni.EndsWith(".js"))
                {
                    PrintBuildLine(compilerConfig.ProjectName, nameFile);

                    string outFile = Path.Combine(compilerConfig.OutputPath, nameFile);
                    File.Copy(srcFile, outFile, true);
                    _BuildSucceeded += 1;
                }
                else if (nameFileUni.EndsWith(".css"))
                {
                    PrintBuildLine(compilerConfig.ProjectName, nameFile);

                    string outFile = Path.Combine(compilerConfig.OutputPath, nameFile);
                    File.Copy(srcFile, outFile, true);
                    _BuildSucceeded += 1;
                }
                else
                {
                    PrintBuildLine(compilerConfig.ProjectName, nameFile);

                    string outFile = Path.Combine(compilerConfig.OutputPath, nameFile);
                    File.Copy(srcFile, outFile, true);
                    _BuildSucceeded += 1;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Компилира проект
        /// </summary>
        private void BuildProject(HCompilerConfig compilerConfig)
        {
            // Зарежда локалните настройки
            string      hydraConfigPath = Path.Combine(_WorkspacePath, "hydra.config.json");
            HydraConfig hydraConfig     = LoadHydraConfig(hydraConfigPath);

            compilerConfig.SetHydraConfig(hydraConfig);
            // Компилира файловете
            BuildDirectoryFiles(compilerConfig);

            // Компилира подпроектите
            foreach (string srcProject in Directory.GetDirectories(compilerConfig.WorkspacePath))
            {
                string projectName = srcProject.Substring(compilerConfig.WorkspacePath.Length + 1
                                                          , srcProject.Length - compilerConfig.WorkspacePath.Length - 1);

                if (projectName.StartsWith("."))
                {
                    _BuildSkipped += 1;
                }
                else
                {
                    PrintBuildLine(compilerConfig.ProjectName, projectName);

                    HCompilerConfig compilerConfigProject = new HCompilerConfig()
                    {
                        ProjectName = (String.IsNullOrWhiteSpace(compilerConfig.ProjectName) ? "" : compilerConfig.ProjectName + Path.DirectorySeparatorChar)
                                      + projectName,
                        WorkspacePath = srcProject,
                        OutputPath    = Path.Combine(compilerConfig.OutputPath, projectName),
                        LayoutPath    = compilerConfig.LayoutPath,
                        ViewTitle     = compilerConfig.ViewTitle
                    };
                    Directory.CreateDirectory(compilerConfigProject.OutputPath);
                    BuildProject(compilerConfigProject);
                }
            }
        }