devel: replace FAKE builder with just and nix

This commit is contained in:
2025-12-29 11:10:16 +01:00
parent 9565185fbb
commit fbe9c51f86
21 changed files with 559 additions and 317 deletions

View File

@@ -1,69 +0,0 @@
open Fake.Core
open Fake.IO
open Farmer
open Farmer.Builders
open Helpers
initializeContext()
let srcPath = Path.getFullName "src"
let testPath = Path.getFullName "test"
let libPath = Some srcPath
let deployPath = Path.getFullName "deploy"
let packPath = Path.getFullName "packages"
let versionFile = Path.getFullName ".version"
Target.create "Clean" (fun _ -> Shell.cleanDir deployPath)
Target.create "InstallClient" (fun _ ->
run bun "install" "."
run dotnet "tool restore" "."
)
Target.create "Bundle" (fun _ ->
run dotnet $"publish -c Release -o \"{deployPath}\"" srcPath
)
Target.create "BundleDebug" (fun _ ->
run dotnet $"publish -c Debug -o \"{deployPath}\"" srcPath
)
Target.create "Pack" (fun _ ->
match libPath with
| Some p -> run dotnet $"pack -c Release -o \"{packPath}\"" p
| None -> ()
)
Target.create "Format" (fun _ ->
run dotnet "fantomas . -r" "src"
)
Target.create "Test" (fun _ ->
if System.IO.Directory.Exists testPath then
run dotnet "run" testPath
else ()
)
open Fake.Core.TargetOperators
let dependencies = [
"Clean"
==> "InstallClient"
==> "Bundle"
"Clean"
==> "BundleDebug"
"Clean"
==> "Test"
"Clean"
==> "Pack"
]
[<EntryPoint>]
let main args = runOrDefault args

View File

@@ -1,105 +0,0 @@
module Helpers
open Fake.Core
let initializeContext () =
let execContext = Context.FakeExecutionContext.Create false "build.fsx" [ ]
Context.setExecutionContext (Context.RuntimeContext.Fake execContext)
module Proc =
module Parallel =
open System
let locker = obj()
let colors =
[| ConsoleColor.Blue
ConsoleColor.Yellow
ConsoleColor.Magenta
ConsoleColor.Cyan
ConsoleColor.DarkBlue
ConsoleColor.DarkYellow
ConsoleColor.DarkMagenta
ConsoleColor.DarkCyan |]
let print color (colored: string) (line: string) =
lock locker
(fun () ->
let currentColor = Console.ForegroundColor
Console.ForegroundColor <- color
Console.Write colored
Console.ForegroundColor <- currentColor
Console.WriteLine line)
let onStdout index name (line: string) =
let color = colors.[index % colors.Length]
if isNull line then
print color $"{name}: --- END ---" ""
else if String.isNotNullOrEmpty line then
print color $"{name}: " line
let onStderr name (line: string) =
let color = ConsoleColor.Red
if isNull line |> not then
print color $"{name}: " line
let redirect (index, (name, createProcess)) =
createProcess
|> CreateProcess.redirectOutputIfNotRedirected
|> CreateProcess.withOutputEvents (onStdout index name) (onStderr name)
let printStarting indexed =
for (index, (name, c: CreateProcess<_>)) in indexed do
let color = colors.[index % colors.Length]
let wd =
c.WorkingDirectory
|> Option.defaultValue ""
let exe = c.Command.Executable
let args = c.Command.Arguments.ToStartInfo
print color $"{name}: {wd}> {exe} {args}" ""
let run cs =
cs
|> Seq.toArray
|> Array.indexed
|> fun x -> printStarting x; x
|> Array.map redirect
|> Array.Parallel.map Proc.run
let createProcess exe arg dir =
CreateProcess.fromRawCommandLine exe arg
|> CreateProcess.withWorkingDirectory dir
|> CreateProcess.ensureExitCode
let dotnet = createProcess "dotnet"
let bun =
let bunPath =
match ProcessUtils.tryFindFileOnPath "bun" with
| Some path -> path
| None ->
"bun was not found in path. Please install it and make sure it's available from your path. " +
"See https://safe-stack.github.io/docs/quickstart/#install-pre-requisites for more info"
|> failwith
createProcess bunPath
let run proc arg dir =
proc arg dir
|> Proc.run
|> ignore
let runParallel processes =
processes
|> Proc.Parallel.run
|> ignore
let runOrDefault args =
try
match args with
| [| target |] -> Target.runOrDefault target
| _ ->
Target.runOrDefault "Pack"
0
with e ->
printfn "%A" e
1

View File

@@ -1,20 +0,0 @@
{
"version": 1,
"isRoot": true,
"tools": {
"fable": {
"version": "4.25.0",
"commands": [
"fable"
],
"rollForward": false
},
"fantomas": {
"version": "7.0.3",
"commands": [
"fantomas"
],
"rollForward": false
}
}
}

View File

@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:9.0
FROM mcr.microsoft.com/dotnet/sdk:10.0
# Bun version
ARG BUN_INSTALL=/usr/local

View File

@@ -7,28 +7,38 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
[*.js]
indent_size = 2
max_line_length = 80
[*.scss]
indent_size = 2
max_line_length = 80
[*.nix]
indent_size = 2
max_line_length= 80
[*.scss]
indent_size = 2
max_line_length = 80
[*.fs]
max_line_lengt = 120
# Feliz style
fsharp_single_argument_web_mod = true
fsharp_space_before_colo = false
fsharp_max_if_then_else_short_widt = 60
fsharp_max_infix_operator_expressio = 50
fsharp_max_record_widt = 70
fsharp_max_record_number_of_item = 1
fsharp_max_array_or_list_widt = 70
fsharp_max_array_or_list_number_of_item = 1
fsharp_max_value_binding_widt = 70
fsharp_max_function_binding_widt = 40
fsharp_max_dot_get_expression_widt = 50
fsharp_multiline_block_brackets_on_same_colum = true
max_line_length= 120
fsharp_max_if_then_else_short_width = 60
fsharp_max_infix_operator_expression = 80
fsharp_space_before_uppercase_invocation = true
fsharp_blank_lines_around_nested_multiline_expressions = false
fsharp_newline_between_type_definition_and_members = false
fsharp_multiline_bracket_style = stroustrup
fsharp_newline_before_multiline_computation_expression = true
fsharp_newline_between_type_definition_and_member = false
fsharp_max_elmish_widt = 40
fsharp_align_function_signature_to_indentatio = false
fsharp_alternative_long_member_definition = false
fsharp_multi_line_lambda_closing_newlin = false
fsharp_disable_elmish_synta = false
fsharp_keep_indent_in_branc = false
fsharp_blank_lines_around_nested_multiline_expression = false
fsharp_multi_line_lambda_closing_newline = true
fsharp_array_or_list_multiline_formatter = character_width
fsharp_max_array_or_list_width = 70
fsharp_max_array_or_list_number_of_items = 3
fsharp_record_multiline_formatter = number_of_items
fsharp_max_record_number_of_items = 3
fsharp_max_record_width = 70

View File

@@ -1,11 +1,15 @@
# yaml-language-server: $schema=https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json
variables:
SDK_VERSION: 9.0
SKIP_TESTS: "true"
SKIP_TESTS: "true"
include:
- project: oceanbox/gitlab-ci
ref: v4.1
file: DotnetPackage.gitlab-ci.yml
inputs:
project-name: oceanbox.geojson
project-dir: .
- project: oceanbox/gitlab-ci
ref: v5.0
file: NuGet.gitlab-ci.yml
inputs:
project-name: oceanbox.geojson
project-dir: .
dockerize-fornix:
tags:
- nix

View File

@@ -1,41 +1,39 @@
branches:
- main
- master
- name: develop
prerelease: true
- main
- master
- name: develop
prerelease: true
plugins:
- '@semantic-release/commit-analyzer'
- '@semantic-release/release-notes-generator'
- - '@semantic-release/changelog'
- changelogFile: RELEASE_NOTES.md
changelogTitle: "# Changelog"
- - 'semantic-release-dotnet'
- paths: [ "src/*.fsproj", "src/*/*.fsproj" ]
- - '@semantic-release/exec'
- generateNotesCmd: "echo ${nextRelease.version} > .version"
- - '@semantic-release/git'
- message: "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
assets: [ "RELEASE_NOTES.md", ".version", "src/*.fsproj", "src/*/*.fsproj" ]
- - '@semantic-release/gitlab'
- assets: []
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- - "@semantic-release/changelog"
- changelogFile: RELEASE_NOTES.md
changelogTitle: "# Changelog"
- - "semantic-release-dotnet"
- paths: ["src/*.fsproj", "src/*/*.fsproj"]
- - "@semantic-release/exec"
- generateNotesCmd: "echo ${nextRelease.version} > VERSION"
- - "@semantic-release/git"
- message: "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
assets: ["RELEASE_NOTES.md", "VERSION", "src/*.fsproj", "src/*/*.fsproj"]
- - "@semantic-release/gitlab"
- assets: []
analyzeCommits:
- path: "@semantic-release/commit-analyzer"
releaseRules:
- type: "fix"
release: "patch"
- type: "patch"
release: "patch"
- type: "feat"
release: "minor"
- type: "feature"
release: "minor"
- type: "minor"
release: "minor"
- type: "breaking"
release: "major"
- type: "major"
release: "major"
- path: "@semantic-release/commit-analyzer"
releaseRules:
- type: "fix"
release: "patch"
- type: "patch"
release: "patch"
- type: "feat"
release: "minor"
- type: "feature"
release: "minor"
- type: "minor"
release: "minor"
- type: "breaking"
release: "major"
- type: "major"
release: "major"

View File

@@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include=".build/Helpers.fs" />
<Compile Include=".build/Build.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Fake.Core.Target" Version="6.0.0" />
<PackageReference Include="Fake.DotNet.Cli" Version="6.0.0" />
<PackageReference Include="Fake.IO.FileSystem" Version="6.0.0" />
<PackageReference Include="Farmer" Version="1.8.11" />
</ItemGroup>
</Project>

View File

@@ -9,7 +9,6 @@
<File Path="LICENSE" />
<File Path="README.md" />
</Folder>
<Project Path="Build.fsproj" />
<Project Path="src/Oceanbox.GeoJson.fsproj" />
<Project Path="test/Tests.fsproj" />
</Solution>

View File

View File

@@ -1,5 +1,6 @@
{
"lockfileVersion": 1,
"configVersion": 0,
"workspaces": {
"": {
"devDependencies": {

51
default.nix Normal file
View File

@@ -0,0 +1,51 @@
{
sources ? import ./nix,
system ? builtins.currentSystem,
pkgs ? import sources.nixpkgs { inherit system; },
nix-utils ? import sources.nix-utils { },
}:
let
version =
let
clean = pkgs.lib.removeSuffix "\n";
version = builtins.readFile ./VERSION;
in
clean version;
dotnet-sdk = pkgs.dotnetCorePackages.sdk_10_0;
dotnet-runtime = pkgs.dotnetCorePackages.runtime_10_0;
geojson = pkgs.callPackage ./src {
inherit (nix-utils.output.lib.nuget) deps;
inherit
dotnet-sdk
dotnet-runtime
version
;
};
packages = {
inherit geojson;
};
in
{
default = geojson;
inherit
packages
;
shell = pkgs.mkShell {
packages = with pkgs; [
just
bun
npins
fantomas
fsautocomplete
dotnet-sdk
];
NPINS_DIRECTORY = "nix";
};
}

41
justfile Normal file
View File

@@ -0,0 +1,41 @@
# Install just: https://github.com/casey/just
set dotenv-load
src := "src"
test := "tests"
dist := "dist"
pack := "packages"
# Default recipe - show available commands
default:
@just --list
# Clean build artifacts
clean:
rm -rf {{dist}}
# Build production bundle
bundle: clean
dotnet publish -c Release -o {{dist}} {{src}}
# Build debug bundle
bundle-debug: clean
dotnet publish -c Debug -o {{dist}} {{src}}
# Create NuGet package
pack: clean
dotnet pack -c Release -o {{pack}} {{src}}
# Format code with Fantomas
format:
fantomas {{src}} -r
# Run tests
test: clean
#!/usr/bin/env bash
if [ -d "{{test}}" ]; then
dotnet run {{test}}
fi
# Run (creates package)
run: pack

146
nix/default.nix Normal file
View File

@@ -0,0 +1,146 @@
/*
This file is provided under the MIT licence:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
# Generated by npins. Do not modify; will be overwritten regularly
let
data = builtins.fromJSON (builtins.readFile ./sources.json);
version = data.version;
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
range =
first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
concatMapStrings = f: list: concatStrings (map f list);
concatStrings = builtins.concatStringsSep "";
# If the environment variable NPINS_OVERRIDE_${name} is set, then use
# the path directly as opposed to the fetched source.
# (Taken from Niv for compatibility)
mayOverride =
name: path:
let
envVarName = "NPINS_OVERRIDE_${saneName}";
saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
ersatz = builtins.getEnv envVarName;
in
if ersatz == "" then
path
else
# this turns the string into an actual Nix path (for both absolute and
# relative paths)
builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
if builtins.substring 0 1 ersatz == "/" then
/. + ersatz
else
/. + builtins.getEnv "PWD" + "/${ersatz}"
);
mkSource =
name: spec:
assert spec ? type;
let
path =
if spec.type == "Git" then
mkGitSource spec
else if spec.type == "GitRelease" then
mkGitSource spec
else if spec.type == "PyPi" then
mkPyPiSource spec
else if spec.type == "Channel" then
mkChannelSource spec
else if spec.type == "Tarball" then
mkTarballSource spec
else
builtins.throw "Unknown source type ${spec.type}";
in
spec // { outPath = mayOverride name path; };
mkGitSource =
{
repository,
revision,
url ? null,
submodules,
hash,
branch ? null,
...
}:
assert repository ? type;
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
# In the latter case, there we will always be an url to the tarball
if url != null && !submodules then
builtins.fetchTarball {
inherit url;
sha256 = hash; # FIXME: check nix version & use SRI hashes
}
else
let
url =
if repository.type == "Git" then
repository.url
else if repository.type == "GitHub" then
"https://github.com/${repository.owner}/${repository.repo}.git"
else if repository.type == "GitLab" then
"${repository.server}/${repository.repo_path}.git"
else
throw "Unrecognized repository type ${repository.type}";
urlToName =
url: rev:
let
matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
short = builtins.substring 0 7 rev;
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
in
"${if matched == null then "source" else builtins.head matched}${appendShort}";
name = urlToName url revision;
in
builtins.fetchGit {
rev = revision;
inherit name;
# hash = hash;
inherit url submodules;
};
mkPyPiSource =
{ url, hash, ... }:
builtins.fetchurl {
inherit url;
sha256 = hash;
};
mkChannelSource =
{ url, hash, ... }:
builtins.fetchTarball {
inherit url;
sha256 = hash;
};
mkTarballSource =
{
url,
locked_url ? url,
hash,
...
}:
builtins.fetchTarball {
url = locked_url;
sha256 = hash;
};
in
if version == 5 then
builtins.mapAttrs mkSource data.pins
else
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"

36
nix/sources.json Normal file
View File

@@ -0,0 +1,36 @@
{
"pins": {
"nix-utils": {
"type": "Git",
"repository": {
"type": "Git",
"url": "https://git.sr.ht/~mrtz/nix-utils"
},
"branch": "trunk",
"submodules": false,
"revision": "098f594425d2b9dde0657becad0f6498d074f8b3",
"url": null,
"hash": "0hh52w1fkpr1xx6j8cjm6g88j2352yv2ysqm1q51j59y6f583vyb"
},
"nixpkgs": {
"type": "Channel",
"name": "nixpkgs-unstable",
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.05pre909321.677fbe97984e/nixexprs.tar.xz",
"hash": "0i4jyr0xv8i90gxil1s36yqas4qfnp52bwr02fdx90chp31kchzv"
},
"pre-commit": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "cachix",
"repo": "git-hooks.nix"
},
"branch": "master",
"submodules": false,
"revision": "548fc44fca28a5e81c5d6b846e555e6b9c2a5a3c",
"url": "https://github.com/cachix/git-hooks.nix/archive/548fc44fca28a5e81c5d6b846e555e6b9c2a5a3c.tar.gz",
"hash": "055laj9rhlh0dcdhdp0jzv82xh0zp6jf58h274xqqmj3vhyal55f"
}
},
"version": 5
}

View File

@@ -1,14 +1 @@
{
pkgs ? import <nixpkgs> { },
}:
let
dotnet-sdk = pkgs.dotnet-sdk_9;
in
pkgs.mkShell {
buildInputs = [
dotnet-sdk
pkgs.bun
];
DOTNET_ROOT = "${dotnet-sdk}/share/dotnet";
}
(import ./default.nix { }).shell

View File

@@ -2,12 +2,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<PackageId>Oceanbox.GeoJson</PackageId>
<Authors/>
<Company/>
<Version>1.1.1</Version>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="GeoJson.fs"/>
@@ -17,6 +18,7 @@
<PackageReference Include="FSharpPlus" Version="1.6.1"/>
<PackageReference Include="Thoth.Json" Version="10.2.0"/>
<PackageReference Include="Thoth.Json.Net" Version="12.0.0"/>
<PackageReference Update="FSharp.Core" Version="10.0.101"/>
</ItemGroup>
<ItemGroup>
<Content Include="*.fsproj; *.fs" PackagePath="fable/"/>

28
src/default.nix Normal file
View File

@@ -0,0 +1,28 @@
{
deps,
pkgs,
dotnet-sdk,
nix-gitignore,
dotnet-runtime,
buildDotnetModule,
version,
}:
let
name = "Oceanbox.GeoJson";
in
buildDotnetModule {
pname = name;
inherit dotnet-sdk dotnet-runtime version;
src = nix-gitignore.gitignoreSource [ ] ../.;
projectFile = "src/Oceanbox.GeoJson.fsproj";
dotnetRestoreFlags = "--force-evaluate";
nugetDeps = deps {
inherit pkgs name;
lockfiles = [ ./packages.lock.json ];
};
packNupkg = true;
doCheck = false;
}

151
src/packages.lock.json Normal file
View File

@@ -0,0 +1,151 @@
{
"version": 1,
"dependencies": {
".NETStandard,Version=v2.0": {
"FSharp.Core": {
"type": "Direct",
"requested": "[10.0.101, )",
"resolved": "10.0.101",
"contentHash": "mrS3J7cLtvXM3u3CmiaFq8oyBdlevzZY1VAAAbFk1gUDQtDEjUOybN5XpQglx5wAgJ0wLdDl6OSSfS7ZDFNcpA=="
},
"FSharp.Data": {
"type": "Direct",
"requested": "[6.4.0, )",
"resolved": "6.4.0",
"contentHash": "KfQbbvlLgP0zaZyp8YhS2+FsxBvhYC9o08emNMcwmpAvnLz9vEMbNefYFQiZX5i/0kAMYh5oDqTbvx3RJSbJFA==",
"dependencies": {
"FSharp.Core": "6.0.1",
"FSharp.Data.Csv.Core": "6.4.0",
"FSharp.Data.Html.Core": "6.4.0",
"FSharp.Data.Http": "6.4.0",
"FSharp.Data.Json.Core": "6.4.0",
"FSharp.Data.Runtime.Utilities": "6.4.0",
"FSharp.Data.WorldBank.Core": "6.4.0",
"FSharp.Data.Xml.Core": "6.4.0"
}
},
"FSharpPlus": {
"type": "Direct",
"requested": "[1.6.1, )",
"resolved": "1.6.1",
"contentHash": "HXBoyj7pHxEB5H1YgNBxaPz39ty+KvQFmWQ9AKDaWMtHNGO7r9FH+wq/KL8hz9oIJzG0gKniRUt78qi6WQk4gw==",
"dependencies": {
"FSharp.Core": "6.0.6"
}
},
"NETStandard.Library": {
"type": "Direct",
"requested": "[2.0.3, )",
"resolved": "2.0.3",
"contentHash": "st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0"
}
},
"Thoth.Json": {
"type": "Direct",
"requested": "[10.2.0, )",
"resolved": "10.2.0",
"contentHash": "/I58GViwrhWgp/vvNikjeSbm33V1ng3uSB27Y0BNDSJFDK+EdntCAx1Ephsx6T1dZlsgH/Z3wGmdEOqAlJUYuQ==",
"dependencies": {
"FSharp.Core": "4.7.2",
"Fable.Core": "3.6.2"
}
},
"Thoth.Json.Net": {
"type": "Direct",
"requested": "[12.0.0, )",
"resolved": "12.0.0",
"contentHash": "n2YyONYdWCFS4Pu7wrqgV/l5tPuN+t3gxEfs/2RwqCiQkRnbgKs9dK61zHeZS5YganAoFbxLSwbaNL7SvSrS9g==",
"dependencies": {
"FSharp.Core": "4.7.2",
"Fable.Core": "3.1.6",
"Newtonsoft.Json": "13.0.1"
}
},
"Fable.Core": {
"type": "Transitive",
"resolved": "3.6.2",
"contentHash": "2djeYq1kZvwfYWUYvFAniS3PC8/4G27xHynsF7cALkjTqIfTYj9LM7PqHhnnxa1hs4X0wwm5p+UK94aMbDvJBA=="
},
"FSharp.Data.Csv.Core": {
"type": "Transitive",
"resolved": "6.4.0",
"contentHash": "kpQnKLPq2OjT7b3uWxDCraY0jbSJohA5hFCZ9bcTzOX0TqU6kVgcR5gCT5jN/dA4y5/qqtT5g9wCDVTmBE/enQ==",
"dependencies": {
"FSharp.Core": "6.0.1",
"FSharp.Data.Runtime.Utilities": "6.4.0"
}
},
"FSharp.Data.Html.Core": {
"type": "Transitive",
"resolved": "6.4.0",
"contentHash": "W5yJ0YarszKRKavgiGLFCsbUSmD6CIUNwX3Upq1l8XgICWKU+IIms1xKA3wIsgyHEJlF+Yviy3tp0b7qnq+I5w==",
"dependencies": {
"FSharp.Core": "6.0.1",
"FSharp.Data.Csv.Core": "6.4.0",
"FSharp.Data.Runtime.Utilities": "6.4.0"
}
},
"FSharp.Data.Http": {
"type": "Transitive",
"resolved": "6.4.0",
"contentHash": "Q9JNs1xkvoiVRLRMr+RtK6rQHKEQYaG3SckdVl4vYI17mZmUIrWyBDuzLFnO53K9d7zvHrOIjXzGyZ5bGpLCrA==",
"dependencies": {
"FSharp.Core": "6.0.1"
}
},
"FSharp.Data.Json.Core": {
"type": "Transitive",
"resolved": "6.4.0",
"contentHash": "iJmuQWrSdErpA9I/UwY1Yzo5ZdXzYqPuoA7Kz32aybkgVYTTV7U1LzA/tAEOMVCmYM9/PHi9F6Oam8qDSbgAGw==",
"dependencies": {
"FSharp.Core": "6.0.1",
"FSharp.Data.Http": "6.4.0",
"FSharp.Data.Runtime.Utilities": "6.4.0"
}
},
"FSharp.Data.Runtime.Utilities": {
"type": "Transitive",
"resolved": "6.4.0",
"contentHash": "V5JihdafBjtwJYP2Tgf49K/jwFMvNfq4vRY2cPDJ2sL9bPYJQHiEApLJCF43P1sPFskGkQiNi+mWi0+4zVmTGg==",
"dependencies": {
"FSharp.Core": "6.0.1",
"FSharp.Data.Http": "6.4.0"
}
},
"FSharp.Data.WorldBank.Core": {
"type": "Transitive",
"resolved": "6.4.0",
"contentHash": "Luv+XWQkaANMFzp+0Hr3N/7ALrJp9U80V+OjHs13iYuJiCPGI2Jn2v+SS4rNlMxp+rGb6fW/azbuQMsZfku7PQ==",
"dependencies": {
"FSharp.Core": "6.0.1",
"FSharp.Data.Http": "6.4.0",
"FSharp.Data.Json.Core": "6.4.0",
"FSharp.Data.Runtime.Utilities": "6.4.0"
}
},
"FSharp.Data.Xml.Core": {
"type": "Transitive",
"resolved": "6.4.0",
"contentHash": "t10Mu6N77xyQQ6T6atITp2ZUOetiBy9fAVL124GCUaTDwdZYUcL4sDOp/oY4IX0kvgzR19pMvkEiBk2tlA8Lvg==",
"dependencies": {
"FSharp.Core": "6.0.1",
"FSharp.Data.Http": "6.4.0",
"FSharp.Data.Json.Core": "6.4.0",
"FSharp.Data.Runtime.Utilities": "6.4.0"
}
},
"Microsoft.NETCore.Platforms": {
"type": "Transitive",
"resolved": "1.1.0",
"contentHash": "kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A=="
},
"Newtonsoft.Json": {
"type": "Transitive",
"resolved": "13.0.1",
"contentHash": "ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A=="
}
}
}
}

View File

@@ -3,7 +3,8 @@ module Tests
open Expecto
open Oceanbox.GeoJson
let geoJson = """
let geoJson =
"""
{
"type": "FeatureCollection",
"features": [
@@ -56,30 +57,27 @@ let readCollection () =
| Ok json ->
printfn $"%A{json.BBox}"
printfn $"%A{json.Features}"
| Error e ->
printfn $"{e}"
| Error e -> printfn $"{e}"
fc
let encodeCollection (json: FeatureCollection) = json.Encode ()
let testCollections =
testList
"FeatureCollection"
[
testCase "Decode"
<| fun _ ->
let fc = readCollection ()
Expect.isOk fc "Result should be ok"
testCase "Encode"
<| fun _ ->
match readCollection () with
| Ok fc ->
let json = fc.Encode ()
Expect.isNotEmpty json "Json is not empty"
| Error e -> Expect.isEmpty e "Error is empty"
]
testList "FeatureCollection" [
testCase "Decode"
<| fun _ ->
let fc = readCollection ()
Expect.isOk fc "Result should be ok"
testCase "Encode"
<| fun _ ->
match readCollection () with
| Ok fc ->
let json = fc.Encode ()
Expect.isNotEmpty json "Json is not empty"
| Error e -> Expect.isEmpty e "Error is empty"
]
let all = testList "All" [ testCollections ]
[<EntryPoint>]
let main _ = runTests defaultConfig all
let main _ = runTestsWithCLIArgs [] [||] all

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Tests.fs" />