diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2125666 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto \ No newline at end of file diff --git a/README.md b/README.md index ac4fa95..6afce8f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,70 @@ -# giraffe-template -A dotnet new template for Giraffe web applications. +# Giraffe Template + +![Giraffe](https://raw.githubusercontent.com/giraffe-fsharp/Giraffe/master/giraffe.png) + +Giraffe web application template for the `dotnet new` command. + +[![NuGet Info](https://buildstats.info/nuget/giraffe-template)](https://www.nuget.org/packages/giraffe-template/) + +## Table of contents + +- [Documentation](#documentation) + - [Installation](#installation) + - [Usage](#usage) + - [Updating the template](#updating-the-template) +- [More information](#more-information) +- [License](#license) + +## Documentation + +### Installation + +The easiest way to install the Giraffe template is by running the following command in your terminal: + +``` +dotnet new -i "giraffe-template::*" +``` + +This will pull and install the [giraffe-template NuGet package](https://www.nuget.org/packages/giraffe-template/) in your .NET environment and make it available to subsequent `dotnet new` commands. + +### Usage + +After the template has been installed you can create a new Giraffe web application by simply running `dotnet new giraffe` in your terminal: + +``` +dotnet new giraffe +``` + +After successfully running this command you should be able to restore, build and run your Giraffe web application without any further doing: + +##### Windows example: + +``` +mkdir GiraffeSampleApp +cd GiraffeSampleApp + +dotnet new giraffe + +dotnet restore +dotnet build +dotnet run +``` + + +### Updating the template + +Whenever there is a new version of the Giraffe template you can update it by re-running the [instructions from the installation](#installation). + +You can also explicitly set the version when installing the template: + +``` +dotnet new -i "giraffe-template::0.9.0" +``` + +## More information + +For more information about Giraffe, how to set up a development environment, contribution guidelines and more please visit the [main documentation](https://github.com/giraffe-fsharp/Giraffe#table-of-contents) page. + +## License + +[Apache 2.0](https://raw.githubusercontent.com/giraffe-fsharp/Giraffe.DotLiquid/master/LICENSE) \ No newline at end of file diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md new file mode 100644 index 0000000..73ec77e --- /dev/null +++ b/RELEASE_NOTES.md @@ -0,0 +1,6 @@ +Release Notes +============= + +## 0.9.0 and before + +Previous releases of this library were documented in [Giraffe's release notes](https://github.com/giraffe-fsharp/Giraffe/blob/master/RELEASE_NOTES.md). \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..b63a471 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,24 @@ +version: 0.1.0-{build} +image: Visual Studio 2017 +environment: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 +init: + - git config --global core.autocrlf true +build: off +build_script: + - ps: .\build.ps1 +test: off +artifacts: + - path: '**\giraffe-template.*.nupkg' + name: Giraffe Template package +nuget: + account_feed: true + project_feed: false +deploy: + provider: NuGet + api_key: + secure: +XDgIu4Tmln7LKedNmQgMFnyKTxxuCKFRK3V5oKEfwZiakPXRd5C7OueEGBL50oh + skip_symbols: false + artifact: /.*\.nupkg/ + on: + appveyor_repo_tag: true \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..ad3532b --- /dev/null +++ b/build.ps1 @@ -0,0 +1,69 @@ +# ---------------------------------------------- +# Build script +# ---------------------------------------------- + +$ErrorActionPreference = "Stop" + +# ---------------------------------------------- +# Helper functions +# ---------------------------------------------- + +function Test-IsWindows +{ + [environment]::OSVersion.Platform -ne "Unix" +} + +function Invoke-Cmd ($cmd) +{ + Write-Host $cmd -ForegroundColor DarkCyan + if (Test-IsWindows) { $cmd = "cmd.exe /C $cmd" } + Invoke-Expression -Command $cmd + if ($LastExitCode -ne 0) { Write-Error "An error occured when executing '$cmd'."; return } +} + +function Test-Version ($project) +{ + if ($env:APPVEYOR_REPO_TAG -eq $true) + { + Write-Host "Matching version against git tag..." -ForegroundColor Magenta + + [xml] $xml = Get-Content $project + [string] $version = $xml.package.metadata.version + [string] $gitTag = $env:APPVEYOR_REPO_TAG_NAME + + Write-Host "Project version: $version" -ForegroundColor Cyan + Write-Host "Git tag version: $gitTag" -ForegroundColor Cyan + + if (!$gitTag.EndsWith($version)) + { + Write-Error "Version and Git tag do not match." + } + } +} + +function Update-AppVeyorBuildVersion ($project) +{ + if ($env:APPVEYOR -eq $true) + { + Write-Host "Updating AppVeyor build version..." -ForegroundColor Magenta + + [xml]$xml = Get-Content $project + $version = $xml.package.metadata.version + $buildVersion = "$version-$env:APPVEYOR_BUILD_NUMBER" + Write-Host "Setting AppVeyor build version to $buildVersion." + Update-AppveyorBuild -Version $buildVersion + } +} + +# ---------------------------------------------- +# Main +# ---------------------------------------------- + +$nuspec = ".\src\giraffe-template.nuspec" + +Update-AppVeyorBuildVersion $nuspec +Test-Version $nuspec + +Write-Host "Building giraffe-template package..." -ForegroundColor Magenta + +Invoke-Cmd "nuget pack src/giraffe-template.nuspec" \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..b8e46ef --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/ +pwsh ./build.ps1 \ No newline at end of file diff --git a/src/content/.template.config/template.json b/src/content/.template.config/template.json new file mode 100644 index 0000000..2656443 --- /dev/null +++ b/src/content/.template.config/template.json @@ -0,0 +1,11 @@ +{ + "identity": "Giraffe.Template", + "author": "David Sinclair and contributors", + "classifications": [ "Web", "Giraffe", "ASP.NET", "ASP.NET Core" ], + "name": "Giraffe Web App", + "tags": { + "language": "F#" + }, + "shortName": "giraffe", + "sourceName": "_AppName" +} \ No newline at end of file diff --git a/src/content/Models/Message.fs b/src/content/Models/Message.fs new file mode 100644 index 0000000..ff0b9be --- /dev/null +++ b/src/content/Models/Message.fs @@ -0,0 +1,7 @@ +namespace _AppName.Models + +[] +type Message = + { + Text : string + } \ No newline at end of file diff --git a/src/content/Program.fs b/src/content/Program.fs new file mode 100644 index 0000000..3593a64 --- /dev/null +++ b/src/content/Program.fs @@ -0,0 +1,74 @@ +module _AppName.App + +open System +open System.IO +open System.Collections.Generic +open Microsoft.AspNetCore.Builder +open Microsoft.AspNetCore.Cors.Infrastructure +open Microsoft.AspNetCore.Hosting +open Microsoft.AspNetCore.Http +open Microsoft.Extensions.Logging +open Microsoft.Extensions.DependencyInjection +open Giraffe +open Giraffe.Razor +open _AppName.Models + +// --------------------------------- +// Web app +// --------------------------------- + +let webApp = + choose [ + GET >=> + choose [ + route "/" >=> razorHtmlView "Index" { Text = "Hello world, from Giraffe!" } + ] + setStatusCode 404 >=> text "Not Found" ] + +// --------------------------------- +// Error handler +// --------------------------------- + +let errorHandler (ex : Exception) (logger : ILogger) = + logger.LogError(EventId(), ex, "An unhandled exception has occurred while executing the request.") + clearResponse >=> setStatusCode 500 >=> text ex.Message + +// --------------------------------- +// Config and Main +// --------------------------------- + +let configureCors (builder : CorsPolicyBuilder) = + builder.WithOrigins("http://localhost:8080").AllowAnyMethod().AllowAnyHeader() |> ignore + +let configureApp (app : IApplicationBuilder) = + app.UseCors(configureCors) + .UseGiraffeErrorHandler(errorHandler) + .UseStaticFiles() + .UseGiraffe(webApp) + +let configureServices (services : IServiceCollection) = + let sp = services.BuildServiceProvider() + let env = sp.GetService() + let viewsFolderPath = Path.Combine(env.ContentRootPath, "Views") + services.AddRazorEngine viewsFolderPath |> ignore + services.AddCors() |> ignore + +let configureLogging (builder : ILoggingBuilder) = + let filter (l : LogLevel) = l.Equals LogLevel.Error + builder.AddFilter(filter).AddConsole().AddDebug() |> ignore + +[] +let main argv = + let contentRoot = Directory.GetCurrentDirectory() + let webRoot = Path.Combine(contentRoot, "WebRoot") + WebHostBuilder() + .UseKestrel() + .UseContentRoot(contentRoot) + .UseIISIntegration() + .UseWebRoot(webRoot) + .Configure(Action configureApp) + .ConfigureServices(configureServices) + .ConfigureLogging(configureLogging) + .Build() + .Run() + 0 \ No newline at end of file diff --git a/src/content/Views/Index.cshtml b/src/content/Views/Index.cshtml new file mode 100644 index 0000000..35cf356 --- /dev/null +++ b/src/content/Views/Index.cshtml @@ -0,0 +1,13 @@ +@model _AppName.Models.Message + + + + + Giraffe + + +
+

@Model.Text

+
+ + \ No newline at end of file diff --git a/src/content/_AppName.fsproj b/src/content/_AppName.fsproj new file mode 100644 index 0000000..c867d6e --- /dev/null +++ b/src/content/_AppName.fsproj @@ -0,0 +1,47 @@ + + + + netcoreapp2.0 + portable + _AppName + Exe + _AppName + 2.0.0 + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + \ No newline at end of file diff --git a/src/giraffe-template.nuspec b/src/giraffe-template.nuspec new file mode 100644 index 0000000..e19c73a --- /dev/null +++ b/src/giraffe-template.nuspec @@ -0,0 +1,21 @@ + + + + giraffe-template + 0.9.0 + Giraffe Template for dotnet-new + A dotnet-new template for Giraffe web applications. + A dotnet-new template for Giraffe web applications. + David Sinclair + Dustin Moris Gorski + https://github.com/dustinmoris/Giraffe + https://raw.githubusercontent.com/dustinmoris/giraffe/master/giraffe-64x64.png + false + + en-GB + giraffe web app razor pages micro service dotnet new template + + + + + \ No newline at end of file