-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved all template related code and updated README and build scripts.
- Loading branch information
1 parent
8a09ae3
commit b1df6e9
Showing
12 changed files
with
345 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
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,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) |
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 |
---|---|---|
@@ -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). |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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" |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/ | ||
pwsh ./build.ps1 |
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 |
---|---|---|
@@ -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" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace _AppName.Models | ||
|
||
[<CLIMutable>] | ||
type Message = | ||
{ | ||
Text : string | ||
} |
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 |
---|---|---|
@@ -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<IHostingEnvironment>() | ||
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 | ||
|
||
[<EntryPoint>] | ||
let main argv = | ||
let contentRoot = Directory.GetCurrentDirectory() | ||
let webRoot = Path.Combine(contentRoot, "WebRoot") | ||
WebHostBuilder() | ||
.UseKestrel() | ||
.UseContentRoot(contentRoot) | ||
.UseIISIntegration() | ||
.UseWebRoot(webRoot) | ||
.Configure(Action<IApplicationBuilder> configureApp) | ||
.ConfigureServices(configureServices) | ||
.ConfigureLogging(configureLogging) | ||
.Build() | ||
.Run() | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@model _AppName.Models.Message | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Giraffe</title> | ||
</head> | ||
<body> | ||
<div> | ||
<h3>@Model.Text</h3> | ||
</div> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<DebugType>portable</DebugType> | ||
<AssemblyName>_AppName</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<PackageId>_AppName</PackageId> | ||
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion> | ||
<EnableDefaultContentItems>false</EnableDefaultContentItems> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.0.*"/> | ||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.*" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.*" /> | ||
<PackageReference Include="Giraffe" Version="0.1.0-beta-400" /> | ||
<PackageReference Include="Giraffe.Razor" Version="0.1.0-beta-110" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Watch Include="**\*.cshtml" Exclude="bin\**\*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Models\*.fs" /> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="Views\*.cshtml;WebRoot\**\*"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
</Project> |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package> | ||
<metadata> | ||
<id>giraffe-template</id> | ||
<version>0.9.0</version> | ||
<title>Giraffe Template for dotnet-new</title> | ||
<summary>A dotnet-new template for Giraffe web applications.</summary> | ||
<description>A dotnet-new template for Giraffe web applications.</description> | ||
<authors>David Sinclair</authors> | ||
<owners>Dustin Moris Gorski</owners> | ||
<projectUrl>https://github.com/dustinmoris/Giraffe</projectUrl> | ||
<iconUrl>https://raw.githubusercontent.com/dustinmoris/giraffe/master/giraffe-64x64.png</iconUrl> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<releaseNotes></releaseNotes> | ||
<language>en-GB</language> | ||
<tags>giraffe web app razor pages micro service dotnet new template</tags> | ||
<packageTypes> | ||
<packageType name="Template" /> | ||
</packageTypes> | ||
</metadata> | ||
</package> |