From 2041fcb40a6d58565a2fc808766a5b308f302644 Mon Sep 17 00:00:00 2001 From: Tomi Tuhkanen Date: Sun, 14 Oct 2018 00:27:09 +0300 Subject: [PATCH] Dotnet tool release (#32) --- .travis.yml | 2 +- CHANGELOG.md | 2 ++ FakeServer.Test/FakeServer.Test.csproj | 2 +- FakeServer/FakeServer.csproj | 24 +++++++++++++++++------- FakeServer/Program.cs | 7 ++++--- README.md | 14 ++++++++++++++ 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4eda12d..ba25310 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index a3e3741..5c2decd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/FakeServer.Test/FakeServer.Test.csproj b/FakeServer.Test/FakeServer.Test.csproj index 7513306..ff4a364 100644 --- a/FakeServer.Test/FakeServer.Test.csproj +++ b/FakeServer.Test/FakeServer.Test.csproj @@ -14,7 +14,7 @@ - + diff --git a/FakeServer/FakeServer.csproj b/FakeServer/FakeServer.csproj index 6d1b899..f97d290 100644 --- a/FakeServer/FakeServer.csproj +++ b/FakeServer/FakeServer.csproj @@ -3,10 +3,14 @@ netcoreapp2.1 win-x64;osx-x64;linux-x64 + true + true + fake-server + FakeServer Tomi Tuhkanen Fake JSON Server - 0.7.0 + 0.8.0-rc https://github.com/ttu/dotnet-fake-json-server https://github.com/ttu/dotnet-fake-json-server https://raw.githubusercontent.com/ttu/dotnet-fake-json-server/master/LICENSE @@ -28,22 +32,22 @@ --> - + - - + + - + - + - + @@ -51,6 +55,12 @@ + + PreserveNewest + + + PreserveNewest + PreserveNewest PreserveNewest diff --git a/FakeServer/Program.cs b/FakeServer/Program.cs index 915a8b7..1767085 100644 --- a/FakeServer/Program.cs +++ b/FakeServer/Program.cs @@ -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(); @@ -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) { @@ -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) diff --git a/README.md b/README.md index 707f482..2ef9edb 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) @@ -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.