This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable running for path or current directory.
- Loading branch information
Paul Johnson
committed
Nov 28, 2021
1 parent
70d58c4
commit eb46be4
Showing
7 changed files
with
64 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,71 @@ | ||
using System; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.IO; | ||
using System.Reflection; | ||
using Lamar.Microsoft.DependencyInjection; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Umbraco.Docs.Preview.App.Options; | ||
|
||
namespace Umbraco.Docs.Preview.App | ||
{ | ||
public class Program | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
var directory = Directory.GetCurrentDirectory(); | ||
if (!File.Exists(Path.Combine(directory, "index.md"))) | ||
var rootCommand = new RootCommand | ||
{ | ||
Console.Error.WriteLine("Fatal Error: current directory doesn't appear to be the UmbracoDocs repo."); | ||
return -1; | ||
} | ||
|
||
CreateHostBuilder(args) | ||
.Build() | ||
.Run(); | ||
new Argument | ||
{ | ||
Name = "path", | ||
Arity = new ArgumentArity(0, 1), | ||
Description = "Path to UmbracoDocs repository." | ||
} | ||
}; | ||
rootCommand.Name = "umbracodocs"; | ||
rootCommand.Description = "Run UmbracoDocs preview server"; | ||
rootCommand.Handler = CommandHandler.Create<string>(RunServer); | ||
|
||
return 0; | ||
return rootCommand.Invoke(args); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) | ||
private static int RunServer(string path = null) | ||
{ | ||
// dotnet tools configure cwd as you would expect, but Host.CreateDefaultBuilder isn't expecting that | ||
// to be miles away from appsettings.json and wwwroot etc. | ||
// So more config, less convention for ContentRoot | ||
var applicationFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
path ??= Directory.GetCurrentDirectory(); | ||
|
||
var docsAbsolutePath = Path.GetFullPath(path); | ||
|
||
|
||
if (!File.Exists(Path.Combine(docsAbsolutePath!, "index.md"))) | ||
{ | ||
Console.Error.WriteLine("Fatal Error: current directory doesn't appear to be the UmbracoDocs repo."); | ||
return -1; | ||
} | ||
|
||
return Host.CreateDefaultBuilder(args) | ||
.UseContentRoot(applicationFolder) | ||
Host.CreateDefaultBuilder(new[] { path }) | ||
#if !DEBUG | ||
// dotnet tools configures cwd as you would expect, but Host.CreateDefaultBuilder isn't expecting that | ||
// to be miles away from appsettings.json and wwwroot etc. | ||
// So more prefer configuration over convention for ContentRoot (unless debugging). | ||
.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) | ||
#endif | ||
.UseLamar() | ||
.UseConsoleLifetime() | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
#if !DEBUG | ||
webBuilder.UseEnvironment("Production"); | ||
#endif | ||
webBuilder.ConfigureServices(services => | ||
{ | ||
services.Configure<UmbracoDocsOptions>(cfg => cfg.UmbracoDocsRootFolder = docsAbsolutePath); | ||
}); | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
|
||
}) | ||
.Build() | ||
.Run(); | ||
|
||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=appsettings/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Sitemap/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Umbraco/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Umbraco/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=umbracodocs/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |