Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"make": {
"version": "0.7.0",
"commands": [
"dotnet-make"
],
"rollForward": false
}
}
}
38 changes: 38 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Pull Request
on: pull_request

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true

jobs:

###################################################
# BUILD
###################################################

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: ./site/package-lock.json

- name: Build
shell: bash
run: |
dotnet tool restore
dotnet make ci --trace
20 changes: 15 additions & 5 deletions .github/workflows/site.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Deploy Site

on:
Expand All @@ -11,17 +12,26 @@ jobs:
name: Build Docusaurus
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 22
cache: npm
cache-dependency-path: ./site/package-lock.json

- name: Build website
run: make ci
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4

- name: Build
shell: bash
run: |
dotnet tool restore
dotnet make ci --trace

- name: Upload Build Artifact
uses: actions/upload-pages-artifact@v3
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Artifacts
.artifacts

# Build
build/obj
build/bin

# Other
.vscode
25 changes: 0 additions & 25 deletions Makefile

This file was deleted.

28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ language agnostic interface to CLI applications which allows both humans
and computers to understand how a CLI tool should be invoked without
access to source code or documentation.

[https://opencli.org][opencli]

## Usage

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

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

[discussions]: https://github.com/spectreconsole/open-cli/discussions
## Building

We're using [Cake][cake]
to build the OpenCLI JSON schema, and site.

For this you will need to have the .NET 9.0 SDK installed
which you can find over at [https://dotnet.microsoft.com/en-us/download][dotnet].

After installing the .NET SDK, make sure that you've
restored Cake by running the following in the repository root:

```shell
$ dotnet tool restore
```

After that, running the build is as easy as writing:

```shell
$ dotnet make
```

[opencli]: https://opencli.org
[discussions]: https://github.com/spectreconsole/open-cli/discussions
[cake]: https://github.com/cake-build/cake
[dotnet]: https://dotnet.microsoft.com/en-us/download
10 changes: 10 additions & 0 deletions build/Build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Cake.Sdk/5.0.25198.49-beta">
<PropertyGroup>
<TargetFramework Condition="$(TargetFrameworks) == ''">net9.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)/..</RunWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.50.0" />
<Using Include="Spectre.Console"/>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions build/Build.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="build.csproj" />
</Solution>
102 changes: 102 additions & 0 deletions build/build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
var target = Argument("target", defaultValue: "Default");
if (target == "Default")
{
AnsiConsole.Write(new FigletText("OpenCLI"));
AnsiConsole.Write(
new Table()
.AddColumns("Target", "")
.AddRow("[yellow]clean[/]", "Cleans up artifacts")
.AddRow("[yellow]build-schema[/]", "Builds the JSON schema")
.AddRow("[yellow]build-site[/]", "Builds the site")
.AddRow("[yellow]run-site[/]", "Runs the site locally")
.AddRow("[yellow]ci[/]", "Runs the CI build locally")
);

Environment.Exit(1);
}

//////////////////////////////////////////////////////////////////////
// TARGETS
//////////////////////////////////////////////////////////////////////

Task("CI")
.IsDependentOn("Build-Schema")
.IsDependentOn("Build-Site");

//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////

// Clears all artifacts
Task("Clean")
.Does(ctx =>
{
ctx.CleanDirectory("./.artifacts");
});

// Updates the site contents
Task("Update-Site-Contents")
.Does(ctx =>
{
// Copy the draft.md content into the site
ctx
.TransformTextFile("./site/docs/spec.template", "<%", "%>")
.WithToken("SPEC", System.IO.File.ReadAllText("./draft.md"))
.Save("./site/docs/spec.md");

// Copy the schema
ctx.CopyFile("./schema.json", "./site/static/draft.json");
});

// Builds the JSON schema
Task("Build-Schema")
.IsDependentOn("Clean")
.Does(ctx =>
{
ctx.Npm(arguments: ["install"], workingDirectory: "./typespec");
ctx.Npm(arguments: ["run", "tsp-compile"], workingDirectory: "./typespec");

// TODO: No overload for overwriting?
if (ctx.FileExists("./schema.json"))
{
ctx.DeleteFile("./schema.json");
}

ctx.CopyFile("./.artifacts/@typespec/json-schema/OpenCLI.json", "./.artifacts/schema.json");
ctx.CopyFile("./.artifacts/@typespec/json-schema/OpenCLI.json", "./schema.json");
});

// Builds the site
Task("Build-Site")
.IsDependentOn("Clean")
.IsDependentOn("Update-Site-Contents")
.Does(ctx =>
{
ctx.Npm(
arguments: ["ci"],
workingDirectory: "./site");

ctx.Npm(
arguments: ["run build"],
workingDirectory: "./site");
});

// Runs the site locally
Task("Run-Site")
.IsDependentOn("Update-Site-Contents")
.Does(ctx =>
{
ctx.Npm(
arguments: ["install"],
workingDirectory: "./site");

ctx.Npx(
arguments: ["docusaurus", "start"],
workingDirectory: "./site");
});

//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////

RunTarget(target);
74 changes: 74 additions & 0 deletions build/utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
public static class Utilities
{
public static void Npm(
this ICakeContext context,
string[] arguments,
DirectoryPath? workingDirectory = null)
{
var executable = GetNpmExecutable(context);
if (executable == null)
{
throw new InvalidOperationException("Could not locate 'npm'");
}

RunProcess(context, executable, arguments, workingDirectory);
}

public static void Npx(
this ICakeContext context,
string[] arguments,
DirectoryPath? workingDirectory = null)
{
var executable = GetNpxExecutable(context);
if (executable == null)
{
throw new InvalidOperationException("Could not locate 'npm'");
}

RunProcess(context, executable, arguments, workingDirectory);
}

public static void RunProcess(
this ICakeContext context,
string executable,
string[] arguments,
DirectoryPath? workingDirectory = null)
{
var args = ProcessArgumentBuilder.FromStrings(arguments);
var exitCode = StartProcess(executable, new ProcessSettings
{
Arguments = args,
WorkingDirectory = workingDirectory?.MakeAbsolute(context.Environment),
});

if (exitCode != 0)
{
throw new InvalidOperationException(
$"The tool '{executable}' returned a non-zero exit code");
}
}

private static string? GetNpmExecutable(ICakeContext context)
{
if (context.IsRunningOnWindows())
{
return context.Tools.Resolve("npm.cmd")?.FullPath;
}
else
{
return context.Tools.Resolve("npm")?.FullPath;
}
}

private static string? GetNpxExecutable(ICakeContext context)
{
if (context.IsRunningOnWindows())
{
return context.Tools.Resolve("npx.cmd")?.FullPath;
}
else
{
return context.Tools.Resolve("npx")?.FullPath;
}
}
}
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "http://json.schemastore.org/global",
"sdk": {
"version": "9.0.100",
"rollForward": "latestFeature"
}
}
Loading