Skip to content

Commit

Permalink
Dotnet tool release (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttu committed Oct 13, 2018
1 parent bf299ce commit 2041fcb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: csharp
dist: trusty
sudo: required
mono: none
dotnet: 2.1.300
dotnet: 2.1.403
solution: FakeServer.sln
script:
- dotnet restore
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

### [Unreleased]
* Release as a dotnet tool
* Use executable location as a base path for settings files

### [0.7.0] - 2018-09-30
* JWT blacklist to check token identifier from JWT ID (jti)
Expand Down
2 changes: 1 addition & 1 deletion FakeServer.Test/FakeServer.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="JsonFlatFileDataStore" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="WebSocket4Net" Version="0.15.2" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0">
Expand Down
24 changes: 17 additions & 7 deletions FakeServer/FakeServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<PackAsTool>true</PackAsTool>
<IsPackable>true</IsPackable>
<ToolCommandName>fake-server</ToolCommandName>
<PackageId>FakeServer</PackageId>
<Authors>Tomi Tuhkanen</Authors>
<Company />
<Description>Fake JSON Server</Description>
<Version>0.7.0</Version>
<Version>0.8.0-rc</Version>
<PackageProjectUrl>https://github.com/ttu/dotnet-fake-json-server</PackageProjectUrl>
<RepositoryUrl>https://github.com/ttu/dotnet-fake-json-server</RepositoryUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/ttu/dotnet-fake-json-server/master/LICENSE</PackageLicenseUrl>
Expand All @@ -28,29 +32,35 @@
<Content Include="wwwroot\index.html" />
</ItemGroup>-->
<ItemGroup>
<PackageReference Include="GraphQL" Version="2.0.0" />
<PackageReference Include="GraphQL" Version="2.1.0" />
<PackageReference Include="JsonFlatFileDataStore" Version="2.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.4.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.3" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.5.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
<PackageReference Include="Serilog.Settings.Configuration" Version="2.6.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.8.17" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.8.18" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.5.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="authentication.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="datastore.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
Expand Down
7 changes: 4 additions & 3 deletions FakeServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Program

public static IConfiguration Configuration { get; set; }

private static string _defaultStoreFile = "datastore.json";

public static void Main(string[] args)
{
var dictionary = new Dictionary<string, string>();
Expand All @@ -27,7 +29,7 @@ public static void Main(string[] args)

dictionary.TryGetValue("--file", out string file);

Console.WriteLine($"File: {file ?? "use default"}");
Console.WriteLine($"File: {file ?? _defaultStoreFile}");

foreach (var kvp in dictionary)
{
Expand All @@ -37,12 +39,11 @@ public static void Main(string[] args)
MainConfiguration.Add("currentPath", Directory.GetCurrentDirectory());

if (!MainConfiguration.ContainsKey("file"))
MainConfiguration.Add("file", file ?? "datastore.json");
MainConfiguration.Add("file", file ?? _defaultStoreFile);

var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";

Configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env}.json", optional: true)
.AddJsonFile("authentication.json", optional: true, reloadOnChange: true)
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Fake JSON Server is a Fake REST API that can be used as a Back End for prototypi

* ASP.NET Core 2.1 / C# 7
* Uses [JSON Flat File Data Store](https://github.com/ttu/json-flatfile-datastore) to store data
* Can be installed as a dotnet global tool [#](#install-as-a-dotnet-global-tool)
* Can be used without .NET
* Docker [#](#docker)
* Self-contained Application [#](#self-contained-application)
Expand All @@ -52,6 +53,7 @@ Fake JSON Server is a Fake REST API that can be used as a Back End for prototypi

- [Get started](#get-started)
+ [Start with .NET CLI](#start-with-net-cli)
+ [Install as a dotnet global tool](#install-as-a-dotnet-global-tool)
+ [Docker](#docker)
+ [Self-contained Application](#self-contained-application)
+ [Quick example](#quick-example)
Expand Down Expand Up @@ -135,6 +137,18 @@ $ dotnet run [--file] [--urls]
$ dotnet run --file data.json --urls http://localhost:57602
```

#### Install as a dotnet global tool

Server can be installed as a [dotnet global tool](https://docs.microsoft.com/en-us/dotnet/core/tools/global-tools). Settings files are then located at `%USERPROFILE%\.dotnet\tools` (_Windows_) and `$HOME/.dotnet/tools` (_Linux/macOS_). By default data stores's JSON file will be created to execution directory.

```sh
# install as a global tool
$ dotnet install --global FakeServer

# Example: Start server
$ fake-server --file data.json --urls http://localhost:57602
```

#### Docker

If you don't have .NET installed, you can run the server with Docker.
Expand Down

0 comments on commit 2041fcb

Please sign in to comment.