Skip to content

Commit 3867f29

Browse files
Merge pull request #39 from spectreconsole/feature/xplat-build
Add xplat build
2 parents 9db4feb + 29455b3 commit 3867f29

File tree

17 files changed

+299
-74
lines changed

17 files changed

+299
-74
lines changed

.config/dotnet-tools.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"make": {
6+
"version": "0.7.0",
7+
"commands": [
8+
"dotnet-make"
9+
],
10+
"rollForward": false
11+
}
12+
}
13+
}

.github/workflows/pr.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
name: Pull Request
3+
on: pull_request
4+
5+
env:
6+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
7+
DOTNET_CLI_TELEMETRY_OPTOUT: true
8+
9+
jobs:
10+
11+
###################################################
12+
# BUILD
13+
###################################################
14+
15+
build:
16+
name: Build
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Setup .NET SDK
25+
uses: actions/setup-dotnet@v4
26+
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: 22
31+
cache: npm
32+
cache-dependency-path: ./site/package-lock.json
33+
34+
- name: Build
35+
shell: bash
36+
run: |
37+
dotnet tool restore
38+
dotnet make ci --trace

.github/workflows/site.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
12
name: Deploy Site
23

34
on:
@@ -11,17 +12,26 @@ jobs:
1112
name: Build Docusaurus
1213
runs-on: ubuntu-latest
1314
steps:
14-
- uses: actions/checkout@v4
15+
- name: Checkout
16+
uses: actions/checkout@v4
1517
with:
1618
fetch-depth: 0
17-
- uses: actions/setup-node@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
1822
with:
19-
node-version: 18
23+
node-version: 22
2024
cache: npm
2125
cache-dependency-path: ./site/package-lock.json
2226

23-
- name: Build website
24-
run: make ci
27+
- name: Setup .NET SDK
28+
uses: actions/setup-dotnet@v4
29+
30+
- name: Build
31+
shell: bash
32+
run: |
33+
dotnet tool restore
34+
dotnet make ci --trace
2535
2636
- name: Upload Build Artifact
2737
uses: actions/upload-pages-artifact@v3

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Artifacts
22
.artifacts
33

4+
# Build
5+
build/obj
6+
build/bin
7+
48
# Other
59
.vscode

Makefile

Lines changed: 0 additions & 25 deletions
This file was deleted.

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ language agnostic interface to CLI applications which allows both humans
55
and computers to understand how a CLI tool should be invoked without
66
access to source code or documentation.
77

8+
[https://opencli.org][opencli]
9+
810
## Usage
911

1012
* Create documentation for CLI tools
@@ -19,4 +21,28 @@ with the community to make sure that the first version can be as good as possibl
1921

2022
Head over to our [discussions][discussions] if you have feedback or ideas!
2123

22-
[discussions]: https://github.com/spectreconsole/open-cli/discussions
24+
## Building
25+
26+
We're using [Cake][cake]
27+
to build the OpenCLI JSON schema, and site.
28+
29+
For this you will need to have the .NET 9.0 SDK installed
30+
which you can find over at [https://dotnet.microsoft.com/en-us/download][dotnet].
31+
32+
After installing the .NET SDK, make sure that you've
33+
restored Cake by running the following in the repository root:
34+
35+
```shell
36+
$ dotnet tool restore
37+
```
38+
39+
After that, running the build is as easy as writing:
40+
41+
```shell
42+
$ dotnet make
43+
```
44+
45+
[opencli]: https://opencli.org
46+
[discussions]: https://github.com/spectreconsole/open-cli/discussions
47+
[cake]: https://github.com/cake-build/cake
48+
[dotnet]: https://dotnet.microsoft.com/en-us/download

build/Build.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Cake.Sdk/5.0.25198.49-beta">
2+
<PropertyGroup>
3+
<TargetFramework Condition="$(TargetFrameworks) == ''">net9.0</TargetFramework>
4+
<RunWorkingDirectory>$(MSBuildProjectDirectory)/..</RunWorkingDirectory>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="Spectre.Console" Version="0.50.0" />
8+
<Using Include="Spectre.Console"/>
9+
</ItemGroup>
10+
</Project>

build/Build.slnx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="build.csproj" />
3+
</Solution>

build/build.cs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
var target = Argument("target", defaultValue: "Default");
2+
if (target == "Default")
3+
{
4+
AnsiConsole.Write(new FigletText("OpenCLI"));
5+
AnsiConsole.Write(
6+
new Table()
7+
.AddColumns("Target", "")
8+
.AddRow("[yellow]clean[/]", "Cleans up artifacts")
9+
.AddRow("[yellow]build-schema[/]", "Builds the JSON schema")
10+
.AddRow("[yellow]build-site[/]", "Builds the site")
11+
.AddRow("[yellow]run-site[/]", "Runs the site locally")
12+
.AddRow("[yellow]ci[/]", "Runs the CI build locally")
13+
);
14+
15+
Environment.Exit(1);
16+
}
17+
18+
//////////////////////////////////////////////////////////////////////
19+
// TARGETS
20+
//////////////////////////////////////////////////////////////////////
21+
22+
Task("CI")
23+
.IsDependentOn("Build-Schema")
24+
.IsDependentOn("Build-Site");
25+
26+
//////////////////////////////////////////////////////////////////////
27+
// TASKS
28+
//////////////////////////////////////////////////////////////////////
29+
30+
// Clears all artifacts
31+
Task("Clean")
32+
.Does(ctx =>
33+
{
34+
ctx.CleanDirectory("./.artifacts");
35+
});
36+
37+
// Updates the site contents
38+
Task("Update-Site-Contents")
39+
.Does(ctx =>
40+
{
41+
// Copy the draft.md content into the site
42+
ctx
43+
.TransformTextFile("./site/docs/spec.template", "<%", "%>")
44+
.WithToken("SPEC", System.IO.File.ReadAllText("./draft.md"))
45+
.Save("./site/docs/spec.md");
46+
47+
// Copy the schema
48+
ctx.CopyFile("./schema.json", "./site/static/draft.json");
49+
});
50+
51+
// Builds the JSON schema
52+
Task("Build-Schema")
53+
.IsDependentOn("Clean")
54+
.Does(ctx =>
55+
{
56+
ctx.Npm(arguments: ["install"], workingDirectory: "./typespec");
57+
ctx.Npm(arguments: ["run", "tsp-compile"], workingDirectory: "./typespec");
58+
59+
// TODO: No overload for overwriting?
60+
if (ctx.FileExists("./schema.json"))
61+
{
62+
ctx.DeleteFile("./schema.json");
63+
}
64+
65+
ctx.CopyFile("./.artifacts/@typespec/json-schema/OpenCLI.json", "./.artifacts/schema.json");
66+
ctx.CopyFile("./.artifacts/@typespec/json-schema/OpenCLI.json", "./schema.json");
67+
});
68+
69+
// Builds the site
70+
Task("Build-Site")
71+
.IsDependentOn("Clean")
72+
.IsDependentOn("Update-Site-Contents")
73+
.Does(ctx =>
74+
{
75+
ctx.Npm(
76+
arguments: ["ci"],
77+
workingDirectory: "./site");
78+
79+
ctx.Npm(
80+
arguments: ["run build"],
81+
workingDirectory: "./site");
82+
});
83+
84+
// Runs the site locally
85+
Task("Run-Site")
86+
.IsDependentOn("Update-Site-Contents")
87+
.Does(ctx =>
88+
{
89+
ctx.Npm(
90+
arguments: ["install"],
91+
workingDirectory: "./site");
92+
93+
ctx.Npx(
94+
arguments: ["docusaurus", "start"],
95+
workingDirectory: "./site");
96+
});
97+
98+
//////////////////////////////////////////////////////////////////////
99+
// EXECUTION
100+
//////////////////////////////////////////////////////////////////////
101+
102+
RunTarget(target);

build/utils.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
public static class Utilities
2+
{
3+
public static void Npm(
4+
this ICakeContext context,
5+
string[] arguments,
6+
DirectoryPath? workingDirectory = null)
7+
{
8+
var executable = GetNpmExecutable(context);
9+
if (executable == null)
10+
{
11+
throw new InvalidOperationException("Could not locate 'npm'");
12+
}
13+
14+
RunProcess(context, executable, arguments, workingDirectory);
15+
}
16+
17+
public static void Npx(
18+
this ICakeContext context,
19+
string[] arguments,
20+
DirectoryPath? workingDirectory = null)
21+
{
22+
var executable = GetNpxExecutable(context);
23+
if (executable == null)
24+
{
25+
throw new InvalidOperationException("Could not locate 'npm'");
26+
}
27+
28+
RunProcess(context, executable, arguments, workingDirectory);
29+
}
30+
31+
public static void RunProcess(
32+
this ICakeContext context,
33+
string executable,
34+
string[] arguments,
35+
DirectoryPath? workingDirectory = null)
36+
{
37+
var args = ProcessArgumentBuilder.FromStrings(arguments);
38+
var exitCode = StartProcess(executable, new ProcessSettings
39+
{
40+
Arguments = args,
41+
WorkingDirectory = workingDirectory?.MakeAbsolute(context.Environment),
42+
});
43+
44+
if (exitCode != 0)
45+
{
46+
throw new InvalidOperationException(
47+
$"The tool '{executable}' returned a non-zero exit code");
48+
}
49+
}
50+
51+
private static string? GetNpmExecutable(ICakeContext context)
52+
{
53+
if (context.IsRunningOnWindows())
54+
{
55+
return context.Tools.Resolve("npm.cmd")?.FullPath;
56+
}
57+
else
58+
{
59+
return context.Tools.Resolve("npm")?.FullPath;
60+
}
61+
}
62+
63+
private static string? GetNpxExecutable(ICakeContext context)
64+
{
65+
if (context.IsRunningOnWindows())
66+
{
67+
return context.Tools.Resolve("npx.cmd")?.FullPath;
68+
}
69+
else
70+
{
71+
return context.Tools.Resolve("npx")?.FullPath;
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)