Skip to content

Commit 84b59b7

Browse files
committed
chore: Use Spectre.Console.CLI for build system + Use Fable.Pyxpecto as the test runner for all targets + Prepare a TypeScript target for officially supporting it
#202
1 parent d367e45 commit 84b59b7

34 files changed

+1144
-1536
lines changed

Directory.Build.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
1919
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2020
</PropertyGroup>
21-
<!-- Packages common to all the projects -->
22-
<ItemGroup>
21+
<!-- Packages common to all the projects excepts build project -->
22+
<ItemGroup Condition="'$(PackageId)'!='EasyBuild'">
2323
<!-- Reproducible builds + SourceLink supports -->
2424
<PackageReference Include="DotNet.ReproducibleBuilds" PrivateAssets="All"/>
2525
<!-- Depends on the same version of FSharp.Core for all the projects -->

Directory.Packages.props

+2-9
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,14 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
55
<ItemGroup>
6-
<PackageVersion Include="BlackFox.CommandLine" Version="1.0.0" />
76
<PackageVersion Include="Fable.Package.SDK" Version="0.1.0" />
87
<PackageVersion Include="Fable.Python" Version="4.3.0" />
9-
<PackageVersion Include="Fable.Pyxpecto" Version="1.0.1" />
8+
<PackageVersion Include="Fable.Pyxpecto" Version="1.1.0" />
109
<PackageVersion Include="FSharp.Core" Version="5.0.0" />
11-
<!--
12-
We use an older version of Expecto to keep FSharp.Core version as low as possible
13-
-->
14-
<PackageVersion Include="Expecto" Version="9.0.4" />
1510
<PackageVersion Include="Fable.Core" Version="4.1.0" />
16-
<PackageVersion Include="Fable.Mocha" Version="2.17.0" />
1711
<PackageVersion Include="Ionide.KeepAChangelog.Tasks" Version="0.1.8" />
1812
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
19-
<PackageVersion Include="Semver" Version="2.3.0" />
2013
<PackageVersion Include="SimpleExec" Version="11.0.0" />
2114
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.1.1" />
2215
</ItemGroup>
23-
</Project>
16+
</Project>

Thoth.Json.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Thoth.Json.Tests.Legacy", "
2727
EndProject
2828
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Thoth.Json", "packages\Thoth.Json\Thoth.Json.fsproj", "{D03314F6-68F9-46BD-A0D1-75B2B18E76A0}"
2929
EndProject
30-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Build", "build\Build.fsproj", "{1A292FB0-2CCA-41C2-A9E6-EB69A31BAA5C}"
30+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Build", "build\EasyBuild.fsproj", "{1A292FB0-2CCA-41C2-A9E6-EB69A31BAA5C}"
3131
EndProject
3232
Global
3333
GlobalSection(SolutionConfigurationPlatforms) = preSolution

build.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set PYTHONIOENCODING=utf-8
44
dotnet tool restore
5-
dotnet run --project build/Build.fsproj -- %*
5+
dotnet run --project build/EasyBuild.fsproj -- %*

build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh -x
22

33
dotnet tool restore
4-
dotnet run --project build/Build.fsproj -- $@
4+
dotnet run --project build/EasyBuild.fsproj -- $@

build/Build.fsproj

-22
This file was deleted.

build/Commands/Publish.fs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module EasyBuild.Commands.Publish
2+
3+
open System
4+
open System.IO
5+
open Build.Utils
6+
open Spectre.Console.Cli
7+
open EasyBuild.Commands.Test
8+
open EasyBuild.Workspace
9+
10+
let private publish (projectDir: string) =
11+
printfn $"Publishing {projectDir}"
12+
13+
let nugetKey = Environment.GetEnvironmentVariable("NUGET_KEY")
14+
15+
// Delete the bin folder, so dotnet pack will always create a new package
16+
// Otherwise, if the package already exists, it will not be created
17+
// and we can't get the package path
18+
let binFolder = Path.Combine(projectDir, "bin")
19+
20+
if Directory.Exists binFolder then
21+
Directory.Delete(binFolder, true)
22+
23+
if isNull nugetKey then
24+
failwithf $"Missing NUGET_KEY environment variable"
25+
26+
let nupkgPath = Dotnet.pack projectDir
27+
Dotnet.Nuget.push (nupkgPath, nugetKey, skipDuplicate = true)
28+
29+
type PublishCommand() =
30+
inherit Command<CommandSettings>()
31+
interface ICommandLimiter<CommandSettings>
32+
33+
override _.Execute(context: CommandContext, settings: CommandSettings) =
34+
TestCommand().Execute(context, TestSettings()) |> ignore
35+
36+
publish Workspace.packages.``Thoth.Json``.``.``
37+
publish Workspace.packages.``Thoth.Json.Core``.``.``
38+
publish Workspace.packages.``Thoth.Json.JavaScript``.``.``
39+
publish Workspace.packages.``Thoth.Json.Newtonsoft``.``.``
40+
publish Workspace.packages.``Thoth.Json.Python``.``.``
41+
42+
0

build/Commands/Test.fs

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
module EasyBuild.Commands.Test
2+
3+
open Spectre.Console.Cli
4+
open System.ComponentModel
5+
open BlackFox.CommandLine
6+
open SimpleExec
7+
open EasyBuild.Workspace
8+
open System.IO
9+
10+
type TestSettings() =
11+
inherit CommandSettings()
12+
13+
[<CommandOption("-w|--watch")>]
14+
[<Description("Watch for changes and re-run the tests")>]
15+
member val IsWatch: bool = false with get, set
16+
17+
let cleanUp (dir: string) =
18+
let dir = DirectoryInfo(dir)
19+
20+
if dir.Exists then
21+
dir.Delete(true)
22+
23+
let private outDir = "fableBuild"
24+
25+
let private runTestForJavaScript isWatch cwd =
26+
let fableArgs =
27+
CmdLine.concat
28+
[
29+
CmdLine.empty
30+
|> CmdLine.appendRaw "fable"
31+
|> CmdLine.appendPrefix "--outDir" outDir
32+
|> CmdLine.appendRaw "--noCache"
33+
|> CmdLine.appendRaw "--test:MSBuildCracker"
34+
35+
if isWatch then
36+
CmdLine.empty
37+
|> CmdLine.appendRaw "--watch"
38+
|> CmdLine.appendRaw "--runScript"
39+
else
40+
CmdLine.empty |> CmdLine.appendRaw "--runScript"
41+
]
42+
|> CmdLine.toString
43+
44+
Command.Run("dotnet", fableArgs, workingDirectory = cwd)
45+
46+
type TestJavaScriptCommand() =
47+
inherit Command<TestSettings>()
48+
interface ICommandLimiter<TestSettings>
49+
50+
override _.Execute(context: CommandContext, settings: TestSettings) =
51+
// Remove generated files because this folder is used for both JavaScript and TypeScript tests
52+
cleanUp
53+
VirtualWorkspace.tests.``Thoth.Json.Tests.JavaScript``.fableBuild.``.``
54+
55+
runTestForJavaScript
56+
settings.IsWatch
57+
Workspace.tests.``Thoth.Json.Tests.JavaScript``.``.``
58+
59+
0
60+
61+
62+
type TestNewtonsoftCommand() =
63+
inherit Command<TestSettings>()
64+
interface ICommandLimiter<TestSettings>
65+
66+
override _.Execute(context: CommandContext, settings: TestSettings) =
67+
Command.Run(
68+
"dotnet",
69+
CmdLine.empty
70+
|> CmdLine.appendIf settings.IsWatch "watch"
71+
|> CmdLine.appendRaw "run"
72+
|> CmdLine.appendPrefix
73+
"--project"
74+
Workspace.tests.``Thoth.Json.Tests.Newtonsoft``.``.``
75+
|> CmdLine.toString
76+
)
77+
78+
0
79+
80+
type TestPythonCommand() =
81+
inherit Command<TestSettings>()
82+
interface ICommandLimiter<TestSettings>
83+
84+
override _.Execute(context: CommandContext, settings: TestSettings) =
85+
let runArg =
86+
if settings.IsWatch then
87+
"--runWatch"
88+
else
89+
"--run"
90+
91+
Command.Run(
92+
"dotnet",
93+
CmdLine.empty
94+
|> CmdLine.appendRaw "fable"
95+
|> CmdLine.appendPrefix "--outDir" outDir
96+
|> CmdLine.appendPrefix "--lang" "python"
97+
|> CmdLine.appendRaw "--noCache"
98+
|> CmdLine.appendRaw "--test:MSBuildCracker"
99+
|> CmdLine.appendIf settings.IsWatch "--watch"
100+
|> CmdLine.appendRaw runArg
101+
|> CmdLine.appendRaw "python"
102+
|> CmdLine.appendRaw "fableBuild/main.py"
103+
|> CmdLine.appendRaw "--silent"
104+
|> CmdLine.toString,
105+
workingDirectory = Workspace.tests.``Thoth.Json.Tests.Python``.``.``
106+
)
107+
108+
0
109+
110+
type TestLegacyCommand() =
111+
inherit Command<TestSettings>()
112+
interface ICommandLimiter<TestSettings>
113+
114+
override _.Execute(context: CommandContext, settings: TestSettings) =
115+
runTestForJavaScript
116+
settings.IsWatch
117+
Workspace.tests.``Thoth.Json.Tests.Legacy``.``.``
118+
119+
0
120+
121+
type TestTypeScriptCommand() =
122+
inherit Command<TestSettings>()
123+
interface ICommandLimiter<TestSettings>
124+
125+
override _.Execute(context: CommandContext, settings: TestSettings) =
126+
// Remove generated files because this folder is used for both JavaScript and TypeScript tests
127+
cleanUp
128+
VirtualWorkspace.tests.``Thoth.Json.Tests.JavaScript``.fableBuild.``.``
129+
130+
Command.Run(
131+
"dotnet",
132+
CmdLine.empty
133+
|> CmdLine.appendRaw "fable"
134+
|> CmdLine.appendPrefix "--outDir" outDir
135+
|> CmdLine.appendPrefix "--lang" "typescript"
136+
|> CmdLine.appendRaw "--noCache"
137+
|> CmdLine.appendRaw "--test:MSBuildCracker"
138+
|> CmdLine.appendIf settings.IsWatch "--watch"
139+
|> CmdLine.appendRaw "--runWatch"
140+
|> CmdLine.appendRaw "npx tsc"
141+
|> CmdLine.toString,
142+
workingDirectory =
143+
Workspace.tests.``Thoth.Json.Tests.JavaScript``.``.``
144+
)
145+
146+
0
147+
148+
type TestCommand() =
149+
inherit Command<TestSettings>()
150+
interface ICommandLimiter<TestSettings>
151+
152+
override _.Execute(context: CommandContext, settings: TestSettings) =
153+
TestJavaScriptCommand().Execute(context, settings) |> ignore
154+
// Not stable offically supported, yet as there are bugs that needs to be fixed in Fable
155+
// TestTypeScriptCommand().Execute(context, settings) |> ignore
156+
TestNewtonsoftCommand().Execute(context, settings) |> ignore
157+
TestPythonCommand().Execute(context, settings) |> ignore
158+
TestLegacyCommand().Execute(context, settings) |> ignore
159+
160+
0

build/EasyBuild.fsproj

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ContinuousIntegrationBuild>false</ContinuousIntegrationBuild>
6+
<ManagePackageVersionsCentrally>fasle</ManagePackageVersionsCentrally>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Compile Include="Utils/Nuget.fs" />
10+
<Compile Include="Workspace.fs" />
11+
<Compile Include="Commands/Test.fs" />
12+
<Compile Include="Commands/Publish.fs" />
13+
<Compile Include="Main.fs" />
14+
</ItemGroup>
15+
<ItemGroup>
16+
<PackageReference Include="BlackFox.CommandLine" Version="1.0.0" />
17+
<PackageReference Include="EasyBuild.FileSystemProvider" Version="0.3.0" />
18+
<PackageReference Include="SimpleExec" Version="12.0.0" />
19+
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
20+
<PackageReference Include="FSharp.Core" Version="5.0.0" />
21+
</ItemGroup>
22+
</Project>

0 commit comments

Comments
 (0)