private void BuildSite(SiteObject site, bool server) { site.CommandLine.HandleCommonOptions(); if (site.BaseUrl == null || !site.BaseUrlForce) { site.BaseUrl = DefaultBaseUrl; } if (site.BasePath == null || !site.BaseUrlForce) { site.BasePath = string.Empty; } if (!noWatchOption.HasValue()) { if (site.GetLiveReload()) { SetupLiveReloadClient(site); if (server) { SetupLiveReloadServer(); } } site.Build(); if (server) { var watcher = _watcher.Value; watcher.Start(); watcher.FileSystemEvents += (sender, args) => { var newSite = site.Clone(); if (site.CanTrace()) { site.Info($"Received file events [{args.FileEvents.Count}]"); } try { BuildSite(newSite, false); if (newSite.GetLiveReload()) { OnSiteRebuildLiveReload(newSite); } } catch (Exception ex) { site.Error($"Unexpected error while reloading the site. Reason: {ex.GetReason()}"); } }; } } else { site.Build(); } }
public bool TryInstall(SiteObject site, string extend, string version, IFileSystem outputFileSystem) { if (string.IsNullOrWhiteSpace(version)) { version = "master"; } foreach (var themeDesc in FindAll(site)) { var fullVersion = themeDesc.Url + "/archive/" + version + ".zip"; if (themeDesc.Name == extend) { try { if (site.CanInfo()) { site.Info($"Downloading and installing extension/theme `{extend}` to `{outputFileSystem.ConvertPathToInternal(UPath.Root)}`"); } using (HttpClient client = new HttpClient()) { using (var stream = client.GetStreamAsync(fullVersion).Result) { //site.Content.CreateDirectory(new DirectoryEntry(site.FileSystem, outputFileSystem)); using (var zip = new ZipArchive(stream, ZipArchiveMode.Read)) { var indexOfRepoName = themeDesc.Url.LastIndexOf('/'); string repoName = themeDesc.Url.Substring(indexOfRepoName + 1); var directoryInZip = $"{repoName}-{version}/{themeDesc.Directory}"; zip.ExtractToDirectory(new DirectoryEntry(outputFileSystem, UPath.Root), directoryInZip); } return(true); } } } catch (Exception ex) { site.Error($"Unable to load extension/theme from Url [{fullVersion}]. Reason:{ex.GetReason()}"); break; } } } return(false); }