Esempio n. 1
0
        private static void Push2Git(string projectPath)
        {
            Console.WriteLine("Would you like to update changes to git? y(yes)|n(no) [Default:yes]");
            var answer = Console.ReadLine()?.Trim()?.ToLower();

            if (string.Equals(answer, "n") || string.Equals(answer, "no"))
            {
                return;
            }

            Console.WriteLine("Please enter your changes log.");
            var msg = Console.ReadLine()?.Trim();

            ShellHelper.ExecuteFile("publish_git_osx.sh", $"{projectPath} {msg}", true);
        }
Esempio n. 2
0
        private static bool PublishOneBook(string book, string siteMap)
        {
            try
            {
                //build book
                var success = ShellHelper.ExecuteFile("publish_build_osx.sh", book, true);
                if (!success)
                {
                    return(false);
                }

                //read new items
                var bookName = book.GetFileName();
                var map      = book + GitbookSiteMapPath;
                if (!File.Exists(map))
                {
                    Console.WriteLine($"Warn. {bookName} has no sitemap.xml");
                    return(true);
                }

                var root  = XDocument.Load(map).Root;
                var xmlns = root?.Attribute("xmlns");
                string GetXElementFullName(string shortName) => $"{{{xmlns?.Value}}}{shortName}";

                var urls = root?.Elements(GetXElementFullName("url"));
                if (urls == null || !urls.Any())
                {
                    return(true);
                }


                //clear history
                var lines = File.ReadAllLines(siteMap).ToList();
                var begin = lines.IndexOf(lines.FirstOrDefault(l => l.Contains($"{bookName} begin")));
                var end   = lines.IndexOf(lines.FirstOrDefault(l => l.Contains($"{bookName} end")));
                if (begin > 0 && end > begin)
                {
                    lines.RemoveRange(begin, end - begin + 1);
                }


                //insert new items
                begin = begin > 0 ? begin : lines.IndexOf(lines.FirstOrDefault(l => l.Contains($"</urlset>")));
                lines.Insert(begin,
                             $"<!-- {bookName} begin: {urls.Count() - 1} links with priority=0.6, changefreq=monthly -->");
                for (var i = 1; i < urls.Count(); i++)
                {
                    //edit new item
                    var url = urls.ElementAt(i);
                    var loc = url.Element(GetXElementFullName("loc"));
                    loc?.SetValue(Regex.Replace(loc?.Value, "(https?://.+?)/", $"$1/{bookName}/"));
                    url.Element(GetXElementFullName("changefreq"))?.SetValue(ChangeFreq);
                    url.Element(GetXElementFullName("priority"))?.SetValue(Priority);

                    lines.Insert(begin + i,
                                 url.ToString().Replace(" " + xmlns?.ToString(), string.Empty));
                }

                lines.Insert(begin + urls.Count(), $"<!-- {bookName} end -->");
                File.WriteAllLines(siteMap, lines);

                //deploy book
                success = ShellHelper.ExecuteFile("publish_deploy_osx.sh",
                                                  $"{map} {Path.GetDirectoryName(map)} {bookName}", true);

                return(success);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 3
0
 static bool ExecuteScriptFile()
 {
     return(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
         ? ShellHelper.ExecuteFile("win.bat", "C:\\", true)
         : ShellHelper.ExecuteFile("linux-mac.sh", "-lh", true));
 }