Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        private void ProceedBakeSite()
        {
            Log.LogInformation("Executing pre-build tasks");
            {
                var prebuildCmds = BuildConfig.BeforeBuild;
                if (prebuildCmds.Count > 0)
                {
                    if (!SkipPreBuild)
                    {
                        Log.LogInformation("Executing commands scheduled to run before build");
                        foreach (var cmd in prebuildCmds)
                        {
                            Log.LogInformation(cmd);
                            var exitCode = ShellHelper.Run(cmd);

                            if (exitCode != 0)
                            {
                                Environment.Exit(exitCode);
                            }
                        }
                    }
                    else
                    {
                        Log.LogWarning("The pre-build tasks have been requested to be skipped.");
                    }
                }

                SiteObject.PreBuild();
            }

            Log.LogInformation("Building site content");
            SiteObject.Build();

            Log.LogInformation("Executing post-build tasks");
            SiteObject.PostBuild();
        }